:root {
  --bg: #0c1222;
  --bg-2: #121a2e;
  --panel: #16203a;
  --panel-2: #1c2845;
  --border: #25324f;
  --border-bright: #324466;
  --text: #e8edf7;
  --text-dim: #94a3c4;
  --text-faint: #5e6d92;
  --accent: #5eead4; /* teal — feels like a dev tool */
  --accent-2: #2dd4bf;
  --accent-glow: rgba(94, 234, 212, 0.25);
  --danger: #fb7185;
  --gold: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 70% -10%, #16213d 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.view {
  min-height: 100vh;
}

/* ---------------- Buttons ---------------- */
.btn {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
  color: var(--text);
}
.btn:active {
  transform: translateY(1px);
}
.btn-lg {
  padding: 13px 22px;
  font-size: 15px;
  width: 100%;
}
.btn-primary {
  background: var(--accent);
  color: #06231e;
  box-shadow: 0 6px 20px -8px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-2);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border-bright);
  color: var(--text-dim);
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ---------------- Landing / Error ---------------- */
#view-landing,
#view-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.landing-card {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.7);
}
/* landing intro — joker, title, and tagline lines, all horizontally centered */
.intro {
  text-align: center;
}
.intro .brand {
  justify-content: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand-mark {
  font-size: 40px;
  line-height: 1;
}
.brand-mark.sm {
  font-size: 24px;
}
.landing-card h1 {
  font-size: 30px;
  margin: 0;
  letter-spacing: -0.5px;
}
#view-error h1 {
  margin-top: 8px;
}
.tagline {
  color: var(--text-dim);
  margin: 6px 0 26px;
}
.ephemeral-note {
  margin-top: 22px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------------- Forms ---------------- */
.form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
input[type="text"] {
  font-family: var(--sans);
  font-size: 15px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 13px;
  width: 100%;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.emoji-free {
  margin-top: 8px;
}
.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.emoji-btn {
  font-size: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, transform 0.08s;
}
.emoji-btn:hover {
  transform: translateY(-2px);
  border-color: var(--border-bright);
}
.emoji-btn.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
  background: var(--panel-2);
}
/* An avatar already in use by another participant — not selectable. */
.emoji-btn.taken,
.emoji-btn:disabled {
  opacity: 0.3;
  filter: grayscale(1);
  cursor: not-allowed;
}
.emoji-btn.taken:hover {
  transform: none;
  border-color: var(--border);
}

.deck-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.deck-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.12s;
}
.deck-opt:hover {
  border-color: var(--border-bright);
}
.deck-opt:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.deck-opt input {
  accent-color: var(--accent);
}
.deck-opt-body {
  display: flex;
  flex-direction: column;
}
.deck-opt-name {
  font-weight: 600;
}
.deck-opt-cards {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 1px;
}
.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
}
.checkbox-field input {
  margin-top: 3px;
  accent-color: var(--accent);
}

