* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  /* Mirrors the theme's chrome roles; an e2e test fails on drift. */
  --outline: #120a06;
  --slate: #3a2211;
  --line: #5c3a19;
  --border: #8b5a2b;
  --mute: #a88a68;
  --hint: #c9a97e;
  --text-soft: #d1b894;
  --text: #f4e8c1;
  --accent: #fbbf24;
  --accent-bright: #fde68a;
  --accent-ink: #78350f;
  --danger: #ef4444;
  --rock: #8d8d99;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  padding: 16px 12px calc(32px + env(safe-area-inset-bottom, 0px));
  /* walnut wood: a warm glow over plank lines (borrowed from the sample) */
  background-color: var(--outline);
  background-image:
    radial-gradient(ellipse at 50% 30%, rgba(68, 41, 23, 0.6) 0%, rgba(18, 10, 5, 0.95) 100%),
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0, 0, 0, 0.15) 3px, rgba(0, 0, 0, 0.15) 6px),
    repeating-linear-gradient(90deg, rgba(80, 48, 25, 0.4), rgba(80, 48, 25, 0.4) 30px, rgba(50, 28, 12, 0.4) 30px, rgba(50, 28, 12, 0.4) 60px);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  --board-height: min(74vh, 660px, calc((100vw - 56px) * 1.5));
  --board-height: min(74dvh, 660px, calc((100vw - 56px) * 1.5));
  width: min(100%, calc(var(--board-height) * 2 / 3 + 32px));
  margin: auto;
  padding: 20px 16px 28px;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.masthead {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.masthead h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-bright);
  text-shadow:
    0 2px 0 #8b5a2b,
    0 3px 0 #5c3a19,
    0 4px 8px rgba(0, 0, 0, 0.9);
}

.masthead .back {
  font-size: 0.85rem;
  color: var(--hint);
  text-decoration: none;
}

.masthead .back:hover,
.masthead .back:focus-visible {
  color: var(--accent-bright);
}

.masthead-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mute {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.mute:hover,
.mute:focus-visible {
  color: var(--accent-bright);
  border-color: var(--accent);
}

.hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

/* wooden plaque per stat, in the sample's style */
.hud .stat {
  flex: 1;
  text-align: center;
  padding: 6px 4px;
  border: 2px solid #8b5a2b;
  border-radius: 6px;
  background: linear-gradient(145deg, #3a2211, #1d1007);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.8), 0 3px 6px rgba(0, 0, 0, 0.6);
}

.stat strong {
  color: var(--accent);
  display: inline-block;
  min-width: 2ch;
}

/* A score change pops the counter once, then it settles. */
.stat strong.bump {
  animation: score-bump 0.3s ease-out;
}

@keyframes score-bump {
  40% {
    transform: scale(1.6);
    color: var(--accent-bright);
  }
}

@media (prefers-reduced-motion: reduce) {
  .stat strong.bump {
    animation: none;
  }
}

.board {
  position: relative;
  width: 100%;
  max-width: calc(var(--board-height) * 2 / 3);
  aspect-ratio: 2 / 3;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--outline);
  image-rendering: pixelated;
  touch-action: none;
}

/* Decision buttons: one centered split control, Rotate left / Place right. */
.actions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: flex;
  justify-content: center;
  gap: 0;
  z-index: 2;
}

.actions[hidden] {
  display: none;
}

/* `hidden` on a button needs its own guard: an author rule beats the UA's
   [hidden] { display: none }, so `.actions button` would otherwise override it. */
.actions button[hidden] {
  display: none;
}

.actions button {
  flex: 0 0 auto;
  min-width: 120px;
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* the two halves share one outline: each keeps only its outer corners rounded */
.actions .secondary {
  border-right: 0;
  border-radius: 12px 0 0 12px;
}

.actions .primary {
  border-left: 0;
  border-radius: 0 12px 12px 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.secondary {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #4a2e1b 0%, #29180c 100%);
  color: var(--accent-bright);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 4px rgba(0, 0, 0, 0.5);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Fine pointers click the board to place and press R to rotate, so the buttons
   would only get in the way. */
@media (pointer: fine) {
  .actions {
    display: none;
  }
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--hint);
  text-align: center;
}

/*
 * `hidden` must win over the layout display rules below: author declarations beat
 * the UA's [hidden] { display: none }, so without these the splash would cover the
 * board forever and the game-over overlay could never hide.
 */
.splash[hidden],
.overlay[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  background: rgba(18, 10, 6, 0.6);
  backdrop-filter: blur(3px);
  border-radius: 12px;
}

.overlay h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--accent-bright);
}

.primary {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 22px;
  font: inherit;
  font-weight: 700;
  background: linear-gradient(180deg, #7c4a22 0%, #4a2b13 100%);
  color: var(--accent-bright);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  cursor: pointer;
}

.splash {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  background: rgba(18, 10, 6, 0.95);
  border-radius: 12px;
  cursor: pointer;
}

.splash-title {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: 0.06em;
  color: var(--accent-bright);
}

.splash-tag,
.splash-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.about {
  width: 100%;
  font-size: 0.9rem;
  /* parchment card, in the sample's style */
  background: #e7d7c1;
  background-image: radial-gradient(#d6c2a5 1px, transparent 0);
  background-size: 10px 10px;
  color: #3f2e1e;
  padding: 12px 16px;
  border-radius: 6px;
  border: 1px solid #b59e7d;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6), inset 0 0 20px rgba(160, 120, 70, 0.3);
}

.about h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  color: #2b1d11;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px dashed #a38c6b;
  padding-bottom: 2px;
}

.about ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.about h3 {
  margin: 14px 0 0;
  font-size: 0.95rem;
  color: #2b1d11;
}

.legend {
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.legend li {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
}

.legend canvas {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

.legend strong {
  color: #2b1d11;
}
