:root {
  color-scheme: light;
  --sky-top: #bfe6ff;
  --sky-bottom: #f1faff;
  --surface: #ffffff;
  --ink: #1d2a44;
  --ink-2: #44547a;
  --muted: #7a89a8;
  --line: rgba(29, 42, 68, 0.1);
  --line-strong: rgba(29, 42, 68, 0.2);
  --water: #0a8cff;
  --water-deep: #0062c4;
  --sun: #ffc933;
  --sun-deep: #d99a00;
  --grass: #5cc540;
  --lost: #ff5d73;
  --dig: #ff7a1a;
  --board-top: #c9ecff;
  --board-bottom: #effaff;
  --shadow: rgba(10, 60, 120, 0.14);
  --r: 18px;
  --rb: 14px;
  --round: Fredoka, Nunito, ui-rounded, system-ui, sans-serif;
  --sans: "Petrov Sans", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --sky-top: #0b1733;
    --sky-bottom: #0f1d3d;
    --surface: #17264a;
    --ink: #eef4ff;
    --ink-2: #c3d0ee;
    --muted: #8797bd;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.18);
    --water: #3aa8ff;
    --water-deep: #1a6fd1;
    --board-top: #1f3a73;
    --board-bottom: #142a57;
    --shadow: rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom) 420px) fixed;
  background-color: var(--sky-bottom);
  color: var(--ink);
  font: 500 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 600px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }

header { display: flex; justify-content: space-between; align-items: center; }
h1 {
  display: flex; align-items: center; gap: 6px; margin: 0;
  font: 700 clamp(2rem, 8vw, 2.5rem)/1 var(--round); letter-spacing: -0.01em; color: var(--water);
  text-shadow: 0 3px 0 var(--water-deep);
}
.logo { width: 0.9em; height: 0.9em; filter: drop-shadow(0 3px 0 var(--water-deep)); }
.logo path { fill: var(--water); }
.logo .shine { fill: rgba(255, 255, 255, 0.55); }
.sub { margin: 6px 0 0; color: var(--ink-2); font-size: 0.85rem; font-weight: 700; }
.header-buttons { display: flex; gap: 6px; }
.icon {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--sun); color: var(--ink); font: 700 1.2rem var(--round);
  box-shadow: 0 4px 0 var(--sun-deep);
}
.icon:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--sun-deep); }
.kicker { margin: 0; font: 600 0.8rem var(--round); letter-spacing: 0.08em; text-transform: uppercase; color: var(--water); }

.tries { list-style: none; display: flex; gap: 8px; padding: 0; margin: 18px 0 0; }
.tries li {
  flex: 1; text-align: center; font: 600 0.85rem var(--round);
  color: var(--muted); padding: 8px 0; border-radius: 999px;
  background: var(--surface); border: 2px dashed var(--line-strong);
}
.tries li b { font-weight: 700; }
.tries li.current { color: var(--water); border: 2px solid var(--water); }
.tries li.done { color: var(--ink-2); border: 2px solid var(--line-strong); }
.tries li.best { color: var(--ink); background: var(--sun); border: 2px solid var(--sun-deep); }
.tries li.best::before { content: "★ "; }

