:root {
  --paper: #f7f4ee;
  --card: #fffdf9;
  --ink: #1f1c18;
  --muted: #6f675c;
  --line: #e3dccf;
  --accent: #b23b2d;
  --accent-soft: #f3e2dd;
  --ok: #2f7a53;
  --warn: #a8791c;
  --shadow: 0 1px 2px rgba(40, 32, 20, .06), 0 8px 24px -16px rgba(40, 32, 20, .35);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171614;
    --card: #1f1d1a;
    --ink: #efeae1;
    --muted: #a49a8b;
    --line: #322e28;
    --accent: #e0785f;
    --accent-soft: #3a2521;
    --ok: #6db98c;
    --warn: #d3a754;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 9px;
  padding: 7px 14px;
  transition: background .15s, border-color .15s, color .15s;
}

button:hover { border-color: var(--accent); color: var(--accent); }

button.primary, .login-card button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover, .login-card button:hover { filter: brightness(1.06); color: #fff; }

button.ghost { background: transparent; }

h1, h2, h3 { font-weight: 650; letter-spacing: -.01em; margin: 0; }

h1 { font-size: 22px; }
h2 { font-size: 16px; margin: 26px 0 12px; }
h2:first-child { margin-top: 0; }

.muted { color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- login */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 30px 28px 24px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  margin: 0 0 14px;
}

.login-card h1 { font-size: 20px; margin-bottom: 6px; }

.login-card label { display: block; margin-top: 16px; font-size: 13px; color: var(--muted); }

.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.login-card button { width: 100%; margin-top: 22px; padding: 11px; }

.error { color: var(--accent); font-size: 13px; min-height: 20px; margin: 10px 0 0; }

/* ----------------------------------------------------------------- shell */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.brand .brand-mark { margin: 0; width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }

.top-actions { display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 13px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px clamp(16px, 4vw, 40px) 0;
  max-width: 1180px;
  margin: 0 auto;
}

.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 14px;
}

.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button:hover { color: var(--accent); }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px clamp(16px, 4vw, 40px) 64px;
}

.view-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: 8px 0 16px;
}

.view-head h2 { margin: 0; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.tile .k { color: var(--muted); font-size: 13px; }
.tile .v { font-size: 28px; font-weight: 650; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 12px; }

/* ----------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th, .table td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); }

.table th { color: var(--muted); font-weight: 500; font-size: 12.5px; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--paper); }

.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; min-width: 90px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.pill {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.pill.accent { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.pill.ok { color: var(--ok); }

.empty { color: var(--muted); padding: 22px 18px; margin: 0; font-size: 14px; }

/* -------------------------------------------------------------- set view */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chips button { padding: 4px 12px; font-size: 13px; border-radius: 99px; color: var(--muted); }
.chips button.active { color: #fff; background: var(--accent); border-color: var(--accent); }

.split { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 14px; align-items: start; }

@media (max-width: 820px) {
  .split { grid-template-columns: 1fr; }
}

.list { max-height: 70vh; overflow: auto; padding: 6px; }

.set-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  align-items: baseline;
}

.set-row:hover { background: var(--paper); }
.set-row.active { background: var(--accent-soft); }
.set-row .name { font-weight: 550; }
.set-row .count { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

.detail { padding: 6px 0; min-height: 240px; }

.detail-head { padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.detail-head h3 { font-size: 16px; }
.detail-head .muted { margin-top: 4px; }

.q-item { padding: 12px 18px; border-bottom: 1px solid var(--line); }
.q-item:last-child { border-bottom: 0; }
.q-item .q-body { font-size: 15px; }
.q-item .q-answer { color: var(--accent); font-weight: 600; }
.q-item .q-title { font-size: 13px; color: var(--muted); margin-bottom: 2px; }

/* ----------------------------------------------------------------- plans */

.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }

.plan-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}

.plan-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.plan-card h3 { font-size: 16px; margin-bottom: 4px; }
.plan-card .desc { color: var(--muted); font-size: 13px; min-height: 20px; }
.plan-card .stats { display: flex; gap: 18px; margin-top: 14px; }
.plan-card .stats div { font-size: 12px; color: var(--muted); }
.plan-card .stats b { display: block; font-size: 19px; color: var(--ink); font-variant-numeric: tabular-nums; }

.levels { display: flex; height: 8px; border-radius: 99px; overflow: hidden; margin-top: 12px; background: var(--line); }
.levels span { display: block; height: 100%; }
.levels .new { background: #cfc8bc; }
.levels .weak { background: #d9a05a; }
.levels .growing { background: #7fa6a0; }
.levels .stable { background: #4f8a63; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

.plan-panel { margin-top: 18px; padding: 18px 20px; }
.plan-panel h3 { margin-bottom: 10px; }
.plan-panel ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; }

/* -------------------------------------------------------------- progress */

.board-row { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.board-row:last-child { border-bottom: 0; }
.board-row .label { width: 84px; flex: none; font-weight: 550; }
.board-row .bar { flex: 1; height: 10px; }
.board-row .num { width: 72px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 20;
}

/* ------------------------------------------------------------ mcp dialog */

.mcp-dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 20px 22px 18px;
}

.mcp-dialog::backdrop { background: rgba(20, 16, 10, .42); }

.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h3 { font-size: 16px; }
.dialog-head button { padding: 2px 9px; }

.snippet {
  margin: 12px 0;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 44vh;
  overflow: auto;
}

.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* per-question familiarity */

.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }

.pill.level-new { color: var(--muted); }
.pill.level-weak { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.pill.level-growing { color: #4a7f78; border-color: color-mix(in srgb, #4a7f78 40%, var(--line)); }
.pill.level-stable { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
