:root {
  --bg: #0b1220;
  --bg-soft: #101a2e;
  --card: #16223a;
  --card-2: #1b2a47;
  --line: #24365c;
  --text: #e8eefb;
  --muted: #93a4c7;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #14264a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100%;
}

#app { max-width: 880px; margin: 0 auto; padding: 20px 16px 60px; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px; margin-bottom: 18px;
  background: linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line); border-radius: var(--radius);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand .pulse {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-2), #2563eb); color: white; font-weight: 800;
  box-shadow: 0 4px 14px rgba(14,165,233,.35);
}
.userbox { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.chip {
  background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; font-size: .85rem;
}
button.linkbtn {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: .85rem;
  text-decoration: underline; text-underline-offset: 3px;
}
button.linkbtn:hover { color: var(--text); }

/* ---------- lock screen ---------- */
.lock-wrap {
  max-width: 420px; margin: 8vh auto 0; background: var(--card);
  border: 1px solid var(--line); border-radius: 18px; padding: 30px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.lock-icon {
  width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 14px;
  display: grid; place-items: center; background: rgba(56,189,248,.12);
  border: 1px solid rgba(56,189,248,.35);
}
.lock-wrap input[type="password"] {
  width: 100%; padding: 13px 14px; margin: 14px 0 6px; font-size: 1.05rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg-soft);
  color: var(--text); outline: none;
}
.lock-wrap input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent-2), #2563eb);
  color: white; border: none; border-radius: 10px; padding: 12px 18px;
  font-size: 1rem; font-weight: 600; cursor: pointer; width: 100%;
  transition: transform .06s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--card-2); border: 1px solid var(--line); color: var(--text); }
.btn.small { width: auto; padding: 8px 14px; font-size: .9rem; }
.error-msg { color: var(--bad); font-size: .92rem; min-height: 1.2em; margin: 6px 0; }
.shake { animation: shake .35s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }

.gsignin-slot { display: flex; justify-content: center; margin-top: 14px; min-height: 44px; }

/* ---------- home ---------- */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-card .num { font-size: 1.6rem; font-weight: 800; }
.stat-card .lbl { color: var(--muted); font-size: .82rem; margin-top: 2px; }

.topic-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(255px,1fr)); gap: 14px; }
.topic-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: transform .08s ease, border-color .15s ease;
  display: flex; flex-direction: column; gap: 10px;
}
.topic-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.topic-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.topic-name { font-weight: 700; font-size: 1.02rem; }
.topic-count { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.bar { height: 8px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 99px; transition: width .3s ease; }
.topic-meta { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); }
.badge-done { color: var(--good); font-weight: 700; }

/* ---------- quiz ---------- */
.quiz-topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.back-btn {
  background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; font-size: .95rem;
}
.back-btn:hover { border-color: var(--accent); }
.progress-track { flex: 1; height: 10px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.progress-track > i { display: block; height: 100%; background: linear-gradient(90deg,var(--accent-2),var(--accent)); transition: width .3s ease; }
.q-counter { color: var(--muted); font-size: .88rem; white-space: nowrap; }

.q-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; animation: fadeUp .25s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }
.q-stem { font-size: 1.12rem; line-height: 1.5; margin-bottom: 18px; }

.theme-tag {
  display: inline-block; margin-bottom: 12px; padding: 5px 12px;
  background: rgba(56,189,248,.1); border: 1px solid rgba(56,189,248,.35);
  color: var(--accent); border-radius: 999px; font-size: .78rem; font-weight: 700;
  letter-spacing: .4px;
}

.q-image {
  max-width: 100%; max-height: 340px; border-radius: 12px; border: 1px solid var(--line);
  display: block; margin: 0 auto 10px; background: #0d1626;
}
.q-image-caption {
  text-align: center; color: var(--muted); font-size: .82rem; margin-bottom: 16px;
}

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  text-align: left; width: 100%; padding: 13px 15px; font-size: .99rem; line-height: 1.4;
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; transition: border-color .12s ease, background .12s ease;
  display: flex; gap: 12px; align-items: baseline;
}
.option .key {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px; display: inline-grid; place-items: center;
  background: var(--card-2); border: 1px solid var(--line); font-size: .85rem; font-weight: 700;
}
.option:not(:disabled):hover { border-color: var(--accent); background: #13203c; }
.option:disabled { cursor: default; opacity: .92; }
.option.correct { border-color: var(--good); background: rgba(34,197,94,.12); }
.option.correct .key { background: var(--good); border-color: var(--good); color: #04250f; }
.option.wrong { border-color: var(--bad); background: rgba(239,68,68,.12); }
.option.wrong .key { background: var(--bad); border-color: var(--bad); color: #2b0505; }

.verdict {
  margin-top: 18px; padding: 13px 15px; border-radius: 12px; font-weight: 700; display: flex; align-items: center; gap: 10px;
}
.verdict.ok { background: rgba(34,197,94,.14); color: var(--good); border: 1px solid rgba(34,197,94,.4); }
.verdict.no { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.4); }
.explain {
  margin-top: 12px; padding: 15px 16px; border-radius: 12px;
  background: var(--bg-soft); border: 1px dashed var(--line);
  color: var(--text); line-height: 1.6; font-size: .96rem; animation: fadeUp .3s ease;
}
.explain .tag { color: var(--accent); font-weight: 700; font-size: .8rem; letter-spacing: 1.2px; text-transform: uppercase; display:block; margin-bottom:6px;}
.quiz-actions { display: flex; justify-content: flex-end; margin-top: 18px; }

/* ---------- results ---------- */
.result-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 34px 26px; text-align: center; animation: fadeUp .25s ease;
}
.score-ring { position: relative; width: 148px; height: 148px; margin: 12px auto 18px; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring .score-text {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.7rem; font-weight: 800;
}
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.result-actions .btn { width: auto; }

/* ---------- misc ---------- */
.section-title { display:flex; align-items:center; justify-content:space-between; margin: 22px 0 12px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-size: .92rem; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); transition: opacity .25s ease; opacity: 1;
}
.footer-note { text-align:center; color: var(--muted); font-size:.78rem; margin-top: 40px; line-height:1.6;}

@media (max-width: 520px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .userbox { justify-content: space-between; }
}
