/* ============================================================
   Game shell + shared game-surface primitives
   ============================================================ */

.gameshell {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: minmax(0, 1fr);
  max-width: 1180px;
  margin-inline: auto;
}
@media (min-width: 1000px) {
  .gameshell--sidebar { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .gameshell--sidebar .gs-side { position: sticky; top: 84px; }
}

.gs-head {
  display: flex; align-items: flex-start; gap: var(--sp-4);
  flex-wrap: wrap;
  grid-column: 1 / -1;
}
.gs-head h1 { font-size: var(--fs-2xl); margin: 0 0 var(--sp-1); }
.gs-objective { color: var(--text-muted); margin: 0; max-width: 68ch; font-size: var(--fs-md); }
html[data-band="early"] .gs-objective, html[data-band="junior"] .gs-objective { color: var(--text); }

.gs-progress { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.gs-pip {
  width: 26px; height: 6px; border-radius: var(--r-pill);
  background: var(--surface-3);
  transition: background var(--dur-2) var(--ease);
}
.gs-pip[data-state="done"]    { background: var(--success); }
.gs-pip[data-state="current"] { background: var(--accent); box-shadow: 0 0 0 3px var(--beam-soft); }

.gs-stage {
  position: relative;
  min-height: 260px;
  padding: calc(var(--sp-5) * var(--density));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.gs-stage.is-wrong { animation: cb-shake 420ms var(--ease); }

.gs-side { display: flex; flex-direction: column; gap: var(--sp-3); }
.gs-toolbar {
  display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center;
  grid-column: 1 / -1;
}

/* ---------- Hints ------------------------------------------- */
.hint {
  display: flex; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--solar-soft);
  border: 1px solid #ffc85742;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  animation: cb-fade-up var(--dur-2) var(--ease-out) both;
}
.hint-index {
  flex: 0 0 auto; font-weight: 800; color: var(--warning);
  font-variant-numeric: tabular-nums;
}

/* ---------- Result / explanation ---------------------------- */
.result {
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  padding: calc(var(--sp-5) * var(--density));
  background: var(--surface-2);
  animation: cb-fade-up var(--dur-3) var(--ease-spring) both;
}
.result--win  { border-color: #5fe3a15c; background: linear-gradient(180deg, var(--lime-soft), transparent 70%), var(--surface-2); }
.result--miss { border-color: #ff6b7a52; background: linear-gradient(180deg, var(--flare-soft), transparent 70%), var(--surface-2); }
.result-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.result-head h2 { margin: 0; font-size: var(--fs-xl); }
.result-icon { width: 34px; height: 34px; flex: 0 0 auto; }
.result--win .result-icon { color: var(--success); }
.result--miss .result-icon { color: var(--danger); }
.result dl { margin: 0; display: grid; gap: var(--sp-3); }
.result dt {
  font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-dim); font-weight: 700; margin-bottom: 2px;
}
.result dd { margin: 0; font-size: var(--fs-sm); color: var(--text); }
.result-xp {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--solar-soft); color: var(--warning);
  font-weight: 800; font-variant-numeric: tabular-nums;
}

/* ---------- Generic playfield ------------------------------- */
.playfield { display: grid; gap: var(--sp-4); }
.play-grid {
  display: grid;
  gap: 4px;
  justify-content: center;
  margin-inline: auto;
}
.play-cell {
  position: relative;
  display: grid; place-items: center;
  aspect-ratio: 1;
  border-radius: var(--r-xs);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  font-size: 1.4rem;
}
.play-cell[data-kind="wall"]   { background: var(--hull-500); border-color: var(--hull-400); }
.play-cell[data-kind="goal"]   { background: var(--lime-soft); border-color: #5fe3a163; }
.play-cell[data-kind="hazard"] { background: var(--flare-soft); border-color: #ff6b7a63; }
.play-cell[data-kind="item"]   { background: var(--solar-soft); border-color: #ffc85763; }
.play-actor {
  position: absolute; inset: 8%;
  display: grid; place-items: center;
  transition: transform var(--dur-3) var(--ease-out);
}

/* ---------- Card / token buttons ---------------------------- */
.token {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  min-height: var(--hit); min-width: var(--hit);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  border: 2px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700; font-size: var(--fs-sm);
  transition: transform var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              background var(--dur-1) var(--ease);
}
.token:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); }
.token[aria-pressed="true"], .token.is-selected {
  border-color: var(--accent);
  background: var(--beam-soft);
  box-shadow: 0 0 0 3px var(--beam-soft);
}
.token.is-correct { border-color: var(--success); background: var(--lime-soft); }
.token.is-wrong   { border-color: var(--danger); background: var(--flare-soft); animation: cb-shake 400ms var(--ease); }
.token:disabled { opacity: 0.5; }
.token--big { font-size: clamp(1.9rem, 8vw, 3rem); min-height: 96px; min-width: 96px; padding: var(--sp-3); }
.token--wide { width: 100%; justify-content: flex-start; }

.token-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: center; }

/* ---------- Sequence slots ---------------------------------- */
.slots {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  min-height: calc(var(--hit) + var(--sp-4));
  padding: var(--sp-3);
  background: var(--surface-sunken);
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-md);
  align-items: center;
}
.slots:empty::after {
  content: attr(data-placeholder);
  color: var(--text-dim); font-size: var(--fs-sm); padding: 0 var(--sp-2);
}
.slot-item {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  min-height: calc(var(--hit) - 6px);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  font-weight: 700; font-size: var(--fs-sm);
  animation: cb-pop var(--dur-2) var(--ease-spring) both;
}
.slot-item[data-active="true"] {
  border-color: var(--accent); background: var(--beam-soft);
  box-shadow: 0 0 0 3px var(--beam-soft);
}
.slot-item.is-fail { border-color: var(--danger); background: var(--flare-soft); }

/* ---------- Orderable list (keyboard-first) ----------------- */
.orderable { display: flex; flex-direction: column; gap: var(--sp-2); list-style: none; padding: 0; margin: 0; }
.orderable li { margin: 0; }
.order-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  min-height: var(--hit);
  text-align: left;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  white-space: pre;
  overflow-x: auto;
}
.order-item[aria-grabbed="true"], .order-item.is-lifted {
  border-color: var(--accent); background: var(--beam-soft);
  box-shadow: var(--shadow-2);
}
.order-handle { flex: 0 0 auto; color: var(--text-dim); font-family: var(--font-ui); }
.order-index {
  flex: 0 0 auto; width: 1.6em; text-align: right;
  color: var(--text-dim); font-variant-numeric: tabular-nums;
}
.order-move { display: flex; flex-direction: column; gap: 2px; margin-left: auto; flex: 0 0 auto; }
.order-move button {
  width: 30px; height: 21px; padding: 0;
  border: 1px solid var(--border); border-radius: var(--r-xs);
  background: var(--surface-3); color: var(--text-muted);
  display: grid; place-items: center;
}
.order-move button:hover:not(:disabled) { background: var(--accent); color: var(--accent-contrast); }
.order-move svg { width: 13px; height: 13px; }

