:root {
  --table: #0f5157;
  --paper: #fbf6ea;
  --ink: #26211c;
  --gold: #f0b21c;
  --red: #e0412f;
  --round: "Nunito", "Varela Round", ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  font-family: var(--round);
  color: var(--paper);
  background: var(--table);
  transition: background-color .5s;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
/* a game screen: repeated taps must never select or highlight anything */
.game { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; }
#board { -webkit-tap-highlight-color: transparent; }
body { background: radial-gradient(ellipse 90% 70% at 50% 45%, rgba(255,255,255,.09), transparent 70%), var(--table); transition: background-color .5s; }
.game { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr auto; height: 100dvh; max-width: 1100px; margin: 0 auto; }

.bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px 4px; }
.where { flex: 1; text-align: center; min-width: 0; }
h1 { margin: 0; font-size: .78rem; font-weight: 700; letter-spacing: .02em; opacity: .7; }
.where p { margin: 0; font-size: 1.25rem; font-weight: 800; white-space: nowrap; }
#level-num { font-weight: 600; opacity: .75; font-size: .95rem; margin-left: 4px; }
.cue { margin: 2px auto 0; padding: 0 16px; max-width: 40rem; text-align: center; font-size: .98rem; line-height: 1.35; min-height: 2.7em; }

button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px 6px 9px; border: 0; border-radius: 999px;
  background: rgba(255,255,255,.14); color: var(--paper); font-weight: 700; font-size: .92rem; }
.chip:hover { background: rgba(255,255,255,.22); }
.chip svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.table { position: relative; min-height: 0; }
#board:focus { outline: none; }
#board:focus-visible { outline: 3px solid rgba(240,178,28,.5); outline-offset: -3px; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; }

.result { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); width: min(92%, 25rem); padding: 12px 14px 12px; border-radius: 16px;
  background: var(--paper); color: var(--ink); box-shadow: 0 6px 0 rgba(0,0,0,.25), 0 14px 30px rgba(0,0,0,.25); text-align: center;
  animation: pop .35s cubic-bezier(.2,1.6,.4,1); }
