:root {
  --ink: #292a26;
  --line: #d8d9cf;
  --game-margin: 20px;
}
#game {
  --game-width: 88vw;
  --board-ratio: calc(17 / 10);
  --width: min(var(--game-width), calc(var(--viewport-width, 100vw) - 2 * var(--game-margin)));
  container-type: inline-size;
}
@media (orientation: portrait) and (pointer: coarse) { #game { --board-ratio: calc(10 / 17); } }
#game.fit-board {
  --fitted-board-width: calc((100svh - var(--game-top, 11rem) - var(--game-margin) - var(--game-ui-height, 4rem)) * var(--board-ratio));
  --width: min(var(--game-width), calc(var(--viewport-width, 100vw) - 2 * var(--game-margin)), var(--spacing-width, 100vw) + 2px, max(320px, var(--fitted-board-width) + 2px));
}
button { font: inherit; cursor: pointer; }
.game-title { display: flex; align-items: center; gap: .32em; }
#apple-mark { width: .85em; height: .85em; object-fit: contain; flex: none; }
.game-screen { display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); gap: var(--space-sm); }
.game-toolbar { display: flex; align-items: center; gap: var(--space-md); }
.board-frame {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  box-sizing: border-box;
  width: var(--width);
  margin-inline: calc((100% - var(--width)) / 2);
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}
.game-actions { display: flex; align-items: stretch; gap: 8px; }
#round-button { flex-shrink: 0; min-width: 7.5rem; }
.scoreboard { display: flex; flex: 1; align-items: center; gap: 24px; }
.stat { display: flex; align-items: baseline; gap: 8px; }
.stat span { color: var(--text-grey-color); font-size: .875rem; }
.stat strong { font-family: var(--font-family-mono); font-size: 1.25rem; line-height: 1.2; }
.clock { margin-left: auto; }
.play-area { position: relative; isolation: isolate; background-color: #fffcf7; user-select: none; -webkit-user-select: none; }
#board-guides { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: -1; }
.play-area::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid #94a284;
  border-radius: 7px;
  box-shadow: 0 0 0 2px #e6eadf;
  pointer-events: none;
}
#orchard, #fruit-layer { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
#fruit-layer { pointer-events: none; }
[data-board-style="print"] .play-area { background-color: #faf7ef; --grid-dot: #e1d9c9; }
[data-board-style="cats"] .play-area { background-color: #f4eee4; --grid-dot: #ded7c9; }
:is([data-board-style="print"], [data-board-style="cats"]) .play-area::before {
  content: "";
  position: absolute;
  inset: var(--pad-y) var(--pad-x);
  background-image: radial-gradient(circle, var(--grid-dot) .8px, transparent 1.2px);
  background-size: var(--pitch-x) var(--pitch-y);
  background-position: calc(var(--pitch-x) / 2) calc(var(--pitch-y) / 2);
  pointer-events: none;
}
[data-board-style="print"] .play-area::after {
  border: 1px solid #ccbea7;
  border-top: 2px solid #a24c39;
  border-radius: 2px;
  box-shadow: none;
}
[data-board-style="cats"] .play-area::after { border-color: #ad9d84; box-shadow: 0 0 0 2px #e7dfd2; }
[data-board-style="rabbit"] .play-area {
  background-color: #efcbd8;
  --board-edge: #c48fa3;
}
[data-board-style="apple"] .play-area { background-color: #edf3e5; }
[data-board-style="blueberry"] .play-area { background-color: #f1f2f8; --board-edge: #acb6cd; }
[data-board-style="corgi"] .play-area { background-color: #f5f6ef; --board-edge: #bbb9ac; }
:is([data-board-style="rabbit"], [data-board-style="corgi"], [data-board-style="blueberry"]) .play-area::after { border-color: var(--board-edge); box-shadow: none; }
[data-board-style="cyanotype"] .play-area { background-color: #193e5f; --ink: #f0f4df; }
[data-board-style="cyanotype"] .play-area::after { inset: 1px; border-color: #42637a; border-radius: 4px; box-shadow: none; }
[data-board-style="go"] .play-area { background: linear-gradient(110deg, #eddbb9, #e4c99c); }
[data-board-style="go"] .play-area::after { border-color: #ac906b; box-shadow: 0 0 0 2px #dfc69c; }
.fit-board #fruit-layer { position: static; height: auto; aspect-ratio: var(--board-ratio); }
#orchard { touch-action: none; -webkit-tap-highlight-color: transparent; }
#orchard.live { cursor: crosshair; }
#countdown:not([hidden]) {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: var(--ink);
  font: 600 clamp(2rem, 5cqw, 3rem) / 1.15 var(--font-family-serif);
}
#orchard:focus { outline: none; }
.board-notes { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-block: var(--game-margin) 10px; }
.board-notes p { margin: 0; }
.theme-control { display: inline-flex; flex: none; align-items: center; gap: 7px; margin-left: auto; position: relative; }
.theme-control select { appearance: none; font: inherit; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 5px; padding: 4px 26px 4px 10px; cursor: pointer; }
.theme-control::after { content: ""; position: absolute; right: 10px; width: 5px; height: 5px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); pointer-events: none; }
#size-grip, .size-options button, #move-review button { color: var(--text-color); background: var(--main-bg-color); border: 1px solid var(--control-border-color); border-radius: var(--radius-control); padding: 5px 10px; }
#move-review:not([hidden]) { display: flex; align-items: center; gap: 6px 12px; padding: 0 0 10px; }
#review-nav:not([hidden]) { display: flex; flex: none; gap: 6px; }
.review-readout { display: grid; grid-template-columns: minmax(0, 1fr); flex: 1; min-width: 0; }
.review-detail { grid-area: 1 / 1; align-self: center; display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 12px; font-variant-numeric: tabular-nums; }
#review-measure { visibility: hidden; pointer-events: none; }
@container (max-width: 540px) {
  #move-review:not([hidden]) { flex-direction: column; align-items: flex-start; }
  .review-readout { align-self: stretch; flex: none; }
}
#size-grip { display: inline-flex; align-items: center; gap: 8px; cursor: nwse-resize; touch-action: none; user-select: none; -webkit-user-select: none; }
.theme-control select, #size-grip, .size-options button, #move-review button { box-sizing: border-box; min-height: 32px; line-height: 1.25; }
@media (pointer: coarse) {
  .theme-control select, #size-grip, .size-options button, #move-review button, .game-actions button, .dialog-actions button { min-height: 44px; }
}
#size-grip:hover, #size-grip[aria-expanded="true"], .size-options button:hover { background: #f4f4f0; }
.grip-lines { width: 12px; height: 12px; background: repeating-linear-gradient(135deg, transparent 0 2px, currentColor 2px 3.5px, transparent 3.5px 5px); clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.size-options { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 4px 0 8px; }
.size-options[hidden] { display: none; }
.text-control { gap: 7px; min-width: 7.1rem; white-space: nowrap; }
.text-control svg { width: 18px; height: 18px; }
.text-control[aria-pressed="true"] .sound-mute, .text-control[aria-pressed="false"] .sound-waves { display: none; }
.guide { border-top: 1px solid var(--border-color); padding: 10px 0; }
.guide summary { font-weight: 600; cursor: pointer; width: fit-content; }
.guide p { margin: 8px 0; }
.credit { margin: 4px 0; font-size: .875rem; color: var(--text-grey-color); }
#result-title { color: var(--ink); margin-inline-end: .25em; }
dialog h2 { margin: 0; }
dialog p { margin: 7px 0 16px; }
dialog { box-sizing: border-box; border: 1px solid var(--line); border-radius: 10px; padding: 22px; color: var(--ink); max-width: calc(100% - 2 * var(--game-margin)); }
dialog::backdrop { background: rgb(38 39 31 / 35%); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 600px) and (orientation: portrait), (max-height: 570px) and (orientation: landscape) {
  #game { --game-width: 94vw; }
}
@media (max-height: 570px) and (orientation: landscape) {
  /* The page header scrolls above the game on short screens. */
  #game.fit-board { --fitted-board-width: calc((90svh - var(--game-ui-height, 4rem)) * var(--board-ratio)); }
}
@container (max-width: 720px) {
  .game-toolbar { gap: 10px; }
  .scoreboard { gap: 12px; }
  .stat { gap: 4px; }
  #sound-label { display: none; }
  .text-control { min-width: 44px; padding-inline: 5px; }
  #round-button { min-width: 6rem; padding-inline: 8px; }
}
@container (max-width: 540px) {
  .game-toolbar, .scoreboard { gap: 8px; }
  .game-actions { gap: 4px; }
  #round-button { min-width: 5.5rem; }
  .stat { flex-direction: column; align-items: flex-start; gap: 0; }
  .board-notes { flex-wrap: wrap; gap: 8px; }
  .board-notes p { flex-basis: 100%; }
  .theme-control { margin: 0 auto 0 0; }
}
@container (max-width: 350px) {
  .game-toolbar { gap: 6px; }
  .scoreboard { gap: 5px; }
  .stat strong { font-size: 1.1rem; }
  .stat span { white-space: nowrap; }
}
@container (max-width: 260px) {
  .game-toolbar { flex-wrap: wrap; }
  .scoreboard { flex-basis: 100%; }
  .game-actions { margin-left: auto; }
}
