:root {
  --ink: #0a0a0a;
  --paper: #fafafa;
  --muted: #8a8a8a;
  --line: #e4e4e4;
  --accent: #0a0a0a;
  --radius: 14px;
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100%;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 24px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 32px 0;
  animation: fade 0.25s ease;
}
.screen.active { display: flex; }
/* Board-style screens are tall : anchor them to the top instead of centring. */
.screen.screen-top { justify-content: flex-start; gap: 14px; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Brand ---------- */
.brand { text-align: center; margin-bottom: 24px; }
.brand-mark {
  display: block;
  width: 260px;
  max-width: 78%;
  height: auto;
  margin: 0 auto 18px;
  color: var(--ink);
}
.wordmark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 44px;
  letter-spacing: -0.02em;
  margin: 0;
}
.tagline { color: var(--muted); font-size: 16px; margin: 8px 0 0; }

.home-actions { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius);
  padding: 18px;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--sans);
  cursor: pointer;
  width: 100%;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--ink); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn:disabled { opacity: 0.4; cursor: default; }
.small-btn { font-size: 14px; padding: 12px; margin-top: 4px; }

.app-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0 calc(env(safe-area-inset-bottom) + 16px);
}

.end-game-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 99px;
  cursor: pointer;
}
.end-game-btn:active { transform: scale(0.97); }
.footer-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.footer-actions:empty { display: none; }
.footer-links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.music-link {
  display: inline-block;
  text-decoration: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 99px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.music-link:hover { color: var(--ink); border-color: var(--ink); }
.music-link:active { transform: scale(0.97); }

.back {
  align-self: flex-start;
  background: none; border: none;
  color: var(--muted);
  font-size: 16px;
  padding: 0;
  cursor: pointer;
  position: absolute;
  top: 28px;
}
.screen-title { font-family: var(--serif); font-weight: 500; font-size: 30px; margin: 0; }
.kicker { text-transform: uppercase; letter-spacing: 0.14em; font-size: 12px; color: var(--muted); margin: 0; }
.muted { color: var(--muted); font-size: 15px; }
.error { color: #c0392b; font-size: 14px; min-height: 18px; }

/* ---------- How to play ---------- */
.how-list { margin: 0; padding-left: 20px; color: var(--ink); font-size: 15px; line-height: 1.55; }
.how-list li { margin-bottom: 10px; }
.how-example { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 16px; background: #fff; }
.ex-ends { display: flex; align-items: center; justify-content: center; gap: 10px; font-family: var(--serif); font-size: 17px; margin: 8px 0 14px; text-align: center; }
.ex-arrow { color: var(--muted); }
.ex-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.ex-no { font-family: var(--serif); color: var(--muted); width: 14px; flex: none; }
.ex-t { flex: 1; }
.ex-p { flex: 1; color: var(--muted); }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 14px; color: var(--muted); }
input[type="text"], input[type="tel"] {
  appearance: none;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 18px;
  font-family: var(--sans);
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus { outline: none; border-color: var(--ink); }
input.input-error, input.input-error:focus { border-color: #c0392b; }
.code-input { font-size: 32px; letter-spacing: 0.4em; text-align: center; font-family: var(--serif); }

.count-picker { display: flex; gap: 8px; }
.count {
  flex: 1;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px 0;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
}
.count.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Lobby ---------- */
.big-code {
  font-family: var(--serif);
  font-size: 72px;
  letter-spacing: 0.12em;
  text-align: center;
  margin: 4px 0;
}
.players { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.players li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-size: 17px;
  background: #fff;
}
.players li.disconnected { opacity: 0.45; }
.players li .host-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }

/* ---------- Choosing ---------- */
.actor-input {
  font-family: var(--serif);
  font-size: 26px;
  text-align: center;
  padding: 18px 12px;
  width: 100%;
}
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  margin: 0 auto 8px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Countdown / reveal ---------- */
#screen-countdown { align-items: center; }
.reveal-ends {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 64px;
  line-height: 1;
}
.reveal-ends .arrow { font-size: 40px; color: var(--muted); }
.countdown-num {
  font-family: var(--serif);
  font-size: 140px;
  line-height: 1;
  animation: pop 1s ease infinite;
}
@keyframes pop { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.12); opacity: 0.7; } }

/* ---------- Playing: the board ---------- */
.endpoints {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
  padding-bottom: 12px;
  border-bottom: 1.5px solid var(--ink);
}
.endpoints.small { font-size: 18px; border-bottom-width: 1px; }
.endpoints .ep { flex: 1; }
.endpoints .ep-arrow { color: var(--muted); flex: none; font-size: 0.8em; }

/* The arrow doubles as a swap control: tap it to start from the other actor. */
.ep-swap {
  flex: none;
  width: 38px; height: 38px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  font-family: var(--sans);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.ep-swap:active { transform: scale(0.92); }
.ep-swap:disabled { opacity: 0.35; cursor: default; }
.ep-swap:not(:disabled):hover { border-color: var(--ink); }

.head-hint { font-size: 13px; color: var(--muted); text-align: center; margin: 0; min-height: 16px; }
.head-hint b { color: var(--ink); font-weight: 600; }

.rows { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-no {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--muted);
  width: 14px;
  flex: none;
  text-align: center;
}
.row-boxes { display: flex; gap: 6px; flex: 1; min-width: 0; }
.box {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 12px 10px;
  font-size: 14px;
  font-family: var(--sans);
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.box::placeholder { color: #c2c2c2; }
.box:focus { outline: none; border-color: var(--ink); }

/* Locked-in rows read as text, not fields. */
.row.done .box {
  background: #f2f2f2;
  border-color: #f2f2f2;
  color: var(--ink);
  font-weight: 600;
  display: flex;
  align-items: center;
  min-height: 44px;
  line-height: 1.25;
}
.row.done .row-no { color: var(--ink); }
.row.done .box-person { font-family: var(--serif); font-weight: 500; }
/* The row that completed the connection. */
.row.win .box { background: var(--ink); border-color: var(--ink); color: #fff; }
.row.win .row-no { color: var(--ink); font-weight: 700; }

/* Rows you haven't reached yet: clearly present, clearly not in play. */
.row.locked .box { background: transparent; border-style: dashed; border-color: #dcdcdc; }
.row.checking .box { opacity: 0.55; }
.row.active .box-title { border-color: var(--ink); }

.play-actions { display: flex; gap: 14px; justify-content: center; }
.mini-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 8px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.mini-btn:disabled { opacity: 0.4; cursor: default; text-decoration: none; }

.rivals { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 4px; }
.rivals li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  padding: 5px 2px;
  border-top: 1px solid var(--line);
}
.rivals li .pips { letter-spacing: 3px; font-size: 11px; color: var(--ink); }
.rivals li.spent { opacity: 0.45; }

.combo-msg { font-size: 13px; color: #c0392b; min-height: 16px; margin: 0; text-align: center; }
.combo-msg.checking { color: var(--muted); }
.notice { text-align: center; color: var(--muted); font-size: 13px; min-height: 16px; margin: 0; }

/* ---------- Results ---------- */
.board-block { margin-top: 14px; }
.board-who { font-size: 13px; font-weight: 600; margin: 0 0 6px; display: flex; justify-content: space-between; align-items: baseline; }
.board-who .tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 500; }
.board-who.winner .tag { color: var(--ink); }
.board-chain { border: 1.5px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; }
.board-chain.winner { border-color: var(--ink); }
.board-chain .cr { display: flex; gap: 8px; align-items: baseline; padding: 9px 12px; font-size: 13px; border-top: 1px solid var(--line); }
.board-chain .cr:first-child { border-top: none; }
.board-chain .cr .n { font-family: var(--serif); color: var(--muted); width: 12px; flex: none; }
.board-chain .cr .t { flex: 1; min-width: 0; }
.board-chain .cr .p { flex: 1; min-width: 0; font-family: var(--serif); }
.board-chain .empty { padding: 12px; font-size: 13px; color: var(--muted); }

.scoreboard { list-style: none; padding: 0; margin: 10px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.scoreboard li {
  display: flex; justify-content: space-between;
  padding: 10px 14px;
  font-size: 16px;
}
.scoreboard li .pts { font-family: var(--serif); font-weight: 600; }
.scoreboard li.leader { background: var(--ink); color: #fff; border-radius: 10px; }

/* Game-over recap */
.recap { margin-top: 28px; text-align: left; }
.recap-title { text-transform: uppercase; letter-spacing: 0.14em; font-size: 12px; color: var(--muted); margin: 0 0 10px; text-align: center; }
.recap-round { border-top: 1px solid var(--line); padding: 12px 0; }
.recap-round-no { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.recap-ends { font-family: var(--serif); font-size: 16px; margin-bottom: 6px; }
.recap-ends .arrow { color: var(--muted); }
.recap-chain { font-size: 13px; color: var(--muted); }
.recap-chain .cr { padding: 2px 0; }
.recap-chain .cr .p { color: var(--ink); font-family: var(--serif); }
