:root {
  --bg: #0f1220; --bg2: #161a2e; --card: #1c2138; --card2: #232843;
  --text: #e8eaf2; --muted: #9aa0bd; --line: #2c3257;
  --accent: #6d83ff; --accent-soft: #2a3170;
  --green: #34d399; --green-bg: #103a2e; --red: #f87171; --red-bg: #3a1620;
  --radius: 16px; --shadow: 0 14px 40px rgba(0,0,0,.4);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  min-height: 100vh; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(15,18,32,.85); backdrop-filter: blur(10px); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 1.02rem; flex-shrink: 0; }
.brand .logo { font-size: 1.25rem; }
.top-right { display: flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--muted); min-width: 0; }
.top-right #whoami { max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 6px 7px; font-weight: 700; font-size: .9rem; white-space: nowrap; }

@media (max-width: 520px) {
  .brand #brandName { display: none; }   /* keep just the 📚 logo */
  .top-right #whoami { display: none; }   /* hide the name to make room for the buttons */
  .linkbtn { padding: 6px 5px; font-size: .84rem; }
}

.wrap { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 20px 16px 60px; }

/* login */
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 22px; margin-top: 8vh; text-align: center; }
.login-card h1 { margin: 6px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.field { display: flex; flex-direction: column; gap: 12px; }
input[type=email], input[type=text], input[inputmode] {
  width: 100%; background: var(--card2); border: 1.5px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 15px 16px; font-size: 1.1rem; font-family: inherit;
}
input:focus { outline: none; border-color: var(--accent); }
.btn { background: var(--accent); color: #fff; border: none; border-radius: 12px; padding: 15px 20px; font-size: 1.05rem; font-weight: 800; cursor: pointer; width: 100%; }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--accent-soft); color: #dce2ff; }
.msg { margin-top: 16px; padding: 12px 14px; border-radius: 10px; font-size: .95rem; }
.msg.ok { background: var(--green-bg); color: #cff5e6; }
.msg.err { background: var(--red-bg); color: #ffd7dc; }

/* picker */
.picker h2 { margin: 8px 0 12px; font-size: 1.05rem; color: var(--muted); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.chip {
  background: var(--card); border: 1.5px solid var(--line); color: var(--text);
  padding: 14px 20px; border-radius: 14px; font-size: 1.05rem; font-weight: 700; cursor: pointer; min-width: 64px;
}
.chip:active { transform: scale(.97); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.subject-chip { display: flex; align-items: center; gap: 10px; }
.subject-chip .emoji { font-size: 1.3rem; }
.subject-chip .count { color: var(--muted); font-size: .8rem; font-weight: 600; }

/* progress */
.progress-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.progress-bar { flex: 1; height: 9px; background: var(--card); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #9bb0ff); border-radius: 99px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.progress-text { color: var(--muted); font-size: .82rem; white-space: nowrap; }

/* quiz card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px 20px; animation: rise .3s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.badge { display: inline-block; background: var(--accent-soft); color: #cdd6ff; padding: 5px 12px; border-radius: 99px; font-size: .78rem; font-weight: 700; margin-bottom: 14px; }
.prompt { font-size: 1.4rem; line-height: 1.35; font-weight: 650; margin: 0 0 22px; }
.prompt b { color: #fff; } .prompt em { color: #ffd28a; font-style: normal; }

.options { display: flex; flex-direction: column; gap: 11px; }
.option { display: flex; align-items: center; gap: 12px; background: var(--card2); border: 1.5px solid var(--line); color: var(--text); padding: 16px; border-radius: 13px; font-size: 1.1rem; text-align: left; cursor: pointer; font-family: inherit; }
.option:active { transform: scale(.99); }
.option .key { flex: none; width: 26px; height: 26px; display: grid; place-items: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; font-size: .8rem; font-weight: 800; color: var(--muted); }
.option.correct { border-color: var(--green); background: var(--green-bg); }
.option.wrong { border-color: var(--red); background: var(--red-bg); }
.option .mark { margin-left: auto; font-weight: 800; }

.num-row { display: flex; gap: 10px; }
.num-row input { flex: 1; text-align: center; font-size: 1.4rem; font-weight: 700; }
.num-row .btn { width: auto; padding-left: 26px; padding-right: 26px; }

textarea { width: 100%; background: var(--card2); border: 1.5px solid var(--line); color: var(--text); border-radius: 12px; padding: 14px; font: inherit; font-size: 1.05rem; resize: vertical; }

.reveal { margin-top: 20px; border-left: 4px solid var(--accent); background: var(--bg2); border-radius: 10px; padding: 15px 16px; animation: rise .25s ease both; }
.verdict { font-weight: 800; margin-bottom: 8px; }
.verdict.correct { color: var(--green); } .verdict.wrong { color: var(--red); } .verdict.neutral { color: #cdd6ff; }
.rule { color: #d7dbf0; line-height: 1.55; } .rule b { color: #fff; } .rule em { color: #ffd28a; font-style: normal; }
.reveal-table { margin-top: 12px; overflow-x: auto; }
.reveal-table table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.reveal-table th, .reveal-table td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.reveal-table th { background: var(--accent-soft); color: #e7ecff; }

.actions { margin-top: 22px; }
.actions .btn { display: none; }
.hint { color: var(--muted); font-size: .82rem; text-align: center; margin-top: 12px; }

.done, .center { text-align: center; padding: 30px 10px; }
.done .emoji { font-size: 3rem; }

/* stats */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 22px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 12px; text-align: center; }
.tile .v { font-size: 1.6rem; font-weight: 800; } .tile .l { color: var(--muted); font-size: .78rem; margin-top: 4px; }
.tile.green .v { color: var(--green); } .tile.accent .v { color: var(--accent); }
.topic-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.topic-row .name { flex: none; width: 42%; font-size: .9rem; }
.topic-row .bar { flex: 1; height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; }
.topic-row .bar > div { height: 100%; border-radius: 99px; }
.topic-row .pct { color: var(--muted); font-size: .82rem; width: 56px; text-align: right; }

.hidden { display: none !important; }
