:root {
  --bg: #07090c;
  --bg-soft: #0b0e13;
  --panel: rgba(16, 20, 27, 0.94);
  --panel-strong: #11161e;
  --surface: #151b24;
  --surface-hover: #1a212c;
  --line: #28303b;
  --line-strong: #36404d;
  --red: #ff3158;
  --red-hover: #ff496d;
  --red-soft: rgba(255, 49, 88, 0.11);
  --red-glow: rgba(255, 49, 88, 0.18);
  --green: #43dc8d;
  --text: #f2f4f7;
  --text-dim: #a4adb9;
  --text-faint: #66717f;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 49, 88, 0.10), transparent 27rem),
    radial-gradient(circle at 82% 86%, rgba(255, 49, 88, 0.055), transparent 32rem),
    linear-gradient(180deg, #080a0e 0%, #06080b 100%);
  color: var(--text);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.38;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, black, transparent 88%);
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.22;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015) 0,
    rgba(255, 255, 255, 0.015) 1px,
    transparent 1px,
    transparent 4px
  );
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(20px, 4.5vw, 72px);
  border-bottom: 1px solid rgba(54, 64, 77, 0.72);
  background: rgba(7, 9, 12, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  white-space: nowrap;
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand-mark {
  margin-right: 5px;
  color: var(--text-faint);
}

.brand-accent {
  color: var(--red);
}

.topnav {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2.3vw, 24px);
}

.nav-link {
  position: relative;
  padding: 22px 0 20px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.015em;
  cursor: pointer;
  transition: color 160ms ease;
}

.nav-link::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  border-radius: 999px;
  background: var(--red);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 160ms ease;
}

.nav-link:hover,
.nav-link[data-active="true"] {
  color: var(--text);
}

.nav-link[data-active="true"]::after {
  transform: scaleX(1);
}

.nav-user {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(21, 27, 36, 0.7);
  color: var(--text-faint);
  font-size: 11px;
}

.nav-user::before {
  content: "@";
  color: var(--red);
}

.nav-logout {
  color: var(--text-faint);
}

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

main#app {
  position: relative;
  z-index: 2;
  width: 100%;
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(28px, 5vh, 56px) clamp(16px, 4vw, 40px);
}

.view {
  width: min(100%, 760px);
  display: flex;
  justify-content: center;
}

.panel {
  position: relative;
  width: 100%;
  max-width: 700px;
  overflow: hidden;
  padding: clamp(28px, 4.5vw, 46px);
  border: 1px solid rgba(54, 64, 77, 0.86);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 23%),
    var(--panel);
  box-shadow: var(--shadow);
}

.panel::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--red) 0%, rgba(255, 49, 88, 0.48) 35%, transparent 78%);
}

.panel::after {
  content: "";
  position: absolute;
  top: -100px;
  right: -90px;
  width: 240px;
  height: 240px;
  border: 1px solid rgba(255, 49, 88, 0.08);
  border-radius: 50%;
  box-shadow: 0 0 0 32px rgba(255, 49, 88, 0.018), 0 0 0 64px rgba(255, 49, 88, 0.012);
  pointer-events: none;
}

.auth-panel {
  max-width: 500px;
}

.quiz-panel,
.board-panel {
  max-width: 760px;
}

.results-panel {
  max-width: 650px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "// ";
  color: var(--text-faint);
}

h1,
h2,
p {
  position: relative;
  z-index: 1;
}

