* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { margin: 0; background: #2f1609; font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; -webkit-tap-highlight-color: transparent; }
#game-shell { position: fixed; inset: 0; overflow: hidden; background: #4a2510; }
#game { width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
.screen { position: absolute; inset: 0; }
.title-screen { background: #5e2d10; overflow: hidden; }
.title-screen > img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }
.title-actions { position: absolute; left: 50%; bottom: max(3.5vh, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(94vw, 760px); text-align: center; }
.title-buttons { display: flex; justify-content: center; align-items: center; gap: clamp(.6rem, 2vw, 1rem); flex-wrap: wrap; }
.title-actions p { margin: .7rem auto 0; padding: .45rem 1rem; width: fit-content; color: #fff9df; font-weight: 900; font-size: clamp(.9rem, 2vw, 1.25rem); text-shadow: 0 2px 3px #4a1e08; background: rgb(70 28 7 / 74%); border-radius: 999px; }
.big-button { min-height: 60px; padding: .7rem 2rem; border: 4px solid #fff1a6; border-radius: 999px; color: #fff; background: linear-gradient(#ff6a3c, #db251b); box-shadow: 0 7px 0 #7a180c, 0 11px 24px rgb(39 11 0 / 45%); font-size: clamp(1.2rem, 3.4vw, 2rem); font-weight: 1000; letter-spacing: .04em; cursor: pointer; text-shadow: 0 3px 0 #8b1a0d; }
.secondary-button { background: linear-gradient(#d58a35, #8b431c); box-shadow: 0 7px 0 #52240d, 0 11px 24px rgb(39 11 0 / 45%); }
.story-button { background: linear-gradient(#78b94b, #37822d); box-shadow: 0 7px 0 #20551c, 0 11px 24px rgb(22 48 8 / 45%); }
.big-button:active { transform: translateY(5px); box-shadow: 0 2px 0 #7a180c; }
.big-button:disabled { opacity: .62; cursor: wait; filter: saturate(.55); transform: none; }
.story-screen { z-index: 7; display: grid; grid-template-rows: auto minmax(0, 1fr); background: #241307; }
.story-toolbar { z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 68px; padding: .45rem max(1rem, env(safe-area-inset-right)) .45rem max(1rem, env(safe-area-inset-left)); color: #fff8d9; border-bottom: 4px solid #ffd87a; background: linear-gradient(#713915, #482007); box-shadow: 0 5px 18px rgb(20 7 0 / 55%); }
.story-toolbar h1 { margin: 0; font-size: clamp(1rem, 2.5vw, 1.65rem); line-height: 1; }
.story-toolbar p { margin: .2rem 0 0; color: #ffe5a2; font-size: clamp(.72rem, 1.5vw, .95rem); font-weight: 800; }
.story-toolbar .big-button { min-height: 46px; flex: 0 0 auto; padding: .35rem 1.3rem; font-size: clamp(.9rem, 2vw, 1.15rem); }
.story-scroll { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; scrollbar-color: #e9a33c #321706; }
.story-scroll img { display: block; width: 100%; height: auto; min-width: 0; }
.credits-screen { z-index: 7; overflow: hidden; background: #39200f; }
.credits-screen > img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }
.credits-panel { position: absolute; right: max(2vw, env(safe-area-inset-right)); bottom: max(2.5vh, env(safe-area-inset-bottom)); width: min(92vw, 430px); max-height: calc(100vh - 5vh); overflow: auto; padding: 1rem 1.25rem 1.15rem; text-align: center; color: #fff8d9; border: 4px solid #ffd87a; border-radius: 28px; background: rgb(64 29 10 / 90%); box-shadow: 0 12px 32px rgb(20 7 0 / 55%); touch-action: pan-y; }
.credits-panel h1 { margin: 0 0 .45rem; font-size: clamp(1.75rem, 4vw, 2.7rem); line-height: 1; text-shadow: 0 3px 0 #4b1d08; }
.credits-panel h2 { margin: .25rem 0; color: #ffe89d; font-size: clamp(1.05rem, 2.2vw, 1.35rem); }
.credits-panel p { margin: .32rem 0; font-size: clamp(.9rem, 1.75vw, 1.08rem); font-weight: 800; }
.credits-eyebrow { color: #ffd87a; font-size: clamp(.68rem, 1.3vw, .8rem) !important; letter-spacing: .17em; }
.credits-team { color: #fff; }
.credits-roles { margin: .65rem 0; }
.credits-roles div { display: flex; justify-content: center; gap: .35rem; margin: .25rem 0; }
.credits-roles dt, .credits-roles dd { margin: 0; }
.credits-links { display: flex; justify-content: center; flex-wrap: wrap; gap: .38rem .9rem; margin: .65rem 0; }
.credits-links a { color: #fff1a6; font-weight: 1000; text-underline-offset: 3px; touch-action: manipulation; }
.credits-fineprint { padding-top: .55rem; border-top: 1px solid rgb(255 216 122 / 55%); font-size: clamp(.7rem, 1.3vw, .82rem) !important; font-weight: 600 !important; line-height: 1.35; }
.credits-thanks { margin: .55rem 0 .7rem !important; }
.credits-panel .big-button { min-height: 48px; padding: .45rem 1.6rem; font-size: clamp(1rem, 2vw, 1.3rem); }
.hud { position: absolute; z-index: 5; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: grid; grid-template-columns: 1fr 1fr 1fr auto; align-items: start; gap: .5rem; color: white; font-size: clamp(.8rem, 2.1vw, 1.35rem); font-weight: 1000; text-align: center; text-shadow: 0 2px 0 #421803; }
.hud > span { justify-self: center; min-width: clamp(100px, 14vw, 175px); padding: .55rem .8rem; border: 3px solid #ffd870; border-radius: 999px; background: rgb(78 35 12 / 88%); box-shadow: 0 5px 14px rgb(31 11 0 / 35%); }
.round-button { width: 48px; height: 48px; border: 3px solid #ffe49a; border-radius: 50%; background: #b84b21; color: white; font-size: 1.35rem; font-weight: 1000; cursor: pointer; }
.music-button { position: absolute; z-index: 30; top: max(70px, calc(env(safe-area-inset-top) + 58px)); right: max(10px, env(safe-area-inset-right)); display: flex; align-items: center; justify-content: center; gap: .38rem; min-width: 112px; height: 46px; padding: 0 .8rem; border: 3px solid #ffe49a; border-radius: 999px; background: #2f7b3e; color: white; box-shadow: 0 5px 14px rgb(31 11 0 / 38%); font: inherit; font-size: .88rem; font-weight: 1000; cursor: pointer; text-shadow: 0 2px 0 rgb(31 11 0 / 50%); }
.music-button > span { font-size: 1.35rem; line-height: 1; }
.music-button[aria-pressed="false"] { background: #7a4b37; }
.music-button:disabled { cursor: wait; filter: grayscale(.7); opacity: .66; }
.music-button:focus-visible { outline: 4px solid white; outline-offset: 3px; }
.message-screen { z-index: 8; overflow: hidden; isolation: isolate; background: #3a1b08; }
.message-screen::before { content: ""; position: absolute; z-index: -2; inset: -24px; background: var(--outcome-art) center/cover no-repeat; filter: blur(18px) brightness(.6) saturate(1.15); transform: scale(1.08); }
.message-screen::after { content: ""; position: absolute; z-index: -1; inset: 0; background: rgb(41 18 5 / 18%); }
.message-screen.well-done { --outcome-art: url('assets/runtime/well-done-screen.png'); }
.message-screen.game-over { --outcome-art: url('assets/runtime/game-over-screen.png'); }
.message-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center; display: block; }
.wood-card { position: absolute; z-index: 2; left: 50%; bottom: max(2vh, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: .6rem 1rem; width: min(92vw, 720px); padding: .65rem .9rem; text-align: center; color: #fff8d9; border: 4px solid #ffd87a; border-radius: 24px; background: rgb(73 31 9 / 90%); box-shadow: 0 12px 32px rgb(20 7 0 / 60%); }
.wood-card h1 { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.wood-card p { flex: 1 1 300px; margin: 0; font-size: clamp(.9rem, 2vw, 1.15rem); font-weight: 900; }
.wood-card .big-button { min-height: 48px; padding: .4rem 1.4rem; font-size: clamp(1rem, 2.2vw, 1.35rem); }
.pause-screen { z-index: 10; display: grid; place-items: center; padding: 1rem; background: rgb(37 13 3 / 62%); backdrop-filter: blur(4px); }
.pause-card { display: grid; gap: 1rem; width: min(90vw, 480px); padding: clamp(1.2rem, 4vw, 2.2rem); text-align: center; color: #fff8d9; border: 5px solid #ffd87a; border-radius: 30px; background: rgb(73 31 9 / 94%); box-shadow: 0 16px 45px rgb(24 7 0 / 65%); }
.pause-card h1 { margin: 0; font-size: clamp(2rem, 7vw, 3.8rem); line-height: 1; text-shadow: 0 4px 0 #4b1d08; }
.pause-card .big-button { width: 100%; }
.loading { position: absolute; inset: auto 0 1rem; z-index: 20; text-align: center; color: white; font-weight: 900; text-shadow: 0 2px 3px black; }
@media (max-width: 620px) {
  .hud { left: 6px; right: 6px; width: auto; transform: none; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: .25rem; padding: 0; font-size: clamp(.68rem, 3.3vw, .9rem); }
  .hud > span { min-width: 0; width: 100%; padding: .55rem .15rem; border-width: 2px; }
  .round-button { width: 42px; height: 42px; }
  .music-button { top: max(58px, calc(env(safe-area-inset-top) + 50px)); min-width: 100px; height: 42px; padding: 0 .65rem; font-size: .78rem; }
  .title-actions p { border-radius: 18px; }
  .story-toolbar { min-height: 62px; }
  .story-toolbar p { max-width: 190px; }
  .story-scroll img { width: auto; max-width: none; height: 100%; }
  .wood-card { bottom: max(1.5vh, env(safe-area-inset-bottom)); width: min(92vw, 430px); }
  .wood-card p { flex-basis: 100%; }
  .credits-panel { left: 50%; right: auto; bottom: max(1.5vh, env(safe-area-inset-bottom)); transform: translateX(-50%); max-height: 62vh; }
}
@media (max-height: 620px) {
  .title-actions p { display: none; }
}
@media (max-height: 480px) {
  .title-actions { bottom: 10px; }
  .title-actions p { display: none; }
  .big-button { min-height: 48px; padding: .45rem 1.5rem; }
  .story-toolbar { min-height: 52px; padding-top: .25rem; padding-bottom: .25rem; }
  .story-toolbar p { display: none; }
  .story-toolbar .big-button { min-height: 38px; }
  .wood-card { bottom: 7px; width: min(78vw, 680px); padding: .35rem .65rem; border-width: 3px; border-radius: 18px; }
  .wood-card p { flex: 1 1 280px; font-size: .78rem; }
  .wood-card .big-button { min-height: 38px; padding: .25rem 1rem; font-size: .9rem; }
  .pause-card { grid-template-columns: 1fr 1fr; width: min(92vw, 680px); padding: .7rem; gap: .65rem; }
  .pause-card h1 { grid-column: 1 / -1; font-size: 1.6rem; }
  .pause-card .big-button { min-height: 40px; padding: .3rem .8rem; font-size: .95rem; }
  .credits-panel { left: auto; right: 8px; bottom: 8px; transform: none; width: min(45vw, 390px); max-height: calc(100vh - 16px); padding: .65rem .85rem .75rem; border-width: 3px; border-radius: 20px; }
  .credits-panel h1 { font-size: 1.55rem; }
  .credits-panel h2 { font-size: .98rem; }
  .credits-panel p, .credits-roles, .credits-links { font-size: .78rem; }
  .credits-panel .big-button { min-height: 38px; padding: .3rem 1.2rem; }
  .hud { top: 5px; }
}
@media (max-height: 480px) and (min-width: 621px) {
  .hud { left: 8px; right: auto; width: 108px; display: flex; flex-direction: column; gap: .28rem; font-size: .78rem; }
  .hud > span { width: 108px; min-width: 108px; padding: .35rem .25rem; border-width: 2px; }
  .round-button { width: 42px; height: 42px; align-self: center; }
  .music-button { top: 8px; right: 8px; }
}
@media (prefers-reduced-motion: reduce) { .wood-card { transform: none; } }