/* ---------- Selectable code lines --------------------------- */
.codepick { display: flex; flex-direction: column; gap: 2px; }
.codepick-line {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  width: 100%; text-align: left;
  padding: var(--sp-1) var(--sp-2);
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  background: transparent;
  font-family: var(--font-mono); font-size: var(--fs-sm);
  line-height: 1.7;
  white-space: pre;
  overflow-x: auto;
  color: var(--text);
}
.codepick-line:hover { background: var(--surface-2); border-color: var(--border); }
.codepick-line[aria-pressed="true"] { background: var(--beam-soft); border-color: var(--accent); }
.codepick-line.is-correct { background: var(--lime-soft); border-color: var(--success); }
.codepick-line.is-wrong   { background: var(--flare-soft); border-color: var(--danger); }

/* ---------- Console / output -------------------------------- */
.console {
  padding: var(--sp-3) var(--sp-4);
  background: #04070e;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.65;
  color: #cfe3ff;
  min-height: 76px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
html[data-theme="light"] .console { background: #0b1220; color: #dfeaff; }
.console .err { color: #ff9aa5; }
.console .ok  { color: #8ef0be; }
.console .dimline { color: #7a8aa8; }

/* ---------- Data table (SQL etc.) --------------------------- */
.datatable-wrap {
  overflow: auto; max-height: 320px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-sunken);
}
.datatable { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: var(--fs-2xs); }
.datatable th, .datatable td { padding: 6px var(--sp-3); border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.datatable thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-3); color: var(--text);
  font-weight: 700;
}
.datatable tbody tr:nth-child(even) { background: #ffffff06; }
html[data-theme="light"] .datatable tbody tr:nth-child(even) { background: #0d17300a; }

/* ---------- Diagram surfaces (git, network, trees) ---------- */
.diagram {
  width: 100%;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: auto;
}
.diagram svg { width: 100%; height: auto; display: block; }
.node-circle { fill: var(--surface-3); stroke: var(--border-strong); stroke-width: 2; }
.node-circle.is-active { fill: var(--beam-soft); stroke: var(--accent); }
.node-circle.is-done   { fill: var(--lime-soft); stroke: var(--success); }
.node-circle.is-fail   { fill: var(--flare-soft); stroke: var(--danger); }
.node-label { fill: var(--text); font-family: var(--font-mono); font-size: 12px; text-anchor: middle; dominant-baseline: middle; }
.edge-line { stroke: var(--hull-400); stroke-width: 2; fill: none; }
.edge-line.is-active { stroke: var(--accent); stroke-width: 3; }
.edge-label { fill: var(--text-dim); font-size: 10px; text-anchor: middle; font-family: var(--font-mono); }

/* ---------- Live preview iframe ----------------------------- */
.preview-frame {
  width: 100%; min-height: 240px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: #fff;
}

/* ---------- Editor ------------------------------------------ */
.editor {
  width: 100%;
  min-height: 190px;
  padding: var(--sp-3);
  background: var(--surface-sunken);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.7;
  tab-size: 2;
  resize: vertical;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}
.editor:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--beam-soft); }

/* ---------- Evidence panels (production panic) -------------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab {
  padding: var(--sp-2) var(--sp-3); min-height: 40px;
  border: 0; border-bottom: 2px solid transparent;
  background: transparent; color: var(--text-muted);
  font-size: var(--fs-2xs); font-weight: 700;
  border-radius: var(--r-xs) var(--r-xs) 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabpanel { padding-top: var(--sp-4); }

/* ---------- Sliders / budget bars --------------------------- */
.budget {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  flex-wrap: wrap;
}
.budget-metric { flex: 1 1 130px; min-width: 130px; }
.budget-metric .stat-label { margin-bottom: 4px; }

/* ---------- Speech / read-aloud button ---------------------- */
.speak-btn { color: var(--text-muted); }
.speak-btn.is-speaking { color: var(--accent); animation: cb-pulse 1.2s ease-in-out infinite; }

/* ---------- Confetti-free celebration ----------------------- */
.celebrate { position: relative; }
.celebrate::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: inherit;
  border: 2px solid var(--success);
  opacity: 0;
  animation: cb-ripple var(--dur-4) var(--ease-out) 2 both;
  pointer-events: none;
}
@keyframes cb-ripple {
  from { opacity: 0.9; transform: scale(0.97); }
  to   { opacity: 0; transform: scale(1.05); }
}
