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

[hidden] { display: none !important; }

:root {
  --bg: #0b1020;
  --bg-2: #121a33;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef2ff;
  --muted: #9aa6c9;
  --accent: #6c8cff;
  --accent-2: #22d3ee;
  --good: #34d399;
  --bad: #f4526a;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

html, body { height: 100%; }

body {
  font-family: "Outfit", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1000px 600px at 15% -10%, #1d2a55 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 10%, #16324a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.5;
}

/* locked page: only sidebar scrollable */
body {
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  padding: 28px 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  -webkit-overflow-scrolling: touch;
}

.sidebar::-webkit-scrollbar { width: 10px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); background-clip: content-box; }

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  font-size: 28px; font-weight: 800;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06101f;
  box-shadow: 0 10px 26px rgba(108, 140, 255, 0.35);
}

.brand h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.brand p { color: var(--muted); font-size: 14px; }

.group { display: flex; flex-direction: column; gap: 12px; }

.group-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--muted);
}

.op-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.op.wide { margin-top: 10px; }
.op input { position: absolute; opacity: 0; pointer-events: none; }

.op-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  padding: 12px 8px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  cursor: pointer;
  transition: transform .12s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
  user-select: none;
}
.op-box b { font-size: 30px; line-height: 1; font-weight: 700; }
.op-box i { font-style: normal; font-size: 13px; color: var(--muted); font-weight: 600; }
.op-box:hover { background: var(--panel-2); transform: translateY(-2px); }
.op input:checked + .op-box {
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.16);
  box-shadow: 0 8px 22px rgba(108, 140, 255, 0.22);
}
.op input:checked + .op-box i { color: var(--text); }
.op input:focus-visible + .op-box { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.seg {
  display: flex;
  gap: 6px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.seg button {
  flex: 1 1 0;
  min-width: 0;
  font: inherit; font-size: 15px; font-weight: 600;
  padding: 9px 4px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: linear-gradient(135deg, var(--accent), #4f6fe8);
  color: #fff;
  box-shadow: 0 6px 16px rgba(108, 140, 255, 0.3);
}

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.track {
  width: 50px; height: 28px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  display: flex; align-items: center; padding: 3px;
  transition: background .18s ease;
}
.knob {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted);
  transition: transform .18s ease, background .18s ease;
}
.switch input:checked + .track { background: rgba(52, 211, 153, 0.35); }
.switch input:checked + .track .knob { transform: translateX(22px); background: var(--good); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent-2); outline-offset: 2px; }
.switch-label { font-weight: 600; }

.hint { font-size: 13px; color: var(--muted); line-height: 1.45; }

.sidebar-actions {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0 4px;
  background: linear-gradient(180deg, rgba(14, 20, 40, 0) 0%, rgba(14, 20, 40, 0.85) 38%, rgba(14, 20, 40, 0.96) 100%);
  backdrop-filter: blur(6px);
}

.btn {
  font: inherit; font-size: 18px; font-weight: 700;
  padding: 14px 20px; border: 0; border-radius: 14px;
  cursor: pointer; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line);
  transition: transform .12s ease, filter .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.1); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #5b5bf0);
  color: #fff; border-color: transparent;
  box-shadow: 0 12px 28px rgba(108, 140, 255, 0.35);
}
.btn.ghost { background: transparent; font-size: 16px; padding: 11px 16px; }
.btn.big { font-size: 21px; padding: 16px 34px; }

/* ==================== STAGE ==================== */
.stage {
  position: relative;
  display: flex; flex-direction: column;
  padding: 28px 36px 36px;
  gap: 24px;
  min-height: 0;
  overflow: hidden;
}

.hud {
  display: flex; gap: 14px; flex-wrap: wrap;
}
.hud-item {
  flex: 1 1 0; min-width: 130px;
  padding: 14px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 2px;
}
.hud-label { font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.hud-value { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.hud-value.timer { color: var(--accent-2); }
.hud-value.timer.paused { color: var(--muted); animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1 } 50% { opacity: .45 } }
.hud-value.good { color: var(--good); }
.hud-value.bad { color: var(--bad); }

.board {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 30px;
}

.question-card {
  position: relative;
  padding: 30px 60px 42px;
  border-radius: 28px;
  background: linear-gradient(160deg, rgba(255,255,255,0.09), rgba(255,255,255,0.03));
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}
.q-tag {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--muted);
}
.question {
  font-size: clamp(64px, 13vw, 148px);
  font-weight: 800;
  letter-spacing: -3px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

.question-card.dimmed { opacity: .35; filter: saturate(.5); }
.question-card.wrong {
  background: linear-gradient(160deg, rgba(244,82,106,0.32), rgba(244,82,106,0.12));
  border-color: var(--bad);
  animation: shake .45s cubic-bezier(.36,.07,.19,.97);
}
.question-card.right {
  background: linear-gradient(160deg, rgba(52,211,153,0.28), rgba(52,211,153,0.1));
  border-color: var(--good);
}
@keyframes shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-10px); }
  40%, 60% { transform: translateX(10px); }
}

.answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 340px));
  gap: 18px;
  width: 100%;
  max-width: 720px;
}

.answer {
  font: inherit;
  font-size: clamp(30px, 4.6vw, 46px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 24px 18px;
  border-radius: 20px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--line);
  transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease, opacity .2s ease;
  position: relative;
}
.answer:hover:not(:disabled) {
  transform: translateY(-3px);
  background: rgba(108, 140, 255, 0.18);
  border-color: var(--accent);
  box-shadow: 0 14px 30px rgba(108, 140, 255, 0.25);
}
.answer:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }
.answer:disabled { cursor: default; }
.answer.is-wrong {
  background: rgba(244, 82, 106, 0.16);
  border-color: var(--bad);
  color: #ff9dab;
  opacity: .55;
  text-decoration: line-through;
}
.answer.is-right {
  background: linear-gradient(135deg, var(--good), #22c98a);
  border-color: transparent;
  color: #04231a;
  transform: scale(1.03);
}

.kbd-hint { color: var(--muted); font-size: 15px; display: flex; align-items: center; gap: 6px; }

/* ==================== TYPE ANSWER MODE ==================== */
.type-box {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 720px;
}

.type-input {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font: inherit;
  font-size: clamp(34px, 5.4vw, 54px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 16px 20px;
  color: var(--text);
  background: rgba(9, 14, 30, 0.6);
  border: 3px solid var(--line);
  border-radius: 20px;
  caret-color: var(--accent-2);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  -moz-appearance: textfield;
}
.type-input::placeholder { color: rgba(154, 166, 201, 0.45); }
.type-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.1);
  box-shadow: 0 0 0 5px rgba(108, 140, 255, 0.22);
}
.type-input:focus-visible { outline: none; }
.type-input:disabled { opacity: .5; }
.type-input.is-right {
  border-color: transparent;
  background: linear-gradient(135deg, var(--good), #22c98a);
  color: #04231a;
}
.type-input.is-wrong {
  border-color: var(--bad);
  background: rgba(244, 82, 106, 0.18);
  animation: shake .45s cubic-bezier(.36, .07, .19, .97);
}

.submit-btn {
  flex: 0 0 auto;
  font-size: clamp(19px, 2.4vw, 25px);
  padding: 0 clamp(18px, 3vw, 34px);
  border-radius: 20px;
}

kbd {
  font: inherit; font-size: 13px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--line);
}

/* ==================== OVERLAY ==================== */
.overlay {
  position: absolute; inset: 0;
  display: none;
  place-items: center;
  background: rgba(6, 10, 24, 0.78);
  backdrop-filter: blur(8px);
  padding: 24px;
  z-index: 5;
}
.overlay.show { display: grid; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.overlay-card {
  width: min(760px, 100%);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 42px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(160deg, rgba(255,255,255,0.1), rgba(255,255,255,0.04));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.overlay-card h2 { font-size: 38px; font-weight: 800; letter-spacing: -1px; margin-bottom: 10px; }
.overlay-card p { color: var(--muted); font-size: 19px; max-width: 60ch; margin: 0 auto 26px; }
.overlay-card b { color: var(--text); }

.result-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 14px; margin-bottom: 18px;
}
.result-cell {
  padding: 20px;
  border-radius: 18px;
  background: rgba(9, 14, 30, 0.55);
  border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 3px;
}
.rc-label { font-size: 13px; letter-spacing: 1.3px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.rc-value { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.rc-unit { font-size: 15px; color: var(--muted); }
.result-extra { color: var(--muted); font-size: 17px; margin-bottom: 24px; }

/* ==================== SHARE RESULTS ==================== */
.share {
  text-align: left;
  padding: 18px;
  border-radius: 18px;
  background: rgba(9, 14, 30, 0.55);
  border: 1px solid var(--line);
  margin-bottom: 24px;
}
.share-title {
  display: block;
  font-size: 12px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.share-text {
  width: 100%;
  resize: vertical;
  font: inherit;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(6, 10, 24, 0.6);
  -moz-appearance: textfield;
}
.share-text:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(108, 140, 255, 0.2);
}
.share-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.share-actions .btn { flex: 1 1 auto; font-size: 17px; padding: 12px 18px; }
.share-status {
  margin-top: 10px;
  font-size: 14px;
  min-height: 1.2em;
  color: var(--good);
  opacity: 0;
  transition: opacity .2s ease;
}
.share-status.show { opacity: 1; }
.share-status.warn { color: #fbbf24; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 900px) {
  /* mobile: normal page flow, not locked */
  body { overflow: auto; overscroll-behavior: auto; }
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .sidebar-actions { position: static; background: none; backdrop-filter: none; padding: 0; }
  .stage { padding: 20px 18px 28px; overflow: visible; }
  .question-card { padding: 26px 22px 36px; }
  .question { letter-spacing: -2px; }
  .answers { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .type-box { max-width: 520px; }
  .type-input { padding: 14px 12px; border-width: 2px; }
  .result-grid { grid-template-columns: 1fr; }
  .hud-value { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
