/* Magnetic Poetry — shared styles */
:root {
  --cream: #F4EDE0;
  --cream-2: #EDE3D2;
  --paper: #FBF6EC;
  --ink: #1a1a1a;
  --ink-soft: #3a342c;
  --muted: #6b6356;
  --accent: #B23A48;
  --accent-2: #C97B66;
  --tile-bg: #FDFBF5;
  --tile-edge: #d9cfbb;
  --shadow-tile: 0 1px 2px rgba(0,0,0,0.15), 0 3px 8px rgba(0,0,0,0.08);
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'EB Garamond', 'Fraunces', Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 17px;
  line-height: 1.4;
  min-height: 100vh;
  overscroll-behavior: none;
}

/* Paper grain background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10  0 0 0 0 0.08  0 0 0 0 0.06  0 0 0 0.13 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/></svg>");
  opacity: 0.55;
  mix-blend-mode: multiply;
}

/* layered content above grain */
main, header, footer, .layer { position: relative; z-index: 1; }

h1, h2, h3 { font-family: 'Fraunces', 'Playfair Display', Georgia, serif; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.serif-display { font-family: 'Fraunces', 'Playfair Display', Georgia, serif; }
.typewriter { font-family: 'Special Elite', 'Courier New', monospace; }

button {
  font-family: inherit;
  font-size: 1rem;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 4px;
  padding: 12px 22px;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: transform 80ms ease, opacity 80ms ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
button.accent { background: var(--accent); color: var(--paper); }
button.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }

input[type="text"] {
  font-family: inherit;
  font-size: 1.1rem;
  padding: 12px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

/* ============ TILES ============ */
.tile {
  display: inline-block;
  background: var(--tile-bg);
  color: var(--ink);
  padding: 6px 10px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-tile);
  margin: 3px;
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  line-height: 1.2;
  border: 0.5px solid var(--tile-edge);
  user-select: none;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 120ms ease, box-shadow 120ms ease;
  position: relative;
}
.tile:nth-child(3n) { font-family: 'EB Garamond', serif; font-style: italic; }
.tile:nth-child(5n) { font-family: 'Special Elite', monospace; font-size: 0.95rem; }
.tile:nth-child(7n) { font-family: 'Fraunces', serif; font-weight: 600; }
.tile:nth-child(2n)   { transform: rotate(-1.5deg); }
.tile:nth-child(2n+1) { transform: rotate(1deg); }
.tile:nth-child(4n+1) { transform: rotate(-0.5deg); }
.tile:hover { transform: rotate(0deg) translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.18), 0 6px 14px rgba(0,0,0,0.1); }
.tile.placed { background: #fffdf6; }
.tile.dragging { opacity: 0.5; }

/* ============ SPECTATOR LAYOUT ============ */
.spectator {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.spectator-header {
  padding: 28px 40px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid rgba(26,26,26,0.12);
}
.brand {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 2.6vw, 2.4rem);
  letter-spacing: -0.02em;
}
.brand .accent { color: var(--accent); font-style: italic; }
.spectator-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  position: relative;
}

.lobby-code {
  font-family: 'Special Elite', monospace;
  font-size: clamp(5rem, 14vw, 11rem);
  letter-spacing: 0.18em;
  line-height: 1;
  margin: 16px 0 8px;
  color: var(--accent);
  text-shadow: 2px 2px 0 rgba(178,58,72,0.08);
}
.lobby-instruct {
  font-size: 1.4rem;
  color: var(--ink-soft);
  margin-bottom: 24px;
}
.lobby-instruct .url {
  font-family: 'Special Elite', monospace;
  color: var(--ink);
  background: rgba(178,58,72,0.08);
  padding: 2px 8px;
  border-radius: 4px;
}
.qr-wrap {
  background: white;
  padding: 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-tile);
  display: inline-block;
}
.qr-wrap img, .qr-wrap canvas { display: block; }

.players-pill-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 24px 0;
  max-width: 900px;
}
.player-pill {
  background: var(--paper);
  padding: 10px 18px;
  border-radius: 999px;
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  box-shadow: var(--shadow-tile);
  border: 1px solid var(--tile-edge);
}
.player-pill .score {
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 2px 9px;
  margin-left: 8px;
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
}

.spectator-prompt {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: clamp(2rem, 4vw, 3.4rem);
  max-width: 1100px;
  line-height: 1.15;
  margin: 0 0 28px;
}
.spectator-prompt::before { content: "“"; color: var(--accent); }
.spectator-prompt::after { content: "”"; color: var(--accent); }

.timer-display {
  font-family: 'Special Elite', monospace;
  font-size: 2.6rem;
  color: var(--ink);
  margin-bottom: 24px;
  letter-spacing: 0.05em;
}
.timer-display.urgent { color: var(--accent); }

.submission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  max-width: 900px;
  width: 100%;
  margin: 8px 0;
}
.sub-card {
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  padding: 14px 16px;
  border-radius: 6px;
  font-family: 'Fraunces', serif;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-tile);
}
.sub-card.submitted { background: #f4e9d3; border-color: var(--accent-2); }
.sub-card .check { color: var(--accent); font-weight: 700; }

.reveal-stage {
  font-family: 'Fraunces', serif;
  font-size: clamp(1.6rem, 3vw, 2.6rem);
  line-height: 1.45;
  max-width: 1000px;
  padding: 36px 30px;
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
}
.reveal-stage .tile {
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  padding: 10px 16px;
  margin: 6px;
}
.reveal-counter {
  font-family: 'Special Elite', monospace;
  color: var(--muted);
  margin-bottom: 12px;
  letter-spacing: 0.1em;
}

.winner-banner {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 2.4rem;
  margin: 16px 0 8px;
}
.winner-name {
  color: var(--accent);
  font-style: normal;
  font-weight: 700;
}
.score-anim {
  display: inline-block;
  background: var(--accent);
  color: var(--paper);
  padding: 4px 14px;
  border-radius: 999px;
  font-family: 'Special Elite', monospace;
  margin-left: 8px;
  animation: pop 600ms ease;
}
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.scoreboard {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: rgba(251,246,236,0.94);
  padding: 14px 18px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.08);
  border: 1px solid var(--tile-edge);
  max-width: 280px;
  z-index: 10;
}
.scoreboard h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-bottom: 8px;
  font-family: 'Special Elite', monospace;
  font-weight: 400;
}
.scoreboard ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.scoreboard li {
  display: flex;
  justify-content: space-between;
  font-family: 'Fraunces', serif;
  padding: 3px 0;
  font-size: 1rem;
}
.scoreboard li .score {
  font-family: 'Special Elite', monospace;
  color: var(--accent);
}

