/* Base layout, tokens, shared controls, game/title/settings screens and overlays.
   Board cells and chain tracing live in board.css; orders, station, album and
   overlay content live in screens.css. */

:root {
  --bg: #0E1424;
  --surface: #151D33;
  --surface-2: #1B2440;
  --board: #121A2E;
  --cell: #1A2238;
  --border: #2A3654;
  --text: #E8ECF5;
  --text-2: #C3CCE0;
  --muted: #9AA6C2;
  --faint: #8B97B3;
  --accent: #FF8A3D;
  --gold: #FFD166;
  --teal: #6EE7C8;
  --danger: #FF7A7A;
  --track-off: #222C47;
  --disabled: #3A4566;

  --cols: 6;
  --rows: 7;

  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body.locked { overflow: hidden; }

[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
/* Headings and screen starts get programmatic focus for screen readers only. */
[tabindex="-1"]:focus { outline: none; }

.app { min-height: 100dvh; }

/* ---------- typography ---------- */

.eyebrow {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 600;
}

.h1 {
  margin: 0;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 700;
  font-size: 22px;
  line-height: 1.2;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- screens ---------- */

.screen {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5dvh, 14px);
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  padding:
    calc(14px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(14px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

/* Sections whose inner wrapper (screens.js) already handles padding. */
.screen-flush {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.spacer { flex: 1 1 0; min-height: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

/* ---------- buttons ---------- */

.btn {
  min-height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 16px;
  font: 700 16px Inter, system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
}
.btn.primary { background: var(--accent); color: #0E1424; }
.btn.secondary { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--danger); color: #0E1424; }
.btn.big { height: 60px; min-height: 60px; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn:disabled { background: var(--disabled); color: var(--text-2); cursor: default; }
.btn.secondary:disabled { border-color: var(--disabled); }

.btn-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.muted-on-btn { font-size: 13px; font-weight: 600; opacity: .8; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  padding: 0;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
[data-icon] { display: inline-flex; line-height: 0; }

/* ---------- game screen ---------- */

/* The game screen is exactly one viewport tall: every fixed row takes its own
   height and the board area takes what is left, so the page never scrolls. */
.screen-game {
  height: 100dvh;
  min-height: 0;
  gap: clamp(6px, 1.4dvh, 12px);
}
.screen-game > * { flex: none; }
.screen-game > .spacer { display: none; }
.screen-game > .board-wrap { flex: 1 1 0; min-height: 0; }

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 44px;
}
.game-title { min-width: 0; flex: 1; }
.game-title .h1 {
  font-size: clamp(18px, 5.4vw, 22px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }

.stat-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.stat-row .card { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.progress-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  font-weight: 600;
}
.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--track-off);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--teal);
  border-radius: 4px;
  transition: width .3s ease;
}

.energy-pill {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 15px;
}
.energy-col { display: flex; flex-direction: column; line-height: 1.1; }
.energy-timer {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

/* Top order card (the chain panel covers it while tracing). */
.top-area { position: relative; }
.top-order {
  width: 100%;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  position: relative;
}
.top-order.ready { border-color: var(--accent); }
/* Eyebrow on the first line; chips and title share the second line. */
.top-order-main {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "eyebrow eyebrow"
    "chips title";
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
}
.top-order-main .eyebrow { grid-area: eyebrow; display: block; line-height: 14px; }
.top-order-chips { grid-area: chips; display: flex; flex-wrap: nowrap; gap: 6px; }
.top-order-title {
  grid-area: title;
  min-width: 0;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-order-side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
}
.top-order-count { color: var(--muted); }
.ready-text { color: var(--accent); }
.inline-btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--accent);
  color: #0E1424;
  font-weight: 700;
  font-size: 14px;
}
.order-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--gold);
  color: #0E1424;
  border: 2px solid var(--bg);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The ladder panel over the order card while tracing is styled in board.css. */

/* The board area fills the leftover height; the board is the largest square-celled
   grid that fits in it (width or height bound), centred. */
.board-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
  min-height: 0;
}
.board-wrap > .board {
  width: min(100cqw, calc(100cqh * var(--cols) / var(--rows)));
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 8px;
  font-size: 12px;
  color: var(--text-2);
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.legend-item.locked { color: var(--muted); }
.legend-sep { color: #5C6888; }
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}
.swatch-lock {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--muted);
  color: var(--muted);
}

.spawn-note {
  margin: 0;
  height: 18px;
  line-height: 18px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-height: 700px) {
  .screen-game { gap: 8px; }
  .legend { display: none; }
}

/* ---------- tutorial bubble ---------- */

.tutorial {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}
.tip {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--gold);
  border-radius: 14px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  pointer-events: none;
}
.tip-text { margin: 0; }
.tip-art { display: block; width: 100%; height: auto; }
.tip .btn { align-self: flex-end; pointer-events: auto; }
.float.energy { color: var(--teal); }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 60;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- overlay root (content styled by screens.css) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 15, 28, .92);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Centred when the card is short, top-aligned and scrollable when it is tall. */
  justify-content: safe center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}
.overlay > * {
  flex: none;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}
/* screens.css stretches overlay screens to full height; let them size to their content. */
.overlay > .overlay-screen { min-height: 0; }

/* ---------- title screen ---------- */

.screen-title {
  align-items: center;
  text-align: center;
  padding-top: calc(clamp(24px, 8dvh, 64px) + env(safe-area-inset-top));
}
.title-art { width: 100%; display: flex; justify-content: center; }
.title-art svg { width: min(300px, 80vw); height: auto; display: block; }
.title-art .orbiting {
  transform-box: view-box;
  transform-origin: 150px 130px;
  animation: orbit 60s linear infinite;
}
@keyframes orbit { to { transform: rotate(360deg); } }

.title-text { display: flex; flex-direction: column; gap: 8px; }
.eyebrow-accent {
  margin: 0;
  font-size: 12px;
  color: var(--accent);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 700;
}
.title-h1 {
  margin: 0;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(36px, 11vw, 44px);
  line-height: 1.02;
}
.title-lead {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.5;
}
.title-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.title-progress {
  margin: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 13px;
  color: var(--muted);
}
.credit {
  margin: 0;
  font-size: 12px;
  color: var(--faint);
}

/* ---------- settings screen ---------- */

.screen-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.screen-head .eyebrow { margin: 0 0 2px; }

.setting-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.setting-row {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.setting-note-row {
  padding: 4px 4px;
  font-size: 13px;
  color: var(--muted);
}
.setting-text { display: flex; flex-direction: column; min-width: 0; }
.setting-title { font-weight: 600; font-size: 15px; }
.setting-note { font-size: 12px; color: var(--muted); }

.switch {
  width: 60px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.switch .track {
  position: relative;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--track-off);
  transition: background .2s;
}
.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform .2s;
}
.switch[aria-checked="true"] .track {
  background: var(--teal);
  border-color: var(--teal);
}
.switch[aria-checked="true"] .knob {
  transform: translateX(20px);
  background: #0E1424;
}

.setting-actions { display: flex; flex-direction: column; gap: 10px; }

.confirm {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--danger);
  border-radius: 14px;
}
.confirm p { margin: 0; font-size: 14px; color: var(--text-2); }

.version {
  margin: auto 0 0;
  font-size: 12px;
  color: var(--faint);
  text-align: center;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .title-art .orbiting { animation: none; }
  .bar-fill,
  .toast,
  .switch .track,
  .switch .knob { transition: none; }
}
