:root {
  --bg: #f6f5f1;
  --surface: #fffefa;
  --text: #243d35;
  --muted: #66716b;
  --line: #dddeda;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --soft: #e9f0e8;
  --note: #f4ecdf;
  --danger: #a33a2c;
  --warn-bg: #fff0ce;
  --shadow: 0 3px 12px #243d3506;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161e1a;
    --surface: #202b25;
    --text: #ebeee7;
    --muted: #b0bbb2;
    --line: #3c4a40;
    --accent: #9dd2b8;
    --accent-text: #162c22;
    --soft: #2a3b2f;
    --note: #373226;
    --danger: #ffac9c;
    --warn-bg: #443923;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-underline-offset: 3px; }
button, input, textarea, select { font: inherit; }
button, .upload, select {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 18px;
  color: var(--text);
  background: var(--surface);
}
button, .upload, summary, select { cursor: pointer; }
button:hover, .upload:hover, select:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 10px 0; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; }
button.link.danger { color: var(--danger); }
button.icon { padding: 6px 12px; min-width: 44px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
input, textarea {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 4vw, 2.8rem); line-height: 1.15; letter-spacing: -0.045em; margin-bottom: 12px; }
h2 { font-size: 1.125rem; margin-bottom: 0; font-weight: 650; }
h3 { font-size: 1.3rem; line-height: 1.35; letter-spacing: -0.025em; }
main { max-width: 1168px; margin: 0 auto; padding: 0 max(24px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
main:focus { outline: none; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link:focus { display: block; padding: 12px; background: var(--surface); }
.masthead { max-width: 1168px; margin: 0 auto; padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 24px max(24px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 12px; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.03em; text-decoration: none; color: var(--text); }
.brand-mark { background: var(--accent); color: var(--accent-text); display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; }
.connection { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9375rem; }
.connection::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.connection[data-connected="true"]::before { background: var(--accent); }
.welcome { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 36px 0 32px; }
.eyebrow { color: var(--accent); font-size: 0.9375rem; font-weight: 600; margin-bottom: 12px; }
.intro { color: var(--muted); margin-bottom: 0; max-width: 440px; }
.create-actions { display: flex; gap: 10px; flex-shrink: 0; }
form { margin: 0; }
.browse { display: flex; align-items: center; gap: 10px; padding: 16px; margin-bottom: 32px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.search-field { flex: 1; min-width: 0; }
.search-field input { background: var(--bg); }
.reset-search { padding: 10px 4px; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.meta { color: var(--muted); font-size: 0.9375rem; margin: 0; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: stretch; }
.card { display: flex; flex-direction: column; min-width: 0; padding: 24px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); text-decoration: none; overflow-wrap: anywhere; transition: border-color 120ms; }
.card:hover { border-color: var(--accent); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 18px; }
.card-time { color: var(--muted); font-size: 0.9375rem; white-space: nowrap; }
.kind-label { display: inline-flex; gap: 7px; align-items: center; border-radius: 6px; padding: 3px 9px; font-size: 0.9375rem; font-weight: 600; color: var(--accent); background: var(--soft); }
.card-note .kind-label { background: var(--note); color: var(--text); }
.card h3 { margin-bottom: 14px; }
.card h3.untitled { color: var(--muted); }
.preview { margin: 0 0 18px; white-space: pre-line; }
.checklist-preview { padding: 0; list-style: none; display: grid; gap: 8px; white-space: normal; }
.checklist-preview li { display: flex; gap: 10px; align-items: baseline; }
.preview-box { display: inline-block; width: 15px; height: 15px; border: 1px solid var(--muted); border-radius: 4px; flex: none; }
.empty, .checklist-preview .more { color: var(--muted); }
.card-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: auto; color: var(--muted); font-size: 0.9375rem; }
.card-progress { color: var(--accent); }
.card-footer progress { flex: 1 0 100%; height: 6px; border: 0; border-radius: 3px; background: var(--line); color: var(--accent); overflow: hidden; -webkit-appearance: none; appearance: none; }
.card-footer progress::-webkit-progress-bar { background: var(--line); }
.card-footer progress::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
.card-footer progress::-moz-progress-bar { background: var(--accent); border-radius: 3px; }
.empty-state { grid-column: 1 / -1; text-align: center; padding: 48px 24px; border: 1px dashed var(--line); border-radius: 18px; }
.empty-state p { max-width: 480px; color: var(--muted); margin: 0 auto 16px; }
.empty-mark { display: inline-grid; place-items: center; width: 56px; height: 56px; background: var(--soft); color: var(--accent); border-radius: 18px; font-size: 1.7rem; margin-bottom: 20px; }
.empty-state h3 { margin-bottom: 10px; }
.device-help { margin-top: 36px; padding: 20px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9375rem; }
summary { min-height: 44px; padding: 10px 0; }
.device-help p { max-width: 720px; margin: 8px 0 14px; }
.account { display: flex; justify-content: space-between; gap: 12px 24px; align-items: baseline; flex-wrap: wrap; padding-top: 12px; }
.account-actions { display: flex; gap: 24px; align-items: flex-start; font-size: 0.9375rem; }
.account-menu { color: var(--muted); }
.banner { position: fixed; z-index: 5; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(560px, calc(100% - 32px)); padding: 12px 20px; border-radius: 12px; background: var(--warn-bg); color: var(--text); box-shadow: 0 4px 16px #0000002e; text-align: center; font-size: 0.9375rem; }
.note-page { max-width: 880px; }
.bar { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-bottom: 12px; }
.editor-bar { position: sticky; top: 0; z-index: 4; padding: max(16px, env(safe-area-inset-top)) 0 12px; background: var(--bg); }
.back { flex: 1 1 auto; font-weight: 600; text-decoration: none; padding: 10px 0; }
.save-status { font-size: 0.9375rem; color: var(--muted); }
.note-menu { position: relative; }
.note-menu summary { color: var(--muted); }
.note-menu form { position: absolute; top: 100%; right: 0; z-index: 2; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); white-space: nowrap; }
.paper { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 20px; padding: 32px; }
.paper-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 28px; }
#editor { display: grid; gap: 16px; margin-bottom: 20px; }
#editor input[name="title"] { font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.3; font-weight: 650; letter-spacing: -0.03em; border-color: transparent; background: transparent; padding: 6px 0; border-radius: 2px; }
#editor textarea { min-height: 40vh; resize: none; background: transparent; border-color: transparent; padding: 8px 0; line-height: 1.8; border-radius: 2px; overflow-wrap: anywhere; }
.conflict { background: var(--warn-bg); border-radius: 12px; padding: 16px; margin-bottom: 20px; }
.conflict .theirs { background: var(--surface); border-radius: 8px; padding: 12px; margin: 12px 0; max-height: 40vh; overflow: auto; }
.conflict pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; }
.theirs-title { font-weight: 600; margin: 0 0 4px; }
.conflict button { margin: 4px 0; }
.add-item { display: flex; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.items { display: grid; }
.item { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); padding: 6px 0; }
.item-check { display: grid; place-items: center; min-width: 44px; min-height: 44px; cursor: pointer; }
.item input[type="checkbox"] { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); }
.item .text { border-color: transparent; background: transparent; padding: 10px 4px; }
.item .text:focus { background: var(--bg); }
.item.is-done .text { color: var(--muted); text-decoration: line-through; }
.item-menu { position: relative; }
.item-menu summary { display: grid; place-items: center; list-style: none; border-radius: 8px; min-width: 44px; font-weight: 700; color: var(--muted); }
.item-menu summary::-webkit-details-marker { display: none; }
.item-menu[open] summary { background: var(--soft); }
.item-actions { position: absolute; top: 100%; right: 0; z-index: 3; display: flex; gap: 6px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.done { margin-top: 20px; }
.done summary, .list-empty { color: var(--muted); }
.list-empty { margin: 20px 0; }
.files { margin-top: 28px; padding: 24px 32px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.file { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.file img { max-width: 100%; max-height: 160px; border-radius: 8px; display: block; }
.file a { flex: 1; min-width: 0; }
.upload { display: inline-flex; position: relative; align-items: center; margin-top: 16px; overflow: hidden; }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
.login { max-width: 440px; margin: 12vh auto 0; padding: 36px; display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.login h1 { font-size: 2rem; text-align: center; margin: 0; }
.login-intro { color: var(--muted); text-align: center; margin-bottom: 12px; }
.login .meta { margin-top: 8px; text-align: center; }
.error { color: var(--danger); margin: 0; }
@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .welcome { align-items: flex-start; flex-direction: column; }
}
@media (max-width: 600px) {
  main { padding-right: max(16px, env(safe-area-inset-right)); padding-left: max(16px, env(safe-area-inset-left)); }
  .masthead { padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); }
  .brand { font-size: 1.125rem; gap: 8px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 10px; }
  .welcome { padding: 16px 0 24px; gap: 20px; }
  .welcome .eyebrow, .welcome .intro { display: none; }
  .welcome h1 { margin-bottom: 0; }
  .create-actions { width: 100%; }
  .create-actions form { flex: 1; }
  .create-actions button { width: 100%; }
  .browse { flex-wrap: wrap; padding: 12px; margin-bottom: 28px; }
  .search-field { flex-basis: 100%; }
  .browse select { flex: 1; min-width: 0; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .card { padding: 20px; }
  .card-top { margin-bottom: 14px; }
  .account { display: block; }
  .account-actions { margin-top: 8px; }
  .paper, .files { padding: 20px 16px; border-radius: 16px; }
  .paper-heading { flex-wrap: wrap; margin-bottom: 24px; }
  .bar { gap: 8px 12px; }
  .login { margin-top: 8vh; padding: 28px 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