/* ============ PLAYER LAYOUT ============ */
.player {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px;
  max-width: 600px;
  margin: 0 auto;
}
.player-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  margin-bottom: 14px;
}
.player-header .brand { font-size: 1.3rem; }
.player-header .meta {
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

.join-card {
  background: var(--paper);
  padding: 26px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow-tile);
  border: 1px solid var(--tile-edge);
  margin-top: 30px;
}
.join-card h2 {
  font-family: 'Fraunces', serif;
  font-size: 1.8rem;
  margin-bottom: 8px;
}
.join-card p {
  color: var(--muted);
  margin: 0 0 18px;
  font-size: 0.95rem;
}
.join-card label {
  display: block;
  font-family: 'Special Elite', monospace;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 6px;
  color: var(--muted);
}
.join-card .field { margin-bottom: 16px; }
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em !important;
  font-family: 'Special Elite', monospace !important;
  font-size: 1.4rem !important;
  text-align: center;
}

.prompt-card {
  background: var(--paper);
  padding: 14px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-tile);
  border: 1px solid var(--tile-edge);
  margin-bottom: 12px;
}
.prompt-card .label {
  font-family: 'Special Elite', monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-bottom: 4px;
}
.prompt-card .prompt-text {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 1.25rem;
  line-height: 1.3;
}

.timer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.timer-bar .timer {
  font-family: 'Special Elite', monospace;
  font-size: 1.4rem;
}
.timer-bar .timer.urgent { color: var(--accent); }
.timer-bar .status {
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

.composition {
  min-height: 130px;
  background: var(--paper);
  border: 2px dashed var(--tile-edge);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
}
.composition.empty::before {
  content: "tap tiles below to compose your poem";
  color: var(--muted);
  font-style: italic;
  margin: auto;
  font-size: 0.95rem;
}
.composition .tile { min-height: 36px; min-width: 36px; }

.tray {
  flex: 1;
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--tile-edge);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  min-height: 200px;
}
.tray .tile { min-height: 36px; min-width: 36px; padding: 8px 12px; font-size: 1.05rem; }

.tray .tile.taken { opacity: 0.25; pointer-events: none; }

.submit-bar {
  position: sticky;
  bottom: 0;
  background: var(--cream);
  padding-top: 8px;
}
.submit-bar button {
  width: 100%;
  font-size: 1.1rem;
  padding: 14px;
}

.waiting-card {
  background: var(--paper);
  padding: 24px;
  border-radius: 10px;
  border: 1px solid var(--tile-edge);
  text-align: center;
  margin-top: 20px;
  box-shadow: var(--shadow-tile);
}
.waiting-card h3 {
  font-family: 'Fraunces', serif;
  font-size: 1.4rem;
  margin-bottom: 10px;
}
.waiting-card .your-poem {
  margin-top: 16px;
  padding: 14px;
  background: var(--cream);
  border-radius: 6px;
  font-style: italic;
}
.waiting-card .your-poem .tile { font-size: 0.95rem; }

.judge-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.judge-card {
  background: var(--paper);
  border: 1.5px solid var(--tile-edge);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.judge-card:active { transform: scale(0.98); }
.judge-card.picked { border-color: var(--accent); background: #fff8e7; }
.judge-card .tile { font-size: 1rem; }

.lobby-players {
  background: var(--paper);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--tile-edge);
  margin-top: 16px;
}
.lobby-players h4 {
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin: 0 0 8px;
  font-weight: 400;
}
.lobby-players .list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.lobby-players .chip {
  background: var(--cream-2);
  padding: 4px 10px;
  border-radius: 999px;
  font-family: 'Fraunces', serif;
  font-size: 0.95rem;
}

.error-msg {
  color: var(--accent);
  font-family: 'Special Elite', monospace;
  font-size: 0.9rem;
  margin-top: 8px;
  min-height: 1.2em;
}

.fade-in { animation: fadeIn 600ms ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

/* ============ LOBBY CARD ============ */
.lobby-card {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  border-radius: 14px;
  padding: 36px 48px 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.06);
  max-width: 980px;
  margin: 0 auto;
}
.icon-btn {
  position: absolute;
  top: 14px; right: 14px;
  background: var(--cream);
  color: var(--ink);
  border: 1px solid var(--tile-edge);
  border-radius: 8px;
  width: 40px; height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-tile);
  transform: rotate(-1.5deg);
  transition: transform 120ms ease, background 120ms ease;
}
.icon-btn:hover { transform: rotate(0) translateY(-1px); background: var(--cream-2); }
.icon-btn svg { display: block; }
.settings-display {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin: -2px 0 18px;
}

button.ghost.small {
  padding: 6px 14px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}

