:root {
  --navy: #1c3f6e;
  --navy-d: #14304f;
  --navy-l: #e8eef6;
  --accent: #c07a2c;
  --ink: #1b2430;
  --ink-2: #5a6675;
  --ink-3: #8c98a6;
  --line: #e2e7ee;
  --bg: #f5f7fa;
  --white: #fff;
  --ok: #2e7d5b;
  --warn: #b4741d;
  --danger: #c0453c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,40,70,.06), 0 6px 20px rgba(20,40,70,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", "Yu Gothic", "Hiragino Sans", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .01em; }
p { margin: 0; }
input, textarea, select, button { font-family: inherit; font-size: 14px; color: inherit; }

/* ---------- header ---------- */
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.header-inner {
  max-width: 1180px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px; flex: none;
  background: linear-gradient(140deg, var(--navy) 55%, var(--accent) 55%);
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: .02em; }
.brand-sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.save-state { font-size: 11px; color: var(--ink-3); }
.save-state.saving { color: var(--accent); }

.steps { max-width: 1180px; margin: 0 auto; padding: 0 12px; display: flex; gap: 2px; overflow-x: auto; }
.step-btn {
  border: 0; background: none; cursor: pointer; padding: 10px 14px 12px;
  color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap;
  font-size: 13px; display: flex; align-items: center; gap: 7px;
}
.step-btn:hover { color: var(--navy); }
.step-btn.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 700; }
.step-num {
  width: 19px; height: 19px; border-radius: 50%; background: var(--navy-l); color: var(--navy);
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.step-btn.active .step-num { background: var(--navy); color: #fff; }

/* ---------- layout ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }
.pane { display: none; }
.pane.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.pane-head { margin-bottom: 18px; }
.pane-head h1 { font-size: 20px; margin-bottom: 6px; }
.pane-head p { color: var(--ink-2); font-size: 13px; max-width: 860px; }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-title { font-size: 14px; margin-bottom: 12px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .card-title { margin-bottom: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.muted-sm { font-size: 12px; color: var(--ink-3); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- form ---------- */
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 5px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
input[type=text], input[type=number], input[type=date], input[type=url], textarea, .select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: #fcfdfe; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, .select:focus {
  outline: 0; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(28,63,110,.09); background: #fff;
}
textarea { resize: vertical; line-height: 1.75; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.6; }

.btn {
  border: 1px solid var(--line); background: var(--white); border-radius: 7px;
  padding: 7px 13px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--navy); color: var(--navy); }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-d); border-color: var(--navy-d); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.file-btn { display: inline-flex; align-items: center; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--ink-3); font-size: 15px; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line); background: var(--white); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--navy); }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip .x { margin-left: 6px; opacity: .7; }

