:root {
  color-scheme: dark;
  --bg: #0f1720;
  --bg-2: #17202b;
  --panel: #ffffff;
  --ink: #101319;
  --muted: #637083;
  --line: #dce3ea;
  --green: #21c878;
  --cyan: #27b7e8;
  --orange: #ff8a3d;
  --red: #ef4444;
  --yellow: #f4c542;
  --shadow: 0 18px 60px rgba(0, 0, 0, .22);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(39, 183, 232, .14), transparent 32%),
    linear-gradient(315deg, rgba(255, 138, 61, .16), transparent 36%),
    var(--bg);
  color: #f8fbff;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 0;
  background: transparent;
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
}

.brand img {
  flex: 0 0 auto;
}

.topnav {
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .08);
  border-radius: 8px;
}

.nav-btn,
.ghost,
.primary,
.danger {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 800;
  letter-spacing: 0;
}

.nav-btn {
  color: #d9e6f5;
  background: transparent;
}

.nav-btn.active,
.ghost {
  color: #101319;
  background: #fff;
}

.primary {
  color: #07130d;
  background: var(--green);
  box-shadow: 0 10px 24px rgba(33, 200, 120, .25);
}

.danger {
  color: #fff;
  background: var(--red);
}

.xl {
  min-height: 56px;
  font-size: 1rem;
}

.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: .84rem;
}

.app {
  min-height: 70vh;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, .92fr);
  gap: 16px;
}

.panel,
.quiz-card,
.question-card,
.question-editor,
.room-side {
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.panel {
  padding: clamp(18px, 3vw, 30px);
}

.play-panel {
  min-height: 530px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(160deg, rgba(33, 200, 120, .18), transparent 38%),
    #fff;
}

.host-panel {
  background:
    linear-gradient(160deg, rgba(255, 138, 61, .18), transparent 40%),
    #fff;
}

.wide-strip {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
}

.panel-head {
  margin-bottom: 24px;
}

.kicker {
  margin: 0 0 8px;
  color: #007f63;
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .08em;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.6rem);
}

h2 {
  font-size: clamp(1.45rem, 3vw, 2.35rem);
}

h3 {
  font-size: 1rem;
}

.muted,
.quiz-card p {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #28313c;
  font-size: .9rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

textarea {
  min-height: 110px;
  padding-top: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(39, 183, 232, .16);
}

.toggles,
.action-row,
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.toggle input {
  width: 20px;
  min-height: 20px;
  margin: 0;
}

.room {
  display: grid;
  grid-template-columns: 315px minmax(0, 1fr);
  gap: 16px;
}

.room-side {
  padding: 16px;
  align-self: start;
  position: sticky;
  top: 16px;
}

.pin-card {
  display: grid;
  place-items: center;
  min-height: 146px;
  margin-bottom: 16px;
  border-radius: 8px;
  color: #fff;
  background: #101319;
}

.pin-card span {
  font-size: .82rem;
  font-weight: 900;
  color: #9fb2c8;
}

.pin-card strong {
  font-size: clamp(3rem, 8vw, 5.4rem);
  line-height: .95;
}

.player-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.player-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 34px;
  border-radius: 8px;
  padding: 0 10px;
  color: #1f2937;
  background: #edf2f7;
  font-weight: 800;
}

.player-pill.online {
  background: #d8fbe9;
}

.player-pill small {
  color: #64748b;
}

.stage,
.player-screen,
.library,
.editor {
  min-width: 0;
}

.stage {
  display: grid;
  align-content: start;
  gap: 16px;
}

.stage-top {
  display: grid;
  gap: 12px;
}

.stage .stage-top,
.question-card {
  padding: clamp(18px, 3vw, 30px);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.lobby-pulse {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--ink);
}

.lobby-pulse span {
  display: grid;
  place-items: center;
  width: min(220px, 55vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--yellow);
  color: #101319;
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 950;
}

.lobby-pulse p {
  margin: 12px 0 0;
  font-weight: 900;
}

.timer {
  justify-self: start;
  min-width: 86px;
  min-height: 52px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: #101319;
  color: #fff;
  font-size: 1.45rem;
  font-weight: 950;
}

.timer.hot {
  background: var(--red);
}

