:root {
  --bg: #4a1d8c; /* overridden at runtime by BRAND_COLOR */
  --bg-2: color-mix(in srgb, var(--bg), #ffffff 16%);
  --bg-3: color-mix(in srgb, var(--bg), #000000 30%);
  --surface: #ffffff;
  --surface-2: #f3f1f9;
  --text: #1d1631;
  --text-muted: #6b6485;
  --on-bg: #ffffff;
  --on-bg-muted: rgba(255, 255, 255, 0.72);
  --border: #e2def0;
  --accent: #6c3ce0;
  --accent-hover: #5a2ec7;
  --danger: #d6264a;
  --success: #1f9d55;
  --opt-0: #e21b3c;
  --opt-1: #1368ce;
  --opt-2: #d89e00;
  --opt-3: #26890c;
  --gold: #f5b400;
  --silver: #9aa4b1;
  --bronze: #c26d32;
  --radius: 12px;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 20% 0%, var(--bg-2), var(--bg) 55%, var(--bg-3));
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--on-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

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

.hidden {
  display: none !important;
}

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

/* ---------- layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.18);
}

.brand {
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand-sub {
  color: var(--gold);
  font-weight: 700;
  margin-left: 0.3em;
}

.powered {
  margin-top: auto;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.8rem;
  color: var(--on-bg-muted);
  letter-spacing: 0.02em;
}

.powered b {
  color: var(--on-bg);
  font-weight: 700;
}

.topbar .who {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--on-bg-muted);
  min-width: 0;
}

.topbar .who b {
  color: var(--on-bg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}

main:not(.container) {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  gap: 12px;
}

.card {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.conn-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--danger);
  color: #fff;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 16px;
}

/* ---------- forms ---------- */

label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  margin: 12px 0 6px;
}

input[type='text'],
input[type='password'],
input[type='number'],
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  padding: 11px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 70px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 800;
  font-size: 1rem;
  padding: 11px 18px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  text-decoration: none;
  transition: transform 0.05s, background 0.15s;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

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

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn.secondary:hover {
  background: #e6e2f3;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: none;
}

.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.24);
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  padding: 7px 12px;
  font-size: 0.85rem;
}

.btn.big {
  padding: 16px 28px;
  font-size: 1.25rem;
}

.btn.block {
  width: 100%;
}

