/* INTERFACE LAYER — buttons, bars and cards over the 3D board.
   Layout: the board fills the screen; a top bar, a bottom dock and small cards float over it.
   One look on purpose (soft grey, never bright white). */
:root {
  --bg: #c3c9d1;          /* behind the 3D board */
  --panel: #dfe3e8;       /* bars and cards */
  --panel-2: #cfd5dc;     /* buttons */
  --line: #aab2bd;
  --ink: #222831;
  --ink-soft: #55606e;
  --accent: #2d6fe0;      /* selected / Learn & Build */
  --go: #23915a;          /* drop the marble */
  --danger: #c9463f;
  --gold: #b88700;
  --on-color: #f4f6f8;    /* text on colored buttons */
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --r: 14px;
  color-scheme: light;
}

html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

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

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

/* Buttons */
.btn {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--panel-2);
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 16px; min-height: 46px; cursor: pointer;
}
.btn.small { padding: 6px 12px; min-height: 40px; }
.btn.go { background: var(--go); border-color: var(--go); color: var(--on-color); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-color); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .big:focus-visible, .piece:focus-visible, .choice:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
select {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--panel-2);
  border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; min-height: 46px;
}

/* Top bar */
.bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding-block: calc(10px + env(safe-area-inset-top, 0px)) 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-bottom: 2px solid var(--line);
}
.group { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.field { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.seg { display: inline-flex; gap: 4px; }
.spacer { flex: 1 1 0; }
.mode-label { font-weight: 800; font-size: 18px; }
.chip { font-weight: 800; font-size: 14px; padding: 6px 12px; border-radius: 999px; background: var(--panel-2); border: 2px solid var(--line); }
.chip.gold { color: var(--gold); }
.pips { display: inline-flex; gap: 6px; }
.pip { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); background: var(--panel-2); }
.pip.done { background: var(--go); border-color: var(--go); }

/* Selected-piece tools */
.side {
  position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px; padding: 10px;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--r);
}

/* Bottom dock */
.dock {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding-block: 10px calc(10px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-top: 2px solid var(--line);
}
.palette-row { display: flex; gap: 10px; overflow-x: auto; justify-content: safe center; padding-bottom: 2px; }
.piece {
  flex: 0 0 auto; width: 92px; padding: 8px 4px 6px; font: inherit; font-size: 13px; font-weight: 800; color: var(--ink);
  background: var(--panel-2); border: 3px solid var(--line); border-radius: var(--r); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.piece svg { width: 44px; height: 44px; display: block; }
.piece.active { border-color: var(--accent); background: #c3d3ee; }

/* Question card */
.question { display: flex; flex-direction: column; gap: 10px; max-height: 62%; overflow-y: auto; }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.q-prompt { margin: 0; font-size: clamp(20px, 3.2vw, 30px); font-weight: 800; line-height: 1.3; white-space: pre-line; text-align: center; overflow-wrap: anywhere; }
.q-choices { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.choice {
  flex: 1 1 140px; max-width: 320px; min-height: 68px; padding: 10px 14px; font: inherit; font-size: clamp(20px, 3vw, 30px); font-weight: 800;
  color: var(--ink); background: var(--panel-2); border: 3px solid var(--line); border-radius: var(--r); cursor: pointer; overflow-wrap: anywhere;
}
.choice.right { background: var(--go); border-color: var(--go); color: var(--on-color); }
.choice.wrong { opacity: 0.35; text-decoration: line-through; }
.q-hint { margin: 0; text-align: center; font-weight: 700; color: var(--accent); font-size: 18px; }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Toast */
.toast {
  position: absolute; left: 50%; top: 96px; transform: translateX(-50%); max-width: min(560px, calc(100% - 32px));
  padding: 14px 20px; background: var(--ink); color: var(--on-color); font-weight: 800; font-size: 18px; border-radius: var(--r); text-align: center;
}

/* Overlays and cards */
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding-block: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: rgba(34, 40, 49, 0.45); overflow-y: auto;
}
#home.overlay { background: rgba(34, 40, 49, 0.25); }
.card {
  width: min(560px, 100%); background: var(--panel); border: 2px solid var(--line); border-radius: 22px; padding: 24px;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.card h2 { margin: 0; font-size: 30px; }
.card p { margin: 0; font-size: 18px; color: var(--ink-soft); }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.title { margin: 0; font-size: clamp(40px, 8vw, 64px); font-weight: 900; letter-spacing: -0.02em; }
.sub { margin: 0; color: var(--ink-soft); font-size: 18px; }
.home-buttons { display: flex; flex-wrap: wrap; gap: 14px; }
.big {
  flex: 1 1 200px; min-height: 130px; padding: 18px; font: inherit; color: var(--on-color); background: var(--go);
  border: 0; border-radius: 18px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; justify-content: center;
}
.big.learn { background: var(--accent); }
.big strong { font-size: 26px; }
.big span { font-size: 15px; font-weight: 600; }
.home-foot { display: flex; justify-content: center; }
.home-foot .btn { font-size: 14px; position: relative; overflow: hidden; }
.home-foot .btn.holding::after { content: ""; position: absolute; left: 0; bottom: 0; height: 5px; width: 100%; background: var(--accent); transform-origin: left; animation: hold 1.2s linear; }
@keyframes hold { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.settings-card { width: min(680px, 100%); text-align: left; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 15px; min-width: 0; }
.grid label.check { flex-direction: row; align-items: center; gap: 10px; grid-column: 1 / -1; }
.grid input[type="checkbox"] { width: 24px; height: 24px; flex: 0 0 auto; }

@media (max-width: 1280px) { #topbar .mode-label { display: none; } .field { font-size: 13px; } .bar { gap: 8px; } .bar .btn { padding: 8px 12px; } }
@media (max-width: 640px) {
  .btn { padding: 8px 12px; min-height: 42px; }
  .field { font-size: 0; gap: 0; }
  .field > * { font-size: 14px; }
  select { padding: 6px 6px; min-height: 42px; max-width: 132px; }
  .mode-label { display: none; }
  .side { top: auto; bottom: 150px; transform: none; flex-direction: row; left: max(16px, env(safe-area-inset-left, 0px)); justify-content: center; }
  .toast { top: 170px; }
}
@media (prefers-reduced-motion: reduce) { .shake, .home-foot .btn.holding::after { animation: none; } }