/* ---------------- Room header ---------------- */
.room-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(18, 26, 46, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.rh-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.session-id-block {
  display: flex;
  flex-direction: column;
}
.session-id-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
}
.session-id {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  position: relative;
}
.copy-icon {
  font-size: 14px;
  color: var(--text-dim);
}
.session-id:hover .copy-icon {
  color: var(--accent);
}
.copy-feedback {
  position: absolute;
  left: 0;
  top: 110%;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.copy-feedback.show {
  opacity: 1;
}
.rh-center {
  flex: 1;
  min-width: 0;
}
.ticket-input {
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}
.ticket-input:disabled {
  background: transparent;
  border-color: transparent;
  color: var(--text);
  cursor: default;
}
.ticket-input:disabled::placeholder {
  color: var(--text-faint);
}
.rh-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.timer {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  font-variant-numeric: tabular-nums;
}
.my-avatar {
  font-size: 22px;
  line-height: 1;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.my-avatar:hover {
  transform: translateY(-2px);
  border-color: var(--border-bright);
}
.my-avatar:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.banner {
  background: rgba(251, 113, 133, 0.12);
  border-bottom: 1px solid rgba(251, 113, 133, 0.4);
  color: #fecdd3;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
}

/* ---------------- Room body ---------------- */
/* Single centered column by default. When watchers are present, `.has-watchers`
   (toggled by the client) widens it so the "Watching" list can sit in a second
   column to the right of the voting panel. */
.room-body {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 24px 20px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}
.room-body.has-watchers {
  max-width: 1120px;
}

.voting-panel {
  flex: 1;
  min-width: 0;
}
.voting-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.voting-head h2,
.watching-title {
  font-size: 16px;
  color: var(--text-dim);
  font-weight: 600;
}
.voting-head h2 {
  margin: 0;
}
.not-voting-toggle,
.auto-show-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.not-voting-toggle input,
.auto-show-toggle input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
.auto-show-toggle {
  margin-top: 16px;
  width: 100%;
  justify-content: center;
}

/* ---------------- Card deck ---------------- */
.card-deck {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 12px;
}
/* When the "Watching" sidebar is present the voting panel is wider, leaving a
   trailing empty grid track (the cards stop short of the right edge). `auto-fit`
   collapses that empty track so the cards stretch to fill the row, growing a
   little. Desktop only — below 760px the layout stacks and the base sizing wins. */
@media (min-width: 761px) {
  .room-body.has-watchers .card-deck {
    grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  }
}

/* ---------------- Watching (non-voters) ---------------- */
/* Right-hand column, sibling of .voting-panel — sits beside the cards, the
   "Show Votes" bar, and the revealed vote cards. */
.watching-panel {
  flex: 0 0 200px;
}
.watching-title {
  margin: 0 0 14px;
}
.watching-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.watching-item {
  display: flex;
  align-items: center;
  gap: 10px;
}
.watching-emoji {
  font-size: 22px;
  line-height: 1;
}
.watching-name {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.play-card {
  aspect-ratio: 2.5 / 3.5;
  background: linear-gradient(160deg, var(--panel-2) 0%, var(--panel) 100%);
  border: 1.5px solid var(--border-bright);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease,
    background 0.12s ease;
  box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 0.6);
}
.play-card:hover {
  transform: translateY(-8px);
  border-color: var(--accent);
  box-shadow: 0 14px 26px -12px var(--accent-glow);
}
.play-card.selected {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #06231e;
  border-color: var(--accent);
  transform: translateY(-10px);
  box-shadow: 0 18px 34px -12px var(--accent-glow);
}
.play-card.disabled {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.6);
}

/* ---------------- Host controls ---------------- */
.host-controls {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}
.host-controls .btn {
  flex: 1;
}

/* ---------------- The table (per-voter reveal cards) ---------------- */
.vote-table {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: center;
  margin-top: 24px;
  position: relative;
  /* Full-bleed across the page — but only when there's no Watching column to the
     right. Overridden under .has-watchers so the votes stay inside the left
     column instead of sliding under the watchers. */
  width: calc(100vw - 40px);
  margin-left: calc(-50vw + 50% + 20px);
}
.room-body.has-watchers .vote-table {
  width: auto;
  margin-left: 0;
}

.table-card {
  width: 150px;
  height: 206px;
  perspective: 800px;
  flex: 0 0 auto; /* never shrink/overlap — wrap to a new line instead */
}
.table-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.table-card.revealed .table-card-inner {
  transform: rotateY(180deg);
}
.table-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  text-align: center;
  box-shadow: 0 6px 14px -8px rgba(0, 0, 0, 0.6);
}

/* back = face-down. Empty/dashed until that person votes. */
.table-card-back {
  background: var(--bg);
  border: 1.5px dashed var(--border-bright);
  color: var(--text-faint);
}
.table-card.voted .table-card-back {
  background: linear-gradient(160deg, var(--panel-2) 0%, var(--panel) 100%);
  border: 1.5px solid var(--accent);
  color: var(--text);
  box-shadow: 0 10px 22px -10px var(--accent-glow);
}
.table-card.is-you .table-card-back {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tc-emoji {
  font-size: 49px;
  line-height: 1;
  filter: grayscale(0.4);
  opacity: 0.65;
  transition: filter 0.2s, opacity 0.2s;
}
.table-card.voted .tc-emoji {
  filter: none;
  opacity: 1;
}
.tc-name {
  font-size: 21px;
  font-weight: 600;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tc-status {
  height: 26px;
  font-size: 24px;
  font-weight: 700;
  color: #4ade80;
}

/* front = revealed value */
.table-card-front {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #06231e;
}
.table-card-front .tc-name {
  color: #06231e;
  opacity: 0.75;
}
.tc-value {
  font-family: var(--mono);
  font-size: 60px;
  font-weight: 700;
  line-height: 1;
}
.table-card.no-vote .table-card-front {
  background: var(--panel);
  color: var(--text-faint);
}
.table-card.no-vote .table-card-front .tc-name {
  color: var(--text-faint);
}

/* satisfying pop the moment someone votes */
.table-card.just-voted {
  animation: card-pop 460ms cubic-bezier(0.34, 1.45, 0.5, 1);
}
@keyframes card-pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.13) translateY(-5px);
  }
  100% {
    transform: scale(1) translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .table-card-inner {
    transition: none;
  }
  .table-card.just-voted {
    animation: none;
  }
}

