:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --paper: #fff;
  --paper2: #f8f9f9;
  --ink: #273747;
  --muted: #6c7a88;
  --line: #e2e6e5;
  --accent: #f8aa66;
  --mint: #d7f4e6;
  --orange: #fff0dc;
  --violet: #eee6fc;
  --blue: #e3effd;
  --shade: #fff9f3;
  --shadow: 0 12px 35px #2634440a;
  --focus: #fff0d9;
  --next: #d9f3e9;
  --shelf: #e8edf3;
  --maintaining: #dbeafb;
  --archived: #e7e8eb;
  --input: #fff;
  --danger: #a7404c;
  --success: #26745a;
  --stage-idea-bg: #e9e5fc;
  --stage-idea-fg: #614b92;
  --stage-prototype-bg: #e2f2ff;
  --stage-prototype-fg: #275d8d;
  --stage-development-bg: #ffdfbf;
  --stage-development-fg: #85521c;
  --stage-usable-bg: #d7f2e2;
  --stage-usable-fg: #2b7751;
  --stage-published-bg: #d9e8fc;
  --stage-published-fg: #28578b;
  --stage-retired-bg: #e6e8eb;
  --stage-retired-fg: #5d6674;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131b26;
  --paper: #202c3a;
  --paper2: #1b2633;
  --ink: #eef2f6;
  --muted: #a5b4c5;
  --line: #374658;
  --accent: #e8a465;
  --mint: #264e43;
  --orange: #543a24;
  --violet: #44385d;
  --blue: #304b69;
  --shade: #302d30;
  --shadow: 0 12px 35px #0002;
  --focus: #68472f;
  --next: #315f51;
  --shelf: #364456;
  --maintaining: #2c516f;
  --archived: #39404a;
  --input: #192634;
  --danger: #ffadb3;
  --success: #89dfbc;
  --stage-idea-bg: #45395e;
  --stage-idea-fg: #dfcffd;
  --stage-prototype-bg: #294963;
  --stage-prototype-fg: #bddffa;
  --stage-development-bg: #59432e;
  --stage-development-fg: #ffd5ac;
  --stage-usable-bg: #2b5040;
  --stage-usable-fg: #b8efcd;
  --stage-published-bg: #2c486a;
  --stage-published-fg: #c6dcfb;
  --stage-retired-bg: #424750;
  --stage-retired-fg: #ced2da;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; min-height: 100%; background: var(--bg); }