h1 {
  max-width: 18ch;
  margin: 0 0 16px;
  color: var(--text);
  font-size: clamp(27px, 4vw, 38px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.045em;
}

h2.q-text {
  max-width: 28ch;
  margin: 25px 0 26px;
  color: var(--text);
  font-size: clamp(20px, 3vw, 27px);
  line-height: 1.38;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.lede {
  max-width: 66ch;
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.78;
}

.lede-small {
  max-width: 64ch;
  margin: -2px 0 24px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.65;
}

.accent {
  color: var(--red);
}

/* ---------- Forms ---------- */

.stack {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 17px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

.field input {
  width: 100%;
  min-height: 49px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  background: rgba(7, 9, 12, 0.74);
  color: var(--text);
  font-size: 13px;
  caret-color: var(--red);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.field input::placeholder {
  color: #525d6a;
}

.field input:hover {
  border-color: var(--line-strong);
}

.field input:focus {
  border-color: rgba(255, 49, 88, 0.8);
  background: rgba(10, 13, 18, 0.96);
  box-shadow: 0 0 0 4px var(--red-glow);
}

.error {
  margin: -2px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 49, 88, 0.25);
  border-radius: 9px;
  background: var(--red-soft);
  color: #ff8198;
  font-size: 11px;
  line-height: 1.6;
}

.btn {
  min-height: 47px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 120ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

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

.btn:active {
  transform: translateY(0) scale(0.99);
}

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

.btn-primary {
  border-color: var(--red);
  background: var(--red);
  color: #17030a;
  box-shadow: 0 8px 24px rgba(255, 49, 88, 0.14);
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--red-hover);
  background: var(--red-hover);
  box-shadow: 0 12px 32px rgba(255, 49, 88, 0.22);
}

.btn-outline {
  border-color: var(--line-strong);
  background: rgba(21, 27, 36, 0.42);
  color: var(--text-dim);
}

.btn-outline:hover {
  border-color: rgba(255, 49, 88, 0.48);
  background: rgba(255, 49, 88, 0.06);
  color: var(--text);
}

.btn:focus-visible,
.nav-link:focus-visible,
.link-btn:focus-visible,
.opt-btn:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.btn-lg {
  width: 100%;
  min-height: 52px;
  margin-top: 3px;
  font-size: 13px;
}

.switch-line {
  position: relative;
  z-index: 2;
  margin: 21px 0 0;
  color: var(--text-faint);
  font-size: 11px;
  text-align: center;
}

.link-btn {
  padding: 0 0 0 5px;
  border: 0;
  background: transparent;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- Stats ---------- */

.stat-row {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 4px 0 26px;
}

.stat-box {
  min-height: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.006));
  text-align: center;
}

.stat-num {
  display: block;
  color: var(--text);
  font-size: clamp(19px, 2.8vw, 24px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.stat-label {
  display: block;
  margin-top: 8px;
  color: var(--text-faint);
  font-size: 10px;
  line-height: 1.25;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.best-line {
  margin: 15px 0 0;
  color: var(--text-faint);
  font-size: 11px;
  text-align: center;
}

/* ---------- Quiz ---------- */

.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.q-count {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(21, 27, 36, 0.54);
}

.q-score {
  color: var(--red);
}

.timer-track {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0a0d12;
}

.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--red);
  box-shadow: 0 0 20px rgba(255, 49, 88, 0.28);
  transform-origin: left;
  transition: width 1s linear, background 250ms ease;
}

.timer-num {
  display: block;
  margin-top: 7px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  text-align: right;
}

.options {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.opt-btn {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(21, 27, 36, 0.72);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.opt-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(255, 49, 88, 0.58);
  background: var(--surface-hover);
  color: var(--text);
}

.opt-btn:disabled {
  cursor: default;
}

.opt-key {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(7, 9, 12, 0.4);
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 800;
}

.opt-btn.is-correct {
  border-color: rgba(67, 220, 141, 0.58);
  background: rgba(67, 220, 141, 0.075);
  color: var(--text);
}

.opt-btn.is-correct .opt-key {
  border-color: rgba(67, 220, 141, 0.55);
  color: var(--green);
}

.opt-btn.is-wrong {
  border-color: rgba(255, 49, 88, 0.68);
  background: rgba(255, 49, 88, 0.08);
  color: var(--text);
}

.opt-btn.is-wrong .opt-key {
  border-color: rgba(255, 49, 88, 0.55);
  color: var(--red);
}

.q-feedback {
  min-height: 18px;
  margin: 18px 0 0;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* ---------- Results ---------- */

.results-panel {
  text-align: center;
}

.results-panel h1 {
  margin-inline: auto;
}

.score-hero {
  position: relative;
  z-index: 2;
  margin: 25px 0 30px;
  padding: 24px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(7, 9, 12, 0.4);
}

.score-hero-num {
  display: block;
  color: var(--red);
  font-size: clamp(48px, 9vw, 70px);
  line-height: 0.95;
  font-weight: 800;
  letter-spacing: -0.065em;
  text-shadow: 0 0 32px rgba(255, 49, 88, 0.16);
}

.score-hero-label {
  display: block;
  margin-top: 10px;
  color: var(--text-faint);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.results-actions {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 12px;
  margin-top: 7px;
}

.results-actions .btn {
  flex: 1;
}

/* ---------- Leaderboard ---------- */

.board-table-wrap {
  position: relative;
  z-index: 2;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(7, 9, 12, 0.34);
}

.board-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 11px;
}

.board-table th {
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  background: rgba(21, 27, 36, 0.74);
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-align: left;
  text-transform: uppercase;
}

.board-table td {
  padding: 13px 15px;
  border-bottom: 1px solid rgba(40, 48, 59, 0.82);
  color: var(--text-dim);
}

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

.board-table tbody tr {
  transition: background 150ms ease;
}

.board-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.018);
}

.board-table tr.is-me td {
  background: rgba(255, 49, 88, 0.055);
  color: var(--text);
}

.board-table td:first-child {
  width: 46px;
  color: var(--text-faint);
}

.board-table tr:nth-child(1) td:first-child {
  color: var(--red);
  font-weight: 800;
}

.board-empty {
  padding: 30px 20px !important;
  color: var(--text-faint) !important;
  text-align: center;
}

/* ---------- Footer ---------- */

.foot {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-top: 1px solid rgba(40, 48, 59, 0.7);
  background: rgba(7, 9, 12, 0.46);
}

.conn-status {
  color: var(--text-faint);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.conn-status.ok {
  color: var(--green);
}

.conn-status.bad {
  color: var(--red);
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .topbar {
    min-height: 60px;
    padding-inline: 16px;
  }

  .brand {
    font-size: 13px;
  }

  .topnav {
    gap: 10px;
  }

  .nav-link {
    padding-block: 19px 17px;
    font-size: 10px;
  }

  .nav-user {
    display: none;
  }

  main#app {
    align-items: flex-start;
    padding: 22px 14px 30px;
  }

  .panel {
    padding: 26px 22px;
    border-radius: 12px;
  }

  h1 {
    font-size: clamp(25px, 8vw, 32px);
  }

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

  .opt-btn {
    min-height: 62px;
  }
}

@media (max-width: 480px) {
  .stat-row {
    gap: 8px;
  }

  .stat-box {
    min-height: 82px;
    padding-inline: 6px;
  }

  .stat-num {
    font-size: 18px;
  }

  .stat-label {
    font-size: 8px;
  }

  .results-actions {
    flex-direction: column;
  }

  .topnav .nav-logout {
    display: none;
  }
}

@media (max-height: 720px) and (min-width: 721px) {
  main#app {
    align-items: flex-start;
    padding-top: 28px;
    padding-bottom: 28px;
  }

  .panel {
    padding-top: 32px;
    padding-bottom: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