.error {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 1.2em;
  margin-top: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1d1631;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-weight: 600;
  z-index: 100;
  max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ---------- auth page ---------- */

.auth-wrap {
  width: 100%;
  max-width: 400px;
}

.auth-wrap .logo {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.auth-wrap .logo .brand-sub {
  display: block;
  font-size: 1.3rem;
  margin: 2px 0 0;
  letter-spacing: 0;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.tabs button {
  flex: 1;
  font: inherit;
  font-weight: 700;
  padding: 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.tabs button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ---------- answer options ---------- */

.opt-0 {
  background: var(--opt-0);
}
.opt-1 {
  background: var(--opt-1);
}
.opt-2 {
  background: var(--opt-2);
}
.opt-3 {
  background: var(--opt-3);
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: left;
  box-shadow: var(--shadow);
  word-break: break-word;
}

button.option {
  cursor: pointer;
  transition: transform 0.06s, opacity 0.2s, filter 0.2s;
}

button.option:active:not(:disabled) {
  transform: scale(0.97);
}

.option .shape {
  flex: none;
  font-size: 1.5rem;
  line-height: 1;
  width: 1.5rem;
  text-align: center;
}

.option.dim {
  opacity: 0.3;
  filter: grayscale(0.6);
}

.option.picked {
  outline: 4px solid #fff;
  outline-offset: -4px;
}

.option .tick {
  margin-left: auto;
  font-size: 1.4rem;
}

/* ---------- player ---------- */

.pin-input {
  text-align: center;
  font-size: 1.8rem !important;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.player-q {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  color: var(--on-bg-muted);
}

.q-text {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 1.2rem;
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow);
  word-break: break-word;
}

.q-image {
  display: block;
  max-width: 100%;
  max-height: 32vh;
  margin: 0 auto;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.15);
}

.timebar {
  height: 10px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.timebar > div {
  height: 100%;
  width: 100%;
  background: var(--gold);
  transform-origin: left;
}

.timer-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.big-emoji {
  font-size: 4rem;
  line-height: 1;
}

.result-banner {
  width: 100%;
  max-width: 420px;
  padding: 24px 16px;
  border-radius: var(--radius);
  font-weight: 900;
  font-size: 1.8rem;
  box-shadow: var(--shadow);
}

.result-banner.good {
  background: var(--success);
}

.result-banner.bad {
  background: var(--danger);
}

.result-banner small {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  margin-top: 6px;
  opacity: 0.9;
}

.score-pill {
  display: inline-block;
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
}

.pulse {
  animation: pulse 1.6s ease-in-out infinite;
}

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

/* ---------- podium ---------- */

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 640px;
  margin: 12px auto 0;
}

.podium .place {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.3, 1.2) backwards;
}

.podium .place.p1 {
  animation-delay: 1.4s;
}
.podium .place.p2 {
  animation-delay: 0.8s;
}
.podium .place.p3 {
  animation-delay: 0.2s;
}

.podium .name {
  font-weight: 800;
  font-size: 1.1rem;
  margin-bottom: 4px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium .pts {
  font-size: 0.9rem;
  color: var(--on-bg-muted);
  margin-bottom: 6px;
}

.podium .block {
  width: 100%;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10px;
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.15);
}

.podium .p1 .block {
  height: 180px;
  background: var(--gold);
}
.podium .p2 .block {
  height: 130px;
  background: var(--silver);
}
.podium .p3 .block {
  height: 95px;
  background: var(--bronze);
}

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

/* ---------- host screen ---------- */

.host {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.host-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.2);
  flex-wrap: wrap;
}

.host-bar .title {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.host-bar .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.host-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 18px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

.lobby {
  display: grid;
  grid-template-columns: minmax(260px, 380px) 1fr;
  gap: 20px;
  align-items: start;
}

.join-card {
  text-align: center;
}

.join-card .join-url {
  font-size: 1.1rem;
  font-weight: 700;
  word-break: break-all;
}

.join-card .pin {
  font-size: 3.4rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.1;
  margin: 4px 0 8px;
}

.join-card img {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1;
  border-radius: 8px;
}

.players-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.count-badge {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 900;
  font-size: 1.3rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  background: #fff;
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 800;
  animation: pop 0.3s ease-out;
  border: 0;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.chip:hover {
  text-decoration: line-through;
  background: #ffe3e8;
}

@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

.host-q-text {
  background: #fff;
  color: var(--text);
  text-align: center;
  font-size: clamp(1.3rem, 3vw, 2.3rem);
  font-weight: 800;
  padding: 18px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  word-break: break-word;
}

.host-q-mid {
  flex: 1;
  display: grid;
  grid-template-columns: 110px 1fr 110px;
  align-items: center;
  gap: 16px;
  min-height: 160px;
}

.host-q-mid img {
  justify-self: center;
  max-width: 100%;
  max-height: 42vh;
  border-radius: 8px;
  object-fit: contain;
}

.stat-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 2.2rem;
  line-height: 1;
}

.stat-circle small {
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 4px;
}

.stat-circle.timer {
  background: var(--accent);
}

.stat-circle.answers {
  background: rgba(0, 0, 0, 0.3);
}

.host .options .option {
  min-height: 90px;
  font-size: clamp(1rem, 2vw, 1.5rem);
}

.bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 18px;
  height: 100%;
  min-height: 180px;
}

.bars .bar {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.bars .bar .fill {
  width: 100%;
  border-radius: 6px 6px 0 0;
  min-height: 8px;
  transition: height 0.6s ease-out;
}

.bars .bar .label {
  font-weight: 900;
  font-size: 1.4rem;
  margin-top: 6px;
}

.leaderboard {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  color: var(--text);
  padding: 14px 18px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1.2rem;
  box-shadow: var(--shadow);
  animation: slide 0.4s ease-out backwards;
}

.lb-row .rank {
  width: 2em;
  color: var(--text-muted);
}

.lb-row .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-row .streak {
  font-size: 0.9rem;
}

@keyframes slide {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.results-table th,
.results-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.results-table th {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.results-table td.num,
.results-table th.num {
  text-align: right;
}

/* ---------- admin ---------- */

.admin-nav {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.admin-nav a {
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 700;
  text-decoration: none;
  color: var(--on-bg-muted);
  white-space: nowrap;
}

.admin-nav a.active {
  background: #fff;
  color: var(--text);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.section-head h2 {
  margin: 0;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row-card {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.row-card .grow {
  flex: 1;
  min-width: 180px;
}

.row-card .title {
  font-weight: 800;
  font-size: 1.05rem;
  word-break: break-word;
}

.row-card .sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.row-card .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
  flex: none;
}

.q-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex: none;
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--on-bg-muted);
}

.option-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border-radius: 8px;
  color: #fff;
}

.option-edit input[type='text'] {
  border-color: transparent;
}

.option-edit .correct-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: 0.8rem;
  white-space: nowrap;
  cursor: pointer;
}

.option-edit input[type='radio'] {
  width: 20px;
  height: 20px;
  accent-color: #fff;
  cursor: pointer;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.image-preview img {
  max-width: 180px;
  max-height: 120px;
  border-radius: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-row > * {
  flex: 1;
  min-width: 160px;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge.admin {
  background: #ede5ff;
  color: var(--accent);
}

.badge.live {
  background: #ffe3e8;
  color: var(--danger);
}

.medal {
  font-size: 0.9rem;
  margin-right: 10px;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

.past-results {
  width: 100%;
  max-width: 420px;
  text-align: left;
}

.past-results .row-card {
  padding: 12px 14px;
  gap: 10px;
}

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

@media (max-width: 760px) {
  .lobby {
    grid-template-columns: 1fr;
  }

  .host-q-mid {
    grid-template-columns: 1fr 1fr;
  }

  .host-q-mid img {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .host-q-mid .stat-circle {
    justify-self: center;
  }

  .option-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .topbar .brand-sub,
  .topbar .who .greet {
    display: none;
  }

  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .topbar .brand {
    font-size: 1rem;
    white-space: nowrap;
  }

  .topbar .who {
    gap: 6px;
    font-size: 0.85rem;
  }

  .topbar .who > span {
    display: none;
  }

  .topbar .btn.small {
    padding: 6px 9px;
    white-space: nowrap;
  }

  .options {
    grid-template-columns: 1fr;
  }

  .option {
    min-height: 60px;
  }

  .podium .p1 .block {
    height: 140px;
  }
  .podium .p2 .block {
    height: 100px;
  }
  .podium .p3 .block {
    height: 72px;
  }
}