/* ============ SETTINGS MODAL ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26,26,26,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeBg 180ms ease;
}
@keyframes fadeBg {
  from { background: rgba(26,26,26,0); }
  to { background: rgba(26,26,26,0.45); }
}
.modal-sheet {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: min(440px, 100%);
  padding: 30px 28px 26px;
  text-align: left;
  animation: sheetIn 220ms cubic-bezier(.2,.7,.2,1);
}
@keyframes sheetIn {
  from { opacity: 0; transform: translateY(14px) rotate(-0.6deg); }
  to { opacity: 1; transform: translateY(0) rotate(0); }
}
.modal-sheet::before {
  /* magnetic-tile accent corner */
  content: "";
  position: absolute;
  top: -10px; left: 28px;
  width: 36px; height: 16px;
  background: var(--accent);
  border-radius: 4px;
  transform: rotate(-3deg);
  box-shadow: var(--shadow-tile);
}
.modal-sheet h2 {
  font-family: 'Fraunces', serif;
  font-size: 1.6rem;
  margin: 0 0 4px;
}
.modal-sub {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin: 0 0 20px;
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  color: var(--ink);
  border: none;
  width: 32px; height: 32px;
  padding: 0;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  text-transform: none;
  letter-spacing: 0;
}
.modal-close:hover { background: var(--cream-2); transform: none; }
.modal-field {
  margin-bottom: 18px;
}
.modal-field label {
  display: block;
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 6px;
}
.modal-field input[type="number"] {
  font-family: 'Fraunces', serif;
  font-size: 1.3rem;
  padding: 10px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--cream);
  color: var(--ink);
  width: 100%;
  outline: none;
  box-shadow: var(--shadow-tile);
}
.modal-field input[type="number"]:focus { border-color: var(--accent); }
.field-hint {
  font-family: 'Special Elite', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.05em;
}

/* ============ PREPARING SPINNER ============ */
.tile-spinner {
  display: inline-flex;
  gap: 6px;
  margin-top: 18px;
}
.tile-spinner .spin-tile {
  display: inline-block;
  background: var(--tile-bg);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-tile);
  border: 0.5px solid var(--tile-edge);
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  animation: tileFloat 1.4s ease-in-out infinite;
}
.tile-spinner .spin-tile:nth-child(2) { animation-delay: 0.18s; font-family: 'EB Garamond', serif; font-style: italic; }
.tile-spinner .spin-tile:nth-child(3) { animation-delay: 0.36s; font-family: 'Special Elite', monospace; }
@keyframes tileFloat {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}

/* ============ SPECTATOR VOTING ============ */
.voting-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  max-width: 1100px;
  width: 100%;
  margin: 18px auto;
}
.vote-poem-card {
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  border-radius: 10px;
  padding: 14px 16px 16px;
  box-shadow: var(--shadow-tile);
  text-align: left;
  min-height: 110px;
  position: relative;
}
.vote-poem-num {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.vote-poem-body { display: flex; flex-wrap: wrap; gap: 3px; }
.vote-poem-body .tile { font-size: 0.95rem; padding: 5px 9px; }

.vote-status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 900px;
  margin: 8px auto 0;
}
.vote-status-pill {
  background: var(--cream-2);
  border: 1px solid var(--tile-edge);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: 'Fraunces', serif;
  font-size: 0.95rem;
}
.vote-status-pill.voted { background: #e9ddc0; border-color: var(--accent-2); }
.vote-status-pill.voted .dot { color: var(--accent); font-weight: 700; }
.vote-status-pill .dot {
  font-family: 'Special Elite', monospace;
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 6px;
  letter-spacing: 0.05em;
}

/* ============ SCORING RESULTS ============ */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  max-width: 1100px;
  width: 100%;
  margin: 18px auto 0;
}
.result-card {
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  border-radius: 10px;
  padding: 10px 12px 12px;
  box-shadow: var(--shadow-tile);
  text-align: left;
}
.result-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-family: 'Special Elite', monospace;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.result-name { color: var(--ink); }
.result-votes { color: var(--accent); font-weight: 700; }
.result-body { display: flex; flex-wrap: wrap; gap: 2px; }
.result-body .tile { font-size: 0.85rem; padding: 3px 7px; }

