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

:root {
  --bg: #0a0a0a;
  --bg-2: #0e0e10;
  --panel: #111114;
  --panel-2: #16161a;
  --line: rgba(255,255,255,0.08);
  --line-bright: rgba(255,255,255,0.18);
  --fg: #ededed;
  --fg-dim: #8a8a8f;
  --fg-faint: #4a4a50;

  --strat-eon: #2a2624;
  --strat-era: #37302c;
  --strat-period: #433931;
  --strat-epoch: #4f4238;

  --accent: #d9a472;
  --accent-dim: #c08a5a;
  --cool: #6a8597;
  --warm: #b28560;
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-weight: 300;
}

body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(192,138,90,0.05) 0%, transparent 70%),
    radial-gradient(ellipse 60% 60% at 20% 10%, rgba(106,133,151,0.04) 0%, transparent 70%);
}

.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "top   top    top"
    "left  stage  right";
  height: 100vh;
  width: 100vw;
}

/* ---------- TOP ---------- */
.topbar {
  grid-area: top;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
}
.back {
  color: var(--fg-dim); text-decoration: none; font-size: 0.85rem;
  letter-spacing: 0.02em; transition: color 0.2s;
}
.back:hover { color: var(--fg); }

.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0%, var(--accent) 50%, #5c3a20 100%);
  box-shadow: 0 0 10px rgba(217,164,114,0.45);
  align-self: center;
}
.brand-title { font-size: 0.95rem; font-weight: 500; }
.brand-sub { font-size: 0.7rem; color: var(--fg-dim); letter-spacing: 0.15em; }

.model-note {
  font-size: 0.72rem;
  color: var(--fg-dim);
  letter-spacing: 0.05em;
}
.model-note abbr {
  text-decoration: dotted underline;
  text-underline-offset: 3px;
  color: var(--accent-dim);
  cursor: help;
}

/* ---------- PANELS ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.panel-left { grid-area: left; border-top: 0; border-right: 0; border-bottom: 0; }
.panel-right { grid-area: right; border-top: 0; border-left: 0; border-bottom: 0; }

.section { display: flex; flex-direction: column; gap: 0.6rem; }
.section-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  color: var(--fg-dim);
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.4rem;
}
.section-sub { font-size: 0.65rem; color: var(--fg-faint); letter-spacing: 0.1em; }

/* ---------- LEVEL TOGGLE ---------- */
.level-toggle {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}
.level-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  padding: 0.45rem 0.2rem;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  line-height: 1.2;
}
.level-btn .lv-ar {
  font-size: 0.85rem;
  font-weight: 500;
}
.level-btn .lv-en {
  font-size: 0.62rem;
  color: var(--fg-faint);
  letter-spacing: 0.08em;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
.level-btn.active .lv-en { color: var(--accent-dim); }
.level-btn:hover { color: var(--fg); border-color: var(--line-bright); }
.level-btn.active {
  background: rgba(217,164,114,0.12);
  border-color: var(--accent-dim);
  color: var(--accent);
}
.level-hint {
  font-size: 0.72rem;
  color: var(--fg-faint);
  line-height: 1.5;
}

/* ---------- FOCUS CONTROLS ---------- */
.focus-presets { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.focus-preset {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--fg-dim);
  padding: 0.35rem 0.6rem;
  font-family: inherit;
  font-size: 0.72rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}
.focus-preset:hover { color: var(--fg); border-color: var(--line-bright); }
.focus-preset.active {
  background: rgba(217,164,114,0.12);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.focus-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.3rem;
}
.focus-input {
  display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.68rem;
  color: var(--fg-dim);
  letter-spacing: 0.05em;
}
.focus-input input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  border-radius: 3px;
  direction: ltr;
  text-align: left;
  width: 100%;
  transition: border-color 0.2s;
}
.focus-input input:focus {
  outline: none;
  border-color: var(--accent-dim);
}
.focus-input input.invalid {
  animation: focusShake 0.4s ease;
  border-color: #b85a5a;
}
@keyframes focusShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
.focus-note {
  font-size: 0.68rem;
  color: var(--fg-faint);
  margin-top: 0.3rem;
}

