:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1a2233;
  --ink-soft: #5a667d;
  --muted: #8a94a8;
  --line: #e4e8f1;
  --line-soft: #eef1f7;
  --accent: #3b6ef0;
  --accent-soft: #eaf0ff;
  --accent-ink: #2a51c4;
  --green: #1f9d63;
  --green-soft: #e6f6ee;
  --amber: #b7791f;
  --amber-soft: #fbf2dd;
  --violet: #7c3aed;
  --violet-soft: #f1ebfe;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,30,60,.05), 0 8px 28px rgba(20,30,60,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1320;
    --panel: #171c2b;
    --ink: #e7ebf5;
    --ink-soft: #aab3c9;
    --muted: #717c95;
    --line: #29314a;
    --line-soft: #222a40;
    --accent: #6b93ff;
    --accent-soft: #1e2740;
    --accent-ink: #aac2ff;
    --green: #4cc98a;
    --green-soft: #16301f;
    --amber: #e3b256;
    --amber-soft: #322713;
    --violet: #b08aff;
    --violet-soft: #271a3f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 26px; width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); border-radius: 12px;
}
.brand-text h1 { font-size: 19px; margin: 0; letter-spacing: -.2px; }
.brand-text p { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); }
.brand-tag {
  font-size: 12px; color: var(--green); background: var(--green-soft);
  padding: 6px 12px; border-radius: 999px; font-weight: 600; white-space: nowrap;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 460px) 1fr;
  gap: 20px;
  padding: 20px clamp(16px, 4vw, 40px);
  align-items: start;
  max-width: 1500px; margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { font-size: 15px; margin: 0; }

/* Input */
.input-panel { position: sticky; top: 20px; }
@media (max-width: 900px) { .input-panel { position: static; } }
.input-actions { display: flex; gap: 8px; }
.doc-input {
  width: 100%; border: none; resize: vertical;
  min-height: 340px; padding: 16px 18px;
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.7; color: var(--ink);
  background: transparent; outline: none; display: block;
}
.doc-input::placeholder { color: var(--muted); }
.input-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-top: 1px solid var(--line-soft);
}

/* Buttons */
.btn {
  font-family: inherit; font-size: 13px; font-weight: 600;
  border-radius: 9px; padding: 9px 16px; cursor: pointer;
  border: 1px solid transparent; transition: .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost {
  background: transparent; color: var(--ink-soft); border-color: var(--line);
}
.btn-ghost:hover { background: var(--line-soft); color: var(--ink); }

/* Stats */
.stats {
  display: grid; grid-template-columns: repeat(3, auto) 1fr;
  gap: 22px; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
}
@media (max-width: 560px) { .stats { grid-template-columns: repeat(3, 1fr); } .stat-progress { grid-column: 1 / -1; } }
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.stat-label { font-size: 11.5px; color: var(--muted); }
.stat-progress { min-width: 120px; }
.progress-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.progress-row .stat-num { font-size: 15px; }
.progress-track { height: 7px; border-radius: 999px; background: var(--line); margin-top: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--green); border-radius: 999px; transition: width .3s ease; }

/* Gaps */
.gaps {
  margin: 16px 18px 0; padding: 12px 14px;
  background: var(--amber-soft); border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
  border-radius: 11px;
}
.gaps-head { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--amber); }
.gaps-icon { font-size: 14px; }
.gaps-list { margin: 8px 0 0; padding-left: 4px; list-style: none; display: grid; gap: 6px; }
.gaps-list li {
  font-size: 13px; color: var(--ink-soft); padding-left: 18px; position: relative;
}
.gaps-list li::before { content: "›"; position: absolute; left: 4px; color: var(--amber); font-weight: 700; }

/* Empty */
.empty { text-align: center; padding: 56px 24px; color: var(--ink-soft); }
.empty-art { font-size: 44px; margin-bottom: 8px; }
.empty p { margin: 6px 0; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Board */
.board {
  display: grid; gap: 16px; padding: 18px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.phase {
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background: color-mix(in srgb, var(--panel) 100%, var(--bg) 40%);
  display: flex; flex-direction: column;
}
.phase-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
}
.phase-idx {
  flex: none; width: 24px; height: 24px; border-radius: 7px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.phase-title { font-size: 14.5px; font-weight: 700; flex: 1; outline: none; }
.phase-title:focus { background: var(--accent-soft); border-radius: 5px; }
.phase-count { font-size: 11.5px; color: var(--muted); flex: none; }

.tasks { list-style: none; margin: 0; padding: 8px; display: grid; gap: 6px; }
.task {
  display: grid; grid-template-columns: auto 1fr; gap: 9px;
  padding: 9px 10px; border-radius: 9px; background: var(--panel);
  border: 1px solid var(--line-soft);
}
.task.done { opacity: .62; }
.task-check {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  width: 17px; height: 17px; margin-top: 2px; flex: none;
  border: 1.8px solid var(--muted); border-radius: 5px; position: relative; transition: .15s;
}
.task-check:checked { background: var(--green); border-color: var(--green); }
.task-check:checked::after {
  content: ""; position: absolute; left: 5px; top: 1.5px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.task-body { min-width: 0; }
.task-text { font-size: 13.5px; color: var(--ink); outline: none; word-break: break-word; }
.task.done .task-text { text-decoration: line-through; }
.task-text:focus { background: var(--accent-soft); border-radius: 5px; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.tag-accept { background: var(--green-soft); color: var(--green); }
.tag-dep { background: var(--violet-soft); color: var(--violet); }
.task-accept { font-size: 12px; color: var(--ink-soft); margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--green); outline: none; }
.task-accept:focus { background: var(--accent-soft); border-radius: 4px; }

/* Footer */
.footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; padding: 18px clamp(16px, 4vw, 40px);
  font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--line);
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s ease; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