/* ---- consensus: everyone agreed → cards turn gold with a rotating gold ring ---- */
@property --gold-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}
/* the spinning conic ring sits just behind the (opaque) card faces, so only its
   edge shows as an animated border around each card */
.table-card.consensus::before {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 15px;
  z-index: 0;
  background: conic-gradient(
    from var(--gold-angle),
    #b8860b,
    #ffd700,
    #fff4c2,
    #ffd700,
    #b8860b,
    #ffd700,
    #fff4c2,
    #ffd700,
    #b8860b
  );
  animation: gold-spin 10s linear infinite;
  box-shadow: 0 0 7px -3px rgba(255, 215, 0, 0.5);
}
@keyframes gold-spin {
  to {
    --gold-angle: 360deg;
  }
}
/* keep the flipping faces above the ring */
.table-card.consensus .table-card-inner {
  z-index: 1;
}
/* the revealed value goes gold */
.table-card.consensus .table-card-front {
  background: linear-gradient(160deg, #ffe27a 0%, #f4c430 55%, #e0a800 100%);
  color: #4a3500;
}
.table-card.consensus .table-card-front .tc-name {
  color: #4a3500;
  opacity: 0.8;
}
@media (prefers-reduced-motion: reduce) {
  .table-card.consensus::before {
    animation: none;
  }
}

/* ---------------- Results ---------------- */
.results {
  margin-top: 28px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-faint);
}
.stat-value {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.histogram {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 14px;
  min-height: 130px;
  padding-top: 8px;
}
.histo-col {
  flex: 0 0 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.histo-bar-wrap {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.histo-bar {
  width: 60%;
  min-height: 4px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 6px 6px 0 0;
  position: relative;
  transition: height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.histo-count {
  position: absolute;
  top: -20px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.histo-label {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
}

/* count badge, shared by the history panel header */
.pp-count {
  color: var(--text-dim);
  font-weight: 600;
}

/* ---------------- History ---------------- */
.history-panel {
  max-width: 1200px;
  margin: 0 auto 24px;
  padding: 0 20px;
  width: 100%;
}
.history-toggle {
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-toggle:hover {
  border-color: var(--border-bright);
}
.chevron {
  transition: transform 0.15s;
  display: inline-block;
}
.history-toggle[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}
.history-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 8px 16px 16px;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th {
  text-align: left;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
}
.history-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.history-table td.num {
  font-family: var(--mono);
}
.history-empty {
  color: var(--text-faint);
  text-align: center;
  padding: 16px;
  font-size: 13px;
}

.room-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 8px 20px 28px;
}

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 20, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.8);
}
.modal h2 {
  margin: 0;
  font-size: 22px;
}
.modal-sub {
  color: var(--text-dim);
  margin: 6px 0 22px;
}
.modal-error {
  color: var(--danger);
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.4);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: 0 0 18px;
  font-size: 14px;
  font-weight: 600;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 760px) {
  .room-header {
    flex-wrap: wrap;
  }
  .rh-center {
    order: 3;
    flex-basis: 100%;
  }
  .room-body {
    padding: 16px 14px;
  }
  .room-body {
    flex-direction: column;
  }
  .watching-panel {
    flex-basis: auto;
    width: 100%;
  }
  .card-deck {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 10px;
  }
  .play-card {
    font-size: 20px;
  }
  .result-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .timer {
    font-size: 18px;
  }
  .vote-table {
    gap: 10px;
  }
  .table-card {
    width: 126px;
    height: 175px;
  }
  .tc-value {
    font-size: 50px;
  }
  .tc-emoji {
    font-size: 42px;
  }
  .tc-name {
    font-size: 18px;
  }
}