/* ---------- LEGEND ---------- */
.axis-legend { margin-top: auto; }
.legend-row {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.75rem;
  color: var(--fg-dim);
}
.legend-swatch {
  width: 16px; height: 12px;
  border: 1px solid var(--line-bright);
  border-radius: 2px;
}
.legend-swatch.s-eon { background: var(--strat-eon); }
.legend-swatch.s-era { background: var(--strat-era); }
.legend-swatch.s-period { background: var(--strat-period); }
.legend-swatch.s-epoch { background: var(--strat-epoch); }
.legend-note {
  font-size: 0.68rem;
  color: var(--fg-faint);
  margin-top: 0.4rem;
  line-height: 1.6;
}

/* ---------- STAGE / COLUMN ---------- */
.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 1.5rem 2rem 2.5rem;
}
.column {
  width: 100%;
  height: 100%;
  display: block;
}
.stage-hint {
  position: absolute;
  bottom: 0.8rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--fg-faint);
  letter-spacing: 0.12em;
  text-align: center;
  pointer-events: none;
}

/* ---------- COLUMN SVG STYLING ---------- */
.strat-band {
  cursor: pointer;
  transition: filter 0.2s, stroke 0.2s;
}
.strat-band:hover {
  filter: brightness(1.25);
}
.strat-band.selected {
  stroke: var(--accent);
  stroke-width: 1.5;
}
.strat-label-ar {
  fill: var(--fg);
  font-family: 'Tajawal', inherit;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.6);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.strat-label-en {
  fill: var(--accent);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.04em;
  pointer-events: none;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.6);
  stroke-width: 2.5px;
  stroke-linejoin: round;
}
.strat-label-sub {
  fill: var(--fg-dim);
  font-family: inherit;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: rgba(0,0,0,0.6);
  stroke-width: 2.5px;
  stroke-linejoin: round;
}
.axis-tick {
  stroke: var(--fg-faint);
  stroke-width: 1;
}
.axis-tick-label {
  fill: var(--fg-dim);
  font-family: inherit;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  dominant-baseline: middle;
}
.axis-line {
  stroke: var(--line-bright);
  stroke-width: 1;
}
.empty-column-msg {
  fill: var(--fg-faint);
  font-family: inherit;
  font-size: 12px;
  text-anchor: middle;
}

