:root {
  color-scheme: light;
  --navy: #061d45;
  --gold: #f6c64c;
  --mist: #f1f5fa;
  --muted: #52647b;
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--navy);
  background: var(--mist);
}
* { box-sizing: border-box; }
body { margin: 0; }
.lipno-puzzle-page { line-height: 1.5; background: var(--mist); }
:where(#puzzle, #coloring) button, :where(#puzzle, #coloring) select, :where(#puzzle, #coloring) input { font: inherit; }
:where(#puzzle, #coloring) button, :where(#puzzle, #coloring) select, :where(#puzzle, #coloring) a { touch-action: manipulation; }
:where(#puzzle, #coloring) button, :where(#puzzle, #coloring) select { min-height: 44px; border-radius: 12px; padding: .6rem 1rem; color: var(--navy); }
:where(#puzzle, #coloring) button { border: 2px solid transparent; background: var(--gold); font-weight: 700; cursor: pointer; }
:where(#puzzle, #coloring) button:disabled { cursor: default; opacity: .65; }
:where(#puzzle, #coloring) button:hover:not(:disabled) { filter: brightness(.96); }
:where(#puzzle, #coloring) button.secondary { background: white; border-color: #d6dfec; }
:where(#puzzle, #coloring) select { background: white; border: 1px solid #aab9cb; max-width: 100%; }
a { color: inherit; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid #087e9c; outline-offset: 3px; }
[hidden] { display: none !important; }
.puzzle-header { z-index: 50; }
.puzzle-header .lipno-header-inner { max-width: 1180px; margin: auto; align-items: center; }
main { max-width: 1240px; margin: auto; padding: 1.8rem 1.5rem 2.5rem; }
.eyebrow { text-transform: uppercase; font-size: .8rem; font-weight: 750; letter-spacing: .12em; margin: 0 0 .4rem; color: var(--muted); }
h1 { font-size: clamp(1.8rem, 4vw, 2.65rem); line-height: 1.12; margin: 0 0 1.2rem; letter-spacing: -.04em; }
.puzzle-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.puzzle-controls label { font-size: .875rem; font-weight: 650; display: grid; gap: .3rem; }
.icon-control { display: flex; align-items: center; gap: .5rem; }
.puzzle-controls svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.puzzle-guidance { margin: 1rem 0; min-height: 1.5em; }
.instructions, .feedback { margin: 0; color: var(--muted); }
.instructions-short { display: none; }
.tray-swipe { font-size: .875rem; color: var(--muted); white-space: nowrap; }
.feedback { font-weight: 650; color: var(--navy); }
.feedback:empty, .puzzle-guidance:has(.feedback:not(:empty)) .instructions { display: none; }
.puzzle-workspace { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(250px, 1fr); gap: 1.5rem; align-items: start; }
.puzzle-board-wrap { min-width: 0; }
.puzzle-board-frame { min-width: 0; }
.puzzle-board { position: relative; display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr); width: 100%; aspect-ratio: var(--ratio); background: #dde6ef; isolation: isolate; box-shadow: 0 4px 20px #061d4510; border: 8px solid white; border-radius: 14px; }
.puzzle-guide { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .24; z-index: -1; border-radius: 6px; pointer-events: none; }
.puzzle-board.no-hint .puzzle-guide { opacity: 0; }
.puzzle-cell { position: relative; background: transparent; border: 0; border-radius: 0; min-height: 0; min-width: 0; padding: 0; overflow: visible; }
.puzzle-cell:not(.is-filled)::after { content: ''; position: absolute; inset: 0; border: 1px dashed #52647b5c; pointer-events: none; }
.puzzle-cell:hover:not(:disabled) { background: #fff3; }
.puzzle-cell.is-filled { border-color: transparent; opacity: 1; }
.puzzle-cell.is-target { background: #f6c64c66; outline: 3px solid var(--gold); z-index: 2; }
.puzzle-cell svg { position: absolute; inset: -18%; width: 136%; height: 136%; overflow: visible; pointer-events: none; }
.puzzle-board.is-complete { border-color: var(--gold); }
.puzzle-board.is-complete .puzzle-guide { opacity: 1; }
.puzzle-board { overflow: clip; }
.puzzle-cell:focus-visible { outline-offset: -3px; z-index: 3; }
.puzzle-progress { display: flex; align-items: center; gap: 1rem; margin-top: .75rem; font-size: .875rem; font-weight: 650; }
.puzzle-progress progress { width: 100%; height: 8px; accent-color: #087e9c; }
.puzzle-progress span { white-space: nowrap; }
.puzzle-tray-wrap { display: grid; grid-template-rows: auto minmax(0, 1fr); background: white; border-radius: 18px; padding: 1rem; min-width: 0; min-height: 0; }
.puzzle-tray-heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.puzzle-tray-wrap h2 { font-size: 1rem; margin: 0; }
.puzzle-tray { display: grid; grid-auto-flow: column; grid-auto-columns: 94px; grid-template-rows: repeat(var(--tray-rows, 3), minmax(0, 1fr)); gap: 6px; padding: 3px 2px 8px; min-height: 0; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; touch-action: pan-x; scrollbar-width: thin; scrollbar-color: #b2bfd1 transparent; }
.puzzle-piece { position: relative; width: 100%; height: 100%; min-height: 44px; min-width: 0; background: transparent; border: 2px solid transparent; padding: 10px; touch-action: pan-x; border-radius: 10px; cursor: grab; }
.puzzle-piece svg { display: block; width: 100%; height: 100%; overflow: visible; pointer-events: none; filter: drop-shadow(0 2px 1px #061d4533); }
.puzzle-piece[aria-pressed=true] { background: #f6c64c35; border-color: #be8b12; }
.puzzle-piece:active { cursor: grabbing; }
.puzzle-piece.is-dragging { opacity: .3; }
.puzzle-ghost { position: fixed; pointer-events: none; z-index: 1000; opacity: .94; filter: drop-shadow(0 6px 6px #061d4566); }
.puzzle-ghost svg { width: 100%; height: 100%; overflow: visible; }
:is(#puzzle-help, #coloring-help) { max-width: min(540px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.4rem; border: 0; border-radius: 20px; color: var(--navy); line-height: 1.6; }
:is(#puzzle-help, #coloring-help)::backdrop { background: #061d4580; }
.puzzle-help-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.puzzle-help-heading h2 { margin: 0; }
#close-help { min-width: 44px; padding: 0; font-size: 1.5rem; }
.puzzle-back { display: inline-block; padding-block: .7rem; }

/* A single play screen: reserve the rail and controls, fit the complete photo in what remains. */
@media (max-width: 760px), (max-height: 540px) and (max-width: 1100px) {
  main.has-game { padding: 10px 12px max(8px, env(safe-area-inset-bottom)); display: grid; grid-template-areas: "heading" "controls" "guidance" "game"; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto; gap: 8px; }
  .puzzle-heading { grid-area: heading; }
  .puzzle-heading .eyebrow { display: none; }
  h1 { font-size: 1.2rem; line-height: 1.2; margin: 0; letter-spacing: -.025em; }
  .puzzle-controls { grid-area: controls; gap: 8px; align-items: center; flex-wrap: nowrap; min-width: 0; }
  .puzzle-controls > label { min-width: 0; }
  .difficulty-control { flex: 1; }
  .picture-control { flex: 1; }
  .puzzle-controls:has(.picture-control:not([hidden])) { display: grid; grid-template-columns: minmax(0, 1fr) repeat(3, 44px); }
  .puzzle-controls .picture-control:not([hidden]) { grid-column: 1 / -1; }
  .puzzle-controls label > span, .icon-control span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .puzzle-controls select { width: 100%; font-size: 1rem; padding: .45rem .55rem; }
  .icon-control { flex: 0 0 44px; padding: 0; justify-content: center; }
  .puzzle-guidance { grid-area: guidance; min-height: 2.6em; margin: 0; font-size: .875rem; line-height: 1.3; }
  .instructions-full { display: none; }
  .instructions-short { display: inline; }
  #load-status { grid-area: game; }
  .puzzle-workspace { grid-area: game; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .puzzle-board-wrap { flex: none; min-height: 0; display: grid; grid-template-rows: auto auto; gap: 6px; }
  .puzzle-board-frame { min-height: 0; display: flex; align-items: center; justify-content: center; }
  .puzzle-board { flex: none; border-width: 5px; }
  .puzzle-progress { margin: 0; gap: .75rem; line-height: 1.3; }
  .puzzle-tray-wrap { flex: none; padding: 7px 8px 4px; border-radius: 14px; }
  .puzzle-tray-heading { margin-bottom: 0; }
  .puzzle-tray-wrap h2 { margin: 0; font-size: .875rem; line-height: 1.3; }
  .tray-swipe { display: inline; font-size: .875rem; color: var(--muted); }
  .puzzle-tray { display: grid; grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 78px; grid-template-rows: repeat(var(--tray-rows, 1), var(--tray-row-height, 72px)); height: calc(var(--tray-rows, 1) * (var(--tray-row-height, 72px) + 6px) + 10px); align-content: start; gap: 6px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; touch-action: pan-x; scrollbar-width: thin; scrollbar-color: #b2bfd1 transparent; padding: 4px 2px; }
  .puzzle-piece { flex: 0 0 78px; width: 78px; height: var(--tray-row-height, 72px); padding: 9px; touch-action: pan-x; }
}
@media (max-height: 540px) and (max-width: 1100px) and (orientation: landscape) {
  .puzzle-header { display: none; }
  main.has-game { height: 100dvh; grid-template-areas: "board controls" "board guidance" "board tray"; grid-template-columns: minmax(0, 1fr) clamp(250px, 34vw, 310px); grid-template-rows: auto auto minmax(0, 1fr); padding-block: 6px; gap: 6px 12px; }
  .puzzle-heading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .puzzle-guidance { min-height: 2.6em; }
  .puzzle-workspace { display: contents; }
  .puzzle-board-wrap { grid-area: board; grid-template-rows: minmax(0, 1fr) auto; }
  .puzzle-tray-wrap { grid-area: tray; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
  .puzzle-tray { display: grid; grid-auto-flow: row; grid-auto-columns: auto; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: 64px; height: auto; min-height: 0; align-content: start; gap: 4px; overflow-x: hidden; overflow-y: auto; touch-action: pan-y; overscroll-behavior-y: contain; }
  .puzzle-piece { height: 64px; width: 100%; padding: 7px; touch-action: pan-y; }
  .tray-swipe { display: none; }
}
@media (prefers-reduced-motion: no-preference) { .puzzle-board.is-complete { transition: border-color .3s; } .puzzle-piece { transition: background .15s; } }

/* Prevent Safari's selection/callout on the play area, preserving native rail panning. */
.puzzle-workspace, .puzzle-workspace *, .puzzle-ghost, .puzzle-ghost * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.puzzle-workspace :is(img, svg, image), .puzzle-ghost * { -webkit-user-drag: none; }
.puzzle-controls button[aria-pressed=true] { border-color: #b58b20; background: #f6c64c3d; }
