:root {
  --bg: #0d0f10;
  --card: #171a1c;
  --card-2: #202428;
  --text: #f7f7f5;
  --muted: #aeb5b9;
  --accent: #d9ff43;
  --danger: #ff6b6b;
  --success: #65e58b;
  --border: #34393d;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(
      circle at 20% 0%,
      rgba(217, 255, 67, 0.1),
      transparent 32rem
    ),
    radial-gradient(
      circle at 100% 100%,
      rgba(163, 115, 255, 0.1),
      transparent 30rem
    ),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app {
  width: 100%;
  max-width: 760px;
  min-width: 0;
  min-height: min(720px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
}

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-size: 0.93rem;
}

.brand img {
  display: block;
  width: auto;
  height: 0.72em;
  flex: none;
}

.brand span,
.leader-pos {
  color: var(--accent);
}

.pill {
  border: 1px solid var(--border);
  background: rgba(23, 26, 28, 0.8);
  padding: 9px 13px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.88rem;
}

.card {
  flex: 1;
  background: rgba(23, 26, 28, 0.94);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 28px;
  padding: clamp(22px, 5vw, 44px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.screen {
  display: none;
  animation: fade 0.28s ease;
}

.screen.active {
  display: block;
}

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

h1 {
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 0.98;
  margin: 0 0 20px;
  letter-spacing: -0.045em;
}

h2 {
  font-size: clamp(1.45rem, 4vw, 2.35rem);
  line-height: 1.12;
  margin: 0 0 24px;
  letter-spacing: -0.025em;
}

p {
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow {
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.78rem;
  margin-bottom: 14px;
}

.hero-note {
  max-width: 590px;
  font-size: 1.05rem;
}

.rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 28px 0;
}

.rule {
  background: var(--card-2);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 18px;
}

.rule strong {
  display: block;
  font-size: 1.25rem;
  margin-bottom: 4px;
}

.rule span {
  color: var(--muted);
  font-size: 0.88rem;
}

.btn {
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 16px 18px;
  font-weight: 850;
  background: var(--accent);
  color: #111;
  transition:
    0.18s transform,
    0.18s filter;
}

.btn:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

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

.quiz-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 28px;
}

.progress-wrap {
  min-width: 0;
}

.question-counter {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.progress {
  height: 8px;
  background: #2a2e31;
  border-radius: 99px;
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

.timer {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 5px solid var(--accent);
  font-size: 1.25rem;
  font-weight: 900;
  background: #111;
}

.timer.warning {
  border-color: var(--danger);
  color: var(--danger);
  animation: pulse 0.65s infinite alternate;
}

@keyframes pulse {
  to {
    transform: scale(1.04);
  }
}

.answers {
  display: grid;
  gap: 12px;
}

.answer {
  width: 100%;
  text-align: left;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: 16px;
  font-weight: 650;
  transition: 0.16s;
}

.answer:hover {
  border-color: #6d7478;
  transform: translateX(2px);
}

.answer:disabled {
  cursor: default;
}

.answer.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(217, 255, 67, 0.15) inset;
}

.timeout {
  color: var(--danger);
  font-weight: 750;
  margin-top: 14px;
  min-height: 22px;
}

.retry-answer {
  border: 0;
  border-bottom: 1px solid currentcolor;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
}

.retry-answer:disabled {
  opacity: 0.6;
}

.form-grid {
  display: grid;
  gap: 14px;
  margin: 24px 0;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
}

input[type="text"] {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--border);
  background: #101214;
  color: var(--text);
  padding: 14px 15px;
  border-radius: 13px;
  outline: none;
}

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

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.check input {
  margin-top: 4px;
}

.result-number {
  font-size: clamp(4.5rem, 18vw, 8rem);
  font-weight: 950;
  letter-spacing: -0.07em;
  line-height: 0.9;
  color: var(--accent);
  margin: 14px 0 20px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 24px;
}

.stat {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px;
  text-align: center;
}

.stat strong {
  display: block;
  font-size: 1.35rem;
  margin-bottom: 4px;
}

.stat span {
  font-size: 0.78rem;
  color: var(--muted);
}

.leaderboard {
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow-x: auto;
  background: #111416;
}

.leaderboard-head,
.leader-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 72px minmax(104px, max-content);
  gap: 8px;
  padding: 12px 14px;
}

.leaderboard-head {
  color: var(--muted);
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.leader-row {
  align-items: center;
  border-bottom: 1px solid #292e31;
  font-size: 0.9rem;
}

.leader-row:last-child {
  border-bottom: 0;
}

.leader-row.me {
  background: rgba(217, 255, 67, 0.1);
  box-shadow: inset 3px 0 0 var(--accent);
}

.leader-pos,
.leader-name {
  font-weight: 900;
}

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

.leader-score,
.leader-time {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.page-app {
  max-width: 1180px;
}

.page-card {
  justify-content: flex-start;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-heading h1,
.page-heading h2 {
  margin-bottom: 8px;
}

.page-heading p {
  margin: 0;
}

.secondary-btn {
  width: auto;
  flex: none;
  padding: 11px 16px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
}

.saved-results {
  display: grid;
  gap: 14px;
}

.saved-result {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  background: var(--card-2);
}

.saved-result h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
}

.saved-result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
}

.saved-result-grid div {
  min-width: 0;
}

.saved-result-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.saved-result-grid dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.saved-code {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.35rem;
  letter-spacing: 0.12em;
}

.pin-form {
  max-width: 420px;
}

.pin-input {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 14px 15px;
  background: #101214;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.2em;
  outline: none;
}

.pin-input:focus {
  border-color: var(--accent);
}

.pin-form .btn {
  margin-top: 16px;
}

.data-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #111416;
}

.data-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid #292e31;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.numeric-cell,
.timestamp-cell {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.code-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.board-code {
  min-width: 4.5em;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.code-toggle {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 10px;
  background: var(--card-2);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 800;
}

.status {
  font-size: 0.9rem;
  margin-top: 14px;
  min-height: 22px;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.restart {
  margin-top: 20px;
}

.empty-ranking {
  padding: 16px;
  color: var(--muted);
}

@media (max-width: 600px) {
  body {
    padding: 12px;
  }

  .app {
    min-height: calc(100vh - 24px);
  }

  .card {
    border-radius: 22px;
    padding: 22px;
  }

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

  .rule {
    display: flex;
    gap: 12px;
    align-items: center;
  }

  .rule strong {
    margin: 0;
    min-width: 52px;
  }

  .timer {
    width: 62px;
    height: 62px;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .leaderboard-head,
  .leader-row {
    grid-template-columns: 36px minmax(84px, 1fr) 50px minmax(78px, max-content);
    padding-left: 10px;
    padding-right: 10px;
    font-size: 0.78rem;
  }

  .leaderboard-head {
    font-size: 0.64rem;
  }

  .page-heading {
    display: block;
  }

  .page-heading .secondary-btn {
    margin-top: 16px;
  }

  .saved-result-grid {
    grid-template-columns: 1fr;
  }
}
