:root {
  --bg: #f7f5ef;
  --bg-2: #fffdf8;
  --card: #ffffff;
  --ink: #1e2433;
  --ink-2: #3d465a;
  --muted: #79808f;
  --line: #e8e4d9;
  --brand: #3b5bdb;
  --brand-ink: #2a44ad;
  --brand-soft: #eaeeff;
  --amber: #f7a325;
  --amber-soft: #fff3dd;
  --ok: #17945a;
  --ok-soft: #e4f7ec;
  --bad: #d94f4f;
  --bad-soft: #fdeaea;
  --radius: 20px;
  --shadow-sm: 0 1px 2px rgba(30, 36, 51, .06), 0 4px 14px -8px rgba(30, 36, 51, .16);
  --shadow-md: 0 2px 6px rgba(30, 36, 51, .05), 0 18px 40px -24px rgba(30, 36, 51, .35);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 12% -10%, #eef1ff 0%, rgba(238, 241, 255, 0) 60%),
    radial-gradient(900px 500px at 100% 0%, #fff4e2 0%, rgba(255, 244, 226, 0) 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px clamp(16px, 4vw, 32px);
  background: rgba(247, 245, 239, .82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid rgba(232, 228, 217, .8);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 18px;
  box-shadow: 0 6px 16px -6px rgba(59, 91, 219, .8);
}
.brand-text { display: flex; align-items: baseline; gap: 8px; font-weight: 700; letter-spacing: .02em; }
.brand-text em { font-style: normal; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: .08em; }
.nav { display: flex; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.nav a {
  padding: 6px 14px; border-radius: 999px; color: var(--ink-2); font-size: 14px; font-weight: 500;
}
.nav a:hover { background: #f3f4f8; text-decoration: none; }
.nav a.on { background: var(--brand); color: #fff; }

/* ---------- layout ---------- */
.view { max-width: 1080px; margin: 0 auto; padding: clamp(18px, 3vw, 32px) clamp(16px, 4vw, 28px) 48px; }
.foot { max-width: 1080px; margin: 0 auto; padding: 8px clamp(16px, 4vw, 28px) 40px; color: var(--muted); font-size: 12.5px; }
.foot p { margin: 4px 0; }
.foot-dim { color: #9aa0ad; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.section { margin-top: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 18px; letter-spacing: .01em; }
.section-head .hint { color: var(--muted); font-size: 13px; }

/* ---------- hero ---------- */
.hero {
  display: grid; grid-template-columns: 1.15fr .85fr; gap: 22px;
  align-items: center; padding: clamp(22px, 3vw, 34px);
  background: linear-gradient(135deg, #ffffff 0%, #fbfaff 55%, #fff8ec 100%);
  border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow-md);
}
.hero h1 { margin: 0 0 8px; font-size: clamp(26px, 3.4vw, 36px); line-height: 1.25; letter-spacing: -.01em; }
.hero h1 span { color: var(--brand); }
.hero p { margin: 0; color: var(--ink-2); font-size: 15px; }
.hero-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-2);
}
.pill b { color: var(--brand); font-size: 13.5px; }
.hero-art { display: grid; place-items: center; }

/* ---------- setup panel ---------- */
.setup { padding: 22px; }
.setup-row { display: grid; grid-template-columns: 86px 1fr; gap: 14px; align-items: start; margin-bottom: 16px; }
.setup-label { font-size: 13.5px; color: var(--muted); padding-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  padding: 8px 14px; border-radius: 12px; font: inherit; font-size: 14px; cursor: pointer;
  transition: transform .08s ease, border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: #c9cfe6; transform: translateY(-1px); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 8px 18px -12px rgba(59, 91, 219, .9); }
.chip small { opacity: .7; font-size: 11.5px; margin-left: 4px; }
.start-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.btn {
  appearance: none; border: 0; font: inherit; cursor: pointer; border-radius: 14px;
  padding: 12px 22px; font-weight: 600; font-size: 15px; transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 12px 24px -14px rgba(59, 91, 219, 1); }
.btn-primary:hover { background: #3350cb; }
.btn-ghost { background: #fff; color: var(--ink-2); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: #c9cfe6; }
.btn-lg { padding: 15px 30px; font-size: 16.5px; border-radius: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- progress / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px;
}
.stat .num { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .lab { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- practice ---------- */
.practice-wrap { max-width: 760px; margin: 0 auto; }
.pbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.pbar-track { flex: 1; height: 8px; border-radius: 999px; background: #e9e7de; overflow: hidden; }
.pbar-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, #6f8bff, var(--brand)); transition: width .35s ease; }
.pbar-text { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.qcard { padding: clamp(20px, 3vw, 30px); }
.qmeta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.tag {
  font-size: 12px; padding: 3px 9px; border-radius: 8px; background: #f2f3f8; color: var(--ink-2);
}
.tag.subject { background: var(--brand-soft); color: var(--brand-ink); }
.tag.trace { background: var(--amber-soft); color: #95610a; }
.tag.diff-challenge, .tag.diff-advanced { background: #fdeee9; color: #b4442b; }
.qprompt { font-size: clamp(19px, 2.4vw, 23px); line-height: 1.55; font-weight: 600; letter-spacing: .01em; margin: 0 0 20px; }
.qprompt .sub { display: block; font-weight: 400; font-size: 15px; color: var(--muted); margin-top: 8px; }

.choices { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff;
  font: inherit; font-size: 16.5px; color: var(--ink); cursor: pointer; transition: border-color .15s, background .15s, transform .08s;
}
.choice:hover:not(:disabled) { border-color: #b9c3e8; background: #fbfbff; }
.choice:active:not(:disabled) { transform: scale(.995); }
.choice .key {
  flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: #f2f3f8; color: var(--ink-2); font-size: 13.5px; font-weight: 700;
}
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .key { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .key { background: var(--bad); color: #fff; }
.choice:disabled { cursor: default; }

.answer-row { display: flex; gap: 10px; flex-wrap: wrap; }
.answer-row input[type=text] {
  flex: 1; min-width: 180px; padding: 13px 16px; border-radius: 14px; border: 1.5px solid var(--line);
  font: inherit; font-size: 17px; background: #fff; color: var(--ink); outline: none;
}
.answer-row input[type=text]:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(59, 91, 219, .12); }

.feedback { margin-top: 18px; border-radius: 16px; padding: 16px 18px; border: 1px solid transparent; animation: rise .22s ease; }
.feedback.ok { background: var(--ok-soft); border-color: #bfe9d2; }
.feedback.bad { background: var(--bad-soft); border-color: #f5c9c9; }
.fb-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.feedback.ok .fb-head { color: var(--ok); }
.feedback.bad .fb-head { color: var(--bad); }
.fb-body { margin-top: 8px; color: var(--ink-2); font-size: 15px; }
.fb-answer { margin-top: 8px; font-size: 14.5px; }
.fb-answer b { color: var(--ink); }
.fb-tip { margin-top: 10px; font-size: 13.5px; color: #8a5a12; background: #fff7e6; border: 1px dashed #f0d3a0; padding: 10px 12px; border-radius: 12px; }
.fb-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.fb-actions .ghost-link { background: none; border: 0; padding: 6px 2px; color: var(--muted); font-size: 13.5px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- result ---------- */
.result-hero { padding: clamp(22px, 4vw, 32px); text-align: center; }
.result-ring { width: 132px; height: 132px; margin: 0 auto 12px; position: relative; }
.result-ring svg { transform: rotate(-90deg); }
.result-ring .val {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.result-hero h1 { margin: 6px 0 6px; font-size: clamp(22px, 3vw, 28px); }
.result-hero p { margin: 0; color: var(--muted); }
.stars { font-size: 22px; letter-spacing: 4px; margin-top: 10px; }

.gap-list { display: grid; gap: 12px; }
.gap-card { padding: 16px 18px; border-radius: 16px; border: 1px solid #f0dcc0; background: linear-gradient(180deg, #fffdf7, #fff8ec); }
.gap-card h3 { margin: 0 0 4px; font-size: 17px; }
.gap-card .path { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.gap-card ul { margin: 0 0 12px; padding-left: 18px; font-size: 14px; color: var(--ink-2); }
.gap-card ul li { margin: 3px 0; }

.review-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px dashed var(--line); font-size: 14.5px; }
.review-row:first-child { border-top: 0; }
.review-row .mark { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; }
.review-row .mark.ok { background: var(--ok); }
.review-row .mark.bad { background: var(--bad); }
.review-row .txt { flex: 1; color: var(--ink-2); }
.review-row .tp { font-size: 12px; color: var(--muted); }

/* ---------- map ---------- */
.map-layout {
  display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start;
  grid-template-areas: "side canvas" "detail canvas";
}
.map-side { grid-area: side; padding: 16px; }
.map-canvas-wrap { grid-area: canvas; }
.map-side h3 { margin: 0 0 10px; font-size: 15px; }
.map-canvas-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow-sm); }
#map-detail { grid-area: detail; }
canvas#graph { display: block; width: 100%; height: 560px; touch-action: none; cursor: grab; }
canvas#graph.dragging { cursor: grabbing; }
.map-tools { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .94);
  display: grid; place-items: center; cursor: pointer; font-size: 16px; color: var(--ink-2);
}
.icon-btn:hover { border-color: #c9cfe6; }
.map-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.map-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.select {
  width: 100%; appearance: none; font: inherit; font-size: 14px; color: var(--ink-2);
  padding: 9px 34px 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2379808f' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; cursor: pointer;
}
.select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(59, 91, 219, .12); }

.detail { padding: 18px; }
.detail h3 { margin: 0 0 4px; font-size: 19px; }
.detail .meta-line { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.detail h4 { margin: 16px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.detail p { margin: 0 0 8px; font-size: 14.5px; color: var(--ink-2); }
.detail ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--ink-2); }
.detail ul li { margin: 4px 0; }
.link-list { display: flex; flex-wrap: wrap; gap: 6px; }
.link-pill {
  font-size: 12.5px; padding: 4px 10px; border-radius: 9px; background: #f4f5fa; color: var(--ink-2);
  border: 1px solid #e9eaf2; cursor: pointer;
}
.link-pill:hover { background: var(--brand-soft); color: var(--brand-ink); border-color: #cdd6f7; text-decoration: none; }
.std { font-size: 13px; color: var(--ink-2); background: #faf9f5; border-left: 3px solid #e3ddcc; padding: 8px 10px; border-radius: 0 8px 8px 0; margin-bottom: 6px; }
.empty { color: var(--muted); font-size: 14px; padding: 12px 0; }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1e2433; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; z-index: 90;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .5);
}
.history-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.history-item:first-child { border-top: 0; }
.history-item .r { color: var(--muted); font-size: 12.5px; }
.bar-list { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr 90px 40px; gap: 10px; align-items: center; font-size: 13.5px; }
.bar { height: 8px; border-radius: 999px; background: #eeece4; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffce7a, var(--amber)); }
.bar-row .pct { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { display: none; }
  .map-layout { grid-template-columns: 1fr; grid-template-areas: "side" "canvas" "detail"; }
  canvas#graph { height: 420px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 14px; }
  .brand-text em { display: none; }
  .nav a { padding: 6px 11px; font-size: 13px; }
  .setup-row { grid-template-columns: 1fr; gap: 6px; }
  .setup-label { padding-top: 0; }
  .view { padding-bottom: 32px; }
  .stat-grid { grid-template-columns: 1fr; }
}