/* ---------- DETAIL CARD ---------- */
.detail-card {
  display: flex; flex-direction: column; gap: 0.8rem;
  font-size: 0.85rem;
  line-height: 1.7;
}
.rock-slab {
  width: 100%;
  background: radial-gradient(ellipse at center, rgba(217,164,114,0.08) 0%, transparent 70%);
  padding: 0.5rem 0.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
}
.rock-slab-svg {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  max-width: 100%;
}
.en-inline {
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 0.72rem;
  color: var(--fg-faint);
  letter-spacing: 0.03em;
}
.empty-hint {
  color: var(--fg-faint);
  font-size: 0.8rem;
  line-height: 1.7;
  padding: 0.5rem 0;
}
.detail-title {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--fg);
}
.detail-en {
  font-size: 0.75rem;
  color: var(--fg-dim);
  letter-spacing: 0.08em;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
.detail-range {
  font-size: 0.8rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}
.detail-level-badge {
  display: inline-block;
  font-size: 0.65rem;
  color: var(--fg-dim);
  letter-spacing: 0.15em;
  border: 1px solid var(--line);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
.detail-row {
  display: flex; flex-direction: column; gap: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}
.detail-row-label {
  font-size: 0.68rem;
  color: var(--fg-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.detail-row-body {
  color: var(--fg);
  font-size: 0.88rem;
}
.detail-tree {
  font-size: 0.78rem;
  color: var(--fg-dim);
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 0.3rem;
}
.detail-tree .tree-head {
  font-size: 0.68rem;
  color: var(--fg-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}
.detail-tree .tree-key {
  color: var(--accent-dim);
  font-weight: 500;
  margin-inline-end: 0.25rem;
}

/* ---------- DID-YOU-KNOW FACT ---------- */
.detail-fact {
  position: relative;
  background: linear-gradient(135deg, rgba(217,164,114,0.10) 0%, rgba(217,164,114,0.04) 100%);
  border: 1px solid rgba(217,164,114,0.45);
  border-radius: 6px;
  padding: 0.7rem 0.85rem 0.8rem;
  display: flex; flex-direction: column; gap: 0.3rem;
  box-shadow: 0 1px 0 rgba(217,164,114,0.08) inset;
}
.detail-fact::before {
  content: "";
  position: absolute;
  inset-inline-start: -1px; top: -1px; bottom: -1px;
  width: 3px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dim) 100%);
  border-radius: 6px 0 0 6px;
}
html[dir="rtl"] .detail-fact::before {
  inset-inline-start: auto;
  inset-inline-end: -1px;
  border-radius: 0 6px 6px 0;
}
.fact-label {
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.12em;
}
.fact-body {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--fg);
}

/* ---------- WELCOME (EMPTY STATE) ---------- */
.welcome {
  display: flex; flex-direction: column; gap: 1rem;
  font-size: 0.85rem;
  line-height: 1.7;
  padding: 0.2rem 0;
}
.welcome-head { display: flex; flex-direction: column; gap: 0.15rem; }
.welcome-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--fg);
}
.welcome-sub {
  font-size: 0.72rem;
  color: var(--fg-dim);
  letter-spacing: 0.08em;
}
.welcome-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 0.6rem 0.2rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.welcome-list li {
  display: flex; gap: 0.6rem; align-items: flex-start;
  font-size: 0.83rem;
  color: var(--fg);
  line-height: 1.6;
}
.wl-num {
  flex: 0 0 auto;
  width: 1.4rem; height: 1.4rem;
  border-radius: 50%;
  background: rgba(217,164,114,0.12);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  margin-top: 0.05rem;
}
.welcome-analogy {
  display: flex; flex-direction: column; gap: 0.35rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.7rem 0.85rem;
}
.wa-head {
  font-size: 0.68rem;
  color: var(--fg-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.wa-body {
  font-size: 0.82rem;
  color: var(--fg);
  line-height: 1.75;
}
.wa-body ul {
  list-style: none;
  padding: 0.25rem 0 0;
  display: flex; flex-direction: column; gap: 0.2rem;
}
.wa-body li::before {
  content: "·";
  color: var(--accent-dim);
  margin-inline-end: 0.4rem;
}
.wa-body strong {
  color: var(--accent);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.welcome-start {
  background: linear-gradient(180deg, rgba(217,164,114,0.14), rgba(217,164,114,0.06));
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; flex-direction: column; align-items: stretch; gap: 0.15rem;
  text-align: start;
}
.welcome-start:hover {
  background: linear-gradient(180deg, rgba(217,164,114,0.22), rgba(217,164,114,0.10));
  color: #f0c898;
}
.ws-sub {
  font-size: 0.7rem;
  color: var(--fg-dim);
  font-weight: 300;
  letter-spacing: 0.02em;
}
.welcome-start:hover .ws-sub { color: #b59a7a; }

/* ---------- BAND TOOLTIP ---------- */
.band-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  max-width: 260px;
  background: rgba(18,16,14,0.96);
  border: 1px solid rgba(217,164,114,0.35);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  font-family: 'Tajawal', inherit;
  color: var(--fg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  direction: rtl;
}
.band-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}
.band-tooltip .tt-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent);
}
.band-tooltip .tt-fact {
  font-size: 0.78rem;
  color: var(--fg);
  line-height: 1.55;
  margin-top: 0.25rem;
}
.band-tooltip .tt-hint {
  font-size: 0.65rem;
  color: var(--fg-faint);
  letter-spacing: 0.1em;
  margin-top: 0.35rem;
}
@media (hover: none) {
  .band-tooltip { display: none; }
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px auto 1fr auto;
    grid-template-areas:
      "top"
      "left"
      "stage"
      "right";
  }
  .panel-left, .panel-right {
    max-height: 40vh;
    border: 0;
    border-bottom: 1px solid var(--line);
  }
  .panel-right { border-top: 1px solid var(--line); border-bottom: 0; }
  .model-note { font-size: 0.6rem; }
}

@media (max-width: 480px) {
  .topbar { padding: 0 0.8rem; gap: 0.5rem; }
  .brand-sub { display: none; }
  .stage { padding: 1rem 0.75rem 2rem; }
  .focus-presets { gap: 0.25rem; }
  .focus-preset { padding: 0.3rem 0.5rem; font-size: 0.68rem; }
}

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