:root {
  --bg-1: #14103a;
  --bg-2: #1e1550;
  --card: rgba(255, 255, 255, 0.06);
  --card-strong: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f0ff;
  --muted: #9d97c9;
  --accent: #ffc93c;
  --accent-2: #ff6b6b;
  --teal: #4ecdc4;
  --violet: #a78bfa;
  --green: #3ddc84;
  --red: #ff5252;
  --radius: 16px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(120% 90% at 80% -10%, var(--bg-2), var(--bg-1));
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(40% 30% at 12% 8%, rgba(255, 107, 107, 0.18), transparent),
    radial-gradient(35% 28% at 88% 20%, rgba(78, 205, 196, 0.14), transparent),
    radial-gradient(45% 35% at 50% 110%, rgba(167, 139, 250, 0.16), transparent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}

.logo {
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text);
  text-decoration: none;
  font-size: 1rem;
}

.logo span {
  color: var(--accent);
}

.room-tag {
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}

.stage {
  max-width: 520px;
  margin-inline: auto;
  padding: 0.5rem 1.1rem 3rem;
}

.view {
  animation: fadein 0.35s ease;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.hidden {
  display: none !important;
}

.title {
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  margin-top: 1.5rem;
}

.title em {
  font-style: normal;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.small-title {
  font-size: 1.6rem;
  margin: 1.2rem 0;
}

.tagline {
  text-align: center;
  color: var(--muted);
  margin: 0.9rem 0 1.6rem;
  font-size: 0.92rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(8px);
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.8rem;
}

.field span,
.setting-row label span {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

input[type="text"],
select {
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

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

select option {
  color: #222;
}

.btn {
  display: inline-block;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  border-radius: 12px;
  padding: 0.8rem 1.4rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ff9f43);
  color: #201400;
  box-shadow: 0 8px 22px rgba(255, 201, 60, 0.25);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--line);
}

.btn-outline:hover,
.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-block {
  width: 100%;
}

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

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 1rem 0;
}

.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

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

.code-box {
  text-align: center;
  margin-bottom: 1.1rem;
}

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

.muted.small {
  font-size: 0.78rem;
}

.code-display {
  display: inline-block;
  background: none;
  border: none;
  font-family: inherit;
  font-weight: 800;
  font-size: 3rem;
  letter-spacing: 0.35em;
  color: var(--accent);
  cursor: pointer;
  text-indent: 0.35em;
}

.players {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.85rem 0.35rem 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #101010;
  flex-shrink: 0;
}

.crown {
  color: var(--accent);
  font-size: 0.8rem;
}

.offline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
}

.topic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.chip {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip.on {
  background: rgba(78, 205, 196, 0.16);
  border-color: var(--teal);
  color: var(--teal);
}

.chip[disabled] {
  opacity: 0.55;
  cursor: default;
}

.setting-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}

.waiting-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.9rem 0;
}

.toast {
  text-align: center;
  color: var(--red);
  font-size: 0.88rem;
  margin-top: 1rem;
  min-height: 1.2em;
}

.q-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.timer-track {
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  margin-bottom: 1.2rem;
}

.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green), var(--accent) 55%, var(--accent-2));
  transition: width 0.2s linear;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  min-height: 3.6em;
  margin-bottom: 1.1rem;
}

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.answer-btn {
  position: relative;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.85rem 0.85rem 2.6rem;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
  word-break: break-word;
}

.answer-btn .key {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #101010;
}

.answer-btn[data-key="A"] .key { background: var(--accent-2); }
.answer-btn[data-key="B"] .key { background: var(--accent); }
.answer-btn[data-key="C"] .key { background: var(--teal); }
.answer-btn[data-key="D"] .key { background: var(--violet); }

.answer-btn:hover:not([disabled]) {
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
}

.answer-btn.picked {
  border-color: var(--accent);
  background: rgba(255, 201, 60, 0.12);
}

.answer-btn.correct {
  border-color: var(--green);
  background: rgba(61, 220, 132, 0.16);
}

.answer-btn.wrong {
  border-color: var(--red);
  background: rgba(255, 82, 82, 0.14);
}

.answer-btn[disabled] {
  cursor: default;
}

.score-strip {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.9rem 0.1rem 0.2rem;
  scrollbar-width: none;
}

.score-strip::-webkit-scrollbar {
  display: none;
}

.score-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 500;
}

.score-pill b {
  color: var(--accent);
}

.reveal-head {
  text-align: center;
  margin-bottom: 1rem;
}

.correct-line {
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
  font-weight: 600;
}

.gain-line {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 0.3rem;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.board-row {
  display: grid;
  grid-template-columns: 26px 32px 1fr auto auto;
  align-items: center;
  gap: 0.55rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.board-row.me {
  border-color: var(--accent);
  background: rgba(255, 201, 60, 0.09);
}

.rank {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.choice-mark {
  font-weight: 700;
  font-size: 0.85rem;
  text-align: center;
}

.choice-right { color: var(--green); }
.choice-wrong { color: var(--red); }
.choice-none { color: var(--muted); }

.b-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.b-gain {
  color: var(--green);
  font-weight: 600;
  font-size: 0.8rem;
  min-width: 3ch;
  text-align: right;
}

.b-score {
  font-weight: 700;
  min-width: 5ch;
  text-align: right;
}

.podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 0.7rem;
  margin: 1rem 0 1.3rem;
}

.pedestal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.pedestal .avatar {
  width: 44px;
  height: 44px;
  font-size: 1rem;
}

.medal {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: #1b1400;
}

.medal.g1 { background: gold; }
.medal.g2 { background: silver; }
.medal.g3 { background: peru; }

.p-name {
  font-size: 0.8rem;
  font-weight: 600;
  max-width: 9ch;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.p-score {
  font-size: 0.78rem;
  color: var(--muted);
}

.pillar {
  width: 100%;
  border-radius: 10px 10px 0 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--line);
  border-bottom: none;
}

.mini-podium {
  grid-template-columns: repeat(3, 1fr);
}

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

  .setting-row {
    grid-template-columns: 1fr;
  }

  .question-text {
    min-height: 2.6em;
    text-align: left;
  }
}

.avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.score-pill {
  gap: 0.45rem;
}

.score-pill .avatar {
  width: 22px;
  height: 22px;
}

.pill-name {
  white-space: nowrap;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  opacity: 0.4;
}
