/* DinoVerse — layout first, theme second.
 *
 * Three-section layout:
 *   · Desktop (>=1024px): .layout grid 340px / 1fr / 340px, full height.
 *     LEFT  (.col-left)  = DATA — header card on top, info panel below
 *                          filling the remaining height (internal scroll).
 *     CENTER (#stage)    = THE ASSET — the 3D canvas fills the column;
 *                          tooltip overlays it, hint sits at its bottom.
 *     RIGHT (.col-right) = SWITCHER/OPTIONS — Dinosaur Explorer (search,
 *                          Era/Diet chips, scrolling dinosaur list) plus
 *                          the Prev/Next + View-whole-hall controls.
 *     Side columns have a dark panel background and a 1px divider
 *     against the stage.
 *   · 641–1023px: same grid with 272px side columns.
 *   · <=640px: single-column stack — header -> stage (56vh) ->
 *     switcher/explorer -> data/info -> controls — full width, 12px
 *     margins. (The side columns use display:contents on mobile so
 *     their children can be ordered individually in the stack.)
 *   · #loading / #webgl-fail stay outside the grid as fixed overlays.
 *
 * Theme: warm sandstone, bronze and amber — a fossil hall at golden hour.
 */

:root {
  --margin: 20px;
  --bg: #0b0806;
  : rgba(22, 16, 11, 0.92);
  --panel-solid: #16100b;
  --panel-border: rgba(224, 158, 74, 0.30);
  --text: #f3e9d8;
  --muted: #b3a189;
  --accent: #e09a4a;       /* warm amber */
  --accent2: #8fb573;      /* fossil-leaf green */
  --gold: #d9a441;
  --radius: 18px;
}

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

html, body { height: 100%; overflow-x: hidden; }

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 800px at 62% 18%, #2a1b0e 0%, var(--bg) 58%) fixed;
  color: var(--text);
  overflow: hidden;
}

/* ---------- three-section layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px 1fr 340px;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

.col-left,
.col-right {
  display: flex;
  flex-direction: column;
  gap: var(--margin);
  padding: var(--margin);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--panel-solid);
}
.col-left { border-right: 1px solid var(--panel-border); }
.col-right { border-left: 1px solid var(--panel-border); }

#stage {
  position: relative;
  z-index: 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- shared panel chrome ---------- */

.panel {
  position: relative;
  z-index: 10;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 50px rgba(0, 0, 0, 0.45);
}

/* ---------- header card (left column, top) ---------- */

#site-header {
  flex: none;
  padding: 14px 20px 16px;
}
.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.back-link:hover { text-decoration: underline; }
#site-header h1 {
  font-family: "Archivo", Georgia, serif;
  font-size: 1.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 5px;
  line-height: 1.05;
}
#site-header h1 .accent { color: var(--accent); }
#site-header .subtitle { color: var(--muted); font-size: 0.87rem; margin-top: 5px; line-height: 1.45; }

/* ---------- explorer (right column, fills height) ---------- */

#explorer {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.explorer-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--panel-border); flex: none; }
.explorer-head h2 { font-family: "Archivo", Georgia, serif; letter-spacing: -0.01em; font-size: 1.05rem; font-weight: 600; margin-bottom: 10px; }
#search {
  width: 100%;
  height: 38px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224, 154, 74, 0.25); }
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.chip {
  display: inline-flex; align-items: center;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
}
.chip:hover { color: var(--text); border-color: var(--accent); transform: translateY(-1px); }
.chip.active {
  background: linear-gradient(135deg, var(--accent), #f2bc77);
  color: #0b0e18; border-color: transparent; font-weight: 600;
  box-shadow: 0 4px 18px rgba(224, 154, 74, 0.45);
}

#dino-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 10px 14px; scrollbar-width: thin; scrollbar-color: rgba(224,154,74,.4) transparent; }
#dino-list::-webkit-scrollbar { width: 6px; }
#dino-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 3px; }
.dino-group { margin-top: 10px; }
.dino-group h3 {
  font-size: 11px;  letter-spacing: 0.01em;
  color: var(--muted); padding: 4px 6px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06); margin-bottom: 6px;
}
.dino-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  min-height: 40px;
  padding: 8px 12px; border-radius: 12px;
  font-size: 0.9rem; cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
.dino-item:hover { background: rgba(255, 255, 255, 0.05); transform: translateX(2px); }
.dino-item.selected { background: rgba(224, 154, 74, 0.14); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.dino-item .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.dino-item .meta { margin-left: auto; color: var(--muted); font-size: 0.72rem; flex: none; }
.empty-note { color: var(--muted); font-size: 0.85rem; padding: 8px 6px; }

/* ---------- controls (right column, below the explorer) ---------- */

.controls-panel { flex: none; padding: 14px 16px; }
.controls-panel .info-nav { margin-top: 0; }

/* ---------- info panel (left column, fills remaining height) ---------- */

#info-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(224,154,74,.4) transparent;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#info-panel.closed { opacity: 0; transform: translateY(14px); pointer-events: none; }
#info-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; color: var(--muted);
  font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 4px;
}
#info-close:hover { color: var(--text); }
.info-eyebrow {
  font-size: 11px;  letter-spacing: 0.01em;
  color: var(--accent); font-weight: 600;
}
#info-name { font-family: "Archivo", Georgia, serif; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; margin: 4px 0 2px; }
.info-hook { color: var(--muted); font-style: italic; font-size: 0.93rem; margin-bottom: 10px; line-height: 1.4; }

