:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #66706b;
  --line: #dfe2dd;
  --accent: #2f6f5e;
  --danger: #a33a2c;
  --warn-bg: #fff4d6;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161917;
    --surface: #202522;
    --text: #e9ece8;
    --muted: #9aa49f;
    --line: #333a36;
    --accent: #6cc0a5;
    --danger: #ef8a7a;
    --warn-bg: #3d3420;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}

h1 { font-size: 1.5rem; margin: 0; flex: 1; }
h2 { font-size: 1.05rem; margin: 0 0 4px; }

button, .upload {
  font: inherit;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
}
button:hover, .upload:hover { border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--muted); padding: 6px 0; min-height: 0; text-decoration: underline; }
button.icon { padding: 4px 10px; min-width: 40px; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.bar form { margin: 0; }
.back { color: var(--accent); text-decoration: none; font-weight: 600; flex: 1; }
.meta { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }

.banner { position: sticky; top: 0; z-index: 2; background: var(--warn-bg); text-align: center; padding: 6px; font-size: 0.9rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  color: inherit;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.card:hover { border-color: var(--accent); }
.preview { margin: 0; white-space: pre-line; color: var(--text); }
ul.preview { padding-left: 1.1em; }
.empty { color: var(--muted); }
.account { display: flex; gap: 16px; margin-top: 32px; }

#editor { display: grid; gap: 10px; margin-bottom: 16px; }
#editor input[name="title"] { font-size: 1.25rem; font-weight: 600; }
#editor textarea { min-height: 40vh; resize: vertical; field-sizing: content; overflow-wrap: anywhere; }

.conflict { background: var(--warn-bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.conflict .theirs { background: var(--surface); border-radius: 8px; padding: 8px 10px; margin: 8px 0; max-height: 40vh; overflow: auto; }
.conflict pre { white-space: pre-wrap; font: inherit; margin: 0; }
.theirs-title { font-weight: 600; margin: 0 0 4px; }

.add-item { display: flex; gap: 8px; margin-bottom: 12px; }
.items { display: grid; gap: 6px; }
.item { display: flex; align-items: center; gap: 6px; }
.item input[type="checkbox"] { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }
.item .text { border-color: transparent; background: transparent; padding: 8px; }
.item .text:focus { background: var(--surface); }
.item.is-done .text { color: var(--muted); text-decoration: line-through; }
.done { margin-top: 16px; }
.done summary { color: var(--muted); cursor: pointer; margin-bottom: 8px; }

.files { margin-top: 28px; }
.file { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; overflow-wrap: anywhere; }
.file img { max-width: 160px; max-height: 160px; border-radius: 8px; display: block; }
.file a { color: var(--accent); flex: 1; }
.upload { display: inline-block; margin-top: 8px; }
.upload input { display: none; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

.login { max-width: 340px; margin: 18vh auto 0; display: grid; gap: 10px; }
.login h1 { text-align: center; margin-bottom: 8px; }
.error { color: var(--danger); margin: 0; }
