:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-2: #0b1728;
  --panel: rgba(13, 27, 48, 0.82);
  --panel-strong: rgba(15, 35, 61, 0.96);
  --card: rgba(255, 255, 255, 0.065);
  --card-2: rgba(255, 255, 255, 0.1);
  --text: #edf7ff;
  --muted: #9db2c9;
  --muted-2: #7087a0;
  --line: rgba(161, 214, 255, 0.15);
  --accent: #1ed6ff;
  --accent-2: #2b7cff;
  --good: #36e59f;
  --warn: #ffd166;
  --bad: #ff5b7c;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
  --radius: 24px;
  --radius-sm: 16px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef6ff;
  --bg-2: #f8fbff;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --card: rgba(9, 31, 63, 0.055);
  --card-2: rgba(9, 31, 63, 0.09);
  --text: #07111f;
  --muted: #4b5f77;
  --muted-2: #687b90;
  --line: rgba(11, 73, 122, 0.14);
  --accent: #008fcc;
  --accent-2: #2b65ff;
  --shadow: 0 22px 60px rgba(40, 86, 130, 0.2);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(circle at 18% 8%, rgba(30, 214, 255, 0.2), transparent 32rem),
    radial-gradient(circle at 88% 12%, rgba(43, 124, 255, 0.18), transparent 30rem),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }

.bg-orb {
  position: fixed;
  width: 26rem;
  height: 26rem;
  border-radius: 999px;
  filter: blur(46px);
  opacity: 0.28;
  pointer-events: none;
  z-index: 0;
}
.orb-a { background: var(--accent); left: 16rem; top: -10rem; }
.orb-b { background: var(--accent-2); right: -10rem; bottom: 8rem; }

.sidebar {
  position: fixed;
  inset: 1rem auto 1rem 1rem;
  width: 290px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--panel);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 0.8rem; padding: 0.35rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 900;
  letter-spacing: -0.06em;
  box-shadow: 0 12px 34px rgba(30, 214, 255, 0.28);
}
.brand-title { font-weight: 850; font-size: 1.05rem; }
.brand-subtitle { color: var(--muted); font-size: 0.82rem; margin-top: 0.1rem; }

.nav { display: grid; gap: 0.35rem; }
.nav-link {
  width: 100%;
  text-align: left;
  color: var(--muted);
  background: transparent;
  padding: 0.85rem 0.95rem;
  border-radius: 16px;
  transition: 0.18s ease;
}
.nav-link:hover, .nav-link.active {
  color: var(--text);
  background: var(--card-2);
}
.nav-link.active { box-shadow: inset 3px 0 0 var(--accent); }

.sidebar-card {
  margin-top: auto;
  padding: 1rem;
  border-radius: 22px;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
}
.sidebar-card p { color: var(--muted); margin: 0.8rem 0 0; line-height: 1.45; font-size: 0.88rem; }
.tiny-label { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar-score { font-size: 2.3rem; font-weight: 900; letter-spacing: -0.06em; margin: 0.3rem 0; }
.progress-track { width: 100%; height: 0.6rem; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--good)); transition: width 0.3s ease; }

.app-shell {
  position: relative;
  z-index: 1;
  margin-left: 320px;
  padding: 1rem 1.2rem 2.2rem;
  max-width: 1500px;
}
.topbar {
  min-height: 98px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
h1 { margin: 0; font-size: clamp(1.9rem, 3vw, 3.2rem); letter-spacing: -0.06em; }
.eyebrow { margin: 0 0 0.3rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.13em; font-size: 0.75rem; font-weight: 800; }
.top-actions { display: flex; gap: 0.6rem; align-items: center; }

.view { display: none; animation: rise 0.22s ease both; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 1.2rem;
}
.card.soft { background: var(--card); box-shadow: none; }
.card h2, .card h3 { margin: 0 0 0.75rem; letter-spacing: -0.035em; }
.card p { color: var(--muted); line-height: 1.58; }

.metric {
  position: relative;
  overflow: hidden;
  min-height: 132px;
}
.metric::after {
  content: "";
  position: absolute;
  inset: auto -30px -60px auto;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 214, 255, 0.22), transparent 65%);
}
.metric-label { color: var(--muted); font-size: 0.84rem; font-weight: 700; }
.metric-value { font-size: clamp(2.1rem, 5vw, 4rem); font-weight: 950; letter-spacing: -0.08em; margin: 0.25rem 0 0; }
.metric-foot { color: var(--muted-2); font-size: 0.86rem; margin-top: 0.3rem; }