.stat-row { display: flex; gap: 8px; margin-bottom: 10px; }
.stat {
  flex: 1 1 0;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 6px 9px;
  min-width: 0;
}
.stat-label { display: block; font-size: 10px; letter-spacing: 0.01em; color: var(--muted); }
.stat-value { display: block; font-size: 15px; font-weight: 600; margin-top: 2px; line-height: 1.3; }

.info-desc { color: #e6d9c4; font-size: 14px; line-height: 1.65; }

.fact {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(224, 154, 74, 0.08);
  border-left: 3px solid var(--accent);
}
.fact-label { font-size: 0.72rem; letter-spacing: 0.01em; color: var(--accent); margin-bottom: 4px; font-weight: 700; }
.fact-text { font-size: 0.87rem; line-height: 1.5; color: #e2efda; }

.info-nav { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btn {
  appearance: none;
  flex: 1 1 0;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: rgba(224, 154, 74, 0.14); transform: translateY(-1px); }
.btn:active { transform: scale(0.97); }
.btn-wide { flex-basis: 100%; }

/* ---------- stage hint (bottom of the center stage) ---------- */

#hint {
  position: absolute;
  z-index: 9;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: rgba(8, 5, 3, 0.92);
  padding: 6px 14px;
  border-radius: 999px;
  pointer-events: none;
}

/* ---------- tooltip / overlays ---------- */

#tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(10, 7, 4, 0.9);
  color: #ffd9a3;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  transform: translate(-50%, -170%);
}
#tooltip.show { opacity: 1; }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: var(--bg); color: var(--muted);
  font-size: 15px; letter-spacing: 0.05em; text-align: center; padding: 24px;
  transition: opacity 0.5s ease;
}
.overlay.gone { opacity: 0; pointer-events: none; }
.overlay-error { background: rgba(11, 8, 6, 0.97); line-height: 1.6; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid rgba(224, 154, 74, 0.2); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tablet: same three sections, narrower side columns ---------- */

@media (max-width: 1023px) {
  .layout { grid-template-columns: 272px 1fr 272px; }
  .col-left, .col-right { padding: 16px; gap: 16px; }
  #site-header h1 { font-size: 1.6rem; }
  #site-header .subtitle { font-size: 0.8rem; }
}

/* ---------- mobile: single-column stack ---------- */

@media (max-width: 640px) {
  :root { --margin: 12px; }

  html, body { height: auto; overflow-x: hidden; }
  body { overflow-y: auto; }

  .layout {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    height: auto;
    min-height: 100vh;
  }

  /* Flatten the side columns so each child stacks in the order below. */
  .col-left, .col-right { display: contents; }

  /* 1 — compact header */
  #site-header {
    order: 1;
    width: 100%;
    padding: 10px 14px 12px;
  }
  #site-header h1 { font-size: 1.35rem; display: inline-block; margin-left: 10px; }
  #site-header .subtitle { display: none; }
  .back-link { font-size: 0.72rem; }

  /* 2 — unobstructed canvas block */
  #stage {
    order: 2;
    width: 100%;
    height: 56vh;
    min-height: 320px;
    border-radius: var(--radius);
    border: 1px solid var(--panel-border);
    flex: none;
  }
  #hint { bottom: 10px; }

  /* 3 — switcher / explorer */
  #explorer {
    order: 3;
    width: 100%;
    max-height: 46vh;
    flex: none;
  }

  /* 4 — data / info */
  #info-panel {
    order: 4;
    width: 100%;
    max-height: none;
    overflow-y: visible;
    flex: none;
  }
  #info-panel.closed { display: none; }

  /* 5 — controls */
  .controls-panel { order: 5; width: 100%; }

  /* equal 2-column button grid */
  .info-nav { display: grid; grid-template-columns: 1fr 1fr; }
  .btn-wide { grid-column: 1 / -1; }
}

/* The fail overlay must obey its hidden attribute (author display rules would otherwise override it) */
#webgl-fail[hidden]{display:none !important}

/* ================= PREMIUM UI PASS ================= */
::selection { background: var(--accent); color: #0b0e18; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#stage::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.38) 100%);
}
#stage canvas { cursor: grab; }
#stage canvas:active { cursor: grabbing; }
#dino-list::-webkit-scrollbar, #info-panel::-webkit-scrollbar { width: 8px; }
#dino-list::-webkit-scrollbar-thumb, #info-panel::-webkit-scrollbar-thumb { background: rgba(224, 154, 74, 0.35); border-radius: 99px; }
@keyframes panelIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.panel-in { animation: panelIn 0.45s cubic-bezier(0.22, 0.8, 0.32, 1); }
.loader-wordmark { font-family: "Inter", sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 0.01em; color: var(--muted); margin: 0; }
.loader-bar { width: 160px; height: 3px; border-radius: 99px; background: rgba(255, 255, 255, 0.10); overflow: hidden; }
.loader-bar span { display: block; height: 100%; width: 40%; border-radius: 99px; background: var(--accent); animation: loadslide 1.2s ease-in-out infinite; }
@keyframes loadslide { 0% { transform: translateX(-110%); } 100% { transform: translateX(280%); } }
.overlay-error > p {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 18px;
  padding: 28px 30px; max-width: 540px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 50px rgba(0, 0, 0, 0.45);
}
.overlay-error > p strong { font-family: "Archivo", Georgia, serif; letter-spacing: -0.01em; font-size: 22px; font-weight: 600; color: var(--text); display: block; margin-bottom: 8px; }
@media (prefers-reduced-motion: reduce) {
  .panel-in { animation: none; }
  .loader-bar span { animation: none; transform: none; width: 60%; }
}
