/* ===== DESIGN TOKENS ===== */
:root {
  --bg: #0f1419;
  --bg-elevated: #171d29;
  --bg-inset: #0a0d12;
  --ink: #f2ead9;
  --ink-dim: #a89a80;
  --gold: #d4af37;
  --gold-bright: #e8c765;
  --wine: #8b2635;
  --wine-dim: rgba(139, 38, 53, 0.35);
  --rule: rgba(212, 175, 55, 0.2);
  --success: #4ade80;
  --danger: #e0655f;

  --font-display: 'Cinzel', Georgia, serif;
  --font-accent: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'EB Garamond', Georgia, serif;
}

:root[data-theme="light"] {
  --bg: #f7f2e7;
  --bg-elevated: #fffdf7;
  --bg-inset: #efe8d8;
  --ink: #2b2116;
  --ink-dim: #6b5d47;
  --gold: #a8791a;
  --gold-bright: #8b6314;
  --wine: #7a1f2b;
  --wine-dim: rgba(122, 31, 43, 0.15);
  --rule: rgba(122, 63, 15, 0.25);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f2e7;
    --bg-elevated: #fffdf7;
    --bg-inset: #efe8d8;
    --ink: #2b2116;
    --ink-dim: #6b5d47;
    --gold: #a8791a;
    --gold-bright: #8b6314;
    --wine: #7a1f2b;
    --wine-dim: rgba(122, 31, 43, 0.15);
    --rule: rgba(122, 63, 15, 0.25);
  }
}

/* ===== RESET ===== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
::selection { background: var(--gold); color: var(--bg); }

/* ===== LAYOUT ===== */
#app {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  height: 100vh;
}

@media (max-width: 1024px) {
  #app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
}

.panel-left {
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  border-right: 1px solid var(--rule);
  overflow-y: auto;
}

.panel-right {
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-elevated);
}

@media (max-width: 1024px) {
  .panel-left { border-right: none; border-bottom: 1px solid var(--rule); min-height: 46vh; }
  .panel-right { min-height: 54vh; }
}

/* ===== HEADER / BRAND ===== */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.brand svg { height: 40px; width: auto; }
.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.5px;
}
.brand-tagline {
  font-family: var(--font-accent);
  font-style: italic;
  font-size: 12px;
  color: var(--ink-dim);
}

.theme-toggle {
  margin-left: auto;
  background: var(--bg-inset);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--gold); }

/* ===== MAP ===== */
#map {
  flex: 1;
  border: 1px solid var(--rule);
  border-radius: 8px;
  margin-bottom: 16px;
  min-height: 280px;
  background: var(--bg-inset);
}
#map { position: relative; overflow: hidden; }
.maplibregl-popup-content {
  background: var(--bg-elevated);
  color: var(--ink);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-body);
}
.maplibregl-popup-tip { border-top-color: var(--gold) !important; border-bottom-color: var(--gold) !important; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.map-marker-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.5px;
}

.map-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink-dim);
  border: 2px solid rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.map-marker:hover { transform: scale(1.25); }
.map-marker.active {
  background: var(--gold);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.9);
  transform: scale(1.3);
}

/* ===== TIMELINE ===== */
.timeline-section { border-top: 1px solid var(--rule); padding-top: 14px; }
.timeline-label {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 10px;
}
.timeline-track {
  position: relative;
  height: 6px;
  background: var(--bg-inset);
  border-radius: 3px;
  margin-bottom: 8px;
}
.timeline-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--wine), var(--gold));
  border-radius: 3px;
}
.timeline-handle {
  position: absolute;
  top: 50%;
  width: 16px; height: 16px;
  background: var(--gold);
  border: 2px solid var(--bg);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: grab;
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}
.timeline-handle:active { cursor: grabbing; }
.timeline-range {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.timeline-current {
  text-align: center;
  font-family: var(--font-accent);
  font-style: italic;
  font-size: 14px;
  color: var(--gold);
  margin-top: 10px;
}

/* ===== SCRIPT LIST (mobile / fallback) ===== */
.script-list { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.script-list-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
}
.script-list-item:hover { border-color: var(--rule); }
.script-list-item.active { border-color: var(--gold); background: rgba(212, 175, 55, 0.08); }
.script-list-era { color: var(--ink-dim); font-variant-numeric: tabular-nums; font-size: 11px; }

/* ===== SCRIPT CARD ===== */
.script-header { margin-bottom: 20px; border-bottom: 1px solid var(--rule); padding-bottom: 16px; }
.script-name {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.5px;
  margin: 0 0 6px;
}
.script-original {
  font-size: 24px;
  color: var(--ink-dim);
  margin-bottom: 12px;
}
.script-status-badge {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: 3px;
  padding: 2px 6px;
  margin-bottom: 10px;
}
.script-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 12px; }
.meta-item { display: flex; flex-direction: column; }
.meta-label {
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-size: 10.5px;
  margin-bottom: 3px;
}
.meta-value { font-size: 13px; }

.script-description {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  margin: 14px 0 0;
  max-width: 62ch;
}
.btn-share {
  margin-top: 16px;
  width: auto;
  padding: 9px 16px;
  border-color: var(--wine);
  color: var(--ink);
}
.btn-share:hover:not(:disabled) { border-color: var(--gold); background: rgba(212, 175, 55, 0.08); }

/* ===== TABS ===== */
.tab-buttons { display: flex; gap: 0; margin: 20px 0 16px; border-bottom: 1px solid var(--rule); }
.tab-btn {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== GLYPHS ===== */
.section-title {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--wine);
  margin-bottom: 12px;
}
.glyph-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.glyph-card {
  background: var(--bg-inset);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}
