/* ═══════════════════════════════════════════════════════════════
   Ultimate Quiz Game — terminal-inspired web theme
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #05070d;
  --bg-soft: #0a0f1c;
  --panel: rgba(11, 17, 30, 0.82);
  --line: #1d2a44;
  --line-bright: #2c4266;

  --text: #dce8ff;
  --muted: #7f8daa;
  --dim: #576480;

  --cyan: #4de2ff;
  --green: #4ef08a;
  --red: #ff5f7a;
  --yellow: #ffd166;
  --magenta: #ff79e1;
  --purple: #a855f7;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 16px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(77, 226, 255, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3vw, 40px);
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(77, 226, 255, 0.10), transparent 60%),
    radial-gradient(900px 600px at 100% 110%, rgba(168, 85, 247, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Ambient background ─────────────────────────────────────── */

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(77, 226, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(77, 226, 255, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, #000 25%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 25%, transparent 78%);
  pointer-events: none;
  z-index: 0;
}

.glow {
  position: fixed;
  width: 460px;
  height: 460px;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.16;
  pointer-events: none;
  z-index: 0;
}

.glow-cyan {
  top: -180px;
  left: -120px;
  background: var(--cyan);
}

.glow-magenta {
  bottom: -200px;
  right: -140px;
  background: var(--purple);
}

/* ── Layout ─────────────────────────────────────────────────── */

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
}

.terminal {
  background: linear-gradient(180deg, rgba(14, 21, 37, 0.95), rgba(8, 12, 22, 0.97));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(14px);
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--line);
}

.traffic {
  display: flex;
  gap: 7px;
  flex: 0 0 auto;
}

.traffic span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: block;
}