/* ---------- milestones / stats ---------- */
.milestones { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.ms { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.ms label { font-size: 11px; color: var(--ink-3); display: block; margin-bottom: 4px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: #fcfdfe; }
.stat-label { font-size: 11px; color: var(--ink-3); }
.stat-value { font-size: 22px; font-weight: 700; color: var(--navy); line-height: 1.3; }
.stat-value small { font-size: 12px; color: var(--ink-3); font-weight: 500; margin-left: 3px; }
.bar { height: 5px; border-radius: 3px; background: var(--navy-l); margin-top: 7px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--navy); border-radius: 3px; transition: width .3s; }

/* ---------- benchmark ---------- */
.bench-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.bench {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fcfdfe;
}
.bench .bench-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.bench input[type=text], .bench input[type=url], .bench textarea { background: #fff; }
.bench .name-in { font-weight: 700; border: 0; border-bottom: 1px dashed var(--line); border-radius: 0; padding: 3px 2px; background: transparent; }
.bench .sub-in { border: 0; padding: 2px; font-size: 12px; background: transparent; color: var(--ink-2); }
.bench .memo { margin-top: 8px; }
.bench .memo textarea { font-size: 12px; padding: 6px 8px; }
.empty { color: var(--ink-3); font-size: 13px; padding: 20px; text-align: center; border: 1px dashed var(--line); border-radius: 8px; }

.matrix-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line); padding: 6px 8px; }
table.matrix thead th {
  position: sticky; top: 0; background: #f0f3f8; z-index: 2; font-weight: 500;
  font-size: 11px; text-align: center; vertical-align: bottom; min-width: 64px;
}
table.matrix thead th:first-child { text-align: left; z-index: 3; left: 0; min-width: 240px; }
table.matrix tbody td:first-child { position: sticky; left: 0; background: #fff; z-index: 1; }
table.matrix tbody tr:hover td { background: #f8fafc; }
table.matrix tbody tr.cat-row td { background: var(--navy-l); font-weight: 700; color: var(--navy); font-size: 11px; letter-spacing: .04em; }
table.matrix td.check { text-align: center; }
table.matrix input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--navy); }
.rate-cell { text-align: right; font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-2); margin-bottom: 10px; flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.tier-must { background: var(--navy); }
.tier-rec { background: #6d94c4; }
.tier-diff { background: var(--accent); }
table.rates { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rates th { text-align: left; font-size: 11px; color: var(--ink-3); font-weight: 500; border-bottom: 1px solid var(--line); padding: 6px 8px; }
table.rates td { border-bottom: 1px solid var(--line); padding: 7px 8px; vertical-align: middle; }
table.rates tr:hover td { background: #f8fafc; }
.rate-bar { height: 6px; background: var(--navy-l); border-radius: 3px; width: 110px; overflow: hidden; }
.rate-bar > i { display: block; height: 100%; border-radius: 3px; }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-2); background: #fff; white-space: nowrap;
}
.tag.must { background: var(--navy); border-color: var(--navy); color: #fff; }
.tag.rec { background: #6d94c4; border-color: #6d94c4; color: #fff; }
.tag.diff { background: #fff3e3; border-color: #e8c79a; color: #8a5a15; }
.tag.in-toc { background: #e7f3ec; border-color: #b9dcc8; color: var(--ok); }

/* ---------- structure ---------- */
.page-meter { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; font-size: 13px; flex-wrap: wrap; }
.page-meter .bar { flex: 1; min-width: 200px; height: 8px; margin: 0; }
.page-meter .over > i { background: var(--danger); }
.toc-list { display: flex; flex-direction: column; gap: 8px; }
.toc-item {
  border: 1px solid var(--line); border-radius: 8px; background: #fcfdfe; padding: 10px 12px;
  display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start;
}
.toc-item .idx { font-size: 12px; color: var(--ink-3); text-align: center; padding-top: 7px; font-variant-numeric: tabular-nums; }
.toc-main .title-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toc-main .title-in { font-weight: 500; border: 0; border-bottom: 1px dashed var(--line); border-radius: 0; background: transparent; flex: 1; min-width: 180px; padding: 4px 2px; }
.toc-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.toc-meta .mini { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-3); }
.toc-meta input[type=number] { width: 62px; padding: 4px 7px; }
.toc-meta input[type=text] { width: 120px; padding: 4px 7px; }
.toc-meta .select { width: auto; padding: 4px 7px; font-size: 12px; }
.toc-actions { display: flex; gap: 4px; align-items: center; }
.cat-badge { font-size: 10px; padding: 1px 7px; border-radius: 4px; background: var(--navy-l); color: var(--navy); white-space: nowrap; }
.st { font-size: 11px; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.st-0 { background: #f0f2f5; color: var(--ink-3); }
.st-1 { background: #fdf3e3; color: var(--warn); }
.st-2 { background: #e9f0fa; color: var(--navy); }
.st-3 { background: #e7f3ec; color: var(--ok); }

/* ---------- writing ---------- */
.split { display: grid; grid-template-columns: 262px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) {
  /* 1カラムになったら sticky を解除。そのままだとサイドバーが本文を覆う。
     .split-side の定義がこの後ろにあるため、詳細度を上げて確実に勝たせる */
  .split { grid-template-columns: 1fr; }
  .split .split-side { position: static; }
  .split .write-nav { max-height: 240px; }
}
.split-side { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; position: sticky; top: 108px; }
.side-head { padding: 10px 14px; font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--line); background: #fafbfd; }
.write-nav { max-height: 62vh; overflow-y: auto; }
.wn-item { padding: 9px 14px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.wn-item:hover { background: #f7f9fc; }
.wn-item.active { background: var(--navy-l); color: var(--navy); font-weight: 500; box-shadow: inset 3px 0 0 var(--navy); }
.wn-item .wn-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-main { min-width: 0; }
.count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.count.over { color: var(--warn); }
.ref-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fcfdfe; }
.ref-item .ref-top { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.ref-item .select { width: auto; flex: 1; padding: 5px 8px; font-size: 12px; }
.body-area { min-height: 320px; }

/* ---------- design ---------- */
.palette-edit { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 10px; margin-bottom: 12px; }
.pal { text-align: center; }
.pal input[type=color] { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 7px; padding: 2px; background: #fff; cursor: pointer; }
.pal .pal-label { font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.pal .pal-hex { font-size: 10px; color: var(--ink-3); font-family: ui-monospace, monospace; }
.sample-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.sample { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fcfdfe; display: flex; flex-direction: column; }
.sample .thumb { height: 130px; background: #eef1f5; display: grid; place-items: center; color: var(--ink-3); font-size: 12px; overflow: hidden; position: relative; }
.sample .thumb img { width: 100%; height: 100%; object-fit: cover; }
.sample .thumb .up-label { position: absolute; inset: 0; display: grid; place-items: center; cursor: pointer; font-size: 12px; }
.sample .thumb img + .up-label { opacity: 0; background: rgba(0,0,0,.45); color: #fff; transition: opacity .15s; }
.sample .thumb:hover img + .up-label { opacity: 1; }
.sample .s-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sample .s-body input { padding: 5px 8px; font-size: 12px; }
.sample .s-body textarea { font-size: 12px; padding: 6px 8px; }
.covers { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-top: 14px; }
.cover-card { cursor: pointer; border: 2px solid transparent; border-radius: 8px; padding: 6px; transition: all .15s; }
.cover-card:hover { border-color: #c7d3e2; }
.cover-card.on { border-color: var(--navy); background: var(--navy-l); }
.cover-card canvas { width: 100%; height: auto; display: block; border-radius: 4px; box-shadow: 0 3px 14px rgba(20,40,70,.18); background: #fff; }
.cover-card .cc-label { font-size: 11px; color: var(--ink-2); text-align: center; margin-top: 7px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,32,48,.5); z-index: 100; display: grid; place-items: center; padding: 20px; }
/* display:grid が [hidden] の display:none を打ち消すため、明示的に消す */
.modal[hidden] { display: none !important; }
.modal-box { background: #fff; border-radius: 12px; width: min(760px, 100%); max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-body textarea { min-height: 340px; }
.steps-list { margin: 0 0 16px; padding-left: 20px; font-size: 13px; color: var(--ink-2); line-height: 1.9; }
.steps-list li { margin-bottom: 2px; }
.steps-list a { color: var(--navy); }
.alert:empty { display: none; }

.app-footer { border-top: 1px solid var(--line); background: #fff; padding: 14px 20px; text-align: center; font-size: 11px; color: var(--ink-3); }

/* ---------- 画面切替 / 起動 ---------- */
.screen[hidden] { display: none !important; }
.screen.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.boot { text-align: center; color: var(--ink-3); font-size: 13px; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto 12px;
  border: 3px solid var(--navy-l); border-top-color: var(--navy);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ログイン ---------- */
.auth-box {
  width: min(420px, 100%); background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: 0 10px 40px rgba(20,40,70,.10);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-sub { white-space: normal; line-height: 1.5; }
.tabs-sm { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; margin-bottom: 16px; }
.tab-sm {
  flex: 1; border: 0; background: none; padding: 7px; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--ink-2);
}
.tab-sm.active { background: #fff; color: var(--navy); font-weight: 700; box-shadow: 0 1px 3px rgba(20,40,70,.10); }
.btn-wide { width: 100%; padding: 10px; margin-top: 4px; }
.auth-foot { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.link-btn { border: 0; background: none; color: var(--navy); cursor: pointer; font-size: 12px; padding: 0; text-decoration: underline; }
.link-btn:hover { color: var(--navy-d); }
.alert {
  font-size: 12px; padding: 9px 12px; border-radius: 7px; margin-bottom: 12px;
  background: #fdf3e3; border: 1px solid #e8d3ac; color: #7d5313; line-height: 1.6;
}
.alert.err { background: #fdecea; border-color: #f0c2bd; color: #8f2f27; }
.alert.ok  { background: #e7f3ec; border-color: #b9dcc8; color: #1f5c42; }
.alert code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }

/* ---------- プロジェクト一覧 ---------- */
main.narrow { max-width: 900px; margin: 0 auto; padding: 24px 20px 64px; }
.mode-badge {
  font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: #f0f2f5; color: var(--ink-3); border: 1px solid var(--line);
}
.mode-badge.on { background: #e7f3ec; border-color: #b9dcc8; color: var(--ok); }
.pj-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fcfdfe; margin-bottom: 8px; flex-wrap: wrap;
}
.pj-row:last-child { margin-bottom: 0; }
.pj-main { min-width: 0; }
.pj-name { font-weight: 700; }
.code { font-family: ui-monospace, monospace; background: var(--navy-l); color: var(--navy); padding: 1px 6px; border-radius: 4px; letter-spacing: .06em; }
.code-big {
  font-family: ui-monospace, monospace; font-size: 28px; letter-spacing: .16em;
  text-align: center; padding: 16px; background: var(--navy-l); color: var(--navy);
  border-radius: 10px; font-weight: 700;
}
.member-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

/* ---------- メンバー表示 ---------- */
.members { display: flex; gap: -4px; }
.mchip {
  width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-grid; place-items: center;
  border: 2px solid #fff; margin-left: -6px;
}
.mchip.more { background: var(--ink-3); }
.save-state.err { color: var(--danger); }
.over-txt { color: var(--danger); }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(24,36,52,.94); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 200; box-shadow: 0 8px 28px rgba(0,0,0,.25); max-width: 90vw;
}
.toast[hidden] { display: none; }

@media print {
  .app-header, .app-footer, .row-actions, .header-actions, .toast { display: none !important; }
  .pane { display: block !important; }
  .card { break-inside: avoid; box-shadow: none; }
  body { background: #fff; }
}