body {
  min-height: 100%; margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.48 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, textarea, select { font: inherit; }
button, .btn, .tab, summary { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 1.12rem; margin: 0; }
h2 { font-size: 1.56rem; letter-spacing: -.035em; margin-bottom: 3px; }
h3 { font-size: 1.04rem; margin-bottom: 6px; }
small, .muted { color: var(--muted); }
a { color: inherit; }
.small { font-size: 12px; }
.container { width: min(1200px, calc(100% - 34px)); margin: auto; }
.hide { display: none !important; }
.centre { text-align: center; }
.inline-row { display: flex; gap: 7px; align-items: center; }
.full { display: block; width: 100%; margin-top: 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.offline-banner {
  position: sticky; top: 0; z-index: 100; padding: 9px 18px; text-align: center;
  background: #7c3f16; color: #fff; font-size: 13px; font-weight: 700;
}

.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.auth-card {
  width: min(520px, 100%); padding: clamp(24px, 5vw, 42px); background: var(--paper);
  border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 80px #1e2e3a1c;
}
.auth-brand { margin-bottom: 30px; }
.auth-card h2 { margin-bottom: 8px; }
.auth-actions { display: grid; gap: 9px; margin-top: 22px; }
.auth-status { margin: 14px 0 0; padding: 11px 12px; border-radius: 11px; background: var(--shade); color: var(--danger); }
.auth-foot { margin: 24px 0 0; text-align: center; }
.back-link { border: 0; background: none; color: var(--muted); padding: 0; margin-bottom: 18px; }

.topbar { background: var(--paper); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top-inner { padding: 15px 0 8px; display: flex; gap: 15px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px;
  background: var(--accent); color: #40301e; font-size: 26px; font-weight: 900; transform: rotate(-5deg);
}
.brand span { display: block; color: var(--muted); font-size: 11px; margin-top: -3px; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.sync-state { color: var(--muted); font-size: 12px; min-width: 68px; text-align: right; }
.sync-state.saving { color: #a0661d; }
.sync-state.saved { color: var(--success); }
.sync-state.error { color: var(--danger); }
.mode-strip { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 11px; }
.mode-badge { border-radius: 100px; padding: 3px 7px; background: var(--mint); color: var(--ink); font-weight: 800; }
.mode-badge.local { background: var(--violet); }
.btn {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 9px 13px;
  min-height: 42px; border-radius: 12px; font-weight: 650;
}
.btn:hover { filter: brightness(.97); border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.soft { background: var(--orange); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.tiny { min-height: 33px; padding: 6px 10px; font-size: 12px; }
.btn.danger, .danger { color: var(--danger); }
.btn.icon-only { width: 42px; padding: 8px; }
.tabs { display: flex; gap: 6px; padding: 10px 0; }
.tab { border: 0; border-radius: 12px; background: transparent; padding: 9px 14px; color: var(--muted); font-weight: 750; }
.tab.active { background: var(--ink); color: var(--bg); }
.tab-count { font-size: 11px; opacity: .75; margin-left: 5px; }

.main { padding: 29px 0 50px; }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 17px; }
.intro p { color: var(--muted); margin: 0; }
.pill {
  border-radius: 100px; padding: 5px 9px; font-size: 11px; font-weight: 800; display: inline-flex;
  align-items: center; white-space: nowrap; gap: 4px; background: var(--shelf); color: var(--ink);
}
.pill.focus { background: var(--focus); }
.pill.next { background: var(--next); }
.pill.shelf { background: var(--shelf); }
.pill.maintaining { background: var(--maintaining); }
.pill.archived { background: var(--archived); }
.pill.stage-idea { background: var(--stage-idea-bg); color: var(--stage-idea-fg); }
.pill.stage-prototype { background: var(--stage-prototype-bg); color: var(--stage-prototype-fg); }
.pill.stage-development { background: var(--stage-development-bg); color: var(--stage-development-fg); }
.pill.stage-usable { background: var(--stage-usable-bg); color: var(--stage-usable-fg); }
.pill.stage-published { background: var(--stage-published-bg); color: var(--stage-published-fg); }
.pill.stage-retired { background: var(--stage-retired-bg); color: var(--stage-retired-fg); }
.pill.stage-other { background: var(--violet); }

.focus-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.focus-card {
  border: 1px solid var(--line); background: var(--paper); border-radius: 20px; min-height: 300px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
.focus-card:nth-child(1) { border-top: 5px solid #f5ae75; }
.focus-card:nth-child(2) { border-top: 5px solid #a2dcca; }
.focus-card:nth-child(3) { border-top: 5px solid #c5b1ee; }
.focus-card-inner { padding: 17px 20px 20px; display: flex; flex-direction: column; flex: 1; }
.focus-card .card-top { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.focus-card h3 { font-size: 1.22rem; letter-spacing: -.025em; margin: 13px 0 8px; overflow-wrap: anywhere; }
.where {
  color: var(--muted); font-size: 14px; flex: 1; white-space: pre-line; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.thumb { display: block; object-fit: cover; background: var(--paper2); border: 0; flex: none; aspect-ratio: 3 / 2; }
.thumb-placeholder { background: var(--paper2) url("placeholder.svg") center / cover no-repeat; }
.focus-thumb { width: 100%; }
.row-thumb { width: 91px; border-radius: 10px; }
.next-thumb { width: 72px; border-radius: 8px; }
.drawer-thumb { width: min(300px, 100%); border-radius: 12px; margin-top: 8px; }
.step-preview { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 13px; font-size: 13px; }
.step-preview b { display: block; font-size: 11px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; margin-bottom: 3px; }
.card-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 14px; }
.placeholder {
  background: var(--paper2); border: 2px dashed var(--line); min-height: 290px; justify-content: center;
  align-items: center; text-align: center; padding: 25px; color: var(--muted);
}
.placeholder .plus { font-size: 28px; background: var(--paper); border: 1px solid var(--line); border-radius: 15px; width: 54px; height: 54px; margin-bottom: 13px; color: var(--ink); }
.section { margin-top: 31px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2 { font-size: 1.24rem; margin: 0; }
.section-head p { font-size: 13px; color: var(--muted); margin: 0; }
.list { border: 1px solid var(--line); background: var(--paper); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.project-row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.project-row:last-child { border-bottom: 0; }
.row-info { min-width: 0; flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(160px, 1fr); gap: 13px; align-items: center; }
.row-info.next { grid-template-columns: minmax(0, 1fr) minmax(150px, .9fr); }
.row-name { font-size: 15px; font-weight: 800; background: none; border: 0; text-align: left; padding: 0; color: var(--ink); overflow-wrap: anywhere; }
.row-name:hover { text-decoration: underline; }
.row-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.row-text { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; white-space: pre-line; }
.row-text strong { color: var(--ink); }
.row-desc { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; margin: 3px 0 5px; font-size: 13px; color: var(--muted); }
.row-actions { display: flex; align-items: center; gap: 7px; flex: none; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.stat { padding: 16px 18px; text-align: left; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); }
.stat:hover { border-color: var(--accent); transform: translateY(-1px); }
.stat strong { font-size: 24px; display: block; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.filters { display: grid; grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(118px, 1fr)); gap: 9px; margin: 18px 0 15px; }
.field, .textarea { width: 100%; padding: 10px 12px; min-height: 43px; border-radius: 11px; border: 1px solid var(--line); background: var(--input); color: var(--ink); }
.textarea { resize: vertical; min-height: 85px; }
.field.input-big { font-size: 19px; font-weight: 750; }
.compact-select { width: auto; min-height: 35px; padding: 6px; font-size: 12px; }
.result-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.footer { text-align: center; color: var(--muted); padding: 0 18px calc(36px + env(safe-area-inset-bottom)); font-size: 12px; }
.footer b { color: var(--ink); }
.welcome { padding: 26px; border-radius: 20px; background: var(--shade); border: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 23px; }
.welcome h2 { margin: 0 0 5px; }
.welcome p { margin: 0; color: var(--muted); }

.overlay { position: fixed; inset: 0; background: #121c2ba9; z-index: 20; display: flex; justify-content: flex-end; padding-top: env(safe-area-inset-top); }
.drawer { background: var(--bg); width: min(650px, 100%); height: 100%; overflow-y: auto; overscroll-behavior: contain; box-shadow: -15px 0 55px #0002; }
.drawer-head { position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line); background: var(--paper); padding: 15px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.drawer-head strong { font-size: 17px; }
.drawer-body { padding: 20px 20px calc(50px + env(safe-area-inset-bottom)); }
.edit-card { padding: 19px; background: var(--paper); border: 1px solid var(--line); border-radius: 17px; margin-bottom: 15px; }
.edit-card h3 { margin-bottom: 13px; }
.edit-card.accent { border-left: 5px solid var(--accent); }
.label { font-size: 12px; color: var(--muted); font-weight: 750; display: block; margin-bottom: 6px; }
.form-block { margin-bottom: 13px; }
.form-block:last-child { margin-bottom: 0; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tiny-hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.steps { display: grid; gap: 8px; margin: 12px 0; }
.step-item { display: flex; gap: 9px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper2); }
.step-item input[type="checkbox"] { width: 20px; height: 20px; accent-color: #69bca0; flex: none; margin: 3px 0; }
.step-item span { flex: 1; overflow-wrap: anywhere; }
.step-item.done span { text-decoration: line-through; color: var(--muted); }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; padding: 2px 6px; line-height: 1; }
.icon-btn:hover { color: var(--danger); }
.inline-add { display: flex; gap: 8px; }
.inline-add .field { min-width: 0; }
.journal-entry { border-left: 3px solid #cdb6ec; padding: 4px 0 12px 12px; margin: 13px 0; white-space: pre-line; overflow-wrap: anywhere; }
.journal-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.journal-top input { min-height: 34px; padding: 4px 8px; max-width: 170px; font-size: 12px; }
.journal-top .icon-btn { margin-left: auto; }
.details-toggle { font-weight: 750; cursor: pointer; }
.details-toggle + div { padding-top: 17px; }
.project-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 3px; }

.modal-wrap { position: fixed; inset: 0; z-index: 30; background: #111b29b3; display: grid; place-items: center; padding: max(15px, env(safe-area-inset-top)) 15px max(15px, env(safe-area-inset-bottom)); }
.modal { background: var(--paper); border: 1px solid var(--line); width: min(540px, 100%); max-height: 90dvh; overflow: auto; border-radius: 20px; padding: 23px; box-shadow: 0 20px 70px #0003; }
.modal.wide { width: min(820px, 100%); }
.modal h3 { font-size: 21px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.choice { border: 1px solid var(--line); border-radius: 12px; background: var(--paper2); padding: 10px 12px; text-align: left; width: 100%; margin: 5px 0; font-weight: 700; color: var(--ink); }
.choice:hover { border-color: var(--accent); }
.picker-results { max-height: 48vh; overflow: auto; margin-top: 12px; }
.picker-result { display: flex; gap: 9px; align-items: center; justify-content: space-between; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--paper2); color: var(--ink); border-radius: 12px; padding: 11px 12px; margin-bottom: 7px; }
.picker-result:hover { border-color: var(--accent); }
.picker-result small { display: block; font-weight: 400; line-height: 1.4; }
.key-box { padding: 14px; border: 2px solid var(--accent); border-radius: 13px; background: var(--shade); word-break: break-all; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; user-select: all; }
.comparison { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.comparison > div { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper2); white-space: pre-wrap; overflow-wrap: anywhere; }

.menu-wrap { position: fixed; inset: 0; z-index: 25; background: #131c2b9c; display: flex; justify-content: flex-end; padding-top: env(safe-area-inset-top); }
.menu { width: min(345px, 88vw); height: 100%; overflow: auto; background: var(--paper); padding: 19px 19px calc(19px + env(safe-area-inset-bottom)); box-shadow: -10px 0 35px #0003; }
.menu h2 { font-size: 21px; }
.menu .btn { display: block; width: 100%; text-align: left; margin: 8px 0; }
.menu-title { display: flex; align-items: center; justify-content: space-between; }
.menu-title .btn { width: auto; margin: 0; }
.menu-rule { border-top: 1px solid var(--line); padding-top: 17px; margin-top: 17px; }
.import-table { width: 100%; font-size: 12px; border-collapse: collapse; margin-top: 10px; }
.table-scroll { overflow-x: auto; }
.import-table td, .import-table th { border-bottom: 1px solid var(--line); padding: 8px 5px; text-align: left; vertical-align: top; }
.import-table th { color: var(--muted); }
.import-table select { font-size: 12px; max-width: 100%; }
.notice { border-radius: 12px; padding: 12px; background: var(--shade); border: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; z-index: 60; transform: translateX(-50%); padding: 12px 17px; background: var(--ink); color: var(--bg); border-radius: 12px; box-shadow: 0 10px 26px #0003; max-width: calc(100% - 36px); font-size: 13px; }
#scrollSentinel { height: 15px; }

@media (max-width: 940px) {
  .focus-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-info, .row-info.next { grid-template-columns: minmax(0, 1fr); }
  .row-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  .sync-state { display: none; }
}

@media (max-width: 600px) {
  .container { width: calc(100% - 24px); }
  .top-inner { padding: 11px 0 6px; gap: 8px; }
  .toolbar { gap: 5px; }
  .toolbar .btn { padding: 8px 9px; font-size: 13px; }
  .toolbar .btn.icon-only { width: 40px; }
  .toolbar #shareApp { display: none; }
  .wide-label { display: none; }
  .brand .logo { width: 38px; height: 38px; }
  .brand span { display: none; }
  .focus-grid { grid-template-columns: 1fr; }
  .focus-card, .placeholder { min-height: 0; }
  .focus-card-inner { padding: 15px; }
  .placeholder { padding: 20px; }
  .main { padding-top: 18px; }
  .intro h2 { font-size: 1.42rem; }
  .stat { padding: 14px; }
  .section { margin-top: 26px; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters #search { grid-column: 1 / -1; }
  .field, .textarea, .compact-select, .journal-top input { font-size: 16px; }
  .project-row { gap: 10px; padding: 12px; }
  .row-thumb { width: 67px; }
  .next-thumb { width: 60px; }
  .row-actions .btn { padding: 6px 8px; font-size: 11px; }
  .row-meta { gap: 4px; }
  .pill { font-size: 10px; padding: 4px 7px; }
  .two-col, .comparison { grid-template-columns: 1fr; }
  .edit-card { padding: 15px; }
  .drawer-body { padding: 14px 14px calc(40px + env(safe-area-inset-bottom)); }
  .drawer-head { padding: 13px; }
  .welcome { display: block; padding: 19px; }
  .welcome .btn { margin-top: 14px; }
  .modal { padding: 18px; }
  .project-row .row-text { display: none; }
  .project-row.portfolio-row .row-desc { -webkit-line-clamp: 2; }
  .project-foot { align-items: flex-start; flex-direction: column; }
  .auth-shell { padding: 12px; }
  .auth-card { padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
