:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #16213a;
  --muted: #5b6680;
  --line: #e1e6f0;
  --brand: #2453d6;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --good: #1f9d55;
  --good-soft: #e3f6ec;
  --bad: #d64545;
  --bad-soft: #fdecec;
  --warn: #c27c0e;
  --warn-soft: #fdf3e1;
  --mark: #7b3fc4;
  --mark-soft: #f1e9fb;
  --grey: #b9c1d1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 33, 58, 0.06), 0 4px 16px rgba(22, 33, 58, 0.06);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 719px) { .g4, .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.hide { display: none !important; }
[hidden] { display: none !important; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { color: var(--bad); border-color: #f1c4c4; }
.btn.mark { color: var(--mark); border-color: #dcc8f3; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* forms */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; }
input[type='text'], input[type='password'], input[type='number'], input[type='datetime-local'], input[type='search'], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid var(--brand-soft); border-color: var(--brand); }
.check { display: flex; gap: 10px; align-items: center; min-height: 40px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.err { color: var(--bad); font-weight: 600; }

/* stats */
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat span { font-size: 0.85rem; color: var(--muted); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.mark { background: var(--mark-soft); color: var(--mark); }
.bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
table.t { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.t th, table.t td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.scroll-x { overflow-x: auto; }

/* toast + sheet */
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; z-index: 100; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.sheet-back { position: fixed; inset: 0; background: rgba(10, 16, 32, 0.45); z-index: 60; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow: auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); z-index: 61; }
@media (min-width: 720px) { .sheet { left: 50%; transform: translateX(-50%); width: 640px; bottom: 5vh; border-radius: 18px; } }

/* math + question text */
.qtext { white-space: pre-wrap; overflow-wrap: anywhere; }
.qtext .katex-display, .opt .katex-display { overflow-x: auto; overflow-y: hidden; }
.katex { font-size: 1.05em; }

/* login */
.login { max-width: 400px; margin: 10vh auto; padding: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; }
.brand i { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; color: #fff; font-style: normal; font-size: 0.9rem; }

@media print {
  .noprint, nav, header, .bottomnav { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