button.primary, button.secondary, button.ghost, .pill {
  border-radius: 999px;
  padding: 0.78rem 1.05rem;
  font-weight: 800;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
button.primary {
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 35px rgba(30, 214, 255, 0.2);
}
button.secondary { color: var(--text); background: var(--card-2); border: 1px solid var(--line); }
button.ghost { color: var(--muted); background: transparent; border: 1px solid var(--line); }
button.full { width: 100%; }
button:hover { transform: translateY(-1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; margin-bottom: 1rem; }
.input, select, textarea {
  width: 100%;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.85rem 0.95rem;
  outline: none;
}
.input:focus, select:focus, textarea:focus { border-color: rgba(30, 214, 255, 0.55); box-shadow: 0 0 0 4px rgba(30, 214, 255, 0.1); }
.toolbar .input { max-width: 380px; }

.question-card { display: grid; gap: 1rem; }
.question-meta { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.7rem;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 0.8rem;
}
.pill.good { color: var(--good); border-color: rgba(54, 229, 159, 0.35); }
.pill.warn { color: var(--warn); border-color: rgba(255, 209, 102, 0.35); }
.pill.bad { color: var(--bad); border-color: rgba(255, 91, 124, 0.35); }
.question-text { font-size: clamp(1.18rem, 2vw, 1.55rem); line-height: 1.52; margin: 0; font-weight: 760; }
.choices { display: grid; gap: 0.75rem; }
.choice {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.85rem;
  align-items: start;
  text-align: left;
  color: var(--text);
  padding: 1rem;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
}
.choice:hover { background: var(--card-2); }
.choice.correct { border-color: rgba(54, 229, 159, 0.65); background: rgba(54, 229, 159, 0.12); }
.choice.wrong { border-color: rgba(255, 91, 124, 0.7); background: rgba(255, 91, 124, 0.1); }
.choice-letter {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--card-2);
  color: var(--accent);
  font-weight: 950;
}
.choice-text { line-height: 1.45; }

.feedback {
  display: none;
  border-radius: 20px;
  padding: 1rem;
  border: 1px solid var(--line);
  background: var(--card);
}
.feedback.active { display: block; }
.feedback.correct { border-color: rgba(54, 229, 159, 0.45); }
.feedback.wrong { border-color: rgba(255, 91, 124, 0.45); }
.feedback h3 { margin: 0 0 0.4rem; }
.feedback p { margin: 0.35rem 0; }
.rating-row { display: flex; flex-wrap: wrap; gap: 0.55rem; margin-top: 0.9rem; }

.chapter-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}
.chapter-row:last-child { border-bottom: 0; }
.chapter-title { font-weight: 830; }
.chapter-sub { color: var(--muted); font-size: 0.88rem; margin-top: 0.18rem; }
.bars { display: grid; gap: 0.4rem; }
.bar-line { display: flex; align-items: center; gap: 0.55rem; color: var(--muted); font-size: 0.83rem; }
.bar-line .progress-track { height: 0.42rem; flex: 1; }

.exam-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1rem; }
.exam-panel { position: sticky; top: 1rem; align-self: start; }
.exam-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.exam-dot {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 800;
}
.exam-dot.answered { color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.exam-dot.wrong { background: rgba(255, 91, 124, 0.16); color: var(--bad); }
.exam-dot.correct { background: rgba(54, 229, 159, 0.16); color: var(--good); }

.result-hero {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.2rem;
  align-items: center;
}
.score-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--accent) var(--pct, 0%), var(--card-2) 0);
  box-shadow: inset 0 0 0 12px var(--panel), var(--shadow);
  font-weight: 950;
  font-size: 2.25rem;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.85rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.question-list { display: grid; gap: 0.75rem; }
.search-hit { padding: 1rem; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.search-hit h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.search-hit p { margin: 0.3rem 0; }

.toast {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 10;
  padding: 0.9rem 1rem;
  color: white;
  background: rgba(7, 17, 31, 0.9);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }

.empty { padding: 2rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); background: var(--card); }
.kbd { padding: 0.15rem 0.35rem; border-radius: 7px; background: var(--card-2); border: 1px solid var(--line); }
.hidden { display: none !important; }

@media (max-width: 1050px) {
  .sidebar { position: static; width: auto; margin: 0.75rem; }
  .nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .app-shell { margin-left: 0; padding: 0.75rem; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .exam-layout { grid-template-columns: 1fr; }
  .exam-panel { position: static; }
  .chapter-row { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-actions, .toolbar, .rating-row { width: 100%; }
  .top-actions button, .toolbar button, .rating-row button { flex: 1; }
  .result-hero { grid-template-columns: 1fr; }
  .score-ring { margin: 0 auto; }
  .choice { padding: 0.9rem; }
}

/* v3 account/admin enhancements */
.auth-box { display:flex; align-items:center; gap:.5rem; }
.auth-chip { display:flex; align-items:center; gap:.65rem; padding:.55rem .75rem; border:1px solid var(--border); border-radius:999px; background:var(--card-soft); font-size:.86rem; }
.small { padding:.35rem .55rem !important; font-size:.78rem !important; }
.modal-backdrop { position:fixed; inset:0; z-index:1000; background:rgba(0,0,0,.62); display:grid; place-items:center; padding:1rem; backdrop-filter: blur(12px); }
.modal { max-width:860px; width:min(860px, 96vw); position:relative; }
.modal-close { position:absolute; top:1rem; right:1rem; width:2.1rem; height:2.1rem; border-radius:999px; border:1px solid var(--border); background:var(--card-soft); color:var(--text); cursor:pointer; font-size:1.35rem; }
.full { width:100%; }
.between { justify-content:space-between; align-items:flex-start; }
.danger { background:linear-gradient(135deg,#ef4444,#991b1b); color:white; border:0; border-radius:14px; padding:.85rem 1rem; font-weight:800; cursor:pointer; box-shadow:0 10px 25px rgba(239,68,68,.2); }
.question-form { display:grid; gap:.75rem; }
.question-form textarea { min-height:84px; resize:vertical; }
.account-card { border-color:rgba(34,211,238,.35); }
.admin-login { max-width:900px; }
@media (max-width: 860px) {
  .auth-box { width:100%; }
  .auth-chip { width:100%; justify-content:space-between; border-radius:18px; }
  .top-actions { align-items:stretch; }
  .modal { width:100%; }
}
