:root {
  color-scheme: dark;
  --bg: #0c100e;
  --panel: #1d2721;
  --text: #eeeae0;
  --muted: #a2ac9d;
  --accent: #edab72;
  --line: #414d3e;
  --serif: Georgia, 'Times New Roman', serif;
  --mono: Consolas, 'Courier New', monospace;
  --toolbar-height: 48px;
  --inventory-height: 60px;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { min-height: 100dvh; display: grid; place-items: center; background: var(--bg); }
button, input, select { font: inherit; color: inherit; border-radius: 4px; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:active:not(:disabled) { transform: translateY(1px); }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
p { line-height: 1.65; }
.eyebrow { font: 10px/1.5 var(--mono); letter-spacing: 1.4px; color: var(--muted); }
.game-shell {
  --scene-ratio: 1.77777778;
  width: min(100vw, calc((100dvh - var(--toolbar-height) - var(--inventory-height)) * var(--scene-ratio)));
  max-width: 100%;
  margin: auto;
  background: #121813;
  box-shadow: 0 0 80px #0006;
}
.site-header { height: var(--toolbar-height); padding: 0 12px 0 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-size: 10px; letter-spacing: 2.5px; color: #abb5a4; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 3px; margin-left: auto; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; flex: none; padding: 0; background: transparent; border: 1px solid transparent; color: #cbd2c2; font-size: 21px; line-height: 1; }
.icon-button:hover:not(:disabled) { color: #fff4d8; background: #ffffff09; }
.icon-button.active { color: var(--accent); }
main { margin: 0; width: 100%; }
.stage { width: 100%; aspect-ratio: var(--scene-ratio); position: relative; overflow: hidden; isolation: isolate; background: #17221c; }
.room-background { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; user-select: none; }
#scene-objects { position: absolute; inset: 0; }
.scene-object { position: absolute; z-index: 2; margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; perspective: 800px; }
.scene-object:active:not(:disabled) { transform: none; }
.object-layer { position: absolute; display: block; inset: 0; pointer-events: none; }
.object-layer img { position: absolute; display: block; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: fill; pointer-events: none; user-select: none; }
.object-moving { transform-origin: left center; backface-visibility: hidden; }
.scene-object[data-animation=door][data-state=open] .object-moving { transform: perspective(800px) rotateY(-78deg); }
.scene-object[data-animation=drawer][data-state=open] .object-moving { transform: translateY(30px) scale(1.02); transform-origin: center center; }
.scene-object[data-animation=curtain][data-state=open] .object-moving { transform: translateX(-8%) scaleX(.13); }
.scene-object.scene-patch { overflow: hidden; }
.scene-patch .object-layer { overflow: hidden; }
.scene-object.scene-patch[data-state=open] .object-moving { opacity: 0; transform: none; }
.scene-object:focus-visible { outline: 2px dashed #efc991; outline-offset: -2px; }
.scene-object.pickup-object { z-index: 4; }
.pickup-object .object-layer img { object-fit: contain; }
.scene-object.pickup-object:hover .object-image { filter: drop-shadow(0 0 7px #fbd89370); }
.reveal .scene-object { outline: 1px dashed #efc991a0; outline-offset: -2px; }
.scene-arrow { position: absolute; top: 50%; z-index: 7; display: grid; place-items: center; width: 40px; height: 54px; padding: 0; border: 1px solid #ffffff17; border-radius: 5px; background: #0a100c66; color: #f2e5c9; transform: translateY(-50%); font: 42px/.7 Arial, sans-serif; opacity: .6; transition: opacity .15s, background .15s; }
.scene-arrow:active:not(:disabled) { transform: translateY(-50%); }
.scene-arrow:hover:not(:disabled), .scene-arrow:focus-visible { opacity: 1; background: #10190ec9; }
.scene-arrow-prev { left: 10px; }
.scene-arrow-next { right: 10px; }
.hover-label { position: absolute; bottom: 12px; left: 50%; z-index: 6; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 7px 13px; border-radius: 4px; background: #0e1611b8; color: #e8e9df; font-size: 11px; text-align: center; pointer-events: none; opacity: 0; transition: opacity .12s; }
.hover-label.visible { opacity: 1; }
.inventory-panel { height: var(--inventory-height); display: flex; align-items: center; justify-content: center; border-top: 1px solid #364032; padding: 5px 12px; }
.inventory { display: flex; align-items: center; justify-content: safe center; gap: 7px; max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 2px; scrollbar-width: thin; }
.inventory-slot, .inventory-item { flex: none; display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid #56604950; border-radius: 5px; background: #090f0b38; }
.inventory-slot { box-shadow: inset 0 1px 5px #0003; }
/* Portrait images must shrink to the slot instead of enlarging its automatic grid track. */
.inventory-item { grid-template: minmax(0, 1fr) / minmax(0, 1fr); padding: 3px; border-color: #7383649a; background: #2c382659; }
.inventory-item:hover { border-color: var(--accent); background: #3a462e; }
.inventory-item img { display: block; min-width: 0; min-height: 0; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 2px #0005); }
.language-picker { display: flex; align-items: center; gap: 12px; margin: 0 0 18px; text-align: left; }
.language-picker .field-label { margin: 0; }
.language-picker select { flex: 1; min-width: 0; width: auto; }
.primary-button { min-height: 46px; padding: 12px 20px; border: 1px solid var(--accent); border-radius: 4px; background: var(--accent); color: #262c23; font-size: 13px; font-weight: 600; text-align: center; }
.primary-button:hover:not(:disabled) { background: #f5bd87; border-color: #f5bd87; }
.game-dialog { width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 28px); overflow: auto; overscroll-behavior: contain; padding: 23px 28px 28px; border: 1px solid #667157; border-radius: 7px; background: #222d25; color: var(--text); box-shadow: 0 25px 100px #0009; }
.game-dialog::backdrop { background: #08120ea6; backdrop-filter: blur(3px); }
.dialog-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 9px; }
.dialog-top .eyebrow { font-size: 9px; }
.dialog-top .icon-button { width: 34px; height: 34px; font-size: 16px; }
.game-dialog h2 { margin-bottom: 22px; font: 30px/1.2 var(--serif); font-weight: 400; }
.game-dialog p { color: #bdc9b3; font-size: 13px; }
.game-dialog .primary-button, .game-dialog .secondary-button { display: block; width: 100%; margin: 12px 0; }
.secondary-button { min-height: 44px; padding: 12px 18px; border: 1px solid #60734f; background: #344230; color: #d5dfc5; font-size: 12px; }
.secondary-button:hover:not(:disabled) { background: #45593a; }
.text-button { padding: 8px 0; background: none; border: 0; color: var(--accent); text-align: left; font-size: 12px; line-height: 1.5; }
.text-button:hover:not(:disabled) { text-decoration: underline; }
.small-print { color: #96a68a !important; font-size: 11px !important; line-height: 1.7; }
.quiet { color: #a0af94 !important; }
.note-text { white-space: pre-line; line-height: 1.85 !important; }
.note-card { margin: 15px 0; padding: 17px 18px; border: 1px solid #45503d; border-left: 3px solid #94a874; background: #1a251c; }
.note-card h3 { margin-bottom: 10px; color: #e0e5d3; font: 20px var(--serif); }
.note-card p { margin: 0; font-size: 12px; }
.item-preview { display: block; width: 130px; height: 130px; margin: 12px auto 24px; object-fit: contain; }
.requirement-box { margin-bottom: 18px; padding: 18px; border: 1px solid #876741; background: #463b273d; }
.requirement-box .eyebrow { color: #dbb37a; }
.requirement-box p { margin: 12px 0 0; color: #cebd9f; }
.success-banner { padding: 18px; border: 1px solid #6e8b53; background: #496c393d; color: #c9dfb8 !important; }
.puzzle-form > p { margin-bottom: 22px; font-size: 13px; line-height: 1.7; }
.puzzle-form label { display: block; color: #aab99d; font: 11px var(--mono); }
.code-display { display: block; width: 100%; min-height: 64px; margin: 10px 0 18px; padding: 14px; border: 1px solid #546543; border-radius: 3px; background: #101d17; color: #e0d9ac; font: 32px var(--mono); letter-spacing: 10px; text-align: center; }
.code-display::placeholder { color: #819173; font-size: 18px; letter-spacing: 2px; }
input[data-focus=calculation-input] { letter-spacing: 1px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; max-width: 290px; margin: 0 auto 23px; }
.keypad button { min-height: 44px; border: 1px solid #596649; background: #33402d; color: #d6ddc7; font: 19px var(--mono); }
.keypad button:hover { background: #4c6040; }
.keypad button:nth-child(10) { grid-column: 2; }
.keypad button:nth-child(11) { grid-column: 3; }
.puzzle-help { margin-top: 10px; }
.color-slots { display: flex; gap: 10px; margin: 24px 0; }
.color-slot { flex: 1; min-width: 0; text-align: center; }
.color-swatch { display: grid; place-items: center; width: 56px; height: 56px; margin: 12px auto 14px; border: 4px solid #1a251c; border-radius: 50%; outline: 1px solid #697452; color: #1b2922; font-size: 25px; box-shadow: inset 0 0 15px #ffffff38, 0 2px 6px #0005; }
select { display: block; width: 100%; min-height: 44px; padding: 11px; border: 1px solid #647753; background: #2d3b29; color: #e0e6d1; font-size: 12px; }
.color-slot select { max-width: 100%; padding: 9px 3px; font-size: 10px; text-align: center; }
.calculation-terms { display: grid; grid-template-columns: 1fr auto; gap: 0; margin: 22px 0; padding: 8px 17px; border: 1px solid #455c38; background: #18251b; }
.calculation-terms dt, .calculation-terms dd { margin: 0; padding: 12px 0; border-bottom: 1px solid #36472d; font-size: 12px; }
.calculation-terms dt { color: #b2c1a6; }
.calculation-terms dd { padding-left: 20px; color: var(--accent); text-align: right; font: 18px var(--mono); }
.calculation-terms > :nth-last-child(-n+2) { border-bottom: 0; }
.field-label { display: block; margin: 17px 0 9px; color: #b2c29e; font: 11px var(--mono); }
.toggle-row { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; color: #bdc9b3; font-size: 12px; }
.toggle-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.menu-stats { display: grid; grid-template-columns: auto 1fr; gap: 12px 20px; padding-bottom: 20px; margin: 0 0 24px; border-bottom: 1px solid var(--line); font-size: 12px; }
.menu-stats dt { color: #aab99d; }
.menu-stats dd { margin: 0; text-align: right; color: #dddcc7; }
.danger { color: #dcaa89; }
.win-seal { display: grid; place-items: center; width: 68px; height: 68px; margin: 15px auto 24px; border: 1px solid #94ab75; border-radius: 50%; color: #bad29b; font: 34px var(--mono); }
.win-time { margin: 25px 0 8px; text-align: center; color: var(--accent); font: 44px var(--mono); }
.win-time + .small-print { text-align: center; }
.ad-dialog { z-index: 50; border-color: var(--accent); }
#videoad { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1000; }
#videoad:empty { display: none !important; }
.ad-dialog .eyebrow { color: var(--accent); font-size: 9px; }
.dialog-feedback { margin: 15px 0 0; padding-top: 14px; border-top: 1px solid #778560; color: #f0c491 !important; }
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
@media (max-width: 520px) {
  .site-header { padding-left: 12px; padding-right: 6px; }
  .brand { font-size: 9px; letter-spacing: 1.6px; }
  .header-actions { gap: 1px; }
  .icon-button { width: 38px; height: 42px; }
  .scene-arrow { width: 34px; height: 46px; font-size: 36px; }
  .scene-arrow-prev { left: 5px; }
  .scene-arrow-next { right: 5px; }
  .hover-label { bottom: 7px; padding: 5px 9px; font-size: 10px; }
  .game-dialog { padding: 16px 19px 22px; }
  .game-dialog h2 { font-size: 27px; }
  .color-slots { gap: 6px; }
  .color-swatch { width: 45px; height: 45px; font-size: 22px; }
  .color-slot select { padding: 9px 1px; font-size: 9px; }
  .puzzle-form label { font-size: 10px; }
  .calculation-terms { padding: 6px 12px; }
  .calculation-terms dt { font-size: 11px; }
  .calculation-terms dd { font-size: 17px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  :root { --toolbar-height: 44px; --inventory-height: 50px; }
  .site-header { padding: 0 8px; }
  .icon-button { width: 40px; height: 40px; }
  .inventory-item, .inventory-slot { width: 39px; height: 39px; }
  .inventory-panel { padding: 3px 8px; }
}

/* Reveal background and saved-state layers together after decoding. */
.stage[data-scene-loading] > #room-background,.stage[data-scene-loading] > #scene-objects { visibility:hidden; }
.stage[data-scene-loading] #scene-objects * { transition:none!important;animation:none!important; }
.scene-transition-cover { position:absolute;inset:0;z-index:20;overflow:hidden;background:#17221c;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:#f2e5c9; }
.scene-transition-cover * { transition:none!important;animation:none!important;pointer-events:none; }
.scene-transition-cover > button { pointer-events:auto; }
