:root {
  --bg: #121212;
  --board: #000;
  --gold: #d4af37;
  --text: #fff;
  --muted: #c8c8c8;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

html:has(body.play),
body.play {
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  font-family: Nunito, "Trebuchet MS", sans-serif;
  font-weight: 700;
}

button { font: inherit; cursor: pointer; }
h1, h2, p { margin: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

.app {
  width: min(720px, 100%);
  height: 100dvh;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

h1 {
  font-size: 40px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.top p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
  max-width: 34ch;
}

.scores { display: flex; gap: 8px; }

.chip {
  position: relative;
  min-width: 88px;
  background: var(--board);
  border: 2px solid var(--gold);
  padding: 6px 10px 8px;
  text-align: center;
}

.chip span {
  display: block;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chip strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.gain {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  color: var(--text);
  font-weight: 800;
  animation: float-up 600ms ease forwards;
  pointer-events: none;
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.board {
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  background: var(--board);
  border: 2px solid var(--gold);
  padding: 8px;
  touch-action: none;
}

.board:focus {
  outline: none;
}

.cells {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.cell {
  aspect-ratio: 1;
  background: var(--board);
  border: 2px solid var(--gold);
}

.tiles {
  position: absolute;
  inset: 8px;
  pointer-events: none;
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  transition: transform 110ms ease-out;
}

.face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #161616;
  border: 2px solid #161616;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.06em;
}

.tile.born .face { animation: appear 180ms ease 100ms backwards; }
.tile.pop .face { animation: pop 180ms ease 100ms backwards; }

@keyframes appear {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes pop {
  0% { transform: scale(0); }
  55% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes float-up {
  from { transform: translateY(8px); opacity: 1; }
  to { transform: translateY(-18px); opacity: 0; }
}

.veil {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 20px;
}

.veil h2 { font-size: 32px; font-weight: 800; }
.veil p { color: var(--muted); max-width: 28ch; }

.actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.name-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text);
  font-weight: 800;
  text-align: left;
}

.name-row input {
  background: var(--board);
  color: var(--text);
  border: 2px solid var(--gold);
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 8px 10px;
  width: min(240px, 70vw);
}

.veil-note { color: var(--gold); }

.leaders-app { height: auto; min-height: 100dvh; overflow: visible; }
.leaders-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.leaders-bar h1 { font-size: 32px; }
.leaders-note, .leaders-status { color: var(--muted); }
.leaders-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.leaders-list li {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  background: var(--board);
  border: 2px solid var(--gold);
  color: var(--text);
  font-weight: 800;
  padding: 8px 12px;
}
.leaders-list li.mine { background: #1c1c1c; }
.leaders-list .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn, .pad button {
  background: var(--board);
  color: var(--text);
  border: 2px solid var(--gold);
  font-weight: 800;
  min-height: 44px;
  padding: 0 16px;
}

.btn:hover, .pad button:hover,
.btn:focus-visible, .pad button:focus-visible {
  background: #1c1c1c;
}

.pad {
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 8px;
  justify-content: center;
}

.pad button { padding: 0; font-size: 20px; }
.pad button[data-dir="up"] { grid-area: up; }
.pad button[data-dir="left"] { grid-area: left; }
.pad button[data-dir="down"] { grid-area: down; }
.pad button[data-dir="right"] { grid-area: right; }

@media (max-width: 640px) {
  h1 { font-size: 32px; }
  .top { align-items: stretch; flex-direction: column; }
  .chip strong { font-size: 18px; }
  .top p { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile.born .face,
  .tile.pop .face,
  .gain { animation: none; }
}
