#puzzle-root { scroll-margin-top: 90px; }
.puzzle-shell { max-width: 1180px; width: 100%; }
.puzzle-hero { display: grid; grid-template-columns: 1.25fr 1fr; gap: 32px; padding: clamp(24px,4vw,52px); background: radial-gradient(ellipse at top right,#e5484d18,transparent 65%),var(--panel); border: 1px solid var(--line-2); border-radius: 24px; overflow: hidden; }
.puzzle-hero h2 { font-size: clamp(32px,4vw,52px); max-width: 600px; margin: 14px 0 20px; }
.puzzle-hero p { max-width: 540px; color: var(--text-2); }
.puzzle-hero .controls { margin-top: 24px; }
.puzzle-demo { display: grid; place-items: center; padding: 12px; }
.puzzle-demo .quiz-art { width: 190px; transform: rotate(5deg); box-shadow: 0 18px 50px #0008; }
.puzzle-demo p { margin-top: 20px; text-align: center; }
.puzzle-rules { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; margin: 24px 0; }
.puzzle-rules > div { padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.puzzle-rules strong { display: block; font-size: 22px; margin: 8px 0; }
.puzzle-fine { margin-top: 16px; color: var(--steel); }
.puzzle-result { padding: 28px; border: 1px solid var(--line-2); background: var(--panel); border-radius: 20px; }
.puzzle-result .big-score { font: 700 clamp(40px,7vw,64px) var(--display); margin: 12px 0; }
.puzzle-summary { display: grid; gap: 8px; margin: 20px 0; }
.puzzle-summary > div { display: flex; justify-content: space-between; gap: 10px; }
.puzzle-review { margin-top: 24px; display: grid; gap: 12px; }
.puzzle-review details { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.puzzle-review summary { cursor: pointer; font-weight: 600; }
.puzzle-review p { margin-top: 12px; }
/* During a round, prioritize the question and its evidence. Setup keeps the Play navigation. */
.puzzles-page.puzzle-active .play-head { display: none; }
.puzzle-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.puzzle-context { display: grid; line-height: 1.35; }
.puzzle-context > span { color: var(--steel); }
.puzzle-time { font: 700 22px var(--mono); min-width: 70px; text-align: right; }
.puzzle-time[data-urgent=true] { color: var(--red-hi); }
.puzzle-sound { min-height: 44px; }
.puzzle-progress { display: flex; gap: 5px; margin-bottom: 14px; }
.puzzle-progress span { height: 4px; flex: 1; background: var(--panel-3); border-radius: 3px; }
.puzzle-progress .answered { background: var(--steel); }
.puzzle-progress .current { background: var(--red); }
.puzzle-question { margin-bottom: 14px; font-size: clamp(22px,2.5vw,30px); }
.puzzle-grid { display: grid; grid-template-columns: minmax(0,.85fr) minmax(0,1.15fr); gap: 20px; align-items: start; }
.puzzle-grid > *, .puzzle-visual > *, .quiz-duel > * { min-width: 0; }
.puzzle-visual { display: grid; justify-items: center; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: radial-gradient(ellipse at center,#252930,var(--panel) 75%); }
.puzzle-visual figure,.puzzle-demo figure { display: grid; justify-items: center; align-items: center; gap: 8px; width: 100%; }
.quiz-art { position: relative; width: min(100%,220px); aspect-ratio: 300/416; overflow: hidden; border-radius: 8px; background: #000; }
.quiz-art img { width: 100%; height: 100%; object-fit: cover; }
.quiz-art .quiz-mask { position: absolute; z-index: 2; background: #08090b; border: 1px solid #4a4f57; }
.quiz-art.mask-name .quiz-mask { left: 23%; right: 13%; bottom: 1%; height: 9%; }
.quiz-art.mask-stats .quiz-mask { left: 0; top: 0; width: 31%; height: 23%; }
.quiz-art.mask-family .quiz-mask { right: 0; top: 0; width: 38%; height: 22%; }
.quiz-art.mask-rarity .quiz-mask { inset: 0 0 auto; height: 22%; }
.quiz-caption { text-align: center; font-weight: 600; }
.quiz-duel { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; width: 100%; }
.quiz-duel .quiz-art { max-width: 150px; }
.quiz-rule { padding: 12px; text-align: center; }
.quiz-rule .i { width: 40px; height: 40px; margin: 0 auto 8px; color: var(--red); }
/* Top/right/bottom/left match the physical card, independent of image size. */
.quiz-edge-values { --diamond: 108px; display: inline-grid; grid-template-columns: repeat(3,1fr); grid-template-rows: repeat(3,1fr); width: var(--diamond); height: var(--diamond); flex: 0 0 var(--diamond); position: relative; isolation: isolate; }
.quiz-edge-values::before { content: ''; position: absolute; inset: 22%; transform: rotate(45deg); border: 1px solid var(--line-2); background: #080a0d; z-index: -1; }
.quiz-edge-values > span { display: grid; place-items: center; border-radius: 7px; background: #080a0d; border: 1px solid var(--line-2); }
.quiz-edge-values [data-side=top] { grid-area: 1 / 2; }
.quiz-edge-values [data-side=right] { grid-area: 2 / 3; }
.quiz-edge-values [data-side=bottom] { grid-area: 3 / 2; }
.quiz-edge-values [data-side=left] { grid-area: 2 / 1; }
.edge-value { color: #fff; font: 700 28px/1 var(--mono); }
.quiz-edge-values .emphasis { border-color: var(--red); background: var(--red-soft); }
.puzzle-choices { display: grid; gap: 8px; }
.puzzle-choice { position: relative; display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 56px; padding: 12px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel); text-align: left; font-size: 16px; }
.choice-letter { display: grid; place-items: center; flex: 0 0 26px; height: 26px; border-radius: 6px; background: var(--panel-3); color: var(--steel); }
.choice-text { min-width: 0; overflow-wrap: anywhere; }
.choice-result { position: absolute; right: 4px; top: 2px; font-weight: 700; }
.puzzle-choice:hover:not(:disabled) { border-color: var(--text-2); background: var(--panel-2); }
.puzzle-choice.correct { border-color: #85bd86; background: #25412c; }
.puzzle-choice.incorrect { border-color: var(--red); background: var(--red-soft); }
.puzzle-choice:disabled { cursor: default; opacity: 1; }
.puzzle-choice[data-numeric] .choice-text { font: 700 22px/1.4 var(--mono); }
[data-type=edges] .puzzle-choices,[data-type=best] .puzzle-choices { grid-template-columns: repeat(2,minmax(0,1fr)); }
[data-type=edges] .puzzle-choice { justify-content: center; padding: 12px 30px; }
[data-type=edges] .choice-letter { position: absolute; left: 8px; top: 8px; }
[data-type=best] .puzzle-choice { display: grid; grid-template-columns: 90px minmax(0,1fr); gap: 8px; }
[data-type=best] .quiz-edge-values { grid-area: 1 / 1; }
[data-type=best] .move-copy { grid-area: 1 / 2; }
[data-type=best] .quiz-edge-values { --diamond: 90px; }
[data-type=best] .choice-letter { grid-area: 1 / 1; justify-self: center; align-self: center; width: 26px; height: 26px; z-index: 1; }
.move-copy { display: grid; gap: 3px; min-width: 0; line-height: 1.25; }
.move-copy strong { overflow-wrap: anywhere; }
.move-destination { color: var(--text); font-weight: 600; }
.move-meta { color: var(--steel); }
.capture-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.capture-card > div { display: grid; gap: 4px; }
.capture-card .quiz-edge-values { --diamond: 90px; }
.puzzle-feedback { padding: 16px; margin-top: 12px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); }
.puzzle-feedback h3 { margin-bottom: 8px; }
.puzzle-feedback p { color: var(--text-2); margin-bottom: 12px; }
.puzzle-help { margin-top: 8px; color: var(--steel); }
.puzzle-help:empty { display: none; }
.puzzle-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.board-key { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 16px; color: var(--text-2); }
.puzzle-board { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 4px; width: min(100%,300px); }
.puzzle-square { position: relative; min-width: 0; aspect-ratio: 1; border: 2px solid var(--line-2); border-radius: 6px; background: var(--bg); overflow: hidden; }
.puzzle-square.owner-0 { border-color: var(--you); }
.puzzle-square.owner-1 { border-color: var(--opp); }
.puzzle-square img { position: absolute; inset: 0; height: 100%; width: 100%; object-fit: cover; opacity: .55; }

.puzzle-square .puzzle-owner,.puzzle-square .puzzle-family { position: absolute; bottom: 0; background: #080a0de8; font-size: 16px; line-height: 1; }
.puzzle-owner { left: 1px; }
.puzzle-family { right: 1px; }
.puzzle-square .puzzle-level { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); background: #080a0de8; font-weight: 700; line-height: 1; }
.puzzle-square .edge-num { font-size: 20px; font-weight: 800; line-height: 22px; min-width: 22px; padding: 0 1px; height: 22px; color: #fff; background: #080a0d; border-radius: 3px; }
.puzzle-square .edge-num.t { top: 0; }
.puzzle-square .edge-num.b { bottom: 0; }
.puzzle-square .edge-num.l { left: 0; top: 50%; }
.puzzle-square .edge-num.r { right: 0; top: 50%; }
.puzzle-guide { position: relative; color: var(--text-2); font-size: 16px; }
.puzzle-guide summary { cursor: pointer; text-align: center; min-height: 44px; display: grid; place-items: center; }
.puzzle-guide p { position: absolute; bottom: 100%; right: 0; z-index: 5; width: 250px; padding: 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel); box-shadow: 0 8px 24px #0008; }
@media (max-width: 700px) {
 #puzzle-root { scroll-margin-top: 72px; }
 .puzzle-hero,.puzzle-grid { grid-template-columns: minmax(0,1fr); gap: 8px; }
 .puzzle-demo { display: none; }
 .puzzle-rules { gap: 8px; }
 .puzzle-rules > div { padding: 12px 8px; }
 .puzzle-rules strong { font-size: 18px; }
 .puzzle-result { padding: 20px; }
 .puzzles-page.puzzle-active .nav { display: none; }
 .puzzles-page.puzzle-active #main { padding-top: 8px; padding-bottom: 12px; }
 .puzzle-top { display: grid; grid-template-columns: minmax(0,1fr) auto 44px; grid-template-rows: 22px 22px; gap: 0 8px; margin-bottom: 8px; }
 .puzzle-context { grid-area: 1 / 1 / 3 / 2; line-height: 22px; }
 .puzzle-top > .mono { grid-area: 1 / 2; line-height: 22px; text-align: right; }
 .puzzle-top .puzzle-time { grid-area: 2 / 2; line-height: 22px; }
 .puzzle-top .puzzle-sound { grid-area: 1 / 3 / 3 / 4; }
 .puzzle-context { font-size: 16px; }
 .puzzle-time { font-size: 20px; min-width: 40px; }
 .puzzle-top > .mono { white-space: nowrap; }
 .puzzle-top .puzzle-sound { width: 44px; padding: 0; flex: 0 0 44px; }
 .puzzle-top .puzzle-sound span { display: none; }
 .puzzle-progress { margin-bottom: 8px; }
 .puzzle-question { font-size: 20px; line-height: 1.2; margin-bottom: 8px; }
 .puzzle-visual { padding: 8px; gap: 6px; }
 .quiz-art { width: min(100%,156px); }
 .quiz-duel .quiz-art { max-width: 110px; }
 .quiz-duel { gap: 8px; }
 .quiz-edge-values { --diamond: 90px; }
 .edge-value { font-size: 26px; }
 .puzzle-choices { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px; }
 .puzzle-choice { padding: 8px; gap: 6px; min-height: 48px; }
 .choice-letter { flex-basis: 20px; height: 20px; }
 [data-type=edges] .puzzle-choice { padding: 8px 24px; }
 [data-type=edges] .choice-letter { top: 4px; left: 4px; width: 20px; }
 [data-type=best] .puzzle-choice { grid-template-columns: 66px minmax(0,1fr); padding: 6px; gap: 6px; }
 [data-type=best] .quiz-edge-values { --diamond: 66px; }
 [data-type=best] .edge-value { font-size: 20px; }
 [data-type=best] .choice-letter { width: 22px; height: 22px; }
 .move-copy { gap: 2px; line-height: 1.15; }
 .puzzle-board { max-width: 210px; gap: 3px; }
 .capture-card { padding: 6px 8px; }
 .capture-card .quiz-edge-values { --diamond: 66px; }
 .capture-card .edge-value { font-size: 22px; }
 .puzzle-visual .revealed-card { grid-template-columns: minmax(0,1fr) auto; max-width: 320px; }
 .revealed-card .quiz-caption { grid-column: 1 / -1; grid-row: 2; }
 .revealed-card .quiz-edge-values { grid-column: 2; grid-row: 1; }
 [data-phase=feedback] .quiz-duel { grid-template-columns: minmax(0,1fr); }
 .quiz-duel .revealed-card { grid-template-columns: 60px minmax(0,1fr) 90px; max-width: none; }
 .quiz-duel .revealed-card .quiz-caption { grid-column: 2; grid-row: 1; }
 .quiz-duel .revealed-card .quiz-edge-values { grid-column: 3; grid-row: 1; }
 [data-type=rule] .puzzle-visual { display: none; }
 .puzzle-guide summary { min-height: 44px; }
}
@media (max-width: 700px) and (max-height: 750px) {
 .puzzle-progress { display: none; }
 .puzzle-board { max-width: 200px; }
 .quiz-art { max-width: 130px; }
 .quiz-duel .quiz-art { max-width: 90px; }
}
@media (max-width: 360px) {
 .puzzle-top { column-gap: 6px; }
 .puzzle-context { min-width: 0; }
 .puzzle-base-points { display: none; }
 .puzzle-time { font-size: 16px; }
 [data-type=best] .puzzle-choice { text-align: center; }
 [data-type=best] .move-copy { display: contents; }
 [data-type=best] .move-copy strong { grid-area: 1 / 1 / 2 / 3; }
 [data-type=best] .quiz-edge-values,[data-type=best] .choice-letter { grid-area: 2 / 1 / 4 / 2; }
 [data-type=best] .move-destination { grid-area: 2 / 2; }
 [data-type=best] .move-meta { grid-area: 3 / 2; }
}

#puzzle-question:focus { outline: none; }

/* Rule context belongs to the question; green location badges are distinct from edges. */
.puzzle-question-context { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font: 600 18px/1.35 var(--sans); margin-bottom: 6px; }
.puzzle-rules-active { color: #f4d58d; font-weight: 800; }
.puzzle-player { color: #8acbff; font-weight: 700; }
.puzzle-opponent { color: #ff9ca9; }
.puzzle-cell { position: relative; min-width: 0; }
.square-reference { display: inline-block; white-space: nowrap; color: #a7edbd; background: #102b1a; border: 1px solid #5caa76; border-radius: 4px; padding: 0 2px; font: 700 16px/20px var(--mono); vertical-align: baseline; }
.puzzle-cell .square-id { position: absolute; top: -6px; left: -7px; z-index: 3; }
.puzzle-board { gap: 6px; }
.board-key { gap: 12px; margin-bottom: 4px; }
.puzzle-controls .puzzle-guide { margin-left: auto; }
.puzzle-answer-area > .puzzle-guide { margin-top: 8px; }
@media (max-width: 700px) {
 .puzzle-question-context { font-size: 16px; line-height: 20px; margin-bottom: 4px; }
 .board-key { margin-bottom: 2px; }
}

@media (max-width: 700px) {
 .move-destination .destination-label { display: none; }
 .move-destination::before { content: '→ '; }
}
