/* Just in Case. Warm paper and ink, like a folder of papers in a kitchen drawer: calm and practical,
   nothing funereal. The accent is a deep green; the terracotta is the envelope's seal. */
:root {
  --bg: #f5f1e8; --card: #fffdf8; --ink: #26231e; --muted: #6b655b; --line: #e2dbcc; --field: #fffefb;
  --accent: #2f5d57; --on-accent: #ffffff; --accent-soft: #e3ece8; --seal: #b5523b; --done: #2f7a55;
  --shadow: 0 1px 2px rgba(60, 50, 30, .06), 0 2px 10px rgba(60, 50, 30, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a19; --card: #1f2322; --ink: #e8e3d8; --muted: #a39d91; --line: #303634; --field: #191c1b;
    --accent: #86bcaf; --on-accent: #0f1f1c; --accent-soft: #24302d; --seal: #d77a62; --done: #7cc39b;
    --shadow: none;
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, .brand span { font-family: ui-serif, "New York", Georgia, "Times New Roman", serif; font-weight: 500; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.defs { position: absolute; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 500; text-align: center;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { min-height: 52px; padding: 12px 22px; font-size: 17px; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 15px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 14px; min-height: 36px; padding: 0 4px; }
.link-btn:hover { color: var(--ink); }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
body:not(.editing) .bar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; white-space: nowrap; }
.brand svg { width: 30px; height: 30px; flex: none; }
.status { margin-left: auto; color: var(--muted); font-size: 14px; line-height: 1.25; text-align: right; }
#saveTop.attention { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
@media (max-width: 520px) {
  .brand span { display: none; }
  .status { font-size: 13px; }
}

/* Welcome */
.welcome { max-width: 640px; margin: 0 auto; padding: 24px 16px calc(40px + env(safe-area-inset-bottom)); }
.hero-mark { width: 64px; height: 64px; display: block; margin: 12px 0 20px; }
.welcome h1 { font-size: clamp(28px, 6.4vw, 40px); line-height: 1.15; text-wrap: balance; }
.lede { margin-top: 14px; font-size: 18px; color: var(--muted); }
.actions { display: grid; gap: 10px; margin-top: 28px; }
@media (min-width: 560px) {
  .actions { grid-template-columns: 1fr 1fr; }
  .actions .primary { grid-column: 1 / -1; }
}
.promises { list-style: none; margin-top: 32px; display: grid; gap: 12px; }
.promises li { padding-left: 26px; position: relative; color: var(--muted); font-size: 16px; }
.promises li::before {
  content: ""; position: absolute; left: 2px; top: 8px; width: 12px; height: 7px;
  border-left: 2.5px solid var(--done); border-bottom: 2.5px solid var(--done); transform: rotate(-45deg);
}
.promises b { color: var(--ink); font-weight: 600; }
.locale { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 28px; font-size: 15px; color: var(--muted); }
.locale select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); min-height: 40px; }
.fine { margin-top: 16px; font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 16px; }

/* Editor */
.editor { max-width: 760px; margin: 0 auto; padding: 8px 16px calc(48px + env(safe-area-inset-bottom)); }
.group { margin-top: 24px; }
.group-head { display: grid; gap: 4px; margin-bottom: 12px; }
.group-head h2 { font-size: 26px; line-height: 1.2; }
.group-head p { color: var(--muted); font-size: 15px; }
.progress { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.meter { flex: 1; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--done); border-radius: 4px; transition: width .3s; }
.progress small { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.sec, .save-panel { scroll-margin-top: 72px; }
.sec { background: var(--card); border: 1px solid var(--line); border-radius: 16px; margin-top: 10px; box-shadow: var(--shadow); }
.sec > summary {
  list-style: none; cursor: pointer; display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px 16px; border-radius: 16px;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after {
  content: ""; width: 9px; height: 9px; margin: 0 4px 4px 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s;
}
.sec[open] > summary::after { transform: rotate(-135deg); margin-bottom: -4px; }
.sec-title { font-weight: 600; font-size: 17px; line-height: 1.3; }
.sec-meta { color: var(--muted); font-size: 14px; white-space: nowrap; }
.tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); position: relative; flex: none; }
.sec.done .tick { background: var(--done); border-color: var(--done); }
.sec.done .tick::after {
  content: ""; position: absolute; left: 5px; top: 4px; width: 8px; height: 5px;
  border-left: 2px solid var(--card); border-bottom: 2px solid var(--card); transform: rotate(-45deg);
}
@media (max-width: 420px) { .sec-meta { display: none; } .sec > summary { grid-template-columns: auto 1fr auto; } }
.sec-body { padding: 0 16px 16px; display: grid; gap: 14px; }
.intro { color: var(--muted); font-size: 15px; }

.field { display: grid; gap: 4px; }
.field > label, .field > span { font-size: 15px; font-weight: 500; }
.hint { color: var(--muted); font-size: 13.5px; line-height: 1.4; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--field);
  font-size: 16px; line-height: 1.4; resize: none; overflow: hidden;
}
.field textarea { min-height: 72px; }
.field.big textarea { min-height: 180px; }
.field input:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }

.rows { display: grid; gap: 10px; }
.rows:empty { display: none; }
.row { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 4px; background: var(--bg); }
.row-fields { display: grid; gap: 10px; }
@media (min-width: 600px) {
  .row-fields { grid-template-columns: 1fr 1fr; align-items: end; } /* boxes line up even when only one has a hint */
  .row-fields .field:first-child { grid-column: 1 / -1; }
}
.row .field > label { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.row .field:first-child > label { color: var(--ink); }
.row .remove { justify-self: end; }
.add-row { justify-self: start; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chips:not(:has(.chip:not([hidden]))) { display: none; }
.chips > span { color: var(--muted); font-size: 13.5px; margin-right: 2px; }
.chip {
  border: 1px dashed var(--muted); background: none; border-radius: 999px; padding: 5px 12px; min-height: 34px;
  font-size: 14px; color: var(--ink); cursor: pointer; text-align: left;
}
.chip::before { content: "+ "; color: var(--muted); }
.chip:hover { border-style: solid; background: var(--accent-soft); }

.sec-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; border-top: 1px solid var(--line); margin-top: 2px; padding-top: 12px; }
.none { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); cursor: pointer; min-height: 40px; }
.none input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Save panel */
.save-panel { margin-top: 32px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px 18px; box-shadow: var(--shadow); }
.save-panel h2 { font-size: 26px; }
.save-panel.prompt { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.steps { margin: 12px 0 0 22px; display: grid; gap: 8px; color: var(--muted); font-size: 15.5px; }
.steps b { color: var(--ink); }
.save-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.msg { margin-top: 10px; font-size: 15px; font-weight: 500; }
.msg:empty { display: none; }
.msg.error { color: var(--seal); }
.extra { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 10px; }
.extra[open] { gap: 12px; }
.extra summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.extra p { color: var(--muted); font-size: 15px; }
.extra .btn { justify-self: start; }
.extra .field input { max-width: 360px; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }

/* Dialogs */
.dialog {
  width: min(480px, calc(100% - 32px)); margin: auto; padding: 22px; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--ink);
}
.dialog::backdrop { background: rgba(20, 18, 15, .5); }
.dialog h2 { font-size: 24px; line-height: 1.2; margin-bottom: 10px; }
.dialog p { color: var(--muted); font-size: 15px; margin-top: 6px; }
.dialog .field { margin-top: 12px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.found { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.found:empty { display: none; }
.found li { min-width: 40px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--muted); }
.found li.ok { background: var(--done); border-color: var(--done); color: var(--card); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 15px; box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
