:root {
  --bg: #0c0c0e;
  --rail: #121215;
  --panel: #18181c;
  --panel-hi: #222228;
  --border: #2a2a32;
  --border-hi: #3f3f4a;
  --ink: #f4f4f6;
  --muted: #8b8b96;
  --card-black: #09090b;
  --card-white: #fafafa;
  --card-ink: #0f0f12;
  --live: #22c55e;
  --accent: #f4f4f6;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.app-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Top Header ─── */
.topbar {
  background: var(--rail);
  border-bottom: 1px solid var(--border);
  padding: 9px 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.brand-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}
.brand-tagline {
  font-size: 0.75rem;
  color: var(--muted);
}
.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

button, .btn-link, input, select {
  font: inherit;
  border-radius: 7px;
  font-size: 0.81rem;
}
input, select {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 6px 10px;
}
@media (max-width: 720px) {
  /* Prevents iOS Discord WebView auto-zoom on input focus */
  input, select { font-size: 16px; }
}
button, .btn-link {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 6px 11px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
button:hover, .btn-link:hover {
  background: var(--panel-hi);
  border-color: var(--border-hi);
}
button:active { transform: translateY(1px); }
button.primary, button.gold {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
button.primary:hover, button.gold:hover {
  background: #dcdce2;
  border-color: #dcdce2;
}
button.danger {
  background: transparent;
  border-color: #5c2427;
  color: #f87171;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.pill-badge {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pill-badge.live {
  color: var(--ink);
  border-color: var(--border-hi);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.dot.live { background: var(--live); }

/* ─── 3-Column Grid ─── */
.stage-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr) 256px;
  min-height: 0;
}
@media (max-width: 1024px) {
  .stage-grid { grid-template-columns: 196px minmax(0, 1fr); }
  .right-rail { grid-column: 1 / -1; border-left: 0 !important; border-top: 1px solid var(--border); }
}
@media (max-width: 720px) {
  .stage-grid { grid-template-columns: 1fr; }
  .left-rail { border-right: 0 !important; border-bottom: 1px solid var(--border); }
}

.left-rail {
  background: var(--rail);
  border-right: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.center-arena {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.right-rail {
  background: var(--rail);
  border-left: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.rail-heading {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ─── Left Rail: Seats & Voice ─── */
.seat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
@media (max-width: 720px) {
  .seat-list { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .seat-card { min-width: 168px; }
}
.seat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.seat-card:hover { border-color: var(--border-hi); }
.seat-card.judge { border-color: var(--ink); }
.seat-card.offline { opacity: 0.4; }

.avatar-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.avatar-img, .avatar-mono {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.72rem;
  background: var(--panel-hi);
  border: 1.5px solid var(--border-hi);
}
.seat-card.speaking .avatar-img,
.seat-card.speaking .avatar-mono {
  border-color: var(--live);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.28);
}

.seat-info { flex: 1; min-width: 0; }
.seat-name {
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat-presence {
  font-size: 0.71rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat-presence.talking { color: var(--live); }

/* ─── Center Stage ─── */
.drama-banner {
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.drama-banner.role-play {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.08);
}
.drama-banner.role-judge {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.08);
}
.drama-banner.role-locked {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.08);
}
.drama-banner.flash {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.drama-banner.flash .muted { color: #52525b; }

.edition-cards-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
@media (max-width: 520px) {
  .edition-cards-row { grid-template-columns: 1fr; }
}
.edition-choice {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  cursor: pointer;
}
.edition-choice:hover { border-color: var(--border-hi); }
.edition-choice.active {
  border-color: var(--ink);
  background: var(--panel-hi);
}
.cta-hero {
  padding: 10px 18px;
  font-size: 0.92rem;
  border-radius: 9px;
}
.card-cta-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 5px 10px;
  border-radius: 6px;
  background: #18181c;
  color: #fafafa;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.blank-slot.filled {
  background: rgba(255, 255, 255, 0.14);
  border-bottom: 2px solid #4ade80;
  border-radius: 4px;
  padding: 1px 6px;
}

.table-top-row {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 820px) {
  .table-top-row { grid-template-columns: 1fr; }
}

.game-card {
  border-radius: 11px;
  padding: 16px;
  min-height: 198px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  user-select: none;
}
.game-card.black {
  background: var(--card-black);
  color: var(--ink);
  border: 1px solid var(--border-hi);
  min-height: 228px;
}
.game-card.white {
  background: var(--card-white);
  color: var(--card-ink);
  border: 1px solid #d4d4d8;
}
.game-card.facedown {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
  align-items: center;
  justify-content: center;
  text-align: center;
}
.game-card small {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
  display: flex;
  justify-content: space-between;
}
.game-card p {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.34;
  letter-spacing: -0.01em;
  flex: 1;
  overflow-wrap: anywhere;
}
.blank-slot {
  border-bottom: 1.5px solid var(--ink);
  color: #fff;
  padding: 0 2px;
}
.game-card.interactive {
  cursor: pointer;
  transition: transform 0.14s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.12s ease, box-shadow 0.14s ease;
}
.game-card.interactive:hover,
.game-card.selected {
  transform: translateY(-4px);
  border-color: var(--ink);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.game-card.white.selected {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.reveal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 11px;
}

.hand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 10px;
}
@media (max-width: 720px) {
  .hand-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 10px;
    padding: 4px 2px 12px;
  }
  .hand-grid .game-card {
    min-width: 78vw;
    scroll-snap-align: center;
  }
}

.waiting-list {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 15px;
}

/* ─── Right Rail ─── */
.panel-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
}
.score-row { margin-top: 7px; }
.score-bar-track {
  height: 4px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.score-bar-fill {
  height: 100%;
  background: var(--ink);
  transition: width 0.25s ease;
}

.feed-list {
  flex: 1;
  min-height: 110px;
  max-height: 250px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.76rem;
  color: var(--muted);
}
.feed-item {
  padding: 3px 6px;
  border-radius: 4px;
}
.feed-item.win { color: var(--ink); font-weight: 600; }
.feed-item.twist { color: #d4d4d8; }

.reaction-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.rx-btn {
  padding: 3px 7px;
  font-size: 0.72rem;
  background: var(--bg);
  color: var(--muted);
}
.rx-btn:hover { color: var(--ink); }

.floating-rx {
  position: fixed;
  bottom: 24px;
  right: 24px;
  pointer-events: none;
  background: var(--panel-hi);
  border: 1px solid var(--border-hi);
  color: var(--ink);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  z-index: 90;
  animation: toastFade 1.9s ease-out forwards;
}
@keyframes toastFade {
  0%   { transform: translateY(8px); opacity: 0; }
  12%  { transform: translateY(0); opacity: 1; }
  80%  { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-10px); opacity: 0; }
}

/* ─── Modern Minimal Winner Modal ─── */
.winner-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 8, 10, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  animation: modalIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}
.winner-modal {
  width: min(620px, 100%);
  background: var(--rail);
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.winner-kicker {
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  text-transform: uppercase;
}
.winner-hero-name {
  font-size: clamp(1.5rem, 3.6vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 2px 0 0;
}
.winner-cards-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 580px) {
  .winner-cards-pair { grid-template-columns: 1fr; }
}

.drawer {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }

body.pip-mode .topbar,
body.pip-mode .left-rail,
body.pip-mode .right-rail {
  display: none !important;
}
body.pip-mode .stage-grid {
  grid-template-columns: 1fr;
}
