:root {
  --bg: #0c1118;
  --bg-elev: #121925;
  --panel: #162032;
  --panel-2: #1e2c40;
  --line: #2a3b52;
  --text: #edf2f7;
  --muted: #9aabbf;
  --accent: #4d9fff;
  --accent-2: #2f7fe0;
  --accent-soft: rgba(77, 159, 255, 0.14);
  --good: #3ecf8e;
  --good-bg: rgba(62, 207, 142, 0.14);
  --bad: #f07178;
  --bad-bg: rgba(240, 113, 120, 0.14);
  --warn: #e0b35a;
  --radius: 18px;
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --display: "Instrument Sans", "DM Sans", system-ui, sans-serif;
  --space: 28px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(900px 480px at 8% -8%, rgba(52, 110, 180, 0.28) 0%, transparent 55%),
    radial-gradient(700px 420px at 92% 0%, rgba(40, 90, 70, 0.18) 0%, transparent 50%),
    linear-gradient(180deg, #0e1520 0%, var(--bg) 40%);
  color: var(--text);
  line-height: 1.55;
}
#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}
.hidden { display: none !important; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 36px;
  padding: 12px 14px 12px 16px;
  background: rgba(18, 25, 37, 0.72);
  border: 1px solid rgba(42, 59, 82, 0.9);
  border-radius: 18px;
  backdrop-filter: blur(14px);
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}
.header-auth {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  color: #041018;
  background: linear-gradient(145deg, #7ec2ff, #3d8bfd 55%, #2a6fd6);
  flex-shrink: 0;
}
.brand-name {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.brand-tag {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

/* Shared button system */
.btn,
.primary,
.secondary,
.ghost,
.login-submit,
.drill-continue,
.header-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.12s ease;
}
.primary,
.login-submit,
.header-cta {
  background: linear-gradient(180deg, #5aa8ff 0%, var(--accent) 55%, var(--accent-2) 100%);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18) inset,
    0 8px 18px rgba(47, 127, 224, 0.28);
}
.primary:hover,
.login-submit:hover,
.header-cta:hover {
  background: linear-gradient(180deg, #6bb2ff 0%, #4d9fff 50%, #2f7fe0 100%);
  transform: translateY(-1px);
}
.primary:active,
.login-submit:active,
.header-cta:active,
.secondary:active,
.ghost:active {
  transform: translateY(0);
}
.primary:disabled,
.login-submit:disabled,
.header-cta:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.secondary {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
}
.secondary:hover {
  background: #24344c;
  border-color: #3b516d;
}
.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  box-shadow: none;
}
.ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border-color: #3b516d;
}
.primary:focus-visible,
.secondary:focus-visible,
.ghost:focus-visible,
.login-submit:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.header-auth .ghost,
.header-auth .primary,
.header-auth .header-cta {
  min-height: 40px;
  padding: 0 16px;
  font-size: 0.9rem;
  border-radius: 11px;
}
.header-user { gap: 10px; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--accent-soft);
  color: #b7d7ff;
}
.user-meta { display: grid; line-height: 1.15; }
.user-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.user-name { font-weight: 700; font-size: 0.92rem; }

.hero {
  margin: 0 0 34px;
  padding: 8px 4px 4px;
  max-width: 46rem;
}
.eyebrow {
  margin: 0 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}
h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.15rem, 4.2vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.1;
}
.sub {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.65;
}

.login-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.login-dialog {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  overflow: hidden;
  border-radius: 24px;
  border: 1px solid rgba(120, 160, 210, 0.28);
  background: #121a26;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  animation: dialogIn 0.22s ease;
}
@keyframes dialogIn {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.login-dialog-art {
  min-height: 100%;
  background:
    linear-gradient(160deg, rgba(77, 159, 255, 0.2), transparent 50%),
    linear-gradient(20deg, rgba(62, 207, 142, 0.12), transparent 42%),
    radial-gradient(420px 280px at 30% 20%, rgba(77, 159, 255, 0.35), transparent 60%),
    #0d1520;
  border-right: 1px solid rgba(120, 160, 210, 0.16);
}
.login-dialog-body {
  padding: 36px 34px 32px;
}
.login-kicker {
  margin: 0 0 10px;
  color: var(--good);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.login-dialog-body h2 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.45rem, 2.4vw, 1.8rem);
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.login-copy {
  margin: 12px 0 22px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.55;
}
.login-form { display: grid; gap: 14px; }
.field { display: grid; gap: 8px; }
.field span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0c121b;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-submit {
  width: 100%;
  margin-top: 6px;
  min-height: 48px;
  font-size: 1rem;
}
.login-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
}
.login-close:hover {
  color: #fff;
  border-color: #3b516d;
  background: rgba(255, 255, 255, 0.06);
}
.login-error {
  color: #ffb4b8;
  margin: 0;
  font-size: 0.9rem;
  background: var(--bad-bg);
  border: 1px solid rgba(240, 113, 120, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
}

@media (max-width: 760px) {
  .login-dialog { grid-template-columns: 1fr; }
  .login-dialog-art { display: none; }
  #btn-open-login-primary { display: none; }
}

.lead {
  color: var(--muted);
  margin: 0 0 28px;
  font-size: 1.05rem;
  max-width: 46rem;
}
.fine {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 28px;
}

.progress-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 28px;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}
.progress-head .primary {
  flex-shrink: 0;
  min-height: 42px;
  padding: 0 16px;
  font-size: 0.9rem;
}
.progress-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.progress-summary { margin-bottom: 8px; font-size: 1rem; }
.muted-box { color: var(--muted); }
.needs-help h3,
.recent-attempts h3 {
  margin: 22px 0 12px;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
.help-list,
.attempt-list { display: grid; gap: 10px; }
.help-row,
.attempt-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 14px 16px;
  background: var(--panel-2);
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 0.94rem;
}
.help-row span:last-child,
.attempt-row span:last-child { color: var(--muted); }
.chip-accent {
  background: var(--accent-soft);
  color: #b7d7ff;
}

.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.exam-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  min-height: 168px;
}
.exam-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.18);
}
.exam-card h3 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.exam-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}
.exam-card .meta {
  margin-top: 18px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 500;
}