.glyph-card:hover { border-color: var(--gold); background: rgba(212, 175, 55, 0.05); transform: translateY(-2px); }
.glyph-card.mastered { border-color: var(--gold); background: rgba(212, 175, 55, 0.1); }
.glyph-char { font-size: 28px; margin-bottom: 8px; min-height: 34px; display: flex; align-items: center; justify-content: center; }
.glyph-translit { font-family: var(--font-accent); font-style: italic; color: var(--gold); font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.glyph-meaning { color: var(--ink-dim); font-size: 11px; }
.glyph-check { font-size: 10px; color: var(--gold); margin-top: 6px; }

.collection-badge {
  display: inline-block;
  font-family: var(--font-body);
  background: rgba(212, 175, 55, 0.15);
  color: var(--gold);
  padding: 6px 10px;
  border-radius: 3px;
  font-size: 11.5px;
  font-weight: 500;
  margin-top: 14px;
}
.progress-bar { width: 100%; height: 6px; background: var(--bg-inset); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--gold), var(--wine)); border-radius: 3px; transition: width 0.4s ease; }

/* ===== GENEALOGY ===== */
.genealogy-empty { color: var(--ink-dim); font-style: italic; font-family: var(--font-accent); font-size: 14px; }
.genealogy-svg-wrap { overflow-x: auto; padding: 4px 0; }
.genealogy-svg-wrap svg { display: block; max-width: 100%; }
.gen-edge { stroke: var(--rule); stroke-width: 1.5; }
.gen-node rect {
  fill: var(--bg-inset);
  stroke: var(--rule);
  stroke-width: 1.5;
  cursor: pointer;
  transition: stroke 0.2s ease, fill 0.2s ease;
}
.gen-node text {
  font-family: var(--font-body);
  font-size: 11px;
  fill: var(--ink);
  pointer-events: none;
}
.gen-node.ancestor rect, .gen-node.descendant rect { cursor: pointer; }
.gen-node.ancestor:hover rect, .gen-node.descendant:hover rect { stroke: var(--gold); }
.gen-node.current rect { fill: rgba(212, 175, 55, 0.15); stroke: var(--gold); stroke-width: 2; }
.gen-node.current text { fill: var(--gold); font-family: var(--font-display); font-weight: 700; }

/* ===== BADGES ===== */
.badges-section { margin-top: 18px; border-top: 1px solid var(--rule); padding-top: 14px; }
.section-title-side {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 10px;
}
.badges-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 5px;
  border: 1px solid var(--rule);
  font-size: 12px;
  cursor: default;
}
.badge-item.unlocked { border-color: var(--gold); background: rgba(212, 175, 55, 0.08); color: var(--ink); }
.badge-item.locked { color: var(--ink-dim); opacity: 0.5; }
.badge-icon { font-size: 16px; }
.badge-label { font-family: var(--font-accent); font-style: italic; }

/* ===== QUIZ ===== */
.quiz-prompt {
  background: var(--wine-dim);
  border-left: 3px solid var(--wine);
  padding: 14px;
  border-radius: 0 6px 6px 0;
  margin-bottom: 14px;
  font-size: 14px;
}
.quiz-glyph-display { font-size: 48px; text-align: center; margin: 8px 0 16px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option {
  background: var(--bg-inset);
  border: 1px solid var(--rule);
  padding: 11px 14px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.quiz-option:hover { border-color: var(--gold); background: rgba(212, 175, 55, 0.08); }
.quiz-option.correct { border-color: var(--success); background: rgba(74, 222, 128, 0.12); }
.quiz-option.incorrect { border-color: var(--danger); background: rgba(224, 101, 95, 0.12); }
.quiz-option[disabled] { cursor: default; }
.quiz-feedback { margin-top: 12px; font-family: var(--font-accent); font-style: italic; font-size: 14px; }
.quiz-feedback.correct { color: var(--success); }
.quiz-feedback.incorrect { color: var(--danger); }

/* ===== BUTTONS ===== */
.button-group { display: flex; gap: 8px; margin-top: 18px; }
.btn {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  background: var(--bg-inset);
  color: var(--ink);
  border-radius: 4px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.btn:hover { border-color: var(--wine); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--gold); color: var(--bg); border-color: var(--gold); font-family: var(--font-display); }
.btn-primary:hover:not(:disabled) { background: var(--gold-bright); }

/* ===== EMPTY STATE ===== */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink-dim);
  gap: 8px;
}
.empty-state-title { font-family: var(--font-accent); font-style: italic; font-size: 18px; color: var(--ink); }

/* ===== SCRIPT OF THE DAY ===== */
.sotd-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(212, 175, 55, 0.1), transparent);
}
.sotd-glyph { font-size: 30px; color: var(--gold); line-height: 1; }
.sotd-text { flex: 1; min-width: 0; }
.sotd-label {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-dim);
}
.sotd-name { font-family: var(--font-display); font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sotd-card .btn { flex: none; padding: 8px 12px; }

/* ===== NAME TRANSCRIBER ===== */
.transcriber-input-row { display: flex; gap: 8px; }
.transcriber-input-row input {
  flex: 1;
  background: var(--bg-inset);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
}
.transcriber-input-row input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  border-color: var(--gold);
}
.transcriber-input-row .btn { flex: none; }
.transcriber-output {
  margin-top: 20px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg-inset);
}
.transcriber-glyphs { font-size: 32px; letter-spacing: 4px; color: var(--gold); padding: 12px; }
.transcriber-disclaimer { font-size: 12px; color: var(--ink-dim); font-style: italic; font-family: var(--font-accent); margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
