:root {
  color-scheme: light;
  --top: max(12px, env(safe-area-inset-top));
  --right: max(12px, env(safe-area-inset-right));
  --bottom: max(12px, env(safe-area-inset-bottom));
  --left: max(12px, env(safe-area-inset-left));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { position: relative; margin: 0; height: 100dvh; background: #d7e8e5; font-family: system-ui, sans-serif; color: #203f47; }
#game-stage { position: absolute; inset: 0; overflow: hidden; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }
#game:focus { outline: none; }
header { position: absolute; top: var(--top); right: var(--right); pointer-events: none; }
.header-actions { display: flex; align-items: center; gap: 8px; }
#status { background: #ffffffe0; padding: 10px 14px; border-radius: 25px; font-size: 12px; white-space: nowrap; }
button { font: inherit; color: #315b60; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 3px solid #bb721c; outline-offset: 3px; }
.utility-button { min-width: 44px; min-height: 44px; border-radius: 14px; background: #fffdf5dc; font-weight: 750; touch-action: manipulation; }
#fullscreen { pointer-events: auto; font-size: 25px; }
aside { position: absolute; top: var(--top); left: var(--left); max-width: calc(100% - var(--left) - var(--right) - 210px); display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 16px; background: #fffef5e3; pointer-events: none; }
.quest-copy { min-width: 0; }
#quest { margin: 0; font-size: 12px; line-height: 1.3; }
#quest-progress { display: block; width: 100%; height: 4px; margin-top: 6px; border: 0; border-radius: 4px; overflow: hidden; appearance: none; background: #315b6026; }
#quest-progress::-webkit-progress-bar { background: #315b6026; border-radius: 4px; }
#quest-progress::-webkit-progress-value { background: #478b79; border-radius: 4px; }
#quest-progress::-moz-progress-bar { background: #478b79; border-radius: 4px; }
#score { display: block; font-size: 20px; color: #a86619; white-space: nowrap; }
#hero-toggle { position: absolute; right: var(--right); bottom: var(--bottom); padding: 0 14px; font-size: 13px; }
#hero-panel { display: none; position: absolute; z-index: 4; right: var(--right); bottom: calc(var(--bottom) + 54px); width: 246px; max-width: calc(100% - var(--left) - var(--right)); max-height: calc(100dvh - var(--top) - var(--bottom) - 116px); overflow-y: auto; padding: 10px; border-radius: 20px; background: #edf4eaf5; box-shadow: 0 8px 32px #21434030; overscroll-behavior: contain; }
body.picker-open #hero-panel { display: block; }
.picker-heading { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 750; margin: -4px -2px 4px 3px; }
#hero-close { font-size: 22px; background: transparent; }
#hero-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.hero-choice { min-width: 0; min-height: 82px; padding: 5px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; background: #fffdf6ed; border: 2px solid transparent; border-radius: 16px; font-size: 10px; font-weight: 650; touch-action: manipulation; }
.hero-choice[aria-pressed="true"] { border-color: #478b79; background: #e8f3df; }
.hero-icon { display: block; width: 33px; height: 44px; }
.animation-link { display: block; padding: 14px 4px 4px; color: #367b70; font-size: 11px; text-align: center; text-decoration: none; }
.animation-link:hover { text-decoration: underline; }
#pad { display: none; position: absolute; left: var(--left); bottom: var(--bottom); grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); gap: 5px; pointer-events: none; }
#pad button { pointer-events: auto; border: 1px solid #ffffffb0; border-radius: 15px; background: #fffdf6b8; font-size: 21px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; box-shadow: 0 3px 10px #21434012; }
#pad button:first-child { grid-column: 2; }
#pad button:nth-child(2) { grid-column: 1; grid-row: 2; }
#pad button:nth-child(3) { grid-column: 2; grid-row: 2; }
#pad button:nth-child(4) { grid-column: 3; grid-row: 2; }
#pad button.is-held, #pad button:active { background: #bcdccd; border-color: #478b79; }
#rotate-hint { display: none; pointer-events: none; }
#screen-message { position: absolute; bottom: calc(var(--bottom) + 62px); right: var(--right); max-width: min(290px, calc(100% - 24px)); padding: 12px 16px; border-radius: 14px; background: #fffdf6; box-shadow: 0 5px 25px #21434025; font-size: 12px; pointer-events: none; z-index: 5; }

/* HUD elements float above the room; no viewport space is reserved for them. */
@media (any-pointer: coarse), (max-width: 700px), (max-height: 600px) {
  #pad { display: grid; }
}
@media (max-width: 700px), (max-height: 600px) {
  #status { font-size: 10px; padding: 8px 10px; }
  .header-actions { gap: 6px; }
  aside { max-width: calc(100% - var(--left) - var(--right) - 190px); padding: 9px 12px; }
  #quest { font-size: 10px; }
  #score { font-size: 18px; }
}
@media (orientation: portrait) and (max-width: 700px) {
  aside { top: calc(var(--top) + 56px); max-width: calc(100% - var(--left) - var(--right)); }
  #quest { font-size: 12px; }
  #rotate-hint { display: block; position: absolute; top: var(--top); left: var(--left); max-width: calc(100% - 195px); padding: 7px 9px; border-radius: 12px; background: #fffef5d9; font-size: 10px; line-height: 1.4; }
}

/* Entry and guest mode */
#access-screen { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px; overflow-y: auto; background: #203f4770; backdrop-filter: blur(7px); }
.access-card { width: min(540px, 100%); margin: auto; padding: clamp(18px, 4vw, 32px); border-radius: 28px; background: #f7faf0; box-shadow: 0 20px 80px #17363340; }
.access-card h1 { margin: 8px 0; font-size: clamp(23px, 5vw, 32px); letter-spacing: -.8px; }
.access-card p { font-size: 14px; line-height: 1.5; }
.access-card .tag { font-size: 10px; font-weight: 800; letter-spacing: 2px; color: #53806b; }
#access-heroes { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin: 20px 0; }
#access-heroes .hero-choice { font-size: 12px; min-height: 112px; }
#access-heroes .hero-icon { width: 42px; height: 56px; }
#access-heroes small { font-size: 10px; color: #677a70; }
#access-form label { display: block; font-size: 14px; margin-bottom: 8px; }
.phrase-row { display: flex; border: 1px solid #9ab5a4; border-radius: 12px; background: white; overflow: hidden; }
#access-phrase { font: inherit; min-width: 0; width: 100%; border: 0; padding: 13px; background: transparent; }
#phrase-reveal { width: 48px; background: transparent; }
#access-form > small { display: block; color: #617d71; margin: 7px 0 12px; }
#access-submit, #guest-enter { width: 100%; min-height: 46px; border-radius: 13px; font-weight: 700; }
#access-submit { color: white; background: #367965; }
#guest-enter { color: #366450; background: #e2ecdc; }
#access-error { color: #a3392e; min-height: 1em; }
button:disabled { opacity: .6; cursor: wait; }
#change-player { pointer-events: auto; padding: 0 12px; font-size: 12px; }
body.spectator #pad, body.spectator aside, body.spectator footer, body.spectator #hero-toggle, body.spectator #rotate-hint { display: none !important; }
body.access-open header { visibility: hidden; }