.traffic .red { background: #ff5f57; }
.traffic .yellow { background: #febc2e; }
.traffic .green { background: #28c840; }

.titlebar-title {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-btn {
  flex: 0 0 auto;
  min-width: 52px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.2s;
}

.link-btn:hover {
  color: var(--cyan);
}

.terminal-body {
  padding: clamp(20px, 4vw, 34px);
}

.footer {
  margin-top: 18px;
  text-align: center;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.04em;
}

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

.footer a {
  color: var(--cyan);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.noscript {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

/* ── Screens ────────────────────────────────────────────────── */

.screen {
  animation: rise 0.35s ease both;
}

.screen.hidden {
  display: none !important;
}

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

/* ── Hero / auth ────────────────────────────────────────────── */

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.logo {
  font-size: 44px;
  line-height: 1;
  filter: drop-shadow(0 0 22px rgba(77, 226, 255, 0.35));
  animation: float 4.5s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

h1 {
  margin: 10px 0 4px;
  font-size: clamp(21px, 4.6vw, 30px);
  letter-spacing: 0.14em;
  font-weight: 700;
  color: #f2f7ff;
  text-shadow: 0 0 28px rgba(77, 226, 255, 0.22);
}

h1 span {
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.03em;
}

.panel {
  background: rgba(6, 10, 19, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: clamp(18px, 3.6vw, 26px);
}

.auth-panel {
  max-width: 470px;
  margin: 0 auto;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px;
  margin-bottom: 22px;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab .num {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 5px;
  border: 1px solid var(--line-bright);
  font-size: 11px;
  color: var(--dim);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: linear-gradient(180deg, rgba(77, 226, 255, 0.16), rgba(77, 226, 255, 0.06));
  color: #eaf9ff;
  box-shadow: inset 0 0 0 1px rgba(77, 226, 255, 0.28);
}

.tab.active .num {
  border-color: rgba(77, 226, 255, 0.5);
  color: var(--cyan);
}

/* ── Forms ──────────────────────────────────────────────────── */

.field,
.prompt-field {
  display: block;
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 7px;
  letter-spacing: 0.02em;
}

.hint {
  display: block;
  font-size: 11.5px;
  color: var(--dim);
  margin: -4px 0 8px;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 13px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-row.big {
  padding: 2px 15px;
}

.input-row:focus-within {
  border-color: rgba(77, 226, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(77, 226, 255, 0.10);
}

.caret {
  color: var(--cyan);
  font-weight: 700;
  user-select: none;
}

input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font: inherit;
  padding: 13px 0;
}

input::placeholder {
  color: #4d5a75;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 20px;
  border-radius: 9px;
  border: 1px solid var(--line-bright);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, filter 0.2s, border-color 0.2s, background 0.2s;
}

.btn:hover {
  border-color: rgba(77, 226, 255, 0.45);
  background: rgba(255, 255, 255, 0.07);
}

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

.btn.primary {
  border: 0;
  color: #04121a;
  background: linear-gradient(135deg, var(--cyan), #7cc7ff 60%, #9d8dff);
  box-shadow: 0 10px 30px rgba(77, 226, 255, 0.22);
}

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

.btn:focus-visible,
.tab:focus-visible,
.option:focus-visible,
.link-btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.error {
  margin: 0 0 14px;
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  color: #ffd7de;
  background: rgba(255, 95, 122, 0.10);
  border: 1px solid rgba(255, 95, 122, 0.35);
}

.error.hidden,
.hidden {
  display: none !important;
}

/* ── Toast popup (login / sign-up errors) ───────────────────── */

.toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: min(440px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 95, 122, 0.55);
  background: linear-gradient(180deg, rgba(30, 12, 20, 0.98), rgba(13, 8, 16, 0.98));
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 95, 122, 0.12);
  transform: translateX(-50%);
  animation: toast-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.toast-icon {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1.3;
}

.toast-body {
  flex: 1;
  min-width: 0;
}

.toast-body strong {
  display: block;
  font-size: 13.5px;
  color: #ffe3e8;
  letter-spacing: 0.02em;
}

.toast-body p {
  margin: 3px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.toast-close {
  flex: 0 0 auto;
  margin: -4px -6px 0 0;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.toast-close:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.fineprint {
  margin: 16px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--dim);
  line-height: 1.5;
}

/* ── Setup ──────────────────────────────────────────────────── */

.welcome {
  text-align: center;
  font-size: clamp(16px, 3.4vw, 21px);
  margin-bottom: 14px;
}

.welcome strong {
  color: var(--yellow);
}

.rule {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0 0 24px;
}

#setup-form {
  max-width: 540px;
  margin: 0 auto;
}

/* ── Loading ────────────────────────────────────────────────── */

.loader {
  text-align: center;
  padding: 48px 0 42px;
}

.spinner {
  font-size: 40px;
  color: var(--cyan);
  line-height: 1;
  text-shadow: 0 0 26px rgba(77, 226, 255, 0.55);
}

.loading-text {
  margin: 18px 0 0;
  color: var(--text);
  font-size: 14px;
}

/* ── Quiz ───────────────────────────────────────────────────── */

.quiz-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#quiz-progress-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.progress {
  letter-spacing: 1px;
  font-size: 12px;
  color: var(--cyan);
  white-space: pre;
  flex: 1;
  min-width: 120px;
}

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

.tally b {
  color: var(--text);
}

.question {
  margin: 0 0 22px;
  font-size: clamp(17px, 3.4vw, 21px);
  line-height: 1.45;
  font-weight: 600;
  color: #f3f8ff;
  overflow-wrap: anywhere;
}

/* The heading is focused programmatically after each question; it is not
   interactive, so it does not need a focus ring. */
.question:focus {
  outline: none;
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.026);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.18s, opacity 0.25s;
}

.option:hover:not(:disabled) {
  border-color: rgba(77, 226, 255, 0.5);
  background: rgba(77, 226, 255, 0.07);
  transform: translateX(3px);
}

.option:disabled {
  cursor: default;
}

.option .letter {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  border-radius: 7px;
  border: 1px solid var(--line-bright);
  color: var(--cyan);
  font-weight: 700;
  font-size: 12.5px;
  transition: all 0.18s;
}

.option .text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.option.correct {
  border-color: rgba(78, 240, 138, 0.65);
  background: rgba(78, 240, 138, 0.10);
  animation: pop 0.3s ease;
}

.option.correct .letter {
  border-color: rgba(78, 240, 138, 0.7);
  background: rgba(78, 240, 138, 0.14);
  color: var(--green);
}

.option.wrong {
  border-color: rgba(255, 95, 122, 0.65);
  background: rgba(255, 95, 122, 0.09);
  animation: shake 0.34s ease;
}

.option.wrong .letter {
  border-color: rgba(255, 95, 122, 0.7);
  background: rgba(255, 95, 122, 0.14);
  color: var(--red);
}

.option.dim {
  opacity: 0.45;
}

@keyframes pop {
  50% { transform: scale(1.015); }
}

@keyframes shake {
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

.feedback {
  min-height: 24px;
  margin: 18px 0 0;
  font-size: 13.5px;
}

.feedback.good {
  color: var(--green);
}

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

.feedback b {
  color: var(--green);
}

#next {
  margin-top: 16px;
}

.kbd-hint {
  margin: 16px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--dim);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--line-bright);
  background: rgba(255, 255, 255, 0.035);
  font-family: inherit;
  font-size: 10.5px;
  color: var(--muted);
}

/* ── Result ─────────────────────────────────────────────────── */

.result-panel {
  text-align: center;
  padding: clamp(24px, 5vw, 38px);
}

.result-title {
  font-size: clamp(19px, 4vw, 25px);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
  text-shadow: 0 0 30px rgba(77, 226, 255, 0.25);
}

.result-score {
  font-size: clamp(16px, 3.4vw, 19px);
  margin-bottom: 16px;
  color: var(--text);
}

.result-score b {
  color: var(--green);
  font-size: 1.18em;
}

.result-score span {
  color: var(--muted);
  font-size: 0.9em;
}

.result-bar {
  text-align: center;
  font-size: 14px;
  letter-spacing: 2px;
  margin-bottom: 14px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 26px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

/* ── Responsive / a11y ──────────────────────────────────────── */

@media (max-width: 560px) {
  body {
    font-size: 14px;
    align-items: flex-start;
  }

  .titlebar-title {
    font-size: 11px;
  }

  .terminal-body {
    padding: 20px 16px 24px;
  }

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

  .option {
    padding: 13px 14px;
    font-size: 13.5px;
  }

  .progress {
    min-width: 90px;
    font-size: 11px;
  }
}

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