/* Layout and type */
:root {
  --paper: #f5f5f0;
  --ink: #273b34;
  --muted: #68766b;
  --green: #315b4c;
  --accent: #d4e3bf;
  --line: #dce1d3;
  --red: #ac423b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; }
body:not(.puzzle-loaded) { min-height: 100svh; background-image: radial-gradient(ellipse at 90% 0%,#e8edde 0,transparent 55%); }
button, input { font: inherit; }
button { cursor: pointer; }
select { font: inherit; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid #8aa568;
  outline-offset: 2px;
}
[hidden] { display: none !important; }
header { height: 64px; max-width: 1040px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 26px; font-weight: 600; letter-spacing: -.9px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-dot { color: var(--green); margin-left: -7px; }
.puzzle-loaded > header { display: none; }
main { max-width: 1040px; margin: 0 auto; padding: 12px 16px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.workspace:has(#explanation[hidden]) { grid-template-columns: minmax(0, 1fr); max-width: 580px; margin: 0 auto; }
.workspace:has(#photo-reference:not([hidden])) { grid-template-columns: repeat(2,minmax(0,1fr)); max-width: none; }
.board-panel, .reasoning-panel, .photo-reference { min-width: 0; padding: 12px; background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 20px #193b2706; }
.photo-reference img { display: block; width: 100%; height: auto; object-fit: contain; }
.reasoning-panel:has(#explanation[hidden]) { display: none; }
.entry-hint { margin: 0 0 10px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.board-title { font-size: 13px; font-weight: 500; margin: 0 0 8px; }
.reviewing-steps .board-title { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
h2 { margin: 0; }

/* Setup is a separate screen; only the active puzzle's controls stay on board. */
.puzzle-chooser { max-width: 940px; margin: 30px auto; }
.chooser-hero { margin-bottom: 30px; }
.puzzle-chooser h1 { margin: 0; font-size: clamp(40px,6vw,64px); line-height: 1.1; font-weight: 500; letter-spacing: -2px; }
.puzzle-chooser h1 em { font-family: Georgia,serif; font-weight: 500; color: var(--green); background: linear-gradient(transparent 76%,var(--accent) 76%,var(--accent) 94%,transparent 94%); }
.hero-note { margin: 12px 0 0; font-size: 15px; color: #526552; }
.chooser-options { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.6fr); gap: 20px; align-items: stretch; }
.chooser-card { min-width: 0; padding: 24px; background: #fffefa; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 10px 35px #26402a08; }
.chooser-card h2 { margin: 0 0 20px; font-size: 22px; font-weight: 500; letter-spacing: -.3px; }
.custom-picker { display: flex; flex-direction: column; color: #f6f7f0; background: #244638; border-color: #244638; box-shadow: 0 10px 35px #173d2e0c; }
.puzzle-art { width: 124px; height: 124px; margin: 0 auto 16px; flex: none; transform: rotate(-5deg); }
.level-choices { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; border: 0; padding: 0; margin: 0; }
.level-card { position: relative; cursor: pointer; border: 1px solid var(--line); border-radius: 10px; padding: 14px 10px; display: flex; flex-direction: column; gap: 6px; min-width: 0; background: #f7f8f0; transition: background .15s,border-color .15s; }
.level-card input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.level-card:has(input:checked) { border-color: #82947a; background: #edf2e6; box-shadow: inset 0 0 0 1px #82947a; }
.level-card:has(input:focus-visible) { outline: 2px solid #8aa568; outline-offset: 3px; }
.level-card strong { font-size: 15px; font-weight: 500; }
.level-card span { font-size: 11px; color: #64766a; }
.technique-choice { display: block; margin: 20px 0 7px; font-size: 12px; font-weight: 500; }
.technique-choice span { margin-left: 5px; font-weight: 400; color: var(--muted); }
#technique-focus { width: 100%; min-width: 0; height: 40px; padding: 6px 10px; border: 1px solid #cbd4bf; border-radius: 8px; background: #fffefa; color: var(--ink); font-size: 13px; }
.focus-description { margin: 8px 0 0; color: #64766a; font-size: 12px; line-height: 1.5; }
.chooser-start { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin-top: 20px; }
.chooser-start .button { padding: 10px 16px; font-size: 13px; min-height: 40px; }
.library-count { font-size: 11px; color: var(--muted); }
.own-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.own-actions .button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; }
.own-actions svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
#import-photo { position: relative; }
.beta-badge { position: absolute; top: -7px; right: 6px; padding: 1px 5px; border: 1px solid #638270; border-radius: 999px; background: var(--accent); color: #173b2d; font-size: 9px; font-weight: 500; line-height: 1.2; letter-spacing: .2px; }
.custom-picker .primary { color: #173b2d; background: var(--accent); }
.custom-picker .primary:hover { background: #dfeacc; }
.custom-picker .secondary { color: #f1f7e7; background: transparent; border-color: #638270; }
.custom-picker .secondary:hover { background: #2a503d; }
.challenge-tip { color: #64766a; font-size: 12px; line-height: 1.5; margin: 8px 0 0; }
.practice-challenge :is(.step-legend,.navigation,#timeline) { display: none; }
.practice-challenge .playback { grid-template-columns: auto auto auto; }
.practice-challenge .playback .button { min-height: 36px; }

/* One lightweight toolbar, with no stacked rows of controls. */
.button { border: 1px solid transparent; border-radius: 7px; padding: 6px 10px; font-size: 12px; font-weight: 500; transition: background .15s,border-color .15s,box-shadow .15s; }
.secondary { background: white; color: var(--ink); border-color: var(--line); }
.secondary:hover { background: #f0f4eb; }
.primary { background: var(--green); color: white; }
.primary:hover { background: #194635; }
.quiet { background: none; color: var(--muted); }
.board-toolbar { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; overflow-x: auto; white-space: nowrap; margin-bottom: 8px; padding: 0 0 4px; scrollbar-width: thin; scrollbar-color: #bdcabb transparent; }
.board-toolbar > * { flex: none; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.toolbar-actions .button { flex: 0 0 auto; width: max-content; margin: 0; }
.board-toolbar .button { padding: 5px 8px; font-size: 11px; min-height: 30px; }
.board-toolbar label { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; min-height: 30px; cursor: pointer; }
.board-toolbar input { margin: 0; accent-color: var(--green); width: 12px; height: 12px; }
.reviewing-steps .board-toolbar { min-height: 26px; padding: 0; margin-bottom: 6px; }
.reviewing-steps .board-toolbar label { min-height: 26px; }

/* Sudoku grid */
.board-stage { min-width: 0; min-height: 0; }
.board-wrap { position: relative; isolation: isolate; aspect-ratio: 1; margin: 0 auto; }
.board { display: grid; grid-template-columns: repeat(9,minmax(0,1fr)); grid-template-rows: repeat(9,minmax(0,1fr)); aspect-ratio: 1; border: 2px solid #536b5e; border-radius: 2px; overflow: hidden; background: white; }
.cell { position: relative; min-width: 0; min-height: 0; border-right: 1px solid #dfe5df; border-bottom: 1px solid #dfe5df; display: flex; align-items: center; justify-content: center; background: white; }
.cell:nth-child(3n) { border-right: 2px solid #829387; }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid #829387; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell input { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 0; background: transparent; text-align: center; font-size: clamp(20px,2.7vw,29px); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--green); outline: none; }
.cell.clue input { color: var(--ink); }
.cell:focus-within { background: #edf3df; box-shadow: inset 0 0 0 2px #709658; z-index: 1; }
.cell.conflict { background: #fff0ed; box-shadow: inset 0 0 0 2px #d17a6b; }
.cell.focus-unit { background: #f1f5e9; }
.cell.source-cell { background: #deece9; box-shadow: inset 0 0 0 2px #6c9d91; }
.cell.target-cell { background: #fff0e9; }
.cell.source-cell.target-cell { background: #e3ede3; }
.cell.placed { background: #e6f0cb; box-shadow: inset 0 0 0 2px #9fba5c; }
.cell.placed input { color: #41642e; }
.candidate-grid { position: absolute; inset: 3px; display: grid; grid-template-columns: repeat(3,1fr); pointer-events: none; font-size: clamp(8px,1vw,11px); color: #7b897e; text-align: center; }
.candidate-grid span { display: flex; align-items: center; justify-content: center; }
.candidate-grid .evidence { color: #1b6e62; font-weight: 700; background: #c9e4dc; border-radius: 50%; box-shadow: 0 0 0 1px #73a698; }
.candidate-grid .fin { color: #8d5900; background: #ffe4ab; box-shadow: 0 0 0 1px #c28c2f; }
.candidate-grid .color-a { color: #2157a1; background: #dbe8fc; box-shadow: 0 0 0 1px #7496c4; }
.candidate-grid .color-b { color: #73429b; background: #efdefb; box-shadow: 0 0 0 1px #ac83c7; }
.cell.fin-cell { background: #fff0cf; }
.candidate-grid .removed { font-weight: 600; color: #b04736; background: #f8d9cc; text-decoration: line-through; text-decoration-thickness: 2px; border-radius: 3px; }
.deduction-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; overflow: visible; }
.guide-unit { fill: none; stroke: #7d9b54; stroke-width: 2; stroke-dasharray: 5 4; opacity: .8; }
.guide-link { fill: none; stroke: #be7560; stroke-width: 1.4; stroke-dasharray: 4 4; opacity: .6; }
.guide-axis { stroke: #508f81; stroke-width: 2.5; opacity: .65; stroke-linecap: round; }
.guide-blocker { stroke: #ab694d; stroke-dasharray: none; opacity: .8; stroke-width: 1.6; }
.guide-strong { stroke: #287d70; stroke-dasharray: none; stroke-width: 2.4; opacity: .85; }
.guide-implication { stroke: #7551a0; stroke-dasharray: 3 3; opacity: .65; }
#proof-choice { font-size: .8rem; display: flex; align-items: center; gap: .5rem; margin-top: .5rem; }
#proof-choice[hidden] { display: none; }
#proof-branch { max-width: 100%; font: inherit; color: inherit; border: 1px solid #cbd5df; border-radius: 4px; background: transparent; padding: .2rem; }
.guide-weak { stroke: #508f81; stroke-dasharray: 4 4; opacity: .75; }
.guide-restriction { fill: none; stroke: #b28050; stroke-width: 1.5; }
.candidate-grid .blocked { color: #9a6541; text-decoration: line-through; background: #f5e7d7; border-radius: 3px; }
.guide-ring { fill: none; stroke: #c05b45; stroke-width: 1.5; }
.guide-cross { stroke: #b24c39; stroke-width: 1.8; stroke-linecap: round; }

/* Explanations and color key share one compact panel. */
.reasoning-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.step-count { white-space: nowrap; color: var(--muted); font-size: 11px; }
.legend { display: flex; align-items: center; flex-wrap: nowrap; gap: 8px; font-size: 9px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.legend i { width: 6px; height: 6px; border-radius: 2px; background: var(--ink); }
.legend .legend-new { background: var(--green); }
.legend .legend-source { background: #6c9d91; }
.legend .legend-unit { background: #a4b879; }
.legend .legend-removed { background: #d18778; }
.technique { display: inline-block; font-size: 10px; font-weight: 500; color: #526a38; background: #edf2e3; padding: 4px 6px; border-radius: 4px; }
.technique-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; }
.technique-link { display: inline-flex; align-items: center; gap: 4px; color: var(--green); font-size: 11px; font-weight: 500; text-underline-offset: 3px; }
.technique-link:hover { color: #153c2d; }
#focus-guide { margin-top: 6px; }
#step-title { font-size: 17px; font-weight: 400; line-height: 1.5; margin-top: 8px; }
#reasoning-details > summary { cursor: pointer; font-size: 11px; color: var(--green); padding-top: 10px; }
.details { list-style: none; padding: 0; margin: 8px 0 0; font-size: 12px; color: #637367; line-height: 1.65; }
.details li { padding: 8px 0; border-bottom: 1px solid #e9ede3; }
.visual-summary { font-size: 10px; line-height: 1.5; margin: 8px 0; color: #5c7464; }
.message { font-size: 11px; line-height: 1.5; color: var(--muted); margin: 10px 0 0; }
.message:empty { display: none; }
.message.error { color: var(--red); }
.message.success { color: var(--green); }
.issues { padding-left: 18px; margin-bottom: 0; font-size: 11px; line-height: 1.6; color: var(--red); }

/* A single-row navigation rail: buttons, timeline and edit share 44px. */
.playback { display: none; }
.reviewing-steps { padding-bottom: calc(var(--dock-height,56px) + 12px); }
.reviewing-steps .playback { display: grid; grid-template-columns: auto minmax(50px,220px) auto; justify-content: center; align-items: center; gap: 16px; position: fixed; inset: auto 0 0; z-index: 20; padding: 5px 16px calc(5px + env(safe-area-inset-bottom,0px)); background: #fff; border-top: 1px solid var(--line); }
.navigation { display: flex; align-items: center; gap: 5px; }
.nav-button { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 44px; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--ink); font-size: 20px; }
.nav-button:hover:not(:disabled) { background: #edf2e7; }
#previous, #next { width: 44px; }
#position { min-width: 47px; text-align: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#timeline { width: 100%; min-width: 0; height: 24px; margin: 0; accent-color: var(--green); }
.edit-button { margin: 0; padding: 6px 9px; font-size: 11px; }

/* Phone playback fits above the rail; detail scrolling never moves the controls. */
@media(max-width:800px) {
  .puzzle-chooser { max-width: 580px; margin: 4px auto; }
  .chooser-hero { margin-bottom: 12px; }
  .puzzle-chooser h1 { font-size: 36px; letter-spacing: -1px; }
  .hero-note { margin-top: 6px; font-size: 12px; }
  .chooser-options { grid-template-columns: minmax(0,1fr); gap: 12px; }
  .chooser-card { padding: 14px; border-radius: 12px; }
  .chooser-card h2 { margin-bottom: 10px; font-size: 19px; }
  .puzzle-art { display: none; }
  .level-choices { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .level-card { padding: 6px 10px; gap: 4px; }
  .technique-choice { margin-top: 12px; }
  .chooser-start { gap: 10px; margin-top: 12px; }
  .chooser-start .button { padding: 9px 12px; font-size: 12px; }
  header { height: 48px; padding: 0 12px; }
  .brand { font-size: 23px; }
  .brand-mark { width: 23px; height: 23px; }
  main { padding: 8px; }
  .workspace { grid-template-columns: minmax(0,1fr); max-width: 580px; margin: auto; gap: 8px; }
  .workspace:has(#photo-reference:not([hidden])) { grid-template-columns: minmax(0,1fr); max-width: 580px; }
  .board-panel, .reasoning-panel, .photo-reference { padding: 8px; border-radius: 6px; }
  .photo-reference img { max-height: 25dvh; }
  .board-toolbar { gap: 7px; }
  .board-toolbar .button { min-height: 30px; }
  body.reviewing-steps { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; padding: 0; }
  .reviewing-steps main { flex: 1; min-height: 0; max-height: calc(100dvh - var(--dock-height,56px)); width: 100%; padding: 6px; }
  .reviewing-steps .workspace { height: 100%; min-height: 0; grid-template-rows: minmax(0,1fr) auto; }
  .reviewing-steps .board-panel { align-self: stretch; display: grid; grid-template-rows: auto minmax(0,1fr); min-height: 0; overflow: hidden; padding: 0; border: 0; background: transparent; }
  .reviewing-steps .board-toolbar { margin-bottom: 4px; min-height: 24px; }
  .reviewing-steps .board-toolbar label { min-height: 24px; font-size: 10px; }
  .reviewing-steps .board-toolbar #solve { display: none; }
  .reviewing-steps :is(#message,#issues) { display: none; }
  .reviewing-steps .board-stage { display: flex; align-items: flex-start; justify-content: center; overflow: hidden; }
  .reviewing-steps .board-wrap { width: var(--board-space,100%); max-width: 100%; flex: none; }
  .reviewing-steps .reasoning-panel { min-height: 0; max-height: 30dvh; overflow: auto; overscroll-behavior: contain; padding: 8px 10px; }
  .reasoning-heading { margin-bottom: 7px; padding-bottom: 7px; gap: 5px; }
  .step-count { font-size: 10px; }
  .legend { gap: 5px; font-size: 8px; }
  #step-title { font-size: 15px; margin-top: 6px; line-height: 1.4; }
  #reasoning-details > summary { padding-top: 7px; }
  .reviewing-steps .playback { grid-template-columns: auto minmax(40px,1fr) auto; padding: 4px 8px calc(4px + env(safe-area-inset-bottom,0px)); gap: 10px; }
  .reviewing-steps :is(#first,#last) { display: none; }
  .navigation { gap: 0; }
  #position { min-width: 44px; font-size: 11px; }
  .edit-button { padding: 6px 8px; }
  .practice-challenge .playback { grid-template-columns: minmax(0,1fr) auto auto; }
  .cell input { font-size: clamp(18px,6vw,28px); }
  .candidate-grid { inset: 2px; font-size: clamp(7px,2.3vw,11px); }
}

@media(prefers-reduced-motion:reduce) {
  .button, .level-card { transition: none; }
}

/* Compare the photo and editable clues together, without crop controls. */
.photo-dialog { width: min(620px,calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 20px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--paper); overflow: auto; }
.photo-dialog::backdrop { background: #152c24a6; backdrop-filter: blur(3px); }
.photo-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.photo-heading h2 { font-size: 21px; font-weight: 600; }
.photo-description, .photo-help { font-size: 12px; color: #69796c; line-height: 1.5; }
.photo-picker { display: flex; gap: 10px; margin: 16px 0; }
.photo-picker label { cursor: pointer; }
.photo-workspace { display: grid; gap: 16px; }
.photo-canvas-wrap { position: relative; background: white; border-radius: 4px; overflow: hidden; }
.photo-canvas-wrap canvas { display: block; max-width: 100%; max-height: 55dvh; width: auto; height: auto; margin: auto; touch-action: none; }
.photo-canvas-wrap img { display: block; width: 100%; height: auto; object-fit: contain; }
.photo-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
#photo-adjust { margin-right: auto; }
.photo-dialog progress { width: 100%; accent-color: var(--green); margin: 10px 0; }
.photo-dialog.has-review { width: min(960px,calc(100% - 24px)); }
.has-review .photo-workspace { grid-template-columns: repeat(2,minmax(0,1fr)); grid-template-areas: "help help" "photo grid" "status status"; align-items: start; margin-top: 10px; }
.has-review #photo-editor { grid-area: photo; width: 100%; max-width: 405px; justify-self: center; }
.has-review #photo-review { display: contents; }
.has-review #photo-review .photo-help { grid-area: help; margin: 0; }
.has-review .photo-review-grid { grid-area: grid; }
.has-review #photo-review-status { grid-area: status; margin: 0; }
.has-review :is(.photo-description,.photo-picker,#photo-instructions,#photo-canvas,#photo-rotate,#photo-status,#photo-read) { display: none; }
#photo-review .photo-help { margin: 0 0 8px; }
.photo-review-grid { width: 100%; max-width: 405px; margin: 0 auto; background: white; }
.photo-review-grid .cell input { font-size: clamp(18px,3vw,27px); color: var(--ink); }
.photo-review-grid .uncertain { background: #fff2cf; box-shadow: inset 0 0 0 2px #d7ac50; }
.photo-review-grid .conflict { background: #fff0ed; box-shadow: inset 0 0 0 2px #c67461; }
@media(max-width:650px) {
  .photo-dialog, .photo-dialog.has-review { padding: 12px; max-height: calc(100dvh - 16px); }
  .photo-heading h2 { font-size: 18px; }
  .has-review .photo-workspace { grid-template-columns: minmax(0,1fr); grid-template-areas: "photo" "help" "grid" "status"; gap: 8px; }
  .has-review #photo-preview { max-height: 22dvh; }
  #photo-review .photo-help { font-size: 11px; }
  .photo-review-grid { max-width: min(100%,39dvh); }
  .photo-actions { margin-top: 12px; }
}