.quiz-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}
.linkish {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 8px 0;
  min-height: auto;
  box-shadow: none;
}
.linkish:hover { color: #7eb8ff; text-decoration: underline; }
.progress-wrap {
  height: 10px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s;
}
.progress-label { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.quiz-exam {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}
.domain {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.question {
  margin: 0 0 24px;
  font-family: var(--display);
  font-size: clamp(1.3rem, 2.4vw, 1.55rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.choices { display: grid; gap: 12px; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  min-height: 56px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: inherit;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.choice:hover:not(:disabled) {
  border-color: #3f5a7a;
  background: var(--panel-2);
  transform: translateY(-1px);
}
.choice:disabled { cursor: default; opacity: 1; transform: none; }
.choice.correct {
  border-color: var(--good);
  background: var(--good-bg);
}
.choice.wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}
.choice .key {
  flex: 0 0 1.5rem;
  font-weight: 700;
  color: var(--muted);
}

.feedback {
  margin-top: 20px;
  padding: 18px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.feedback.ok { border-color: var(--good); background: var(--good-bg); }
.feedback.no { border-color: var(--bad); background: var(--bad-bg); }
.feedback strong { display: block; margin-bottom: 8px; font-size: 1.02rem; }
.feedback p { margin: 0; color: var(--text); }

.quiz-actions {
  margin-top: 24px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.score-card {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  margin: 16px 0 22px;
}
.score-big {
  font-family: var(--display);
  font-size: 3.4rem;
  font-weight: 750;
  margin: 0;
  line-height: 1;
  letter-spacing: -0.04em;
}
.pass-badge {
  padding: 14px 16px;
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
  max-width: 280px;
}
.pass-badge.pass { background: var(--good-bg); color: #8eecc0; }
.pass-badge.fail { background: var(--bad-bg); color: #ffb4b8; }
.pass-badge.close { background: rgba(224, 179, 90, 0.16); color: #efd08a; }

.domain-breakdown {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}
.domain-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
}
.domain-row span:last-child { color: var(--muted); }

/* Duolingo-style drill */
body.drill-mode .site-header,
body.quiz-mode .site-header,
body.drill-mode .hero,
body.quiz-mode .hero { display: none; }
body.drill-mode #app,
body.quiz-mode #app { max-width: 760px; padding-top: 28px; }
body.drill-mode #view-drill { padding-bottom: 220px; }
.drill-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 26px;
}
.drill-progress-wrap {
  height: 16px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid var(--line);
}
.drill-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #58cc02, #89e219);
  transition: width 0.25s ease;
}
.drill-hearts { display: flex; gap: 4px; font-size: 1.25rem; }
.heart.on { color: #ff4b4b; }
.heart.off { color: #4a5563; }
.drill-meta {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}
.drill-q { margin-bottom: 24px; }
.drill-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 20px 22px;
  z-index: 20;
}
.drill-sheet-inner {
  max-width: 760px;
  margin: 0 auto;
  border-radius: 18px;
  padding: 22px 22px 18px;
  border: 2px solid transparent;
  animation: sheetUp 0.2s ease;
}
@keyframes sheetUp {
  from { transform: translateY(24px); opacity: 0.4; }
  to { transform: translateY(0); opacity: 1; }
}
.drill-sheet.ok .drill-sheet-inner {
  background: #163221;
  border-color: #58cc02;
}
.drill-sheet.no .drill-sheet-inner {
  background: #3a1c1f;
  border-color: #ff4b4b;
}
.drill-sheet-title {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 750;
}
.drill-sheet.ok .drill-sheet-title { color: #89e219; }
.drill-sheet.no .drill-sheet-title { color: #ff8a90; }
.drill-sheet-body {
  margin: 0 0 16px;
  color: var(--text);
  line-height: 1.45;
}
.drill-continue {
  width: 100%;
  min-height: 50px;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  box-shadow: none;
}
.drill-sheet.ok .drill-continue {
  background: linear-gradient(180deg, #6de00a, #58cc02);
  color: #123015;
}
.drill-sheet.ok .drill-continue:hover {
  background: linear-gradient(180deg, #7aef18, #61d606);
  transform: translateY(-1px);
}
.drill-sheet.no .drill-continue {
  background: linear-gradient(180deg, #ff6b6b, #ff4b4b);
  color: #fff;
}
.drill-sheet.no .drill-continue:hover {
  background: linear-gradient(180deg, #ff7a7a, #ff5757);
  transform: translateY(-1px);
}

.drill-done {
  text-align: center;
  padding: 40px 12px;
}
.drill-done-emoji { font-size: 3.4rem; margin: 0 0 12px; }
.drill-done-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 28px 0 30px;
}
.drill-done-stats .stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 10px;
}
.drill-done-stats .stat span {
  display: block;
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 750;
  color: #89e219;
}
.drill-done-stats .stat label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@media (max-width: 860px) {
  #app { padding: 28px 18px 72px; }
}

@media (max-width: 560px) {
  .progress-head { flex-direction: column; align-items: flex-start; }
  .quiz-bar { grid-template-columns: 1fr; }
  .score-card { flex-direction: column; align-items: flex-start; }
  .drill-done-stats { grid-template-columns: repeat(2, 1fr); }
  .exam-grid { grid-template-columns: 1fr; }
}
