/* StackThat! — Portrait first. Warm and light since Phase 2a. */

:root {
  /* Warm and light: the same cream the canvas paints, so nothing seams. */
  --bg: #f7f2e6;
  --ink: #2f2a24;
  --ink-dim: #9c9184;
  --accent: #f3b23e;
  --line: #e2d8c4;
  --banner: #efe7d4;
  --banner-h: 50px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none; /* no pull-to-refresh bounce */
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  touch-action: manipulation; /* no 300ms tap delay, no double-tap zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* --- Screens ------------------------------------------------------------- */

.screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--banner-h) + env(safe-area-inset-bottom, 0px));
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
}

body[data-screen="title"]  #screen-title,
body[data-screen="play"]   #screen-play,
body[data-screen="result"] #screen-result { display: flex; }

/* --- Reserved banner slot (empty on web; the store build fills it) -------- */

#banner-slot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: env(safe-area-inset-bottom, 0px);
  height: var(--banner-h);
  background: var(--banner);
}

/* --- Title --------------------------------------------------------------- */

#title-canvas {
  position: absolute;
  inset: 0;
  z-index: 0; /* an absolutely positioned canvas paints over static content */
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

/* ...so everything the player can actually touch is lifted above it. The logo
   block is lifted too, but it is only words, and a big invisible box over the
   top of the screen would swallow taps meant for the sound toggle. */
.title-top,
.title-bottom,
#screen-title .build-stamp {
  position: relative;
  z-index: 1;
}

.title-top { pointer-events: none; }

.sound-toggle { z-index: 2; }

.title-top {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 9vh;
  gap: 6px;
}

.logo {
  margin: 0;
  font-size: 44px;
  letter-spacing: -0.5px;
}

.best {
  margin: 0;
  color: var(--ink-dim);
  font-size: 17px;
}

.title-bottom,
.result-bottom {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 24px 32px;
}

.btn {
  font: inherit;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-primary {
  width: 100%;
  max-width: 320px;
  min-height: 72px;
  background: var(--accent);
  color: #3a2a05;
  font-size: 26px;
  font-weight: 700;
}

.btn-secondary {
  width: 100%;
  max-width: 320px;
  min-height: 48px;
  background: transparent;
  color: var(--ink-dim);
  font-size: 17px;
  border: 1px solid var(--line);
}

/* Silent by default, and the toggle says which way it is. Title screen only —
   there is nothing to decide mid-round. */
/* --- The sound switch ----------------------------------------------------- */
/* One control, two homes. A track and a knob: grey and left is off, accent and
   right is on. No images, and the whole thing is the tap target. */

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  min-height: 46px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink-dim);
  background: rgba(239, 231, 212, 0.9);
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
}

.switch-label {
  pointer-events: none;
}

.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 23px;
  border-radius: 12px;
  background: #d9cfba;
  transition: background 160ms ease;
  pointer-events: none;
}

.switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fbf7ee;
  box-shadow: 0 1px 2px rgba(47, 42, 36, 0.28);
  transition: transform 160ms ease;
}

.switch[aria-checked="true"] {
  color: #7a5a12;
}

.switch[aria-checked="true"] .switch-track {
  background: var(--accent);
}

.switch[aria-checked="true"] .switch-knob {
  transform: translateX(17px);
}

.sound-toggle {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  right: 14px;
}

.build-stamp {
  position: absolute;
  left: 12px;
  bottom: 8px;
  margin: 0;
  font-size: 11px;
  color: #b0a493;
  font-variant-numeric: tabular-nums;
}

/* --- Play ---------------------------------------------------------------- */

#screen-play {
  position: fixed;
  touch-action: none; /* the play area never scrolls */
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* The world behind the HUD runs from cream to near-black, so every readout
   sits on its own chip. Same ink on every band, always legible. */
.hud-height,
.hud-best,
.hud-oops,
.hud-pause,
.hud-sound {
  background: rgba(247, 242, 230, 0.82);
  border: 1px solid rgba(47, 42, 36, 0.10);
  border-radius: 14px;
}

.hud-height {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  min-width: 56px;
  padding: 2px 10px;
  text-align: center;
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.hud-best {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 24px);
  left: 14px;
  margin: 0;
  padding: 5px 10px;
  color: var(--ink-dim);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.hud-oops {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 22px);
  right: 14px;
  display: flex;
  gap: 8px;
  padding: 7px 10px;
  pointer-events: none;
}

/* W's ask: build high, then suddenly have to go. 44px of tap target, clear of
   the oops dots above it and the height counter beside it. */
.hud-pause {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 58px);
  right: 14px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font: inherit;
  font-size: 19px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

/* Sam wanted the speaker where his thumb already is. Same stored value as the
   title screen's, same words, and the two are always in step. */
.hud-sound {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 58px);
  left: 14px;
  min-height: 46px;
}

/* --- Paused overlay ------------------------------------------------------ */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  background: rgba(247, 242, 230, 0.9);
}

.overlay[hidden] { display: none; }

.overlay-top {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay-title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
}

.overlay-bottom {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 24px 32px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.7;
  transition: opacity 250ms ease;
}

.dot.used { opacity: 0.15; }

/* --- Result -------------------------------------------------------------- */

.result-top {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

.result-layer {
  margin: 0;
  font-size: 30px;
  font-weight: 400;
  line-height: 1.15;
}

.result-layer strong { font-weight: 700; }

.result-flavour {
  margin: 0 0 6px;
  max-width: 300px;
  color: var(--ink-dim);
  font-size: 17px;
  line-height: 1.3;
}

/* Phase 3d.2: the units line is two sentences with a two-space gap between
   them, and this is the one element in the game whose whitespace is load-bearing.
   textContent hands the string over intact; without pre-wrap the browser collapses
   the pair to one space and Sam's format degrades silently, on screen only, where
   no rules test could ever see it. pre-wrap and not pre, because the line is long
   and still has to wrap inside max-width. */
.result-units {
  margin: 2px 0 8px;
  max-width: 310px;
  font-size: 19px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.result-line {
  margin: 0;
  font-size: 16px;
  color: var(--ink-dim);
}

.new-best {
  margin: 0;
  color: #c07a12;
  font-size: 20px;
  font-weight: 700;
}

.new-best[hidden] { display: none; }
