/* ============================================
   DM Screen - Dark Fantasy Theme
   ============================================ */

/* Google Fonts loaded via HTML */

:root {
  --bg-dark: #1a1a2e;
  --bg-darker: #12121f;
  --bg-card: #2a2a3e;
  --bg-card-hover: #33334a;
  --parchment: #d4a574;
  --parchment-light: #e8c89e;
  --gold: #c9a85c;
  --gold-light: #dfc07a;
  --gold-dim: #8a7a4a;
  --text-primary: #e8e0d4;
  --text-secondary: #b0a898;
  --text-muted: #7a7268;
  --red: #c44040;
  --red-light: #e05555;
  --green: #4a9e4a;
  --green-light: #5cb85c;
  --blue: #4a6fa5;
  --blue-light: #5a8fd5;
  --purple: #7a5aa5;
  --border-color: #3a3a52;
  --border-gold: rgba(201, 168, 92, 0.3);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-gold: 0 0 15px rgba(201, 168, 92, 0.15);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.25s ease;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Cinzel', 'Times New Roman', serif;
  color: var(--parchment);
  line-height: 1.3;
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--gold-light);
}

img {
  max-width: 100%;
  height: auto;
}

/* ---- Layout ---- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

.page-wrapper {
  flex: 1;
}

/* ---- Header / Nav ---- */

.site-header {
  background: var(--bg-darker);
  border-bottom: 2px solid var(--border-gold);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Cinzel', serif;
  font-size: 1.3rem;
  color: var(--parchment);
  font-weight: 700;
  white-space: nowrap;
}

.logo img, .logo svg {
  width: 32px;
  height: 32px;
}

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-gold);
  color: var(--parchment);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.main-nav a {
  color: var(--text-secondary);
  font-size: 0.88rem;
  padding: 6px 12px;
  border-radius: var(--radius);
  transition: all var(--transition);
  white-space: nowrap;
}

.main-nav a:hover,
.main-nav a.active {
  color: var(--parchment);
  background: rgba(212, 165, 116, 0.1);
}

.main-nav a.active {
  border-bottom: 2px solid var(--gold);
}

/* ---- Hero Section ---- */

.hero {
  padding: 80px 0 60px;
  text-align: center;
  background: linear-gradient(180deg, var(--bg-darker) 0%, var(--bg-dark) 100%);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(201, 168, 92, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

.hero h1 {
  font-size: 3rem;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--parchment), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero .subtitle {
  font-size: 1.2rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 32px;
}

/* ---- Page Header (tool pages) ---- */

.page-header {
  padding: 40px 0 30px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

.page-header h1 {
  font-size: 2.2rem;
  margin-bottom: 10px;
}

.page-header p {
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto;
}

/* ---- Cards ---- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
  padding: 40px 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--parchment), var(--gold));
  opacity: 0;
  transition: opacity var(--transition);
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-gold);
  transform: translateY(-3px);
  box-shadow: var(--shadow-gold);
}

.card:hover::before {
  opacity: 1;
}

.card-icon {
  font-size: 2.2rem;
  margin-bottom: 16px;
  display: block;
}

.card h3 {
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.card .card-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--gold);
  font-weight: 600;
  font-size: 0.9rem;
}

.card .card-link::after {
  content: '\2192';
  transition: transform var(--transition);
}

.card:hover .card-link::after {
  transform: translateX(4px);
}

/* ---- Tool Layout ---- */

.tool-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  padding: 30px 0;
}

.tool-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.tool-panel h2 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.tool-panel.full-width {
  grid-column: 1 / -1;
}

/* ---- Form Elements ---- */

label {
  display: block;
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-darker);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 92, 0.15);
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.form-group {
  margin-bottom: 18px;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.form-row .form-group {
  flex: 1;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--parchment));
  color: var(--bg-darker);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--gold-light), var(--parchment-light));
  box-shadow: 0 4px 15px rgba(201, 168, 92, 0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--gold-dim);
}

.btn-danger {
  background: var(--red);
  color: white;
}

.btn-danger:hover {
  background: var(--red-light);
}

.btn-success {
  background: var(--green);
  color: white;
}

.btn-success:hover {
  background: var(--green-light);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- Dice Buttons ---- */

.dice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.dice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 8px;
  background: var(--bg-darker);
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--parchment);
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
}

