:root {
  color-scheme: dark;
  --ink: #14110e;
  --paper: #f3eadb;
  --muted: #cbbfaa;
  --line: rgba(243, 234, 219, 0.16);
  --accent: #e7a05a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

#stage {
  position: relative;
  height: 100%;
  height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(18px + env(safe-area-inset-top)) 112px 36px;
  text-align: center;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(16, 14, 12, 0.78), rgba(16, 14, 12, 0));
}

#best {
  margin: 0;
  color: var(--muted);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

#score {
  margin: 4px 0 0;
  color: var(--paper);
  font-size: 64px;
  font-weight: 600;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  transform-origin: center top;
}

#score.is-pop { animation: pop 0.28s ease; }

@keyframes pop {
  40% { transform: scale(1.12); color: var(--accent); }
}

#combo.is-hot { color: #ffd7a8; }

#flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 42%, rgba(231, 160, 90, 0.42), transparent 58%);
}

#flash.on { animation: flare 0.42s ease; }

@keyframes flare {
  from { opacity: 1; }
  to { opacity: 0; }
}

#combo {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--accent);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(22px + env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

#hint.is-gone { opacity: 0; }

#sound {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  z-index: 3;
  border: 1px solid var(--line);
  background: rgba(20, 17, 14, 0.45);
  color: var(--muted);
  font: 12px/1 "Avenir Next", "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
}

#sound:hover { color: var(--paper); }

#overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 24px 24px max(28px, 7vw);
  background:
    linear-gradient(90deg, rgba(16, 14, 12, 0.78), rgba(16, 14, 12, 0.28) 58%, rgba(16, 14, 12, 0.08));
}

#overlay[hidden] { display: none; }

.card {
  width: min(440px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  text-align: left;
  color: var(--paper);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(64px, 9vw, 96px);
  font-weight: 600;
  line-height: 0.85;
  letter-spacing: -0.04em;
}

.lede {
  margin: 18px 0 0;
  max-width: 34ch;
  color: var(--muted);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

#start,
#post,
.ghost {
  border: 0;
  font: 600 15px/1 "Avenir Next", "Segoe UI", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 16px 22px;
  border-radius: 999px;
  cursor: pointer;
}

#start,
#post {
  background: var(--paper);
  color: var(--ink);
}

.ghost {
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--line);
}

#share[hidden],
#endless[hidden],
#name-row[hidden] { display: none; }

#name-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

#name {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 17, 14, 0.45);
  color: var(--paper);
  padding: 12px 16px;
  font: 16px/1.2 "Avenir Next", "Segoe UI", sans-serif;
}

#name:focus-visible,
#post:focus-visible,
.ghost:focus-visible,
#start:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#rank,
#board-caption {
  margin: 14px 0 0;
  color: var(--muted);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
  letter-spacing: 0.04em;
}

#rank:empty,
#board-caption:empty { display: none; }

#board-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

#board-list li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

#board-list li.you { color: var(--accent); }
#board-list li.empty {
  border: 0;
  color: var(--muted);
}

#start:hover,
#post:hover { background: #fff8ee; }
.ghost:hover { color: var(--accent); }

@media (max-width: 720px) {
  #score { font-size: 52px; }
  #sound { top: calc(14px + env(safe-area-inset-top)); }
  #overlay {
    align-items: flex-end;
    justify-content: stretch;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(12, 10, 8, 0.96) 0 34%, rgba(12, 10, 8, 0.82) 48%, rgba(12, 10, 8, 0) 78%);
  }
  .card { width: 100%; }
  h1 { font-size: 68px; }
}