.board, .queue, .result {
  margin-top: 14px; background: var(--surface); border-radius: var(--r);
  box-shadow: 0 6px 0 var(--line), 0 10px 30px var(--shadow);
}
.board {
  padding: 12px 8px; position: relative;
  background: linear-gradient(180deg, var(--board-top), var(--board-bottom));
}
.readout { display: flex; justify-content: space-around; text-align: center; }
.readout > div {
  min-width: 84px; padding: 6px 10px; border-radius: var(--rb);
  background: color-mix(in srgb, var(--surface) 75%, transparent);
}
.readout span { display: block; font: 700 1.6rem/1.1 var(--round); }
.readout small { color: var(--muted); font: 600 0.72rem var(--round); letter-spacing: 0.06em; text-transform: uppercase; }
#held { color: var(--water); }
#spilled { color: var(--lost); }
canvas { display: block; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
canvas.grabbing { cursor: grabbing; }
.controls { display: flex; gap: 8px; padding: 0 4px; }
.controls button { flex: 1; }
.controls .primary { flex: 1.4; }
.toast { min-height: 1.4em; margin: 0 0 8px; text-align: center; color: var(--ink-2); font: 600 0.9rem var(--round); }

.primary, .secondary { border-radius: var(--rb); padding: 12px 14px; border: 0; font: 600 1rem var(--round); transition: transform 0.06s ease; }
.primary { background: var(--water); color: #fff; box-shadow: 0 5px 0 var(--water-deep); letter-spacing: 0.02em; }
.primary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--water-deep); }
.secondary { background: var(--surface); color: var(--ink); box-shadow: 0 5px 0 var(--line-strong), inset 0 0 0 2px var(--line-strong); }
.secondary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--line-strong), inset 0 0 0 2px var(--line-strong); }
.link {
  background: none; border: 0; color: var(--ink-2); font: 600 0.88rem var(--round); padding: 8px; display: block; margin: 6px auto 0;
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px;
}
.link:hover { color: var(--water); }

.queue { padding: 14px 14px 12px; }
.queue ol { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.queue li { display: flex; align-items: center; justify-content: center; height: 38px; min-width: 38px; border-radius: 12px; }
.queue li.piece { background: color-mix(in srgb, var(--grass) 14%, var(--surface)); padding: 0 6px; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--grass) 35%, transparent); }
.queue li.piece.dig { background: color-mix(in srgb, var(--dig) 14%, var(--surface)); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--dig) 35%, transparent); }
.queue li.piece.current { background: var(--sun); box-shadow: 0 3px 0 var(--sun-deep); transform: scale(1.12); }
.queue li.piece.used, .queue li.drop.used { opacity: 0.25; }
.queue li svg { display: block; }
.queue li svg rect { fill: var(--grass); }
.queue li.dig svg rect { fill: var(--dig); }
.queue li.piece.current svg rect { fill: #1d2a44; }
.queue li.drop { min-width: 0; padding: 0 9px; gap: 4px; background: var(--water); color: #fff; font: 700 0.95rem var(--round); border-radius: 999px; height: 30px; }
.queue li.drop svg path { fill: #fff; }

.result { padding: 20px 16px; text-align: center; }
.result .primary { width: 100%; margin-top: 10px; }
.score { margin: 6px 0 0; font: 700 4rem/1 var(--round); color: var(--water); text-shadow: 0 4px 0 var(--water-deep); }
.score small { font-size: 1.6rem; }
.verdict { margin: 12px 0 8px; color: var(--ink-2); font-weight: 600; }
.squares { margin: 6px 0 10px; letter-spacing: 1px; }
.note { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }
.footnote { margin: 6px 0 0; }

dialog {
  max-width: min(520px, calc(100vw - 32px)); border: 0; border-radius: var(--r); padding: 22px;
  background: var(--surface); color: var(--ink); box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(8, 30, 70, 0.5); }
dialog h2 { margin: 0 0 8px; font: 700 1.5rem var(--round); color: var(--water); }
dialog ol { padding-left: 20px; margin: 12px 0 16px; font-size: 0.92rem; }
dialog li { margin-bottom: 7px; }
dialog p { font-size: 0.92rem; margin: 0; }
dialog strong { font-weight: 800; }
dialog .primary { width: 100%; }
.dig { color: var(--dig); font-weight: 800; }

/* Wide screens: the board takes the window's width and height, with the
   tries, result and queue in a column beside it. Phones keep one column. */
@media (min-width: 900px) {
  main {
    max-width: none; padding-left: 24px; padding-right: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-areas: "head head" "board tries" "board result" "board queue" "board foot";
    grid-template-rows: auto auto auto auto 1fr;
    column-gap: 20px;
    align-items: start;
  }
  header { grid-area: head; }
  .tries { grid-area: tries; }
  .board { grid-area: board; }
  .result { grid-area: result; }
  .queue { grid-area: queue; }
  .footnote { grid-area: foot; }
  .controls { max-width: 600px; margin: 0 auto; }
}
