:root {
  --bg: #14121c;
  --bg-soft: #1c1a28;
  --ink: #f4ecdd;
  --dim: #b9af9f;
  --warm: #ffcc8a;
  --line: rgba(244, 236, 221, 0.46);
  --line-soft: rgba(244, 236, 221, 0.20);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

main {
  position: relative;
  width: 100%;
  max-width: 430px;
  padding: max(14px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

header { text-align: center; }

h1 {
  margin: 2px 0 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.045em;
  color: var(--ink);
}

.sub {
  margin: 2px 0 0;
  font-size: 16px;
  color: var(--dim);
}

#stage {
  display: block;
  width: min(100%, 340px);
  height: auto;
  aspect-ratio: 176 / 312;
  border-radius: 8px;
  background: #1a1826;
  box-shadow:
    0 0 0 1px var(--line-soft),
    0 18px 44px -20px rgba(0, 0, 0, 0.85),
    0 0 70px -30px rgba(255, 204, 138, 0.20);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  outline: none;
}

#stage:focus-visible {
  box-shadow:
    0 0 0 3px var(--warm),
    0 0 0 6px var(--bg),
    0 18px 44px -20px rgba(0, 0, 0, 0.85);
}

#caption {
  margin: 0;
  min-height: 1.45em;
  font-size: 16px;
  text-align: center;
  color: var(--dim);
  transition: color 260ms ease;
}

#caption.lit { color: var(--warm); }

.foot {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#hint {
  margin: 0;
  font-size: 16px;
  color: var(--dim);
  line-height: 1.35;
}

#hint.hint { color: var(--warm); }

#sound {
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 22px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 200ms ease, border-color 200ms ease;
}

#sound:hover { border-color: rgba(244, 236, 221, 0.62); }

#sound:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 2px;
}

#sound[aria-pressed="true"] {
  color: var(--warm);
  border-color: var(--warm);
}

#sound .glyph { font-size: 18px; line-height: 1; }

@media (pointer: fine) {
  /* The desktop card is sized against the window height, not a fixed
     breakpoint, so the page never scrolls and the sound control never falls
     below the fold at any window height. The stage shares the window with
     184 px of header, caption and controls; 176/312 is the art's own aspect. */
  #stage { width: min(100%, 340px, calc((100dvh - 184px) * 176 / 312)); }
}

@media (min-width: 900px) and (pointer: fine) {
  main { max-width: 470px; }
  #stage { width: min(100%, 380px, calc((100dvh - 184px) * 176 / 312)); }
}

@media (max-height: 700px) and (pointer: fine) {
  .sub { display: none; }
  #stage { width: min(100%, 380px, calc((100dvh - 154px) * 176 / 312)); }
}

/* --- phones: the scene is the whole screen ------------------------------- */

@media (pointer: coarse) {
  html, body { height: 100%; }
  body { overflow: hidden; display: block; }

  main {
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    padding: 0;
    display: block;
    overflow: hidden;
  }

  #stage {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
    box-shadow: none;
    aspect-ratio: auto;
  }

  #stage:focus-visible {
    box-shadow: inset 0 0 0 3px var(--warm);
  }

  header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    padding: max(10px, env(safe-area-inset-top)) 16px 0;
    text-align: center;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(20, 18, 28, 0.62), rgba(20, 18, 28, 0));
  }

  h1 { font-size: 20px; }

  .foot {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 10px 16px max(12px, env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(20, 18, 28, 0.80), rgba(20, 18, 28, 0));
    pointer-events: none;
  }

  #hint { max-width: 58%; pointer-events: none; }
  #sound { pointer-events: auto; }
}

/* landscape phones: keep the title and hint out of the tree's way */
@media (pointer: coarse) and (orientation: landscape) {
  header {
    padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
    text-align: left;
  }
  h1 { font-size: 18px; }
  .foot {
    padding: 8px max(16px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
  }
  #hint { max-width: 44%; }
}

@media (prefers-reduced-motion: reduce) {
  #caption, #sound { transition: none; }
}

@media (prefers-contrast: more) {
  :root { --dim: #ded3c2; --line: rgba(244, 236, 221, 0.75); }
}