.answer-meter,
.locked-answer,
.result-badge {
  min-height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 950;
  box-shadow: var(--shadow);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.choice {
  position: relative;
  min-height: 112px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-weight: 950;
  text-align: left;
  box-shadow: var(--shadow);
}

.choice span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .22);
}

.choice.c0 { background: #d93b4b; }
.choice.c1 { background: #1c8fd7; }
.choice.c2 { background: #d99b17; }
.choice.c3 { background: #239a62; }
.choice.c4 { background: #8155cf; }
.choice.c5 { background: #d95f25; }

.choice.bar {
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-height: 82px;
  color: #fff;
}

.choice.bar strong,
.choice.bar em,
.choice.bar span {
  position: relative;
  z-index: 1;
}

.choice.bar em {
  justify-self: end;
  font-style: normal;
  font-size: 1.15rem;
}

.choice.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  background: rgba(255, 255, 255, .24);
}

.choice.correct {
  outline: 5px solid #37f08d;
}

.choice.selected {
  outline: 5px solid #fff;
}

.leaderboard {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.rank {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 10px;
  background: #f1f5f9;
  color: var(--ink);
}

.rank span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--cyan);
  color: #fff;
  font-weight: 950;
}

.rank strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank em {
  color: #334155;
  font-style: normal;
  font-weight: 900;
}

.player-screen {
  display: grid;
  gap: 16px;
}

.player-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.score-chip,
.meta {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.centered {
  display: grid;
  place-items: center;
  text-align: center;
}

.compact {
  justify-content: center;
}

.result-badge {
  justify-self: start;
  padding: 0 18px;
  margin-bottom: 16px;
}

.result-badge.good {
  background: var(--green);
}

.result-badge.bad {
  background: var(--red);
  color: #fff;
}

.ended {
  display: grid;
  gap: 16px;
  padding: clamp(18px, 3vw, 32px);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.podium {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.podium-card {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 150px;
  border-radius: 8px;
  padding: 16px;
  background: #f1f5f9;
}

.podium-card span {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: #101319;
  background: var(--yellow);
  font-size: 1.4rem;
  font-weight: 950;
}

.place-1 {
  min-height: 205px;
  background: #fff4c2;
}

.place-2 {
  min-height: 175px;
  background: #e7eef8;
}

.place-3 {
  background: #ffe3cf;
}

.quiz-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.quiz-card {
  display: grid;
  gap: 16px;
  align-content: space-between;
  min-height: 250px;
  padding: 18px;
}

.editor-grid {
  display: grid;
  grid-template-columns: 315px minmax(0, 1fr);
  gap: 16px;
}

.editor-grid > .panel {
  align-self: start;
  position: sticky;
  top: 16px;
}

.question-list {
  display: grid;
  gap: 14px;
}

.question-editor {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.question-toolbar,
.two-cols {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-editor-list {
  display: grid;
  gap: 10px;
}

.choice-editor {
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
}

.choice-editor input[type="radio"] {
  width: 20px;
  min-height: 20px;
}

.toast {
  position: fixed;
  z-index: 5;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -140%);
  max-width: min(520px, calc(100vw - 28px));
  border-radius: 8px;
  padding: 12px 16px;
  background: #fff;
  color: #101319;
  font-weight: 900;
  box-shadow: var(--shadow);
  transition: transform .2s ease;
}

.toast.show {
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--red);
  color: #fff;
}

@media (max-width: 860px) {
  .topbar,
  .player-head,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topnav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .home-grid,
  .room,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .room-side,
  .editor-grid > .panel {
    position: static;
  }

  .play-panel {
    min-height: 0;
  }

  .choice-grid,
  .podium {
    grid-template-columns: 1fr;
  }

  .choice {
    min-height: 86px;
  }

  .question-toolbar,
  .two-cols {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .shell {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
  }

  .brand {
    width: 100%;
    justify-content: center;
  }

  .nav-btn,
  .ghost,
  .primary,
  .danger {
    padding-inline: 10px;
  }

  h1 {
    font-size: clamp(1.8rem, 13vw, 3.1rem);
  }

  .pin-card strong {
    font-size: 3.2rem;
  }

  .card-actions,
  .action-row {
    display: grid;
    grid-template-columns: 1fr;
  }
}
