:root {
  --bg: #08080a;
  /* The UI stays dim and low in contrast so the crystals are the brightest thing on screen. */
  --panel: rgba(10, 10, 12, 0.72);
  --panel-solid: #0e0e11;
  --line: rgba(255, 255, 255, 0.06);
  --text: #b7bcc4;
  --muted: #7c828c;
  --faint: #555a62;
  --accent: #8fb3d9;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --tap: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans);
  overflow: hidden; overscroll-behavior: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button {
  font: inherit; color: var(--text); background: rgba(255,255,255,0.045); border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px; padding: 0 16px; min-height: var(--tap); cursor: pointer; touch-action: manipulation;
  transition: background 0.15s, transform 0.08s, border-color 0.15s;
}
button:active { transform: scale(0.96); background: rgba(255,255,255,0.16); }
@media (hover: hover) { button:hover { background: rgba(255,255,255,0.12); } }
button.round { width: var(--tap); height: var(--tap); border-radius: 50%; padding: 0; font-size: 19px; }
button.link { background: none; border: 0; min-height: 0; padding: 4px 0; color: var(--accent); font: 500 13px var(--sans); text-transform: none; letter-spacing: 0; }
.corner { position: fixed; top: 18px; right: 20px; display: flex; gap: 10px; z-index: 4; }
.corner .round { background: rgba(20,20,24,0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

/* ---------- dock ---------- */
#dock {
  position: fixed; left: 16px; right: 16px; bottom: calc(14px + var(--safe-b)); z-index: 3;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 12px 14px 8px;
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
}
.deposits { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; scroll-snap-type: x proximity; }
.deposits::-webkit-scrollbar { display: none; }
.tile {
  flex: 1 0 150px; min-height: 64px; text-align: left; padding: 8px 12px; border-radius: 14px; scroll-snap-align: start;
  display: flex; flex-direction: column; justify-content: center; gap: 2px; position: relative; overflow: hidden;
}
.tile .t-name { font: 600 15px/1.2 var(--sans); letter-spacing: -0.01em; }
.tile .t-place { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 3px 3px 0; background: var(--sw, #888); opacity: 0.55; }
.tile.on::before { opacity: 0.9; }
.tile.on { background: rgba(143,179,217,0.14); border-color: rgba(143,179,217,0.6); color: #d5dae1; }

.dock-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.play { width: 64px; height: 64px; border-radius: 50%; padding: 0; font-size: 20px; background: rgba(143,179,217,0.22); color: #c8daee; border: 1px solid rgba(143,179,217,0.55); font-weight: 700; flex: none; }
.play:active { background: rgba(143,179,217,0.4); }
.ghost { font-size: 22px; flex: none; }
.ghost.lab { font: 600 15px var(--sans); }
.clock { min-width: 170px; flex: 1 1 170px; }
#clock { font: 600 26px/1.1 var(--sans); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stage { color: var(--accent); font-size: 14px; line-height: 1.25; min-height: 18px; }
.tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.group { display: flex; flex-direction: column; gap: 4px; }
.group-label { font: 600 10.5px var(--sans); letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); padding-left: 2px; }
.seg { display: flex; gap: 4px; }
.seg button { padding: 0 12px; font-size: 14px; min-width: 52px; }
.seg button.on { background: rgba(143,179,217,0.22); border-color: var(--accent); }
.ev-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.ev-buttons button { font-size: 14px; padding: 0 13px; }
.ev-buttons button.fired { border-color: var(--accent); background: rgba(143,179,217,0.25); }
#chart { width: 100%; height: 54px; display: block; margin-top: 8px; }

/* ---------- museum label ---------- */
/* Label drawer along the top edge, with a pull tab like the side panel. */
.topdrawer {
  position: fixed; top: 0; left: 16px; right: 16px; z-index: 3; pointer-events: none;
  transform: translateY(-100%); transition: transform 0.35s ease, left 0.35s ease, right 0.35s ease, opacity 0.5s ease;
}
.topdrawer.open { transform: none; }
.topdrawer-body { max-width: 860px; margin: 0 auto; padding-top: 14px; pointer-events: auto; }
.top-tab {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); pointer-events: auto;
  min-height: 40px; height: 40px; padding: 0 18px; border-radius: 0 0 14px 14px; border-top: 0;
  display: flex; align-items: center; gap: 8px;
  background: rgba(20,20,24,0.78); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top-tab span { font: 600 12px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.top-tab i { font-style: normal; font-size: 15px; color: var(--accent); transform: rotate(180deg); transition: transform 0.35s; }
/* Each pane carries its own collapse button; the edge tabs only bring a collapsed pane back. */
.top-tab { transition: opacity 0.3s; }
.topdrawer.open .top-tab { opacity: 0; pointer-events: none; }
.topdrawer-body { position: relative; }
.round.collapse { width: 40px; height: 40px; min-height: 40px; font-size: 20px; color: var(--accent); background: rgba(255,255,255,0.04); }
#labelCollapse { position: absolute; bottom: 10px; right: 10px; font-size: 16px; }
.museum .col { min-width: 0; }
.museum:has(.science[open]) { max-height: 58vh; }
.museum .science { grid-column: 1 / -1; margin-top: 4px; border-top: 1px solid var(--line); padding-top: 4px; }
.museum .science summary {
  list-style: none; cursor: pointer; min-height: 36px; display: flex; align-items: center; gap: 8px;
  font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent);
}
.museum .science summary::-webkit-details-marker { display: none; }
.museum .science summary::after { content: '+'; font-size: 16px; }
.museum .science[open] summary::after { content: '−'; }
.museum .science p { font: 13.5px/1.55 var(--sans); color: var(--muted); margin: 4px 0 8px; max-width: 78ch; }
.museum .science .refs-h { font: 600 11px var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); margin-top: 10px; }
.museum .refs { font: 12px/1.5 var(--sans); color: var(--faint); padding-left: 20px; margin: 4px 0 6px; user-select: text; -webkit-user-select: text; }
.museum .refs li { margin: 2px 0; }
.museum .back { margin-top: 10px; }
.museum {
  display: grid; grid-template-columns: 1.05fr 1fr; gap: 6px 26px; max-height: 32vh; overflow-y: auto; scrollbar-width: none;
  background: rgba(12,12,15,0.78); color: #c3c8cf; border: 1px solid var(--line); border-radius: 14px; padding: 16px 60px 16px 20px;
  font-family: var(--sans); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.museum .mname { font: 600 22px/1.15 var(--sans); letter-spacing: -0.015em; }
.museum .formula { font: 500 15px var(--sans); color: var(--muted); margin-top: 2px; }
.museum .meta { font: 600 11px var(--sans); color: var(--faint); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 6px; }
.museum table { width: 100%; border-collapse: collapse; margin-top: 2px; font: 13px/1.35 var(--sans); }
.museum td { padding: 3px 0; vertical-align: top; }
.museum td:first-child { color: var(--faint); width: 40%; }
.museum .note { font: 13.5px/1.45 var(--sans); margin-top: 10px; color: var(--muted); }
.museum .story { font: 14px/1.5 var(--sans); color: var(--muted); margin-top: 8px; }
.museum .inv { margin-top: 2px; font: 13px var(--sans); }
.museum .inv div { display: flex; justify-content: space-between; padding: 3px 0; border-top: 1px solid var(--line); }
.museum .inv i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 7px; }
.museum .tip { font: 600 11px var(--sans); color: var(--faint); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 10px; }

/* ---------- lab drawer ---------- */
.drawer {
  position: fixed; left: 16px; top: 16px; bottom: 16px; width: 380px; z-index: 5; overflow-y: auto;
  background: rgba(14,14,18,0.94); border: 1px solid var(--line); border-radius: 20px; padding: 0 20px 20px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition: transform 0.35s ease, opacity 0.5s ease; transform: translateX(-110%); scrollbar-width: thin; scrollbar-color: #333 transparent;
  overscroll-behavior: contain;
}
.drawer.open { transform: none; }
.drawer-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 14px 0 8px; background: linear-gradient(rgba(14,14,18,1) 75%, rgba(14,14,18,0)); z-index: 1; }
.drawer-head h2 { margin: 0; font: 600 19px var(--sans); letter-spacing: -0.01em; }
.drawer section, .drawer details { padding: 10px 0; border-top: 1px solid var(--line); }
.drawer h3, .drawer summary { font: 600 11.5px var(--sans); text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.drawer summary { cursor: pointer; list-style: none; min-height: 40px; margin: 0; }
.drawer summary::after { content: '+'; font-size: 18px; color: var(--faint); }
.drawer details[open] summary::after { content: '−'; }
.hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.slider { display: block; margin: 0 -8px; padding: 4px 8px 0; border-radius: 10px; position: relative; }
.srow { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; min-height: 24px; }
.slabel { flex: 1; min-width: 0; }
.slider em { font-style: normal; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend { font-size: 10px; width: 12px; text-align: center; }
.trend.up { color: #e7a36f; }
.trend.down { color: #7fb4e6; }
.sreset { min-height: 30px; height: 30px; width: 30px; padding: 0; border-radius: 50%; font-size: 15px; color: var(--accent); border-color: rgba(143,179,217,0.5); }
.sscript { font-size: 12px; color: var(--accent); margin-top: -2px; padding-bottom: 2px; }
.slider.scripted::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: rgba(143,179,217,0.45); }
.slider.mine { background: rgba(143,179,217,0.08); }
.slider.mine::before { background: var(--accent); }
.slider.mine em { color: var(--accent); }
.slider.jump { animation: jump 1.6s ease-out; }
@keyframes jump { 0% { background: rgba(143,179,217,0.35); } 100% { background: transparent; } }
.slider.mine.jump { animation: none; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; margin: 0; background: transparent; touch-action: pan-y; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.08); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.08); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%; background: #8a9099; border: 0; box-shadow: 0 1px 6px rgba(0,0,0,0.5); }
input[type=range]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #8a9099; border: 0; }
.slider.mine input[type=range]::-webkit-slider-thumb { background: var(--accent); }
.slider.mine input[type=range]::-moz-range-thumb { background: var(--accent); }
.next { color: var(--faint); font-size: 12.5px; line-height: 1.25; min-height: 16px; }
/* Pull tab on the left edge that opens and closes the fluid panel. */
.edge-tab {
  position: fixed; left: 0; top: calc((100% - var(--dock-h, 170px)) / 2); transform: translateY(-50%); z-index: 4;
  width: 46px; min-height: 150px; padding: 14px 0; border-radius: 0 16px 16px 0; border-left: 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(20,20,24,0.78); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: left 0.35s ease, background 0.15s, opacity 0.3s;
}
.edge-tab span { writing-mode: vertical-rl; transform: rotate(180deg); font: 600 12px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.edge-tab i { font-style: normal; font-size: 22px; color: var(--accent); transition: transform 0.35s; }
body.lab-open .edge-tab { opacity: 0; pointer-events: none; }
.edge-tab:active { transform: translateY(-50%) scale(0.96); }

.sat-row { display: grid; grid-template-columns: 110px 1fr 48px; gap: 10px; align-items: center; margin: 6px 0; font-size: 13.5px; }
.sat-row .name { display: flex; align-items: center; gap: 7px; }
.sat-row .name i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.sat-row .bar { position: relative; height: 8px; background: rgba(255,255,255,0.06); border-radius: 4px; }
.sat-row .bar::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: rgba(255,255,255,0.3); }
.sat-row .bar b { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.sat-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sat-note { color: var(--faint); font-size: 13px; margin-top: 6px; }

/* ---------- overlays ---------- */
/* Idle mode: the UI fades away, leaving the specimen. The hint lets touches through,
   so the specimen can still be turned and zoomed. */
.attract { position: fixed; left: 0; right: 0; bottom: calc(36px + var(--safe-b)); z-index: 8; display: flex; justify-content: center; pointer-events: none; }
.attract[hidden] { display: none; }
.attract-inner { text-align: center; padding: 14px 26px; border-radius: 18px; background: rgba(10,10,12,0.5); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: breathe 3.2s ease-in-out infinite; max-width: min(560px, 90vw); }
.attract-title { font: 600 24px/1.2 var(--sans); letter-spacing: -0.015em; color: #e3e7ec; }
.attract-sub { font: 400 15px/1.45 var(--sans); color: var(--muted); margin-top: 4px; }
#dock, .corner, #toast { transition: opacity 0.5s ease; }
body.idle #dock, body.idle .corner, body.idle #toast, body.idle #expert, body.idle .edge-tab, body.idle #labelCard {
  opacity: 0; pointer-events: none !important;
}
body.idle .topdrawer-body, body.idle .top-tab, body.idle .drawer * { pointer-events: none !important; }
/* After a quiet spell the controls dim so the specimen stands out; any touch restores them. */
#dock, .corner, #expert, .edge-tab, #labelCard { transition: opacity 1.2s ease, transform 0.35s ease, left 0.35s ease, right 0.35s ease; }
body.quiet #dock, body.quiet .corner, body.quiet #expert, body.quiet .edge-tab { opacity: 0.3; }
body.quiet #labelCard { opacity: 0.55; }
.corner .round svg { display: block; margin: auto; }
@keyframes breathe { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }

dialog#about { max-width: 760px; width: calc(100% - 32px); max-height: calc(100% - 48px); padding: 0; border: 1px solid var(--line); border-radius: 20px; background: var(--panel-solid); color: var(--text); overscroll-behavior: contain; }
dialog::backdrop { background: rgba(0,0,0,0.65); }
.about-body { padding: 24px 32px 30px; font-size: 16px; line-height: 1.6; color: #d0d5dc; user-select: text; -webkit-user-select: text; }
.about-body h2 { font: 600 26px var(--sans); letter-spacing: -0.02em; margin: 0 0 8px; color: #eef1f5; }
.about-body h3 { font: 600 17px var(--sans); margin: 18px 0 4px; color: var(--accent); }
.about-body ul { padding-left: 20px; }
.about-body .small { color: var(--muted); font-size: 14px; }
dialog .close { position: sticky; top: 12px; float: right; margin: 12px 12px 0 0; }

.toast { position: fixed; left: 50%; top: 92px; transform: translateX(-50%); z-index: 7; background: rgba(18,18,22,0.92); border: 1px solid var(--line); padding: 12px 20px; border-radius: 14px; color: var(--text); font: 15px/1.45 var(--sans); max-width: min(620px, 90vw); text-align: center; }
.loading { position: fixed; inset: 0; display: grid; place-items: center; font: 500 18px var(--sans); color: var(--muted); z-index: 10; background: var(--bg); transition: opacity 0.8s; }
.loading.done { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity 0.8s, visibility 0s 0.8s; }

/* Docked lab panel on wide screens. */
@media (min-width: 821px) and (min-height: 561px) {
  .drawer { top: 16px; bottom: calc(var(--dock-h, 170px) + 16px); width: 360px; z-index: 3; }
  body.lab-open .topdrawer { left: 392px; right: 96px; }
  .topdrawer { right: 96px; }

}

/* ---------- smaller and portrait screens ---------- */
@media (max-width: 1100px) {
  .ev-buttons button { padding: 0 10px; }
}
@media (max-width: 820px), (max-height: 560px) {
  :root { --tap: 46px; }
  .topdrawer { left: 8px; right: 8px; }
  .museum { grid-template-columns: 1fr; max-height: 40vh; }
  .museum { padding: 12px 14px; }
  .museum .mname { font-size: 19px; }
  .museum .story { font-size: 13.5px; }
  .drawer { width: auto; right: 16px; }
  .edge-tab { min-height: 120px; width: 40px; }
  .dock-row { gap: 8px; }
  .clock { flex-basis: 120px; min-width: 120px; }
  .tools { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 10px; padding-bottom: 2px; }
  .tools::-webkit-scrollbar { display: none; }
  .ev-buttons, .seg { flex-wrap: nowrap; }
  .tools button { white-space: nowrap; }
  .play { width: 56px; height: 56px; }
  #dock { padding: 10px 10px 6px; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); }
  #clock { font-size: 21px; }
  .tile { flex-basis: 128px; min-height: 54px; }
  .group-label { display: none; }
  #chart { height: 40px; }
  .attract-title { font-size: 20px; }
}

/* ---------- short landscape screens (phones on their side) ---------- */
/* Height is the scarce dimension: one slim dock, labels collapsed until asked for,
   and the fluid panel as a side sheet rather than full width. */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --tap: 40px; }
  #dock {
    left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right));
    bottom: calc(6px + var(--safe-b)); padding: 6px 8px; border-radius: 14px;
  }
  .deposits { padding-bottom: 6px; gap: 6px; }
  .tile { flex: 0 0 auto; min-height: 34px; padding: 4px 12px 4px 14px; border-radius: 10px; }
  .tile .t-name { font-size: 13px; white-space: nowrap; }
  .tile .t-place { display: none; }
  .tile::before { top: 7px; bottom: 7px; }
  .dock-row { flex-wrap: nowrap; gap: 8px; }
  .play { width: 42px; height: 42px; font-size: 15px; }
  .ghost { font-size: 18px; }
  .clock { flex: 0 0 auto; min-width: 0; }
  #clock { font-size: 17px; }
  .stage { font-size: 11.5px; min-height: 0; white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
  .next, #chart { display: none; }
  .tools { flex: 1 1 auto; min-width: 0; }
  .tools button { padding: 0 10px; font-size: 13px; }
  .seg button { min-width: 40px; }

  .corner { top: 8px; right: max(8px, env(safe-area-inset-right)); gap: 6px; }
  .topdrawer { left: calc(52px + env(safe-area-inset-left)); right: calc(150px + env(safe-area-inset-right)); }
  .topdrawer-body { padding-top: 8px; }
  .museum { grid-template-columns: 1fr 1fr; max-height: 58vh; padding: 10px 52px 10px 14px; gap: 4px 18px; }
  .museum .mname { font-size: 17px; }
  .museum .story, .museum .note { font-size: 12.5px; }
  .museum table { font-size: 12px; }

  .drawer { left: max(8px, env(safe-area-inset-left)); right: auto; width: min(340px, 70vw); top: 8px; bottom: 8px; padding: 0 14px 14px; }
  .edge-tab { left: env(safe-area-inset-left); min-height: 100px; width: 36px; top: calc((100% - var(--dock-h, 110px)) / 2); }
  body.lab-open .edge-tab { opacity: 0; pointer-events: none; }

  .attract { bottom: calc(14px + var(--safe-b)); }
  .attract-inner { padding: 8px 18px; }
  .attract-title { font-size: 17px; }
  .attract-sub { font-size: 12.5px; }
  .toast { top: 54px; font-size: 13px; padding: 8px 14px; }
}
