:root {
  color-scheme: light;
  --paper: #f4f2e7;
  --ink: #213e34;
  --dim: #52685b;
  --edge: #b9c2ad;
  --accent: #97552d;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input { font: inherit; }
button {
  color: inherit;
  border: 0;
  background: transparent;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:enabled { background: #e6e8d9; }
button:disabled { opacity: .36; cursor: default; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary { background: #305c49; color: #fffaf0; font-weight: 650; border-radius: 5px; }
button.primary:hover { background: #234a3b; }
[hidden] { display: none !important; }
.game {
  width: min(calc(100% - 24px), 520px);
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 0 max(4px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  container-type: inline-size;
}
header, .board-meta, .tray-header, nav, .dialog-head, .seed-row, .completion {
  display: flex;
  align-items: center;
}
header { gap: 5px; }
h1, h2 { font-family: Georgia, serif; margin: 0; }
h1 { font-size: 34px; line-height: 1; letter-spacing: -.05em; }
.rule { flex: 1; height: 2px; margin: 0 9px; background: var(--edge); }
header button { color: var(--dim); padding: 9px 6px; }
.board-meta, .tray-header {
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.board-meta { margin: 16px 0 7px; }
#board-size { font-weight: 650; }
#progress-text, #solution-label { color: var(--dim); }
.board-frame { position: relative; border: 3px solid #7b8d77; }
#board {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  overflow: hidden;
}
.grid-cell { fill: url(#hatch); stroke: #a3b198; stroke-width: 1.3; }
.board-piece, .tray-piece { cursor: grab; touch-action: none; }
.board-piece .piece-outline, .drag-piece .piece-outline { stroke: #52694d; stroke-width: 2; stroke-linejoin: round; }
.board-piece.selected .piece-outline, .board-piece:focus-visible .piece-outline { stroke: #244b40; stroke-width: 5; }
.preview-path { fill: #a3ccaa; fill-opacity: .55; stroke: white; stroke-width: 2; }
.preview-path.invalid { fill: #fa737e; }
.preview-path.hint { fill: #f7cd6d; stroke: #fff1b8; stroke-dasharray: 6 4; }
.board-piece.dragging { opacity:0; }
.piece-art { transform-box:fill-box;transform-origin:center; }
.piece-depth { stroke:#355646;stroke-width:2;stroke-linejoin:round;filter:brightness(.79); }
.stack-back { stroke:#576e50;stroke-width:2;stroke-linejoin:round;filter:brightness(.91); }
.tray-piece[data-count="0"] .stack-back,.tray-piece[data-count="1"] .stack-back { visibility:hidden; }
.tray-piece[data-count="2"] .stack-back:first-child { visibility:hidden; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--paper); }
.tray-header { padding: 15px 0 4px; }
.tray-area { grid-area:tray; container-type:inline-size; }
.piece-tray {
  display: grid;
  grid-template-columns: repeat(var(--tray-columns,16), minmax(0,1fr));
  grid-auto-flow: row dense;
  grid-auto-rows: var(--unit);
  --unit: calc((100cqw - 6px) / var(--tray-columns,16));
  padding: 5px 0 7px;
  border-radius: 10px;
}
.tray-piece {
  display: grid;
  place-items: center;
  position: relative;
  isolation:isolate;
  border:1px solid #a9b69d66;
  background:#ebeede;
  border-radius:9px;
  transition:background-color 120ms,border-color 120ms,box-shadow 120ms;
  min-width:0;min-height:0;margin:2px;padding:3px 3px 13px;
}
.tray-piece svg, .drag-piece { display: block; }
.tray-piece svg { width:calc(var(--piece-w) * var(--unit));height:calc(var(--piece-h) * var(--unit));overflow:visible;filter:drop-shadow(0 2px 1px #2c4c3824); }
.tray-piece.selected { outline: 1px solid var(--accent); outline-offset: -1px; }
.tray-piece.placed { opacity:.38; }
.stack-count { position:absolute;right:3px;bottom:1px;font:650 11px/1.2 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;font-variant-numeric:tabular-nums;color:#405d46; }
.tray-piece.return-target { border-color:#3f7c5c;background:#dbe7cc;box-shadow:0 0 0 3px #70976733,inset 0 0 16px #a9c99640;opacity:1; }
.drop-ready { background:#b4c89d18; }
nav { gap: 2px; padding-top: 10px; border-top: 1px solid var(--edge); }
nav .primary { margin-left: auto; }
#game-message { margin: 8px 0; color: var(--dim); font-size: 13px; }
#game-message.error { color: var(--accent); }
.drag-piece {
  position:fixed;left:0;top:0;z-index:5;pointer-events:none;overflow:visible;
  transform-origin:0 0;will-change:transform;filter:drop-shadow(0 8px 5px #203d383b);
}
.drag-piece .piece-outline { stroke:#50664e;stroke-width:2.6;stroke-linejoin:round; }
.drag-piece.blocked .piece-outline { stroke:#914c45; }
.landing-target { opacity:0 !important; }
.tray-piece,.board-piece { -webkit-touch-callout:none;user-select:none;-webkit-user-select:none; }
.tray-piece.pressed { background:#dae3ce; }
.board-piece.pressed .piece-outline { stroke:#355a44; }
body.is-dragging { user-select: none; }
#feedback-layer { position:fixed;inset:0;z-index:6;pointer-events:none;overflow:hidden; }
.placement-fleck { position:absolute;width:5px;height:8px;border-radius:1px 5px;pointer-events:none; }
.completion { gap: 7px; padding: 8px 0; flex-wrap: wrap; }
.completion strong { color: #b5cf9b; }
.completion button:first-of-type { margin-left: auto; }
dialog { width: min(380px, calc(100% - 32px)); padding: 22px; border: 1px solid #91a08b; border-radius: 10px; background: var(--paper); color: inherit; }
dialog::backdrop { background: #090911bf; }
.dialog-head { justify-content: space-between; }
.dialog-head button { font-size: 22px; }
dialog h2 { font-size: 25px; }
fieldset { margin: 18px 0; border: 0; padding: 0; }
legend, form > label { display: block; margin-bottom: 6px; }
.choices { display: flex; gap: 5px; }
.choices label { flex: 1; cursor: pointer; padding: 7px 4px; border: 1px solid var(--edge); text-align: center; }
.choices input { accent-color: var(--accent); margin: 0 6px 0 0; }
.choices label:has(:checked) { border-color: var(--accent); }
.choices label:has(:disabled) { opacity: .35; }
.seed-row input { min-width: 0; flex: 1; padding: 8px; color: inherit; background: #fffdf4; border: 1px solid var(--edge); }
#tune-stats, #family-note { color: var(--dim); font-size: 12px; }
@media (max-width: 380px) {
  button { padding-inline: 8px; }
  .game { width: calc(100% - 20px); }
}


.limits { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.limits label, .range-ends { font-size: 13px; color: var(--dim); }
.limits select, .stars-field select, .zone-settings select {
  display: block; width: 100%; margin-top: 4px; padding: 8px;
  font: inherit; font-size: 16px; color: var(--ink);
  background: #fffdf4; border: 1px solid var(--edge);
}
.zone-settings { display:grid;grid-template-columns:minmax(0,2fr) minmax(0,3fr);gap:10px; }
.featured-puzzle { display:flex;justify-content:space-between;align-items:center;gap:8px;padding:13px 10px;margin-top:14px;background:#e6ecdd;color:#315641;border:1px solid #acbca5;border-radius:5px;text-decoration:none; }
.featured-puzzle span { font-size:12px; }

#puzzle-list h3 { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 0 8px; }
#puzzle-list h3 span { color: var(--dim); font: 13px/1.4 system-ui, sans-serif; }
#puzzle-list section > div { display: flex; gap: 6px; }
#puzzle-list a {
  flex: 1; text-align: center; padding: 10px 4px; color: var(--ink);
  border: 1px solid var(--edge); text-decoration: none;
}
#puzzle-list a:hover, #puzzle-list a:focus-visible { border-color: var(--accent); }

/* Inventory may lengthen the page, but never takes space from the board. */
.game > * { flex: none; }
.game > header { grid-area:header; }
.board-meta { grid-area:meta; margin: 4px 0 5px; }
.board-slot { width:100%; aspect-ratio:1; grid-area:board; container-type:size; display:grid; place-items:center; min-width:0; min-height:0; }
.board-frame { width:min(100cqw,100cqh); aspect-ratio:1; }
.completion { grid-area:complete; }
.tray-header { grid-area:traylabel; padding:6px 0 2px; }
.piece-tray { align-content:start; }
nav { grid-area:controls; padding-top:4px; }
#game-message { grid-area:status; min-height:2.5em; line-height:1.25; margin:4px 0 0; }
.preview-path { pointer-events:none; }
.drop-footprint { fill:var(--tile);fill-opacity:.4;stroke:#3d7b59;stroke-width:4;stroke-linejoin:round; }
.drop-footprint.invalid { fill:#b87164;fill-opacity:.2;stroke:#944f44; }
.is-dragging,.is-dragging * { cursor:grabbing; }
.rotation-option { margin:14px 0; cursor:pointer; }
.sound-option { margin:12px 0 18px;cursor:pointer; }
.rotation-option input { accent-color:var(--accent); }
@media (max-width:400px) { nav button { font-size:13px; padding-inline:6px; } }
@media (min-width:900px), (orientation:landscape) and (max-height:550px) and (min-width:550px) {
  .game {
    display:grid; width:min(96vw, 970px); column-gap:14px;
    grid-template-columns:minmax(0,1fr) minmax(0,1fr);
    grid-template-areas:"header header" "meta traylabel" "board tray" "board complete" "board controls" "status status";
    grid-template-rows:auto auto 1fr auto auto auto;
  }
  .board-slot { width:100%; height:min(calc(50cqw - 7px),calc(100svh - 120px)); aspect-ratio:auto; }
  .tray-area { align-self:start; }
  nav button { padding-inline:7px; }
}

@media (max-width:360px) {
  header { gap:0; }
  .rule { margin-inline:4px; }
  header button { font-size:14px; }
}

.stars-field { margin-top:16px; }

body { background: radial-gradient(ellipse at 50% 32%, #fbf9ef, #f1f0e4 78%); min-height:100svh; }
header { padding:2px 0 8px; }
.brand-mark { width:33px; height:33px; margin-right:4px; }
h1 { font-size:36px; letter-spacing:-.065em; }
.rule { height:1px; background:#acb9a8; }
header button { font-size:14px; font-weight:550; border-radius:4px; }
.board-meta { padding:3px 1px; letter-spacing:.025em; }
.board-frame {
  border-color:#788b77; border-radius:5px; background:#e2e6d5;
  box-shadow:0 2px 0 #4b6656,0 6px 13px #344b3520;
}
#board { border-radius:2px; }
.tray-header { margin-top:8px; }
.tray-piece.selected { background:#e9e7d6; }
.tray-piece .piece-outline { stroke:#597052; stroke-width:2; stroke-linejoin:round; }
nav button { border-radius:4px; }
#game-message { font-size:12px; }
#view-park { font-weight:650; color:#275e4a; }
.park-open .board-frame {
  isolation:isolate; border-color:transparent; box-shadow:none;
  background: radial-gradient(ellipse 57% 47% at 52% 60%,#d9e0cd 0%,#e9ecdc 60%,#f2f2e6 100%);
}
.park-open #board { opacity:0; pointer-events:none; }
#park-view { position:absolute; inset:0; touch-action:pan-y; border-radius:4px; outline-offset:-3px; }
#park-view:focus:not(:focus-visible) { outline:none; }
#park-view[data-phase="open"] { cursor:grab; }
#park-view[data-phase="open"]:active { cursor:grabbing; }
#park-view canvas { width:100%; height:100%; display:block; position:absolute; inset:0; }
#park-view::before {
  content:""; position:absolute; inset:31% 9% 9% 11%;
  background:radial-gradient(ellipse closest-side at 52% 60%,#6b796355 2%,#89978032 50%,transparent 100%);
}
.park-open .tray-area,.park-open .tray-header { display:none; }
.park-open .board-meta { border-bottom:1px solid var(--edge); }
.completion { display:block; width:100%; padding:7px 0 4px; }
.park-caption,.park-actions { display:flex;align-items:center;justify-content:space-between;gap:10px; }
.park-caption { border-block:1px solid var(--edge); padding:10px 0; }
.park-caption strong { display:block; font:600 clamp(24px,4vw,32px)/1.12 Georgia,serif; color:#254d3c; letter-spacing:-.04em; }
#completion-copy { display:block; margin-top:3px; font-size:12px; font-variant-numeric:tabular-nums; color:var(--dim); }
.orbit-controls { display:flex; gap:6px; }
.orbit-controls button { width:36px; height:36px; padding:0; border:1px solid var(--edge); border-radius:50%; color:#345c49; font-size:20px; }
.park-actions { padding:8px 0 0; }
.park-actions button:first-of-type { margin-left:0; border:1px solid var(--edge); border-radius:5px; }
.park-open nav button:not(#undo-button):not(#reset-button) { display:none; }
.park-open nav { border:0; justify-content:center; font-size:12px; }
@media (min-width:900px), (orientation:landscape) and (max-height:550px) and (min-width:550px) {
  .game.park-open { grid-template-areas:"header header" "meta ." "board complete" "board complete" "board controls" "status status"; }
}
@media(max-width:370px) {
  .brand-mark { width:27px; height:27px; }
  h1 { font-size:30px; }
}
