:root {
  --bg: #1b1235;
  --bg-2: #2a1b52;
  --panel: rgba(255, 255, 255, 0.08);
  --text: #f7f5ff;
  --muted: #b8b0d6;
  --accent: #ffd166;
  --ok: #2ec27e;
  --ko: #e5484d;
  --opt-0: #e21b3c;
  --opt-1: #1368ce;
  --opt-2: #d89e00;
  --opt-3: #26890c;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 20% 10%, var(--bg-2), var(--bg) 60%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  color: inherit;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
}

.title {
  font-size: 2rem;
  margin: 0 0 6px;
  letter-spacing: 0.5px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 18px;
}

.field {
  display: block;
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: #fff;
  color: #222;
  font-size: 1.1rem;
  text-align: center;
  text-transform: none;
}

.field.code {
  text-transform: uppercase;
  letter-spacing: 6px;
  font-weight: 700;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 14px 20px;
  border-radius: 10px;
  background: var(--accent);
  color: #1b1235;
  font-weight: 700;
  font-size: 1.1rem;
  transition: transform 0.08s;
}

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

.btn.secondary {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text);
}

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

.error {
  color: #ff9aa2;
  min-height: 1.4em;
  margin: 8px 0 0;
  font-weight: 600;
}

.big {
  font-size: 4rem;
  font-weight: 800;
  letter-spacing: 8px;
  margin: 8px 0;
}

.huge {
  font-size: 6rem;
  font-weight: 900;
  line-height: 1;
}

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

/* Options grid */
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.option {
  position: relative;
  min-height: 110px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 14px 14px 52px;
  text-align: left;
  transition: opacity 0.2s, transform 0.08s;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
  overflow-wrap: break-word;
}

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

  .option {
    min-height: 72px;
    font-size: 1.05rem;
  }
}

.option:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.option .letter {
  position: absolute;
  left: 12px;
  top: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.option[data-index="0"] { background: var(--opt-0); }
.option[data-index="1"] { background: var(--opt-1); }
.option[data-index="2"] { background: var(--opt-2); }
.option[data-index="3"] { background: var(--opt-3); }

.option.dim {
  opacity: 0.25;
}

.option.correct {
  outline: 5px solid #fff;
  outline-offset: -5px;
}

/* Timer bar */
.timer {
  width: 100%;
  height: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  margin: 12px 0;
}

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

.timer-value {
  font-size: 2.2rem;
  font-weight: 800;
  min-width: 2.5ch;
}

/* Result */
.result-ok {
  color: var(--ok);
}

.result-ko {
  color: var(--ko);
}

.result-points {
  font-size: 2.6rem;
  font-weight: 900;
  margin: 8px 0;
}

.stats {
  display: flex;
  justify-content: space-around;
  gap: 10px;
  margin-top: 16px;
}

.stats div {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 10px 14px;
  flex: 1;
}

.stats strong {
  display: block;
  font-size: 1.5rem;
}

/* Leaderboard */
.board {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}

.board li {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  font-weight: 600;
  text-align: left;
}

.board.ranked li:nth-child(1) { background: rgba(255, 209, 102, 0.35); }
.board.ranked li:nth-child(2) { background: rgba(200, 200, 220, 0.3); }
.board.ranked li:nth-child(3) { background: rgba(205, 127, 50, 0.3); }

.board .rank {
  color: var(--accent);
  font-weight: 800;
}

.board .score {
  font-variant-numeric: tabular-nums;
}

.board li.me {
  outline: 2px solid var(--accent);
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 14px;
}

.status-dot {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ko);
}

.status-dot.online {
  background: var(--ok);
}

.leave {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 5;
  background: rgba(255, 255, 255, 0.12);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}

.scanner {
  margin-top: 12px;
}

.scanner video {
  width: 100%;
  border-radius: 12px;
  background: #000;
  aspect-ratio: 1;
  object-fit: cover;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.modal {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal p {
  font-size: 1.1rem;
  margin: 0 0 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
}