.dice-btn:hover {
  border-color: var(--gold);
  background: rgba(201, 168, 92, 0.1);
  transform: scale(1.05);
}

.dice-btn .dice-count {
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---- Result Display ---- */

.result-box {
  background: var(--bg-darker);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 80px;
  text-align: center;
}

.result-total {
  font-family: 'Cinzel', serif;
  font-size: 3rem;
  color: var(--gold);
  font-weight: 700;
  line-height: 1;
}

.result-detail {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 8px;
}

.result-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
}

.die-result {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--parchment-light);
}

.die-result.crit {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(201, 168, 92, 0.15);
}

.die-result.min {
  border-color: var(--red);
  color: var(--red);
  background: rgba(196, 64, 64, 0.15);
}

/* ---- Roll Animation ---- */

@keyframes diceRoll {
  0% { transform: scale(0.5) rotate(0deg); opacity: 0.3; }
  25% { transform: scale(1.3) rotate(90deg); opacity: 0.7; }
  50% { transform: scale(0.8) rotate(200deg); opacity: 0.5; }
  75% { transform: scale(1.1) rotate(310deg); opacity: 0.9; }
  100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

.rolling .result-total {
  animation: diceRoll 0.5s ease-out;
}

/* ---- Roll History ---- */

.roll-history {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 16px;
}

.roll-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.88rem;
}

.roll-history-item:last-child {
  border-bottom: none;
}

.roll-history-item .roll-expr {
  color: var(--text-secondary);
}

.roll-history-item .roll-result {
  color: var(--gold);
  font-weight: 600;
  font-family: 'Cinzel', serif;
}

/* ---- NPC Card ---- */

.npc-card {
  background: linear-gradient(145deg, #2e2a22, #252030);
  border: 2px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
}

.npc-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.npc-name {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: var(--parchment);
  margin-bottom: 4px;
}

.npc-title {
  color: var(--gold-dim);
  font-size: 0.95rem;
  margin-bottom: 20px;
  font-style: italic;
}

.npc-section {
  margin-bottom: 16px;
}

.npc-section h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold);
  margin-bottom: 6px;
}

.npc-section p {
  color: var(--text-primary);
  font-size: 0.95rem;
}

.npc-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trait-tag {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(201, 168, 92, 0.1);
  border: 1px solid var(--border-gold);
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--parchment-light);
}

/* ---- Encounter Builder ---- */

.difficulty-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  margin: 16px 0;
  background: var(--bg-darker);
}

.difficulty-bar .segment {
  transition: width 0.3s ease;
}

