/* ------------------------------------------------------------------ base */

:root {
  --bg: #120c1c;
  --bg-2: #1b1329;
  --panel: #221936;
  --panel-2: #2c2145;
  --line: #3a2d58;
  --text: #ece7f7;
  --muted: #a396c4;
  --accent: #f0b429;
  --accent-2: #b98cff;
  --good: #4ade80;
  --bad: #fb7185;
  --radius: 14px;
  --card-ratio: 2 / 3;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(1100px 700px at 15% -10%, #34215c 0%, transparent 60%),
    radial-gradient(900px 600px at 95% 5%, #4a2a55 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.55 ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0 0 0.5em;
}

a {
  color: var(--accent-2);
}

.muted {
  color: var(--muted);
}

.screen[hidden] {
  display: none;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 1.15rem;
  border-radius: 11px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #362a52;
  border-color: var(--accent-2);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #f08a29 100%);
  border-color: transparent;
  color: #2a1a05;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ffc94d 0%, #ff9d3d 100%);
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.86rem;
}

/* ---------------------------------------------------------------- landing */

.home {
  max-width: 620px;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
  text-align: center;
}

.brand {
  font-size: clamp(3.2rem, 12vw, 5rem);
  letter-spacing: -0.03em;
  margin-bottom: 0.1em;
  background: linear-gradient(135deg, #ffd76e, var(--accent-2) 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 auto 2rem;
  max-width: 34ch;
}

.card-panel {
  background: rgba(34, 25, 54, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 1.1rem;
}

.field > span {
  display: block;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input[type="text"] {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font: inherit;
  color: var(--text);
  background: #171024;
  border: 1px solid var(--line);
  border-radius: 11px;
}

input[type="text"]:focus {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

.btn-block {
  width: 100%;
  padding: 0.85rem;
  font-size: 1.05rem;
}

.or {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 1rem 0;
}

/* -------------------------------------------------------- invite landing */

.panel-invite {
  border-color: var(--accent-2);
}

.invite-eyebrow {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.panel-invite .big-code {
  margin: 0.2rem 0 0.4rem;
}

.invite-status {
  font-size: 0.88rem;
  color: var(--muted);
  min-height: 1.4em;
  margin-bottom: 1.25rem;
}

.invite-status.problem {
  color: var(--bad);
}

/* A deliberately quiet escape hatch — it must not compete with "Join game". */
.btn-link {
  display: block;
  margin: 0.9rem auto 0;
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.btn-link:hover {
  color: var(--text);
}

.join-row {
  display: flex;
  gap: 0.5rem;
}

#code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
  text-align: center;
}

.rules {
  margin-top: 2rem;
  text-align: left;
  background: rgba(27, 19, 41, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
}

.rules summary {
  cursor: pointer;
  font-weight: 600;
}

.rules ol {
  margin: 0.9rem 0 0.3rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.94rem;
}

.rules li {
  margin-bottom: 0.55rem;
}

.rules ul {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
}

.rules ul li {
  margin-bottom: 0.25rem;
}

.rules strong {
  color: var(--text);
}

.rules-intro {
  margin: 0.8rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.rules-note {
  margin: 0.7rem 0 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
  opacity: 0.85;
}

.credit-line {
  margin-top: 1.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ------------------------------------------------------------------ game */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 12, 28, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.room-code {
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.05rem;
}

.round-label,
.deck-count {
  color: var(--muted);
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  padding: 1.25rem;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 4.2rem;
  background: rgba(34, 25, 54, 0.6);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.sidebar-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.players {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.player {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 9px;
  background: rgba(23, 16, 36, 0.7);
  font-size: 0.92rem;
}

.player.is-you {
  outline: 1px solid var(--accent-2);
}

.player.is-storyteller {
  background: linear-gradient(90deg, rgba(240, 180, 41, 0.22), transparent);
}

.player-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-score {
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  flex: none;
}

.dot.off {
  background: #6b5f85;
}

.dot.waiting {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.25; }
}

.badge {
  font-size: 0.66rem;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: none;
}

.badge-you {
  background: rgba(185, 140, 255, 0.25);
  color: #ddcaff;
}

.delta {
  font-weight: 700;
  color: var(--good);
  font-size: 0.82rem;
}

.log {
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 150px;
  overflow-y: auto;
}

/* ------------------------------------------------------------- main area */

.main {
  min-width: 0;
}

.stage {
  background: rgba(34, 25, 54, 0.5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.stage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.stage-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}

.stage-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.clue-display {
  text-align: center;
  padding: 1.1rem;
  margin-bottom: 1.25rem;
  background: linear-gradient(135deg, rgba(240, 180, 41, 0.14), rgba(185, 140, 255, 0.14));
  border: 1px solid rgba(240, 180, 41, 0.35);
  border-radius: var(--radius);
}

.clue-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.clue-text {
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 700;
  font-style: italic;
  color: var(--accent);
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------- cards */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.9rem;
}

/* The table is the focal point: fewer, larger cards, centred rather than
   stretched across the full width. */
.card-grid.table-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 215px));
  justify-content: center;
  gap: 1.1rem;
}

.card {
  position: relative;
  aspect-ratio: var(--card-ratio);
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #0d0916;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  padding: 0;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: var(--accent-2);
}

.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.3);
  transform: translateY(-5px);
}

.card.disabled {
  cursor: default;
  opacity: 0.5;
  filter: grayscale(0.5);
}

.card.disabled:hover {
  transform: none;
  border-color: transparent;
  box-shadow: none;
}

.card.storyteller-card {
  border-color: var(--good);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.35);
}

.card-zoom {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.card:hover .card-zoom,
.card-wrap:hover .card-zoom {
  opacity: 1;
}

.card-wrap {
  position: relative;
}

.card-foot {
  margin-top: 0.4rem;
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.2em;
}

.owner-tag {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 5px;
  background: var(--panel-2);
  font-weight: 600;
  color: var(--text);
}

.owner-tag.is-storyteller {
  background: rgba(74, 222, 128, 0.2);
  color: var(--good);
}

.voter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: center;
  margin-top: 0.25rem;
}

.chip {
  font-size: 0.7rem;
  padding: 0.08rem 0.4rem;
  border-radius: 999px;
  background: rgba(185, 140, 255, 0.2);
  color: var(--text);
}

/* ------------------------------------------------------------ hand + bar */

.hand-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.actionbar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.85rem 0;
  background: linear-gradient(transparent, var(--bg) 35%);
}

/* On a phone the bar sits over the card grid, so it needs to be opaque
   rather than a gradient smear. */
@media (max-width: 860px) {
  .actionbar {
    margin: 0 -0.85rem -0.5rem;
    padding: 0.7rem 0.85rem calc(0.7rem + env(safe-area-inset-bottom));
    background: rgba(24, 17, 38, 0.94);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
}

.actionbar input[type="text"] {
  flex: 1;
}

.waiting-note {
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  flex: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------- lobby */

.lobby-box {
  text-align: center;
  padding: 2rem 1rem;
}

.invite {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1rem auto;
  padding: 0.6rem 0.9rem;
  border: 1px dashed var(--line);
  border-radius: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
  word-break: break-all;
}

.big-code {
  font-size: clamp(2.5rem, 11vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin: 0.4rem 0;
}

/* --------------------------------------------------------------- results */

.result-banner {
  text-align: center;
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.result-banner.all-found,
.result-banner.none-found {
  background: rgba(251, 113, 133, 0.16);
  border: 1px solid rgba(251, 113, 133, 0.4);
}

.result-banner.split {
  background: rgba(74, 222, 128, 0.14);
  border: 1px solid rgba(74, 222, 128, 0.4);
}

.podium {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 420px;
  margin: 1.5rem auto;
}

.podium-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: 11px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.podium-row.winner {
  background: linear-gradient(90deg, rgba(240, 180, 41, 0.25), transparent);
  border-color: var(--accent);
}

.podium-rank {
  font-weight: 800;
  color: var(--muted);
  width: 1.5rem;
}

/* --------------------------------------------------------------- credits */

.credits {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.credits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.credit-card img {
  width: 100%;
  aspect-ratio: var(--card-ratio);
  object-fit: cover;
  border-radius: 10px;
  background: #0d0916;
}

.credit-card p {
  font-size: 0.74rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
}

.credit-card strong {
  color: var(--text);
  display: block;
  font-weight: 600;
}

/* ---------------------------------------------------------------- toasts */

.toast-stack {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  pointer-events: none;
  width: min(92vw, 420px);
}

.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: rise 0.25s ease;
}

.toast.error {
  border-left-color: var(--bad);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
}

/* -------------------------------------------------------------- lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 14, 0.94);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.lightbox[hidden] {
  display: none;
}

.lightbox figure {
  margin: 0;
  max-width: min(92vw, 800px);
  text-align: center;
}

.lightbox img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.lightbox figcaption {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.85rem;
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: 2.2rem;
  line-height: 1;
  cursor: pointer;
}

/* ----------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 0.85rem;
    gap: 0.85rem;
  }

  .sidebar {
    position: static;
    /* With a big table the roster would otherwise fill the whole first
       screen and push the cards below the fold. */
    max-height: 34vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .players {
    flex-direction: row;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
  }

  .player {
    flex: 1 1 auto;
    min-width: 128px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
  }

  .log {
    display: none;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 0.6rem;
  }

  /* The desktop table caps card width, which would leave one card per row on
     a phone. Fill the width instead — three across stays tappable. */
  .card-grid.table-grid {
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 0.6rem;
  }

  /* Leave room for the sticky action bar so it never covers the last row. */
  .stage {
    padding-bottom: 0.5rem;
  }

  .deck-count {
    display: none;
  }

  .round-label {
    white-space: nowrap;
  }

  .topbar {
    padding: 0.6rem 0.75rem;
  }

  .actionbar {
    flex-wrap: wrap;
  }

  .actionbar input[type="text"] {
    flex-basis: 100%;
  }

  .actionbar .btn {
    flex: 1;
  }

  /* Touch devices have no hover, so always show the zoom affordance. */
  .card-zoom {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
