
/* Late-game playable test implementation (rooms 5-8) */
.late-room{min-height:100%;background:#ece9df;color:#2d302c;padding-bottom:92px;box-sizing:border-box}
.late-stage{width:min(980px,902.4px);margin:18px auto;padding:20px;border:1px solid #b6b2a8;border-radius:18px;background:#f8f6ef;box-shadow:0 8px 30px #00000012;box-sizing:border-box}
.late-stage.living{background:linear-gradient(160deg,#efe9dd,#d8c7ad)}
.late-stage.othello{display:grid;grid-template-columns:minmax(0,1fr) minmax(230px,320px);gap:18px}
.late-stage.zodiac{display:grid;grid-template-columns:minmax(0,1.2fr) minmax(280px,.8fr);gap:18px}
.late-stage.empty{min-height:313.2px;display:grid;place-items:center;background:linear-gradient(#fafafa,#eeeeea)}
.late-room-note{display:flex;justify-content:space-between;gap:12px;align-items:center;margin-bottom:14px}
.late-object-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-bottom:16px}
.late-object,.r7-book,.r7-doors button,.r6-cell,.late-main-action,.late-sub-action,.late-next,.r8-paper,.r8-final-door,.late-row button{
 min-height:48px;border:1px solid #999;border-radius:10px;background:#fff;color:#333;padding:10px;font:inherit
}
.late-object.done{background:#e7eee6;border-color:#758a76}
.late-main-action{background:#263b4e;color:white;border-color:#263b4e;font-weight:700}
.late-sub-action{background:#f2efe5}
.late-next{background:#365b45;color:#fff;border-color:#365b45;font-weight:700;margin-top:16px}
.late-overlay{z-index:140}
.late-panel{width:min(640px,902.4px);max-height:475.2px;overflow:auto;background:#fffdf6;border-radius:16px;padding:22px;color:#2d302c;box-sizing:border-box;position:relative}
.late-panel h2{margin-top:0;padding-right:44px}
.late-pending{margin:16px 0;padding:13px;border:2px dashed #b27b23;background:#fff5dd;border-radius:10px;color:#6f4b10;line-height:1.65}
.late-row{display:flex;gap:10px;flex-wrap:wrap}
.late-transition{min-height:540px;display:grid;place-items:center;background:#f7f7f4;color:#333;text-align:center}
.late-transition p{font-size:1.5rem}.late-transition span{font-size:2rem}
.r6-map{display:grid;grid-template-columns:repeat(8,minmax(36px,1fr));gap:4px}
.r6-cell{aspect-ratio:1;padding:2px;min-height:36px;font-size:12px}
.r6-cell.white{background:#fff}.r6-cell.black{background:#333;color:#fff}.r6-cell.visited{background:#e1e6de}.r6-cell.unknown{background:#c7cec2}
.late-side{display:flex;flex-direction:column;gap:10px}
.r6-moves{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:12px 0}
.r6-moves button{min-height:44px}
.r7-books,.r7-doors{padding:12px;border-radius:12px;background:#ffffffa8}
.r7-book{display:flex;width:100%;justify-content:space-between;align-items:center;gap:12px;margin:8px 0;text-align:left}
.r7-book small{opacity:.75}.r7-order{line-height:1.6}
.r7-doors{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;align-content:start}
.r7-doors h3,.r7-doors p{grid-column:1/-1}.r7-doors:not(.active){opacity:.62}
.final-living{min-height:297px;display:grid;place-items:center}
.r8-table{width:min(560px,88%);min-height:180px;border-radius:24px;background:#a67e58;color:#fff;display:grid;place-items:center;padding:24px;box-shadow:0 22px 0 #745638;text-align:center}
.r8-table span{display:block}
.r8-paper{width:min(300px,768px);aspect-ratio:1.41;background:#fffdf2;border:1px solid #d7ceb7;box-shadow:0 10px 24px #0002;font-size:1.25rem}
/* Room 8: one pixel-edged desk remains, with the interactive paper on its top. */
.r8-final-stage{overflow:hidden}
.r8-last-desk{position:relative;width:min(560px,94%);height:clamp(235px,248.4px,340px);display:flex;justify-content:center;align-items:flex-start}
.r8-last-desk-top{position:relative;z-index:2;display:grid;place-items:center;box-sizing:border-box;width:100%;height:clamp(140px,124.2px,175px);margin-top:16px;border:6px solid #50392e;border-radius:0;background:repeating-linear-gradient(0deg,#9d7553 0 12px,#a47a55 12px 16px);box-shadow:inset 0 8px #cba17a,inset 0 -8px #775338,0 12px 0 #674631,0 16px 0 #47372c}
.r8-last-desk-legs{position:absolute;z-index:1;top:calc(16px + clamp(140px,124.2px,175px) + 12px);left:8%;right:8%;height:clamp(100px,97.2px,150px);display:flex;justify-content:space-between}
.r8-last-desk-legs::before,.r8-last-desk-legs::after{content:"";display:block;width:clamp(26px,57.6px,48px);height:100%;background:linear-gradient(90deg,#493629 0 20%,#735239 20% 75%,#503a2d 75%);box-shadow:4px 0 0 #3b2a22}
.r8-last-desk-top .r8-paper{box-sizing:border-box;width:min(220px,64%);height:clamp(92px,91.8px,122px);aspect-ratio:auto;border:4px solid #d4c8ab;border-radius:0;background:#fffdf2;box-shadow:6px 6px 0 #64462f,inset 0 0 0 3px #f4eedb;transform:rotate(-3deg);font-size:clamp(15px,21.12px,21px);cursor:pointer}
.r8-last-desk-top .r8-paper:focus-visible{outline:4px solid #355a8a;outline-offset:5px}
.r8-question{font-size:2rem;font-weight:700}
.r8-back{display:none;margin:16px 0;padding:14px;background:#f7f4ea;border-radius:10px}.r8-back.show{display:block}
.r8-answer{display:grid;gap:8px;margin:18px 0}.r8-answer input{font-size:1.25rem;padding:12px;border:1px solid #aaa;border-radius:8px}
.r8-clue-log>div{display:grid;grid-template-columns:52px 1fr 1fr;gap:10px;padding:10px 0;border-bottom:1px solid #ddd}
.r8-clue-log strong{font-size:1.08rem}
.late-log-pulse{animation:lateLogPulse 1s infinite!important;box-shadow:0 0 0 0 rgba(220,120,40,.7)}
@keyframes lateLogPulse{50%{transform:scale(1.08);box-shadow:0 0 0 8px rgba(220,120,40,0)}}
.r8-final-door{width:min(330px,768px);height:220px;background:#5d493a;color:white;font-size:1.3rem}
.late-ending{min-height:540px;display:grid;place-content:center;gap:14px;text-align:center;background:radial-gradient(circle,#fff 0,#f6f0e5 55%,#dfd4c5 100%);color:#342e29}
.late-ending h1{font-size:clamp(56px,134.4px,110px);margin:0;letter-spacing:.12em}.late-ending p{margin:0;font-size:1.2rem}
.late-ending button{margin-top:24px;min-height:48px;padding:10px 24px;border:1px solid #76695e;border-radius:8px;background:#fff}
@container game-viewport (max-width:700px){
 .late-stage.othello,.late-stage.zodiac{grid-template-columns:1fr}
 .late-object-grid{grid-template-columns:repeat(2,1fr)}
 .r6-map{grid-template-columns:repeat(8,minmax(30px,1fr))}
 .r6-cell{font-size:10px;min-height:30px}
 .r7-doors{grid-template-columns:repeat(3,1fr)}
 .r7-book{display:block}.r7-book small{display:block;margin-top:4px}
}
@media(prefers-reduced-motion:reduce){.late-log-pulse{animation:none!important;outline:3px solid #d87828}}

.r6-cell.current{outline:3px solid #c26b21;outline-offset:-3px;font-weight:700}.r6-cell:disabled{opacity:.48;cursor:not-allowed}.r6-cell.current:disabled{opacity:1}

.gameplay-log-row.final-clue{font-weight:800;background:#fff1ba;border-left:5px solid #ba7d18;padding-left:12px}
.gameplay-log-row.final-clue .gameplay-log-text{font-weight:800}

/* Room 5 confirmed counter puzzle */
.late-object small,.late-object strong{display:block}
.late-object small{font-size:11px;opacity:.62;margin-bottom:4px}
.r5-actions{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
.r5-board-panel{width:min(760px,921.6px)}
.r5-problem{padding:14px 16px;border:1px solid #b9b29f;border-radius:10px;background:#f8f3e7;font-weight:700;text-align:center;letter-spacing:.04em}
.r5-art-note{margin:12px 0;padding:10px 12px;border:1px dashed #b27b23;border-radius:8px;background:#fff5dd;color:#6f4b10;font-size:13px;line-height:1.55}
.r5-counter-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:9px;margin:14px 0 20px}
.r5-counter-slot{min-height:96px;padding:9px;border:1px solid #a8a293;border-radius:12px;background:#fff;display:grid;place-items:center;gap:2px;color:#333;font:inherit}
.r5-counter-slot .counter{display:grid;place-items:center;width:38px;height:38px;border-radius:50%;background:#eee9dc;font-size:21px;font-weight:800}
.r5-counter-slot strong{font-size:15px}.r5-counter-slot small{font-size:11px;opacity:.62}
.r5-counter-slot.fixed{background:#edf3e7;border-color:#849b75}.r5-counter-slot.filled{background:#eef5ee;border-color:#739276}
.r5-inventory{display:flex;gap:8px;flex-wrap:wrap;min-height:48px}
.r5-inventory-tile{min-width:72px;min-height:44px;padding:8px 12px;border:1px solid #8e8a80;border-radius:9px;background:#fff;font:inherit}
.r5-inventory-tile.selected{outline:3px solid #b8751b;background:#fff4df}
.r5-board-feedback{min-height:1.6em;margin:10px 0;color:#5a534a}
.r5-code-reveal{margin:18px auto 4px;padding:14px;border-radius:12px;background:#222;color:#fff;text-align:center}
.r5-code-reveal small{display:block;opacity:.72}.r5-code-reveal strong{display:block;font-size:clamp(36px,86.4px,68px);letter-spacing:.18em}
.r5-keypad-panel{width:min(390px,883.2px);text-align:center}
.r5-keypad-display{margin:14px auto;padding:12px;border-radius:10px;background:#1d2420;color:#d8ffdc;font:700 34px/1 monospace;letter-spacing:.2em}
.r5-keypad-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:9px}
.r5-keypad-grid button{min-height:56px;border:1px solid #999;border-radius:9px;background:#fff;font:700 20px/1 sans-serif}
.r5-rabbit-memory{background:#705a45;border-color:#705a45}
@container game-viewport (max-width:700px){
 .r5-counter-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
 .r5-counter-slot{min-height:82px}
 .r5-actions>*{flex:1 1 100%}
}

/* Room 8: restrained text-only epilogue; artwork may replace these stages later. */
.r8-epilogue-fade{min-height:540px;background:#0e1117}
.r8-epilogue-stage{min-height:540px;display:grid;place-items:center;box-sizing:border-box;transition:background .6s ease}
.r8-epilogue-stage[data-place="hospital"]{background:linear-gradient(180deg,#f2f4f5 0%,#e3e9ec 100%);color:#505965}
.r8-epilogue-stage[data-place="home"]{background:linear-gradient(160deg,#e8e1d7 0%,#cfc2b4 100%);color:#605449}
.r8-epilogue-place{font-size:clamp(14px,23.04px,20px);letter-spacing:.24em;opacity:.7;text-align:center;padding:16px}

/* Room 8 approved 4-frame pixel-art dissolve. Keep the exact 1672:941 composition. */
.r8-dissolve-stage{position:relative;display:block;overflow:hidden;aspect-ratio:1672/941;min-height:0;padding:0;border-radius:0;background:#d2b194}
.r8-dissolve-stage .r8-dissolve-fallback{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);z-index:0}
.r8-dissolve-stage.has-r8-image .r8-dissolve-fallback{display:none}
.r8-dissolve-frame{position:absolute;inset:0;display:block;width:100%;height:100%;object-fit:fill;image-rendering:auto;opacity:0;transition:opacity .85s ease-in-out;pointer-events:none}
.r8-dissolve-frame.visible{opacity:1}
.r8-final-stage{position:relative;overflow:hidden;aspect-ratio:1672/941;min-height:0!important;padding:0;display:block!important;border-radius:0;background:#d2b194}
.r8-puzzle-art{display:none;position:absolute;inset:0;width:100%;height:100%;z-index:2}
.r8-final-stage.has-r8-final-image .r8-puzzle-art{display:block}
.r8-final-stage.has-r8-final-image .r8-last-desk{display:none}
.r8-puzzle-image{display:block;width:100%;height:100%;object-fit:fill}
.r8-paper-hit{position:absolute;z-index:3;left:41.5%;top:51%;width:17%;height:16%;min-width:44px;min-height:44px;border:0;border-radius:0;background:transparent;cursor:pointer;color:transparent}
.r8-paper-hit:hover{outline:2px dashed #ffe8ac;outline-offset:-4px;background:#ffffff14}
.r8-paper-hit:focus-visible{outline:4px solid #fff0b1;outline-offset:2px;background:#ffffff22}
@container game-viewport (max-width:640px){.r8-dissolve-stage,.r8-final-stage{width:min(980px,940.8px);margin:10px auto}.r8-paper-hit{top:48%;height:23%;}}

/* Epilogue: first-person ceiling, then the shared home and puzzle notebook. */
.r8-epilogue-stage[data-place="hospital"]{background:#e3e9ec url("images/background/room08/epilogue-hospital.webp") center/cover no-repeat}
.r8-epilogue-stage[data-place="home"]{background:#cfc2b4 url("images/background/room08/epilogue-bedroom-v4.webp") center/cover no-repeat}
.r8-epilogue-place{position:absolute;width:1px;height:1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