.difficulty-easy { background: var(--green); }
.difficulty-medium { background: #c9a85c; }
.difficulty-hard { background: #d48a2c; }
.difficulty-deadly { background: var(--red); }

.difficulty-label {
  font-family: 'Cinzel', serif;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: var(--radius);
  display: inline-block;
  margin: 8px 0;
}

.difficulty-label.easy { color: var(--green-light); border: 1px solid var(--green); }
.difficulty-label.medium { color: var(--gold-light); border: 1px solid var(--gold); }
.difficulty-label.hard { color: #d48a2c; border: 1px solid #d48a2c; }
.difficulty-label.deadly { color: var(--red-light); border: 1px solid var(--red); }

.monster-list {
  margin-top: 12px;
}

.monster-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-darker);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.monster-item .monster-info {
  flex: 1;
}

.monster-item .monster-name {
  font-weight: 600;
  color: var(--parchment-light);
}

.monster-item .monster-cr {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---- Loot Display ---- */

.loot-section {
  margin-bottom: 20px;
}

.loot-section h3 {
  font-size: 1.1rem;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.loot-item {
  padding: 6px 0;
  border-bottom: 1px solid rgba(58, 58, 82, 0.5);
  display: flex;
  justify-content: space-between;
  font-size: 0.93rem;
}

.loot-item:last-child { border-bottom: none; }

.loot-item .item-name { color: var(--text-primary); }
.loot-item .item-value { color: var(--gold); font-weight: 600; }

.loot-rarity-common { color: var(--text-secondary); }
.loot-rarity-uncommon { color: var(--green-light); }
.loot-rarity-rare { color: var(--blue-light); }
.loot-rarity-very-rare { color: var(--purple); }
.loot-rarity-legendary { color: var(--gold); }

/* ---- Initiative Tracker ---- */

.initiative-list {
  list-style: none;
}

.initiative-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-darker);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 6px;
  transition: all var(--transition);
}

.initiative-item.active {
  border-color: var(--gold);
  background: rgba(201, 168, 92, 0.08);
  box-shadow: var(--shadow-gold);
}

.initiative-item.dead {
  opacity: 0.4;
}

.init-order {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold);
  min-width: 36px;
  text-align: center;
}

.init-name {
  flex: 1;
  font-weight: 600;
  color: var(--parchment-light);
}

.init-hp {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hp-bar {
  width: 80px;
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s ease, background 0.3s ease;
  border-radius: 4px;
}

.hp-bar-fill.hurt { background: #d4a52c; }
.hp-bar-fill.critical { background: var(--red); }

.hp-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: center;
}

.init-actions {
  display: flex;
  gap: 4px;
}

.init-actions .btn-sm {
  padding: 4px 8px;
  font-size: 0.78rem;
}

.round-counter {
  text-align: center;
  padding: 16px;
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  color: var(--gold);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.round-counter span {
  font-size: 1.8rem;
  font-weight: 700;
}

/* ---- Ad Slots ---- */

.ad-slot {
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin: 24px 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ---- More Tools Section ---- */

.more-tools {
  padding: 50px 0;
  border-top: 1px solid var(--border-color);
  margin-top: 40px;
}

.more-tools h2 {
  text-align: center;
  margin-bottom: 30px;
  font-size: 1.6rem;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.tool-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-weight: 500;
  transition: all var(--transition);
}

.tool-link:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-gold);
  color: var(--parchment);
  transform: translateX(4px);
}

.tool-link-icon {
  font-size: 1.4rem;
}

/* ---- Content Section (SEO) ---- */

.content-section {
  padding: 40px 0;
  border-top: 1px solid var(--border-color);
}

.content-section h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
}

.content-section h3 {
  font-size: 1.1rem;
  margin-top: 20px;
  margin-bottom: 10px;
}

.content-section p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  max-width: 800px;
}

.content-section ul {
  color: var(--text-secondary);
  margin-left: 20px;
  margin-bottom: 12px;
}

.content-section li {
  margin-bottom: 4px;
}

/* ---- Footer ---- */

.site-footer {
  background: var(--bg-darker);
  border-top: 1px solid var(--border-color);
  padding: 40px 0 24px;
  margin-top: auto;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 40px;
  margin-bottom: 30px;
}

.footer-brand h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.footer-brand p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.footer-links h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold);
  margin-bottom: 12px;
}

.footer-links a {
  display: block;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 3px 0;
}

.footer-links a:hover {
  color: var(--parchment);
}

.footer-bottom {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ---- Toggle / Checkbox ---- */

.toggle-group {
  display: flex;
  gap: 4px;
  background: var(--bg-darker);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 3px;
}

.toggle-btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  border-radius: 5px;
  transition: all var(--transition);
}

.toggle-btn.active {
  background: var(--gold);
  color: var(--bg-darker);
  font-weight: 600;
}

/* ---- Scrollbar ---- */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-darker);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gold-dim);
}

/* ---- Toast / Notification ---- */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--gold);
  color: var(--parchment);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 2000;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
  .tool-layout {
    grid-template-columns: 1fr;
  }

  .footer-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }

  .main-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-darker);
    flex-direction: column;
    padding: 12px 20px;
    border-bottom: 2px solid var(--border-gold);
    gap: 2px;
  }

  .main-nav.open {
    display: flex;
  }

  .main-nav a {
    padding: 10px 12px;
    width: 100%;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero .subtitle {
    font-size: 1rem;
  }

  .page-header h1 {
    font-size: 1.6rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    flex-direction: column;
  }

  .result-total {
    font-size: 2.2rem;
  }

  .dice-grid {
    grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
  }

  .tools-grid {
    grid-template-columns: 1fr 1fr;
  }

  .initiative-item {
    flex-wrap: wrap;
    gap: 8px;
  }

  .init-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 14px;
  }

  .tools-grid {
    grid-template-columns: 1fr;
  }

  .btn-group {
    flex-direction: column;
  }

  .btn-group .btn {
    width: 100%;
  }
}