/* ============ PLAYER VOTING ============ */
.vote-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.vote-card {
  background: var(--paper);
  border: 1.5px solid var(--tile-edge);
  border-radius: 10px;
  padding: 12px 14px 14px;
  cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease, background 100ms ease;
  box-shadow: var(--shadow-tile);
}
.vote-card:active { transform: scale(0.985); }
.vote-card.selected { border-color: var(--accent); background: #fff2e3; box-shadow: 0 0 0 2px rgba(178,58,72,0.2), var(--shadow-tile); }
.vote-card-head {
  display: flex;
  align-items: center;
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
  min-height: 36px;
}
.vote-card-body { display: flex; flex-wrap: wrap; gap: 3px; }
.vote-card-body .tile { font-size: 0.95rem; padding: 5px 9px; }

/* mobile tweaks */
@media (max-width: 480px) {
  .spectator-header { padding: 16px 18px 8px; }
  .spectator-main { padding: 24px 16px; }
  .lobby-card { padding: 24px 18px; }
  .modal-sheet { padding: 24px 18px; }
  .voting-grid { grid-template-columns: 1fr; }
}

/* ============ ROOM CODE PERMANENT OVERLAY ============ */
.room-code-overlay {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 50;
  background: rgba(251, 246, 236, 0.7);
  border: 0.5px solid var(--tile-edge);
  border-radius: 10px;
  padding: 10px 12px 8px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  pointer-events: none;
  user-select: none;
}
.room-code-overlay[hidden] { display: none !important; }
.room-code-overlay .rc-label {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 4px;
  text-align: center;
}
.room-code-overlay .rc-tiles {
  display: flex;
  gap: 4px;
  justify-content: center;
}
.room-code-overlay .rc-tiles .rc-tile {
  display: inline-block;
  background: var(--tile-bg);
  color: var(--ink);
  width: 26px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 1.15rem;
  border-radius: 5px;
  border: 0.5px solid var(--tile-edge);
  box-shadow: var(--shadow-tile);
}
.room-code-overlay .rc-tiles .rc-tile:nth-child(odd)  { transform: rotate(-1deg); }
.room-code-overlay .rc-tiles .rc-tile:nth-child(even) { transform: rotate(1.2deg); }
.room-code-overlay .rc-join {
  margin-top: 6px;
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-align: center;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ ROUND COUNTER ============ */
.round-counter {
  text-align: center;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  margin: 4px 0 12px;
}

/* ============ AUDIO STATUS ============ */
.audio-status {
  display: block;
  text-align: center;
  margin-top: 12px;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  min-height: 1em;
}
.audio-status.ok { color: var(--ink-soft); }
.audio-status.warn { color: var(--accent); }

/* ============ FINAL / GAME OVER ============ */
.final-title {
  text-align: center;
  font-size: 3rem;
  margin: 12px 0 28px;
  font-family: 'Fraunces', serif;
  letter-spacing: -0.02em;
}
.podium {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  align-items: end;
  gap: 18px;
  max-width: 760px;
  margin: 0 auto;
}
.podium-slot {
  background: var(--paper);
  border: 0.5px solid var(--tile-edge);
  border-radius: 10px;
  padding: 18px 14px;
  text-align: center;
  box-shadow: var(--shadow-tile);
}
.podium-slot.first {
  background: linear-gradient(180deg, #FBF6EC 0%, #F4EDE0 100%);
  border-color: var(--accent);
  padding: 26px 16px;
  transform: translateY(-12px);
}
.podium-slot.second { padding-top: 26px; }
.podium-slot.third  { padding-top: 32px; }
.podium-rank {
  font-family: 'Special Elite', monospace;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.podium-slot.first .podium-rank { color: var(--accent); }
.podium-medal { font-size: 2rem; line-height: 1; margin: 8px 0; }
.podium-name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.25rem;
  margin: 4px 0;
}
.podium-slot.first .podium-name { font-size: 1.55rem; }
.podium-score {
  font-family: 'Special Elite', monospace;
  font-size: 1rem;
  color: var(--ink-soft);
}
.final-rest {
  max-width: 540px;
  margin: 32px auto 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.final-rest-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 0.5px solid var(--tile-edge);
  font-family: 'Fraunces', serif;
}
.final-rest-row .rank-num {
  color: var(--muted);
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
  margin-right: 10px;
}
.final-rest-row .score {
  color: var(--ink-soft);
  font-family: 'Special Elite', monospace;
}

@media (max-width: 600px) {
  .room-code-overlay { bottom: 0.75rem; left: 0.75rem; padding: 8px 10px 6px; }
  .room-code-overlay .rc-tiles .rc-tile { width: 22px; height: 28px; line-height: 28px; font-size: 1rem; }
  .room-code-overlay .rc-join { font-size: 0.6rem; max-width: 170px; }
  .final-title { font-size: 2rem; }
  .podium { grid-template-columns: 1fr; gap: 10px; }
  .podium-slot.first { transform: none; }
}

/* mid-round joiner pill */
.player-pill.midround { opacity: 0.6; border-style: dashed; }

/* ============ PLAYER FINAL BOARD ============ */
.final-board {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.final-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--paper);
  border: 0.5px solid var(--tile-edge);
  border-radius: 6px;
  font-family: 'Fraunces', serif;
}
.final-row.me {
  background: linear-gradient(180deg, #FBF6EC 0%, #F4EDE0 100%);
  border-color: var(--accent);
  font-weight: 600;
}

/* Make the tile tray on player scroll if very tall (for tilesPerPlayer up to 80) */
.tray { max-height: 50vh; overflow-y: auto; }

/* ============ PUNCTUATION PALETTE (player) ============ */
.punctuation-palette {
  border-top: 0.5px solid rgba(0,0,0,0.18);
  padding: 6px 8px 4px;
  margin: 0 0 8px;
  background: rgba(255,255,255,0.32);
  border-radius: 6px;
}
.punctuation-palette .punct-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 4px;
  text-align: left;
}
.punctuation-palette .punct-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
}
.tile.tile-punct-source {
  /* Slightly smaller than word tiles; same magnetic aesthetic */
  font-family: 'Special Elite', monospace;
  font-size: 0.95rem;
  padding: 4px 9px;
  min-width: 26px;
  text-align: center;
  color: var(--ink-soft);
  background: var(--paper);
  margin: 2px;
  border-color: rgba(0,0,0,0.14);
}
.tile.tile-punct-source.tile-newline-source {
  color: var(--accent);
  font-size: 1.05rem;
  font-family: 'Fraunces', serif;
  padding: 4px 12px;
}
/* Override the global :nth-child rotation rules so the palette feels tidy but still magnetic */
.tile.tile-punct-source:nth-child(2n)   { transform: rotate(-1deg); }
.tile.tile-punct-source:nth-child(2n+1) { transform: rotate(0.7deg); }
.tile.tile-punct-source:hover { transform: rotate(0) translateY(-1px); }

/* ============ PLACED PUNCTUATION TILES (in composition / reveals) ============ */
.tile.tile-placed-punct {
  font-family: 'Special Elite', monospace;
  font-size: 0.95rem;
  padding: 4px 9px;
  color: var(--ink-soft);
  font-style: italic;
  background: #fffdf6;
  border-color: rgba(0,0,0,0.18);
}
/* Visible thin newline pill — full row width, forces wrap */
.tile.tile-newline {
  flex-basis: 100%;
  width: 100%;
  max-width: 100%;
  text-align: center;
  background: transparent;
  color: var(--accent);
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  border: 0;
  box-shadow: none;
  padding: 2px 0 0;
  margin: 2px 0;
  position: relative;
  font-style: normal;
}
.tile.tile-newline::before,
.tile.tile-newline::after {
  content: '';
  position: absolute;
  top: 50%;
  width: calc(50% - 18px);
  height: 0;
  border-top: 0.5px dashed rgba(178,58,72,0.32);
}
.tile.tile-newline::before { left: 0; }
.tile.tile-newline::after  { right: 0; }

/* poem-line rows: each line wraps independently so newlines break the composition */
.poem-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  width: 100%;
  justify-content: inherit;
}
.poem-line:not(:last-child) { margin-bottom: 2px; }
.reveal-stage .poem-line { justify-content: center; }
.winner-stage .poem-line { justify-content: center; }

/* ============ V4: SPECTATOR LOBBY RESPONSIVE ============ */
.spectator { min-height: 100vh; min-height: 100dvh; }
.spectator-main { min-height: 0; }
.lobby-card { max-height: calc(100dvh - 100px); overflow-y: auto; }

