:root {
  --paper: #f3eee4;
  --ink: #2a241c;
  --ink-dim: rgba(42, 36, 28, 0.62);
  --line: rgba(42, 36, 28, 0.32);
  --panel: rgba(247, 243, 234, 0.86);
  --accent: #c45c26;
  --accent-dim: rgba(196, 92, 38, 0.16);
  --mono: "SFMono-Regular", "ui-monospace", "Menlo", "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1a16;
    --ink: #ebe4d6;
    --ink-dim: rgba(235, 228, 214, 0.62);
    --line: rgba(235, 228, 214, 0.28);
    --panel: rgba(28, 26, 22, 0.78);
    --accent: #e07a3d;
    --accent-dim: rgba(224, 122, 61, 0.18);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

.hud {
  position: fixed;
  z-index: 4;
  pointer-events: none;
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px 12px;
  min-width: 196px;
  max-width: min(320px, calc(50vw - 28px));
  backdrop-filter: blur(8px);
}

.hud b {
  color: var(--accent);
  font-weight: 600;
}

.hud .k {
  color: var(--ink-dim);
}

#hud-tl { top: 16px; left: 16px; }
#hud-tr { top: 16px; right: 16px; text-align: right; min-width: 168px; }
#hud-bl { bottom: 16px; left: 16px; }
#hud-br { bottom: 16px; right: 16px; text-align: right; min-width: 140px; }

#hint {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 12px;
  max-width: min(420px, calc(100vw - 460px));
  backdrop-filter: blur(8px);
  transition: opacity 0.8s ease;
}

#hint.gone {
  opacity: 0;
}

#label {
  position: fixed;
  z-index: 6;
  pointer-events: none;
  max-width: min(280px, calc(100vw - 32px));
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 10px;
  line-height: 1.45;
  color: var(--ink);
  display: none;
}

#stack-labels {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.stack-lab {
  position: absolute;
  right: 16px;
  transform: translateY(-50%);
  max-width: 156px;
  padding: 3px 8px;
  border-left: 2px solid var(--accent);
  background: var(--panel);
  color: var(--ink);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  text-align: left;
}

#label strong {
  display: block;
  color: var(--accent);
  margin-bottom: 3px;
  font-weight: 600;
}

#play {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 26px 16px;
  border: 1px solid var(--accent);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 0 0 6px var(--accent-dim);
}

#play.visible {
  display: flex;
}

#play .tri {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 14px 0 14px 24px;
  border-color: transparent transparent transparent var(--accent);
  margin-left: 6px;
}

#play span {
  font-size: 11px;
}

#play:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (max-width: 1100px) {
  #hint {
    max-width: calc(100vw - 24px);
    bottom: 96px;
  }
}

@media (max-width: 900px) {
  .hud {
    font-size: 10px;
    min-width: 0;
    padding: 8px 9px;
    max-width: calc(48vw - 16px);
  }

  #hint {
    max-width: calc(100vw - 24px);
    bottom: 96px;
  }

  .stack-lab {
    font-size: 9px;
    max-width: 120px;
  }
}

@media (max-height: 700px) {
  .hud {
    font-size: 10px;
    padding: 7px 8px;
  }

  #hint {
    bottom: 96px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #hint,
  .stack-lab {
    transition: none;
  }
}
