:root {
  --bg: #f4f5f3; --surface: #ffffff; --sunk: #eceeeb; --text: #1a201e; --muted: #626b68; --line: #d9ddda;
  --accent: #1f47c6; --accent-soft: #e4e9fb; --on-accent: #ffffff;
  --todo: #6d5bd0; --todo-soft: #ece9fb;
  --doing: #1f47c6; --doing-soft: #e4e9fb;
  --review: #a35a00; --review-soft: #fbefdc;
  --done: #17803d; --done-soft: #e0f2e6;
  --dropped: #6f7774; --dropped-soft: #e7e9e8;
  --ended: #9aa29f; --ended-soft: #eef0ef;
  --bad: #c53030;
  --shadow: 0 1px 2px rgba(20,30,28,.06), 0 2px 8px rgba(20,30,28,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1a1f1d; --sunk: #151a18; --text: #e5e9e7; --muted: #98a29e; --line: #2c3431;
    --accent: #8aa4ff; --accent-soft: #1f2a4d; --on-accent: #0d1430;
    --todo: #b3a7ff; --todo-soft: #29244a;
    --doing: #8aa4ff; --doing-soft: #1f2a4d;
    --review: #f2b45a; --review-soft: #3a2c14;
    --done: #5fd38a; --done-soft: #16301f;
    --dropped: #a3aca8; --dropped-soft: #262d2a;
    --ended: #7d8783; --ended-soft: #1f2523;
    --bad: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 12px; }
.when { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.top { display: flex; align-items: center; gap: 12px; padding: calc(10px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 10px calc(16px + env(safe-area-inset-left, 0px)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
#q { flex: 1 1 220px; min-width: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--sunk); }
.toggle { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; white-space: nowrap; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .5; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .row-item:focus-visible, .pcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.view { padding: 16px; max-width: 1280px; margin: 0 auto; }
.empty { color: var(--muted); font-size: 13px; padding: 16px 4px; text-align: center; }
.banner { padding: 8px 12px; border-radius: 8px; background: var(--review-soft); color: var(--review); font-size: 13px; }

.pill { display: inline-flex; align-items: center; font-size: 11px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; font-weight: 500; }
.sdot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.s-todo { --c: var(--todo); --cs: var(--todo-soft); }
.s-doing { --c: var(--doing); --cs: var(--doing-soft); }
.s-review { --c: var(--review); --cs: var(--review-soft); }
.s-done { --c: var(--done); --cs: var(--done-soft); }
.s-dropped { --c: var(--dropped); --cs: var(--dropped-soft); }
.s-ended { --c: var(--ended); --cs: var(--ended-soft); }
.pill { background: var(--cs); color: var(--c); }
.sdot { background: var(--c); }

/* ---- home: project wall ---- */
.wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 10px; align-content: start; cursor: pointer; text-decoration: none; color: inherit; box-shadow: var(--shadow); min-width: 0; }
.pcard:hover { border-color: var(--accent); }
.pcard .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; min-width: 0; }
.pcard .name { font-weight: 600; font-size: 16px; display: flex; gap: 8px; align-items: center; min-width: 0; }
.pcard .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--sunk); }
.seg span { display: block; background: var(--c); }
.legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend b { color: var(--text); font-weight: 600; margin-left: 3px; }
.mini { display: grid; gap: 6px; }
.mini .r { display: flex; gap: 8px; align-items: center; min-width: 0; }
.mini .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shots { display: flex; gap: 6px; flex-wrap: wrap; }
.shots img { width: 72px; height: 46px; object-fit: cover; border-radius: 5px; border: 1px solid var(--line); background: var(--sunk); }
.more { font-size: 12px; color: var(--accent); }
.pcard.quiet { box-shadow: none; background: transparent; }
.pcard.quiet .name { font-size: 15px; font-weight: 500; }
.pcard .desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.side a.p.quiet { color: var(--muted); }

/* ---- project page ---- */
.proj { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
.side { display: grid; gap: 2px; position: sticky; top: 64px; }
.side .back { font-size: 13px; padding: 6px 8px; text-decoration: none; }
.side a.p { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 7px; text-decoration: none; color: var(--text); border: 1px solid transparent; min-width: 0; }
.side a.p span.n { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.side a.p span.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side a.p[aria-current="page"] { background: var(--surface); border-color: var(--line); font-weight: 600; }
.main { display: grid; gap: 12px; min-width: 0; }
.phead { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.phead h1 { font-size: 20px; margin: 0; display: flex; align-items: center; gap: 8px; }
.phead .spacer { flex: 1; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg-ctl button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; }
.seg-ctl button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.sec { padding: 8px 14px; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--sunk); border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.sec:first-child { border-top: 0; }
.row-item { display: flex; gap: 10px; align-items: center; padding: 9px 14px; border-top: 1px solid var(--line); cursor: pointer; min-width: 0; }
.sec + .row-item { border-top: 0; }
.row-item:hover { background: var(--sunk); }
.row-item .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item .proj-name { color: var(--muted); font-size: 12px; white-space: nowrap; }
.fold { display: block; width: 100%; text-align: left; padding: 9px 14px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--accent); cursor: pointer; font-size: 13px; }
.new-plan { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.new-plan input { flex: 1 1 200px; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--sunk); }

.timeline { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 16px; }
.day { display: grid; gap: 4px; }
.day > .label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .03em; margin-bottom: 4px; }
.entry { display: grid; grid-template-columns: 44px 12px minmax(0, 1fr); gap: 10px; align-items: start; cursor: pointer; padding: 4px 0; border-radius: 6px; }
.entry:hover .t { color: var(--accent); }
.entry .time { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); padding-top: 2px; }
.entry .rail { position: relative; align-self: stretch; }
.entry .rail .sdot { position: absolute; top: 7px; left: 2px; }
.entry .rail::after { content: ""; position: absolute; left: 5.5px; top: 19px; bottom: -8px; width: 1px; background: var(--line); }
.day .entry:last-child .rail::after { display: none; }
.entry .body { display: grid; gap: 5px; min-width: 0; }
.entry .t { font-weight: 500; overflow-wrap: anywhere; }
.entry .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }

/* ---- drawer ---- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 10; display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,.15); }
.drawer-head { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.title-input { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; background: transparent; }
.title-input:hover, .title-input:focus { border-color: var(--line); outline: none; }
.drawer-body { overflow-y: auto; padding: 12px 16px 32px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 12px; margin: 0 0 12px; font-size: 13px; align-items: center; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.facts select { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--sunk); }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.copy { cursor: pointer; border-bottom: 1px dashed var(--muted); }
textarea.note { width: 100%; min-height: 72px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--sunk); resize: vertical; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 12px; }
.tab { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.prompt { border-left: 2px solid var(--accent); padding: 4px 0 4px 12px; margin-bottom: 14px; }
.prompt .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.prompt .text.clamped { max-height: 12em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.linkbtn { font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
h4 { margin: 16px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
ul.files, ul.cmds { list-style: none; margin: 0; padding: 0; }
ul.files li, ul.cmds li { padding: 4px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: baseline; min-width: 0; }
ul.files .p, ul.cmds .p { flex: 1; min-width: 0; overflow-wrap: anywhere; }
ul.cmds .p { white-space: pre-wrap; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; background: var(--sunk); color: var(--muted); white-space: nowrap; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 12px 0 6px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.shot { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--sunk); margin: 0; }
.shot img { display: block; width: 100%; height: 120px; object-fit: cover; cursor: zoom-in; }
.shot .cap { padding: 4px 6px; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; gap: 4px; }
.shot .x { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 2px; }
.dropzone { border: 1px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; color: var(--muted); margin-bottom: 12px; font-size: 13px; cursor: pointer; }
.dropzone.over { border-color: var(--accent); color: var(--accent); }
.confirm { display: inline-flex; gap: 6px; align-items: center; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 20; display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; }

@media (max-width: 599px) {
  .proj { grid-template-columns: 1fr; }
  .side { position: static; display: flex; flex-wrap: wrap; gap: 4px; }
  .side a.p span.n { margin-left: 4px; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: 6px; }
  .toggle { display: none; }
}

/* ---- devices & sign-in ---- */
.modal { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 14px; width: min(460px, 100%); max-height: 100%; overflow: auto; box-shadow: var(--shadow); }
.modal-card h2 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 16px; display: grid; gap: 12px; justify-items: center; text-align: center; }
.modal-body img.qr { width: 220px; height: 220px; image-rendering: pixelated; background: #fff; border-radius: 8px; padding: 8px; }
.pair-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 26px; letter-spacing: .12em; font-weight: 600; }
.modal-body ol { text-align: left; margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: min(380px, 100%); display: grid; gap: 16px; }
.login h1 { margin: 0; font-size: 26px; }
.login-form { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.login-form label { font-weight: 600; font-size: 13px; }
.login-form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--sunk); font-size: 16px; letter-spacing: .04em; }
.login-error { margin: 0; color: var(--bad); font-size: 13px; }