@media (max-height: 720px) {
  .spectator-header { padding: 14px 30px 8px; }
  .spectator-main { padding: 22px 30px; }
  .lobby-code { font-size: clamp(3.2rem, 9vw, 6rem); margin: 8px 0 4px; }
  .lobby-instruct { font-size: 1.1rem; margin-bottom: 14px; }
  .qr-wrap { padding: 10px; }
  .qr-wrap canvas { max-width: 160px; max-height: 160px; }
  .lobby-card { padding: 22px 26px; }
}
@media (max-height: 620px) {
  .lobby-card { padding: 16px 22px; }
  .qr-wrap canvas { max-width: 130px; max-height: 130px; }
  .players-pill-row { margin: 14px 0; }
}

/* ============ V4: PROMPT MINI (voting/scoring/final) ============ */
.prompt-mini {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--muted);
  margin: 6px auto 14px;
  max-width: 800px;
}
.prompt-mini::before { content: "“"; color: var(--accent); margin-right: 2px; }
.prompt-mini::after { content: "”"; color: var(--accent); margin-left: 2px; }
.prompt-mini:empty { display: none; }
.prompt-mini-inline {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 0.92rem;
  color: var(--muted);
  margin-top: 4px;
}
.prompt-mini-inline:empty { display: none; }
.prompt-mini-inline::before { content: "“"; color: var(--accent); }
.prompt-mini-inline::after { content: "”"; color: var(--accent); }

/* ============ V4: SETTINGS TOGGLE FIELDS ============ */
.modal-toggle { padding: 6px 0; }
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  padding: 8px 4px;
}
.toggle-row input[type="checkbox"] {
  margin: 4px 0 0;
  width: 20px; height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-row .toggle-text { display: flex; flex-direction: column; gap: 2px; }
.toggle-row .toggle-title {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  color: var(--ink);
}
.toggle-row .toggle-hint {
  font-family: 'Special Elite', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* ============ V4: PER-PLAYER PREFS MODAL ============ */
.prefs-sheet h2 { font-family: 'Fraunces', serif; font-size: 1.5rem; }
.prefs-sheet h2 span { color: var(--accent); font-style: italic; }
.prefs-tiles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.pref-tile {
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--tile-edge);
  border-radius: 10px;
  padding: 14px 16px;
  text-transform: none;
  letter-spacing: 0;
  text-align: left;
  font-family: 'Fraunces', serif;
  cursor: pointer;
  box-shadow: var(--shadow-tile);
  transition: transform 100ms ease, border-color 100ms ease, background 100ms ease;
  position: relative;
}
.pref-tile:hover { transform: translateY(-1px); }
.pref-tile:nth-child(odd)  { transform: rotate(-0.4deg); }
.pref-tile:nth-child(even) { transform: rotate(0.5deg); }
.pref-tile.selected {
  border-color: var(--accent);
  background: #fff2e3;
  box-shadow: 0 0 0 2px rgba(178,58,72,0.16), var(--shadow-tile);
}
.pref-tile .pref-tile-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pref-tile-title { font-weight: 600; font-size: 1.1rem; }
.pref-tile-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1.5px solid var(--tile-edge);
  font-family: 'Special Elite', monospace;
  color: transparent;
  background: var(--cream);
  font-size: 1rem;
  line-height: 1;
}
.pref-tile.selected .pref-tile-check {
  color: var(--paper);
  background: var(--accent);
  border-color: var(--accent);
}
.pref-tile-hint {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* ============ V4: SORTED TRAY (category groups) ============ */
.tray-group {
  width: 100%;
  margin-bottom: 6px;
}
.tray-group-label {
  font-family: 'Special Elite', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2px 4px 4px;
  display: block;
}
.tray-group-tiles {
  display: flex;
  flex-wrap: wrap;
}

/* ============ V4: UNIFIED FONT MODE ============ */
.tray.unified-font .tile,
.tray.unified-font .tile:nth-child(3n),
.tray.unified-font .tile:nth-child(5n),
.tray.unified-font .tile:nth-child(7n) {
  font-family: 'Inter', 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-style: normal;
  font-weight: 500;
}

/* ============ V4: TILE REFLOW ANIMATION ============ */
.tray .tile { transition: transform 180ms cubic-bezier(.2,.7,.2,1), opacity 140ms ease, box-shadow 120ms ease; }
.tile.removing { opacity: 0; transform: scale(0.6) rotate(0deg); pointer-events: none; }

/* ============ V4: MOBILE FOOTER BUFFER ============ */
.player {
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}
#screen-writing {
  padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
}
.tray { max-height: 46vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
@media (max-height: 700px) {
  .tray { max-height: 38vh; }
}

/* ============ V4: DJ NEXT BUTTON (magnetic tile aesthetic) ============ */
.magnet-btn {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  background: var(--accent);
  color: var(--paper);
  padding: 14px 26px;
  border-radius: 8px;
  text-transform: none;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-tile), 0 8px 24px rgba(178,58,72,0.18);
  border: 1.5px solid rgba(0,0,0,0.04);
  transform: rotate(-0.8deg);
}
.magnet-btn:hover { transform: rotate(0deg) translateY(-2px); }
.dj-wait {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-align: center;
}
.dj-wait span { color: var(--accent); font-weight: 700; }

/* ============ V4: RECONNECTING INDICATOR ============ */
.player-pill.reconnecting,
.scoreboard li.reconnecting {
  opacity: 0.55;
}
.scoreboard li.reconnecting::after {
  content: " (reconnecting…)";
  font-family: 'Special Elite', monospace;
  font-size: 0.72rem;
  color: var(--accent);
  margin-left: 4px;
}
.player-pill.reconnecting::after {
  content: " · reconnecting…";
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--accent);
  opacity: 0.9;
}