.result strong { font-size: 1.35rem; font-weight: 900; }
.result[data-ok="yes"] strong { color: #1b7d55; }
.result[data-ok="no"] strong { color: var(--red); }
.result p { margin: 4px 0 10px; line-height: 1.35; font-size: .95rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px 8px; justify-content: center; }
@keyframes pop { from { transform: translate(-50%, 8px) scale(.85); opacity: 0; } }

.push { min-height: 46px; padding: 8px 20px; border: 0; border-radius: 14px; background: var(--gold); color: var(--ink); font-weight: 900; font-size: 1.05rem;
  box-shadow: 0 5px 0 #a8770a; transform: translateY(0); transition: transform .06s, box-shadow .06s; }
.push:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #a8770a; }
.push:disabled { background: rgba(255,255,255,.18); color: rgba(251,246,234,.55); box-shadow: 0 5px 0 rgba(0,0,0,.18); cursor: default; }
.push.ghost { background: #e9dfc8; box-shadow: 0 5px 0 #b3a586; }
.push.big { min-width: 118px; font-size: 1.2rem; }

.deck { padding: 6px 12px max(12px, env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.tray { display: flex; align-items: center; gap: 8px; min-height: 48px; justify-content: center; flex-wrap: wrap; }
.tray-label { font-weight: 800; font-size: .9rem; opacity: .85; }
.piece { width: 68px; height: 46px; padding: 0; border: 0; border-radius: 10px; background: var(--paper); box-shadow: 0 4px 0 rgba(0,0,0,.3); transition: transform .08s; }
.piece canvas { display: block; width: 100%; height: 100%; pointer-events: none; }
.piece[data-used="yes"] { background: rgba(251,246,234,.45); box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.piece[data-used="yes"] canvas { opacity: .55; }
.piece:disabled { cursor: default; }
.piece[aria-pressed="true"] { background: #fff; transform: translateY(-4px); box-shadow: 0 0 0 4px var(--gold), 0 8px 0 rgba(0,0,0,.3); }
#viewbar { gap: 10px 8px; padding-bottom: 5px; }
#viewbar .push { min-height: 42px; padding: 6px 14px; font-size: .95rem; }
#viewbar .push:disabled { background: rgba(255,255,255,.18); color: rgba(251,246,234,.6); box-shadow: 0 5px 0 rgba(0,0,0,.18); }
.play { display: flex; align-items: center; gap: 12px; padding-left: 104px; }
.scrub { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.scrub label { font-weight: 800; font-size: .9rem; }
.scrub[data-locked="yes"] { opacity: .45; }
#scrub { flex: 1; min-width: 0; accent-color: var(--gold); height: 30px; }
.steps { display: flex; gap: 4px; }
.steps button { min-height: 40px; padding: 4px 10px; border-radius: 10px; border: 0; background: rgba(255,255,255,.15); color: var(--paper); font-weight: 800; }
.steps button[aria-pressed="true"] { background: var(--paper); color: var(--ink); }

.levels { position: fixed; inset: 0; background: rgba(10,12,16,.6); display: grid; place-items: center; padding: 12px; z-index: 5; }
.levels-card { width: min(100%, 44rem); max-height: 100%; overflow: auto; background: #1b1d24; border-radius: 20px; padding: 14px 16px 18px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.levels-head { display: flex; align-items: center; gap: 12px; position: sticky; top: -14px; background: #1b1d24; padding: 4px 0 8px; }
.levels-head h2 { margin: 0; font-size: 1.4rem; font-weight: 900; }
.levels-head p { flex: 1; margin: 0; opacity: .75; font-size: .9rem; }
#level-list section { background: var(--table); border-radius: 14px; padding: 8px 10px 10px; margin-top: 10px; }
#level-list h3 { margin: 0 0 6px; font-size: 1rem; font-weight: 800; }
.level-row { display: flex; flex-wrap: wrap; gap: 8px; }
.level-row button { position: relative; display: grid; place-items: center; width: 86px; height: 70px; border: 0; border-radius: 12px; background: rgba(0,0,0,.22); color: var(--paper); padding: 4px; }
.level-row button canvas { width: 72px; height: 52px; }
.level-row button span { position: absolute; left: 6px; top: 3px; font-weight: 900; font-size: .85rem; }
.level-row button[aria-current] { outline: 3px solid var(--paper); }
.level-row button[data-state="solved"]::after, .level-row button[data-state="helped"]::after, .level-row button[data-state="gold"]::after { content: ""; position: absolute; right: -4px; top: -4px; width: 20px; height: 20px; border-radius: 50%;
  background: #6fc49a; box-shadow: 0 0 0 3px #1b1d24; }
.level-row button[data-state="gold"]::after { background: var(--gold); }
.level-row button[data-state="helped"]::after { background: #1b1d24; border: 3px solid #6fc49a; }

@media (max-width: 560px) {
  .result { padding: 10px 10px; }
  .result p { margin: 2px 0 8px; font-size: .88rem; }
  .result .push { min-height: 40px; padding: 6px 12px; font-size: .95rem; }
  .bar { padding: 8px 8px 2px; gap: 6px; }
  .chip { padding: 6px 10px 6px 8px; font-size: .85rem; }
  .where p { font-size: 1.05rem; }
  .cue { font-size: .9rem; }
  .play { padding-left: 0; flex-wrap: wrap; }
  .scrub { order: 2; flex-basis: 100%; padding-left: 100px; }
  .push.big { order: 1; flex: 1; }
}
@media (max-width: 370px) {
  h1 { display: none; }
  .chip { font-size: .8rem; padding: 5px 9px 5px 7px; gap: 4px; min-height: 38px; }
  .chip svg { width: 17px; height: 17px; }
  .where p { white-space: normal; font-size: .95rem; line-height: 1.15; }
  #level-num { display: block; margin: 0; font-size: .8rem; }
  .cue { font-size: .85rem; padding: 0 10px; }
  .tray .tray-label { flex-basis: 100%; text-align: center; }
  .tray { gap: 6px; }
  #viewbar { gap: 9px 6px; }
  #viewbar .push { padding: 6px 9px; font-size: .85rem; }
  .scrub:has(.steps:not([hidden])) label { display: none; }
  .steps button { padding: 4px 8px; font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
