/* Cell Tycoon — shared UI shell */

:root {
  --bg: #0d1220;
  --bg-2: #131a2c;
  --panel: rgba(19, 26, 44, 0.92);
  --panel-solid: #131a2c;
  --line: rgba(255, 255, 255, 0.12);
  --ink: #e8edf7;
  --ink-dim: #9aa7c2;
  --ink-faint: #6d7a96;
  --accent: #4dd6a8;
  --accent-2: #ffb454;
  --accent-3: #7aa2ff;
  --danger: #ff7a7a;
  --radius: 14px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, select { font-family: inherit; }

/* ---------- layout ---------- */

#app { position: fixed; inset: 0; }
#app canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.loading {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg);
  color: var(--ink-dim);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 50;
  transition: opacity 0.5s;
}
.loading.gone { opacity: 0; pointer-events: none; }

/* ---------- top bar ---------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(13, 18, 32, 0.95), rgba(13, 18, 32, 0));
  pointer-events: none;
  z-index: 10;
}
.topbar > * { pointer-events: auto; }

.brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  flex: none;
}
.brand small {
  color: var(--ink-faint);
  font-weight: 500;
  font-size: 12px;
}

.spacer { flex: 1; }

/* ---------- station rail ---------- */

.rail {
  position: fixed;
  left: 0; right: 0;
  bottom: 76px;
  display: flex;
  gap: 6px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 10;
  scroll-padding: 16px;
}
.rail::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  border: 1px solid var(--line);
  background: rgba(19, 26, 44, 0.8);
  backdrop-filter: blur(8px);
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.chip:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.28); }
.chip .n {
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.55;
  margin-right: 6px;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231a;
}
.chip.active .n { opacity: 0.7; }
.chip.done { color: var(--ink); border-color: rgba(77, 214, 168, 0.4); }

/* ---------- transport controls ---------- */

.controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 14px;
  background: linear-gradient(to top, rgba(13, 18, 32, 0.96), rgba(13, 18, 32, 0));
  z-index: 11;
}

.btn {
  border: 1px solid var(--line);
  background: rgba(19, 26, 44, 0.85);
  backdrop-filter: blur(8px);
  color: var(--ink);
  border-radius: 10px;
  height: 38px;
  min-width: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover { background: rgba(38, 48, 74, 0.9); border-color: rgba(255, 255, 255, 0.26); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231a;
  min-width: 104px;
}
.btn.primary:hover { background: #63e6bb; border-color: #63e6bb; }
.btn[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}
.btn .ico { font-size: 14px; line-height: 1; }
.btn-label { display: inline; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  background: rgba(19, 26, 44, 0.85);
  backdrop-filter: blur(8px);
  border-radius: 10px;
  overflow: hidden;
  height: 38px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  padding: 0 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: rgba(122, 162, 255, 0.2); color: var(--ink); }

/* ---------- info panel ---------- */

.panel {
  position: fixed;
  top: 60px;
  right: 16px;
  width: 372px;
  max-height: calc(100vh - 200px);
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden auto;
  z-index: 12;
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.24s;
}
.panel.hidden { transform: translateX(calc(100% + 24px)); opacity: 0; pointer-events: none; }

.panel-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel-solid);
  z-index: 2;
}
.panel-kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.panel h2 {
  margin: 0 0 4px;
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -0.015em;
}
.panel .tagline {
  margin: 0;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.5;
}
.panel-body { padding: 14px 18px 18px; }

.panel-body h3 {
  margin: 16px 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}
.panel-body h3:first-child { margin-top: 0; }

.facts { margin: 0; padding: 0; list-style: none; }
.facts li {
  position: relative;
  padding: 0 0 0 16px;
  margin-bottom: 9px;
  font-size: 13.5px;
  line-height: 1.55;
  color: #cfd8ea;
}
.facts li::before {
  content: "";
  position: absolute;
  left: 2px; top: 8px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent-3);
}
.facts b, .facts strong { color: var(--ink); font-weight: 650; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
}
.stat .v {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-2);
  line-height: 1.2;
}
.stat .k {
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-top: 3px;
  line-height: 1.35;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cargo {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 180, 84, 0.09);
  border: 1px solid rgba(255, 180, 84, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}
.cargo .swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex: none;
  box-shadow: 0 0 10px currentColor;
}
.cargo .lbl { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.cargo .val { color: var(--ink); font-weight: 650; }

.note {
  margin-top: 16px;
  padding: 10px 12px;
  border-left: 2px solid var(--ink-faint);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-dim);
  border-radius: 0 8px 8px 0;
}
.note b { color: var(--ink); }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.07); }

.panel-head .row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- quiz ---------- */

.quiz-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 17, 0.72);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
  animation: fade 0.2s;
}
@keyframes fade { from { opacity: 0; } }

.quiz {
  width: min(520px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.quiz .kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 10px;
}
.quiz h3 { margin: 0 0 18px; font-size: 17px; line-height: 1.45; font-weight: 650; }

.answers { display: grid; gap: 9px; }
.answer {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--ink);
  border-radius: 11px;
  padding: 13px 15px;
  font-size: 13.5px;
  line-height: 1.45;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.answer:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.3); }
.answer:disabled { cursor: default; }
.answer.correct { border-color: var(--accent); background: rgba(77, 214, 168, 0.16); }
.answer.wrong { border-color: var(--danger); background: rgba(255, 122, 122, 0.14); }

.explain {
  margin-top: 16px;
  padding: 13px 15px;
  border-radius: 11px;
  background: rgba(122, 162, 255, 0.1);
  border: 1px solid rgba(122, 162, 255, 0.26);
  font-size: 13px;
  line-height: 1.6;
  color: #d3ddf2;
}
.explain b { color: #fff; }

.quiz-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
}
.score { font-size: 12px; color: var(--ink-faint); font-family: var(--mono); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: 68px;
  transform: translateX(-50%) translateY(-14px);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 25;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .panel {
    top: auto;
    left: 0; right: 0;
    /* Sits above the transport controls, never on top of them — pausing has to
       stay reachable while you are reading. */
    bottom: 64px;
    width: auto;
    max-height: 50vh;
    border-radius: 18px 18px 0 0;
    padding-bottom: 8px;
  }
  .panel.hidden { transform: translateY(calc(100% + 24px)); }
  .rail { bottom: 70px; }
  .controls { padding: 10px 12px 12px; gap: 6px; }
  .btn { height: 40px; padding: 0 10px; }
  .btn.primary { min-width: 44px; }
  .btn-label { display: none; }
  .seg { height: 40px; }
  .topbar { padding: 10px 12px; }
  .brand small { display: none; }
}

@media (max-width: 900px) {
  /* Only the station rail gets out of the way — the sheet sits where it was. */
  body.sheet-open .rail { opacity: 0; pointer-events: none; }
  body.sheet-open .controls {
    background: linear-gradient(to top, rgba(13, 18, 32, 1) 60%, rgba(13, 18, 32, 0.9));
  }
}

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