/* ============ V4: SPECTATOR AWAITING NEXT ============ */
.awaiting-banner {
  margin-top: 12px;
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.awaiting-banner strong { color: var(--accent); font-weight: 700; }

/* ============ V5: READY STATES IN LOBBY ============ */
.pill-ready-tag {
  margin-left: 6px;
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: #2E8B57;
  letter-spacing: 0.03em;
}
.pill-pending-tag {
  margin-left: 6px;
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}
.player-pill.ready { box-shadow: inset 0 0 0 1px rgba(46, 139, 87, 0.4); }
.player-pill.not-ready { opacity: 0.85; }

/* ============ V5: 's' SUFFIX TILE (palette + placed) ============ */
.tile-suffix-source {
  font-family: 'Special Elite', monospace !important;
  font-size: 0.92rem;
  padding: 4px 11px;
  letter-spacing: 0.02em;
}
.tile-placed-punct.tile-suffix {
  font-family: 'Special Elite', monospace !important;
  font-size: 0.92rem;
  padding: 4px 11px;
}

/* ============ V5: DOUBLE-TAP TENSE TOGGLE ANIMATIONS ============ */
@keyframes mp-tense-flash {
  0%   { background: #6BA3D6; color: #fff; transform: scale(1); }
  40%  { background: #6BA3D6; color: #fff; transform: scale(1.08); }
  100% { background: transparent; color: inherit; transform: scale(1); }
}
.tile.tile-tense-toggle {
  animation: mp-tense-flash 350ms ease-out;
}
@keyframes mp-tense-invalid {
  0%   { transform: rotate(0deg);  background: #C04040; color: #fff; }
  12%  { transform: rotate(6deg);  background: #C04040; color: #fff; }
  25%  { transform: rotate(-6deg); background: #C04040; color: #fff; }
  37%  { transform: rotate(6deg);  background: #C04040; color: #fff; }
  50%  { transform: rotate(-6deg); background: #C04040; color: #fff; }
  62%  { transform: rotate(6deg);  background: #C04040; color: #fff; }
  75%  { transform: rotate(-6deg); background: #C04040; color: #fff; }
  87%  { transform: rotate(6deg);  background: #C04040; color: #fff; }
  100% { transform: rotate(0deg);  background: transparent; color: inherit; }
}
.tile.tile-tense-invalid {
  animation: mp-tense-invalid 400ms ease-in-out;
}

/* ============ V5: SORTABLE DRAG STYLES ============ */
.tile.tile-drag-ghost {
  opacity: 0.35;
  transform: scale(0.96);
}
.tile.tile-drag-chosen {
  cursor: grabbing;
  z-index: 10;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

/* ============ V5: LARGER SPECTATOR PROMPTS (voting + scoring) ============ */
/* Player-side prompt sizing is untouched. Spectator prompt-mini base remains. */
.spectator-prompt-vote {
  font-family: 'Fraunces', serif !important;
  font-style: italic;
  text-align: center;
  font-size: clamp(1.6rem, 3.4vw, 2.6rem) !important;
  line-height: 1.25 !important;
  color: var(--ink-soft) !important;
  margin: 6px auto 14px !important;
  max-width: 80ch;
  /* ~60% of writing-screen .spectator-prompt size */
}
.spectator-prompt-score {
  font-family: 'Fraunces', serif !important;
  font-style: italic;
  text-align: center;
  font-size: clamp(1.2rem, 2.6vw, 2.0rem) !important;
  line-height: 1.25 !important;
  color: var(--ink-soft) !important;
  margin: 4px auto 12px !important;
  max-width: 80ch;
  /* ~45% of writing-screen .spectator-prompt size */
}

/* ============ V5.4: PLAYER BADGE (avatar + name-magnet) ============ */
.player-badge {
  display: inline-flex;
  align-items: center;
  gap: 0;
  white-space: nowrap;
  vertical-align: middle;
}
.player-badge .avatar {
  flex-shrink: 0;
  border-radius: 50%;
  aspect-ratio: 1;
  overflow: hidden;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-badge .avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  object-fit: cover;
}
.player-badge .name-magnet {
  font-family: 'Special Elite', 'Courier New', monospace;
  background: #fefbf3;
  border: 1.5px solid #1a1a1a;
  border-radius: 4px;
  box-shadow: 1px 2px 0 rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.5);
  transform: rotate(-1.5deg);
  margin-left: -14px;
  position: relative;
  z-index: 1;
  white-space: nowrap;
  line-height: 1.2;
}
/* Size variants */
.player-badge.size-sm .avatar { width: 36px; height: 36px; }
.player-badge.size-sm .name-magnet { font-size: 13px; padding: 3px 8px 3px 18px; }
.player-badge.size-md .avatar { width: 64px; height: 64px; }
.player-badge.size-md .name-magnet { font-size: 18px; padding: 5px 12px 5px 22px; }
.player-badge.size-lg .avatar { width: 96px; height: 96px; }
.player-badge.size-lg .name-magnet { font-size: 24px; padding: 7px 16px 7px 30px; }

/* Voter-tally row */
.voter-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}

/* ============ V5.4: AVATAR PICKER (prefs modal) ============ */
.avatar-picker-section {
  margin-bottom: 18px;
}
.avatar-picker-label {
  font-family: 'Special Elite', monospace;
  font-size: 0.88rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.avatar-grid-item {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 120ms ease, opacity 120ms ease, transform 100ms ease;
  padding: 0;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: visible;
}
.avatar-grid-item img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  pointer-events: none;
}
.avatar-grid-item.selected {
  border-color: var(--accent);
  transform: scale(1.06);
}
.avatar-grid-item.taken {
  opacity: 0.38;
  cursor: not-allowed;
}
.avatar-grid-item.taken::after {
  content: 'taken';
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Special Elite', monospace;
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

/* ============ V5.5: BONUS MEDAL BUTTONS (player voting screen) ============ */
.bonus-medals-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--tile-edge);
}
.bonus-medals-label {
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 10px;
  text-align: center;
}
.bonus-medals-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}
.medal-btn {
  width: 80px;
  height: 80px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  position: relative;
  transition: transform 120ms ease, filter 120ms ease;
  opacity: 0.75;
  color: inherit;
  text-transform: none;
  letter-spacing: 0;
}
.medal-btn img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  display: block;
  object-fit: contain;
  pointer-events: none;
}
.medal-btn:hover { opacity: 0.9; transform: translateY(-2px); }
.medal-btn.armed-selected {
  opacity: 1;
  filter: drop-shadow(0 0 8px rgba(178,58,72,0.6));
  transform: scale(1.08);
  animation: medal-pulse 900ms ease-in-out infinite alternate;
}
.medal-btn.spent {
  opacity: 0.48;
  cursor: pointer;
}
.medal-btn.spent::after {
  content: '✓';
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 14px;
  color: var(--accent);
  font-family: sans-serif;
  font-weight: 700;
  text-shadow: 0 0 4px white;
}
@keyframes medal-pulse {
  from { filter: drop-shadow(0 0 6px rgba(178,58,72,0.5)); }
  to   { filter: drop-shadow(0 0 12px rgba(178,58,72,0.85)); }
}

/* Flat badge attached to a vote card */
.vote-card { position: relative; }
.vote-card-bonus-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.bonus-flat-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: contain;
  animation: badge-pop 350ms ease;
}
@keyframes badge-pop {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* ============ V5.5: GRAND REVEAL ANIMATION ============ */
.reveal-stage-wrapper {
  position: relative;
  width: 100%;
  min-height: 100vh;
  overflow: hidden;
}

/* Scattered composition cards */
.reveal-comp-card {
  position: absolute;
  background: var(--paper);
  border: 1px solid var(--tile-edge);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  padding: 16px 18px;
  cursor: default;
  transition: transform 600ms cubic-bezier(0.23, 1, 0.32, 1),
              left 600ms cubic-bezier(0.23, 1, 0.32, 1),
              top 600ms cubic-bezier(0.23, 1, 0.32, 1),
              box-shadow 300ms ease,
              opacity 300ms ease;
  max-width: 280px;
  min-width: 160px;
}
.reveal-comp-card.wobbling {
  /* Wobble uses CSS `translate:` and `rotate:` (separate from `transform`) so
     the card's transform: translate(-50%, -50%) centering is preserved. */
  animation: card-wobble 1200ms ease-in-out infinite alternate;
}
.reveal-comp-card.ranked-first {
  box-shadow: 0 8px 28px rgba(178,58,72,0.35), 0 2px 8px rgba(0,0,0,0.12);
  border-color: var(--accent);
  z-index: 20 !important;
}
.reveal-comp-card .rank-label {
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.reveal-comp-card .author-badge-row {
  margin-bottom: 6px;
}
.reveal-comp-card .reveal-author-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px dashed var(--tile-edge);
}
.reveal-comp-card .reveal-author-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: var(--paper);
  border: 2px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.reveal-comp-card .reveal-author-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.reveal-comp-card .reveal-author-name {
  font-family: 'Special Elite', monospace;
  font-size: 0.95rem;
  color: var(--ink);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
/* On the smaller grid cards (rank 4+), shrink the avatar a touch so it
   doesn't dominate. The card is scaled to 0.88 globally; this trims another bit. */
.reveal-comp-card .reveal-author-avatar {
  /* default size above; grid override would go here if needed */
}
/* Grand reveal round counter */
.grand-round-counter {
  position: absolute;
  top: 24px;
  right: 28px;
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--paper);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--tile-edge);
  z-index: 30;
  animation: prompt-slide-in 600ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
/* Status line that appears after the reveal animation finishes */
.reveal-status-line {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: 0.05em;
  z-index: 55;
  opacity: 0;
  animation: status-fade-in 600ms ease 200ms forwards;
  text-align: center;
}
@keyframes status-fade-in {
  to { opacity: 1; }
}
.reveal-comp-card .comp-text {
  font-family: 'Fraunces', serif;
  font-size: 0.95rem;
  line-height: 1.4;
}
.reveal-comp-card .slam-voters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.reveal-comp-card .voter-slam {
  opacity: 0;
  transform: translateX(80px);
  transition: opacity 250ms ease, transform 250ms cubic-bezier(0.23, 1, 0.32, 1);
}
.reveal-comp-card .voter-slam.slammed {
  opacity: 1;
  transform: translateX(0);
}
/* Shake uses CSS translate (separate from transform) so the card's final
   centering/scale/rotate transform is preserved during the shake. */
.reveal-comp-card.shake {
  animation: card-shake 180ms ease;
}
@keyframes card-shake {
  0%   { translate: 0 0; }
  20%  { translate: -5px 1px; }
  40%  { translate: 5px -1px; }
  60%  { translate: -4px 0px; }
  80%  { translate: 3px 0px; }
  100% { translate: 0 0; }
}
@keyframes card-wobble {
  /* Apply only to `translate:` and `rotate:` properties so the centering
     transform on the card is untouched. The base rotation comes from the
     inline `rotate(${rot}deg)` in `transform`; this wobble adds a small
     extra tilt and translation on top. */
  from {
    translate: var(--wobble-x, 0) var(--wobble-y, 0);
    rotate: 0deg;
  }
  to {
    translate: calc(var(--wobble-x, 0) + 2px) calc(var(--wobble-y, 0) - 1px);
    rotate: 1.2deg;
  }
}
.reveal-comp-card.lit {
  /* Bright spotlight ring + brightness lift. The scale-bump comes from JS
     (inline transform) so it composes with the centering translate. */
  box-shadow:
    0 0 0 3px var(--accent),
    0 0 28px 4px rgba(178,58,72,0.35),
    0 14px 36px rgba(0,0,0,0.30);
  filter: brightness(1.10);
  z-index: 40;
}
.reveal-comp-card.ranked-first.lit,
.reveal-comp-card.ranked-first {
  box-shadow:
    0 0 0 3px var(--accent),
    0 0 40px 6px rgba(178,58,72,0.45),
    0 18px 44px rgba(0,0,0,0.35);
}

/* Grand reveal phase 1: prompt banner */
.grand-prompt-banner {
  position: absolute;
  top: 48px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: clamp(1.6rem, 4vw, 3rem);
  text-align: center;
  max-width: 90%;
  animation: prompt-slide-in 600ms cubic-bezier(0.23, 1, 0.32, 1) both;
  z-index: 30;
  background: var(--paper);
  padding: 12px 24px;
  border-radius: 10px;
  border: 1px solid var(--tile-edge);
  box-shadow: var(--shadow-tile);
}
.grand-prompt-banner::before { content: '\201C'; color: var(--accent); }
.grand-prompt-banner::after  { content: '\201D'; color: var(--accent); }
@keyframes prompt-slide-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-30px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Confetti canvas overlay */
#confetti-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 100;
}

/* Reveal skip hint */
.reveal-skip-hint {
  position: fixed;
  bottom: 20px;
  right: 24px;
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  opacity: 0.55;
  z-index: 50;
  pointer-events: none;
}

/* Continue button in grand reveal */
.reveal-continue-btn {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: none;
}
.reveal-continue-btn.visible { display: block; }

/* ============ V5.5: BONUS SUMMARY SCREEN ============ */
#screen-bonus-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  padding: 40px 24px;
}
.bonus-summary-title {
  font-family: 'Fraunces', serif;
  font-size: 2.4rem;
  font-style: italic;
  margin-bottom: 32px;
  text-align: center;
}
.bonus-awards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  justify-content: center;
  max-width: 800px;
  width: 100%;
}
.bonus-award-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: scale(0);
  transition: opacity 400ms ease, transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.bonus-award-item.revealed {
  opacity: 1;
  transform: scale(1);
}
.bonus-award-item img.award-medal {
  width: 100px;
  height: 100px;
  object-fit: contain;
}
.bonus-award-winners {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  font-family: 'Special Elite', monospace;
  font-size: 0.82rem;
  color: var(--muted);
}
.bonus-award-count {
  font-family: 'Special Elite', monospace;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* ============================================================
   v5.6 — Scored screen: round counter + personal badge tally
   ============================================================ */

.scored-round-counter {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-family: 'Special Elite', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.my-badges-section {
  margin: 18px 0 6px;
  padding: 14px 0 4px;
  border-top: 1px dashed var(--rule, rgba(0,0,0,0.18));
  animation: my-badges-fade-in 0.45s ease-out both;
}
@keyframes my-badges-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.my-badges-title {
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
  margin-bottom: 10px;
}
.my-badges-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px 18px;
}
.my-badge-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
  background: rgba(0,0,0,0.04);
}
.my-badge-medal {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}
.my-badge-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.my-badge-label {
  font-family: 'Fraunces', serif;
  font-size: 0.85rem;
  color: var(--ink, #1a1a1a);
}
.my-badge-count {
  font-family: 'Special Elite', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 1px;
}

/* ============================================================
   v5.6 — Vote screen: per-poem 🔊 replay button
   ============================================================ */

.replay-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--rule, rgba(0,0,0,0.2));
  background: rgba(255,255,255,0.7);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.replay-btn:hover:not(:disabled) {
  background: rgba(0,0,0,0.05);
  transform: scale(1.06);
}
.replay-btn:active:not(:disabled) {
  transform: scale(0.94);
}
.replay-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.replay-btn.playing {
  background: var(--accent, #c8472b);
  border-color: var(--accent, #c8472b);
  animation: replay-pulse 1.2s ease-in-out infinite;
}
@keyframes replay-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); }
  50%      { box-shadow: 0 0 0 6px rgba(0,0,0,0.06); }
}
.replay-icon {
  font-size: 1rem;
  line-height: 1;
  pointer-events: none;
}

/* ============================================================
   v5.6.1 — "Your poem" tag + self-award shake warning
   ============================================================ */

.vote-card-mine {
  position: relative;
  border-style: dashed;
}
.vote-card-mine-tag {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px dashed var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: rgba(200, 71, 43, 0.06);
}
/* When the replay button is present, push the "your poem" tag left so it
   doesn't sit awkwardly next to the round-button. */
.vote-card-head .replay-btn ~ .vote-card-mine-tag,
.vote-card-head .vote-card-mine-tag + .replay-btn { margin-left: 8px; }

.vote-card.mine-warn {
  animation: vote-card-mine-shake 0.45s ease-in-out;
}
@keyframes vote-card-mine-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-7px); }
  40%      { transform: translateX(7px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

/* ============================================================
   v5.6.2 — Final screen: podium + Special Awards side-by-side
   ============================================================ */

.final-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 36px;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  align-items: start;
}
.final-layout:has(.final-awards:not([hidden])) {
  grid-template-columns: minmax(0, 1.55fr) minmax(220px, 0.95fr);
}
.final-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.final-awards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 14px 20px;
  border: 1px solid var(--rule, rgba(0,0,0,0.18));
  border-radius: 14px;
  background: rgba(255,255,255,0.5);
  align-self: start;
  position: relative;
}
.final-awards::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(200, 71, 43, 0.08);
  pointer-events: none;
}
.final-awards-title {
  text-align: center;
  font-family: 'Special Elite', monospace;
  color: var(--accent);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.82rem;
  margin-bottom: 4px;
}
.bonus-awards-grid.bonus-awards-grid--column {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 18px;
  max-width: none;
  width: 100%;
}
.bonus-award-label {
  font-family: 'Fraunces', serif;
  font-size: 1.02rem;
  color: var(--ink, #1a1a1a);
  line-height: 1.2;
}
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.025);
  display: grid;
  grid-template-columns: 64px 1fr;
  grid-template-areas:
    "medal label"
    "medal winners"
    "medal count";
  row-gap: 3px;
  column-gap: 14px;
  align-items: center;
}
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item img.award-medal {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  align-self: center;
}
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item .bonus-award-winners,
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item .bonus-award-count {
  justify-content: flex-start;
}
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item .bonus-award-winners {
  flex-wrap: wrap;
}
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item img.award-medal { grid-area: medal; }
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item .bonus-award-label   { grid-area: label; }
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item .bonus-award-winners { grid-area: winners; }
.bonus-awards-grid.bonus-awards-grid--column .bonus-award-item .bonus-award-count   { grid-area: count; }

/* Narrow screens: stack the awards column under the podium */
@media (max-width: 900px) {
  .final-layout:has(.final-awards:not([hidden])) {
    grid-template-columns: minmax(0, 1fr);
  }
  .final-awards { max-width: 560px; margin: 0 auto; width: 100%; }
}

/* Browsers without :has() — fall back to a flex column. The grid template
   will be ignored harmlessly because grid-template-columns is set above. */
@supports not selector(:has(*)) {
  .final-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .final-main { width: 100%; }
  .final-awards { max-width: 560px; width: 100%; }
}
