:root {
  --bg: #f4f7fb;
  --card: #fff;
  --ink: #1a2332;
  --muted: #5b6b7c;
  --blue: #1e3a5f;
  --blue2: #2c5f8a;
  --soft: #dbeafe;
  --ok: #15803d;
  --rose: #be123c;
  --rose-soft: #ffe4e6;
  --amber: #b45309;
  --line: #d5dee8;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  line-height: 1.45; min-height: 100dvh;
}
button { font: inherit; cursor: pointer; }
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(244,247,251,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-title { flex: 1; font-weight: 700; font-size: 17px; }
.ghost { border: none; background: transparent; color: var(--blue2); padding: 6px 8px; border-radius: 999px; }
.badge-btn { background: var(--rose-soft); color: var(--rose); font-size: 13px; font-weight: 600; }
main { padding: 14px 14px calc(28px + var(--safe-b)); flex: 1; }

.hero {
  background: linear-gradient(145deg, #1e3a5f 0%, #2c5f8a 60%, #3b82a8 100%);
  color: #fff; border-radius: 18px; padding: 18px 16px; margin-bottom: 14px;
}
.hero h1 { margin: 0 0 6px; font-size: 22px; }
.hero p { margin: 0; opacity: .9; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 14px; }
.stat { background: rgba(255,255,255,.12); border-radius: 12px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11px; opacity: .85; }

.section-label { font-size: 12px; color: var(--muted); font-weight: 600; margin: 14px 0 8px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; margin-bottom: 10px;
}
.btn {
  border: none; border-radius: 999px; padding: 10px 14px; font-size: 14px; font-weight: 700;
}
.btn.primary { background: var(--blue2); color: #fff; width: 100%; margin-top: 6px; }
.btn.secondary { background: #e2e8f0; color: #334155; width: 100%; margin-top: 6px; }
.btn.ok { background: #dcfce7; color: var(--ok); }
.btn.bad { background: var(--rose-soft); color: var(--rose); }
.btn.tiny { padding: 6px 10px; font-size: 12px; }
.btn.ghost2 { background: var(--soft); color: var(--blue); }

.unit-list { display: grid; gap: 8px; }
.unit-card {
  display: flex; gap: 10px; align-items: center; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px;
}
.unit-card .idx {
  width: 42px; height: 42px; border-radius: 12px; background: var(--soft); color: var(--blue);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none;
}
.unit-card .meta { flex: 1; min-width: 0; }
.unit-card .meta b { display: block; font-size: 14px; }
.unit-card .meta span { color: var(--muted); font-size: 12px; }

.q-card .meta-line { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.q-card .q-body { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.q-card .q-body .fig { margin: 8px 0; overflow-x: auto; }
.q-card .q-body svg { max-width: 100%; height: auto; }
.q-card input, .q-card textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; background: #fff;
}
.q-card textarea { min-height: 64px; resize: vertical; }
.feedback { margin-top: 6px; font-size: 12px; font-weight: 600; min-height: 1.2em; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--rose); }
.know-tip {
  margin-top: 8px; background: #f0fdf4; border-radius: 10px; padding: 8px 10px;
  font-size: 12px; color: #166534;
}
.progress { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.empty {
  text-align: center; color: var(--muted); padding: 40px 16px;
  background: var(--card); border-radius: 14px; border: 1px dashed var(--line);
}
.wrong-item {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start;
  padding: 12px 0; border-bottom: 1px solid #eef2f0;
}
.wrong-item:last-child { border-bottom: none; }
.tag {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--soft); color: var(--blue); margin-bottom: 4px; font-weight: 600;
}
.footer-note { font-size: 11px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

.card-title { margin: 0 0 10px; font-size: 20px; color: var(--blue); }
.meta-line { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.block { border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13.5px; line-height: 1.55; }
.block .lab {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px;
  border-radius: 999px; margin-right: 6px; margin-bottom: 4px;
}
.block.concept { background: #ecfdf5; }
.block.concept .lab { background: #bbf7d0; color: #166534; }
.block.rules { background: #eff6ff; }
.block.rules .lab { background: #bfdbfe; color: #1e3a5f; }
.block.example { background: #f8fafc; }
.block.example .lab { background: #e2e8f0; color: #475569; }
.block.trap { background: #fff1f2; }
.block.trap .lab { background: #fecdd3; color: #9f1239; }
.block .fig, .block svg { max-width: 100%; height: auto; margin-top: 6px; }

.lvl-row { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 10px; }
.lvl {
  border: 2px solid var(--line); background: #fff; border-radius: 14px;
  padding: 14px 12px; font-size: 15px; font-weight: 700; text-align: center;
}
.lvl.full.on { border-color: #15803d; background: #dcfce7; color: #15803d; }
.lvl.basic.on { border-color: #b45309; background: #ffedd5; color: #b45309; }
.lvl.none.on { border-color: #be123c; background: #ffe4e6; color: #be123c; }
.lvl.full { color: #15803d; }
.lvl.basic { color: #b45309; }
.lvl.none { color: #be123c; }

.badge {
  font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 999px; flex: none;
}
.badge.full { background: #dcfce7; color: #15803d; }
.badge.basic { background: #ffedd5; color: #b45309; }
.badge.none { background: #ffe4e6; color: #be123c; }
.badge.unset { background: #e2e8f0; color: #64748b; }
.idx.mini { font-size: 11px; width: 48px; }

.tip { font-size: 13px; color: #1e3a5f; background: #eff6ff; line-height: 1.5; }

.paper-hint {
  background: #fffbeb; border: 1px dashed #f59e0b; border-radius: 10px;
  padding: 8px 10px; font-size: 12px; color: #92400e; margin: 8px 0;
}
.photo-box { margin: 8px 0; }
.photo-empty {
  border: 1px dashed var(--line); border-radius: 12px; padding: 28px;
  text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 8px;
}
.shot {
  width: 100%; border-radius: 12px; display: block; margin-bottom: 8px;
  border: 1px solid var(--line);
}
.photo-btn { display: block; text-align: center; width: 100%; }
.ans-box {
  background: #f8fafc; border-radius: 10px; padding: 10px; margin: 8px 0; font-size: 13px;
}
.ans-line { margin-bottom: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 8px; }
.row2 .btn { width: 100%; padding: 10px 6px; font-size: 13px; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: rgba(20,35,55,.92); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 50; transition: .2s ease; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.gate[hidden], #app[hidden] { display: none !important; }
.gate {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: var(--bg, #f4f7fb);
}
.gate-card {
  width: min(360px, 100%); background: #fff; border: 1px solid var(--line, #d5dee8);
  border-radius: 18px; padding: 22px 18px; box-shadow: 0 10px 30px rgba(0,0,0,.06);
  text-align: center;
}
.gate-card h1 { margin: 0 0 8px; font-size: 20px; color: var(--blue, var(--teal, #0f766e)); }
.gate-hint { margin: 0 0 16px; font-size: 13px; color: var(--muted, #5b6b7c); }
.gate-card input {
  width: 100%; border: 1px solid var(--line, #d5dee8); border-radius: 12px;
  padding: 12px; font-size: 18px; letter-spacing: 0.2em; text-align: center; margin-bottom: 10px;
}
.gate-card button {
  width: 100%; border: none; border-radius: 999px; padding: 12px;
  background: var(--blue2, var(--teal, #0f766e)); color: #fff; font-size: 15px; font-weight: 700;
}
.gate-err { min-height: 1.2em; color: #be123c; font-size: 13px; font-weight: 600; margin: 8px 0 0; }
