:root {
  color-scheme: light;
  --paper: #faf8ef;
  --ink: #776e65;
  --board: #bbada0;
  --button: #8f7a66;
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  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));
  background: var(--paper);
  color: var(--ink);
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
}
::selection { background: #edc22e; color: #3c3a32; }
.game {
  --board-size: min(500px, calc(100vw - 32px), calc(100vh - 192px));
  --board-size: min(500px, calc(100vw - 32px), calc(100dvh - 192px));
  width: var(--board-size);
  display: grid;
  gap: 12px;
}
.heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }
h1 { font-size: 72px; letter-spacing: -0.04em; line-height: 1; margin: 0; font-weight: 800; }
.scores { display: flex; gap: 8px; min-width: 0; }
.score-box { min-width: 76px; padding: 8px 12px; border-radius: 3px; background: var(--board); color: #fff; text-align: center; position: relative; }
.score-label { display: block; font-size: 11px; font-weight: 700; color: #eee4da; text-transform: uppercase; letter-spacing: 0.6px; }
.score-box strong { display: block; font-size: 24px; line-height: 1.25; font-variant-numeric: tabular-nums; }
#score-add { position: absolute; top: 35px; left: 0; width: 100%; z-index: 3; font-size: 24px; font-weight: 700; color: var(--ink); pointer-events: none; }
#score-add.animate { animation: score-rise 650ms ease-out both; }
@keyframes score-rise { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-55px); } }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }
.control-hint { margin: 0; font-size: 13px; line-height: 1.4; }
.swipe-hint { display: none; }
button { border: 0; border-radius: 3px; background: var(--button); color: #f9f6f2; font: inherit; font-size: 14px; font-weight: 700; padding: 10px 18px; min-height: 44px; cursor: pointer; transition: background 140ms, transform 140ms; touch-action: manipulation; }
button:hover { background: #7d6957; }
button:active { transform: translateY(1px); }
button:focus-visible, canvas:focus-visible { outline: 3px solid #edc22e; outline-offset: 3px; }
#restart { flex-shrink: 0; }
.board-wrap { width: var(--board-size); height: var(--board-size); position: relative; border-radius: 6px; overflow: hidden; background: var(--board); }
canvas { display: block; width: 100%; height: 100%; touch-action: none; -webkit-user-select: none; user-select: none; }
.overlay { position: absolute; inset: 0; z-index: 4; background: rgb(238 228 218 / 85%); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 16px; animation: overlay-in 240ms ease both; }
[hidden] { display: none !important; }
.overlay.won { background: rgb(237 194 46 / 78%); color: #f9f6f2; }
.overlay h2 { font-size: clamp(28px, 7vw, 48px); margin: 0 0 8px; letter-spacing: -0.03em; }
.overlay p { margin: 0 0 20px; font-size: 16px; line-height: 1.5; }
.overlay-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
.touch-controls { display: none; gap: 8px; }
.touch-controls button { flex: 1; min-width: 44px; padding: 6px; font-size: 22px; background: #e8e0d4; color: var(--ink); }
.touch-controls button:hover { background: #dcd0c0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@media (max-width: 560px), (pointer: coarse) {
  .game {
    --board-size: min(500px, calc(100vw - 32px), calc(100vh - 216px));
    --board-size: min(500px, calc(100vw - 32px), calc(100dvh - 216px));
  }
  h1 { font-size: 60px; }
  .score-box { min-width: 64px; padding: 7px 9px; }
  .score-box strong { font-size: 22px; }
  .keyboard-hint { display: none; }
  .swipe-hint { display: inline; }
  .touch-controls { display: flex; }
}
@media (max-width: 350px) {
  h1 { font-size: 52px; }
  .scores { gap: 5px; }
  .score-box { min-width: 58px; padding-inline: 7px; }
  button { padding-inline: 12px; }
}
/* Short, wide screens put controls beside the board, preserving its square. */
@media (max-height: 560px) and (min-aspect-ratio: 6/5) {
  .game {
    --board-size: min(500px, calc(100vh - 32px), calc(100vw - 268px));
    --board-size: min(500px, calc(100dvh - 32px), calc(100vw - 268px));
    width: auto;
    grid-template-columns: 212px var(--board-size);
    grid-template-rows: auto auto auto;
    column-gap: 24px;
    align-items: center;
  }
  .heading { flex-direction: column; gap: 16px; align-self: end; }
  h1 { font-size: 64px; }
  .toolbar { flex-direction: column; gap: 12px; }
  .board-wrap { grid-column: 2; grid-row: 1 / 4; }
  .touch-controls { align-self: start; }
  .overlay h2 { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
