:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #24211d;
  --muted: #7a7268;
  --line: #e4ddd2;
  --accent: #b5562f;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --banner: #fff3d6;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --card: #262421;
    --text: #ece7df;
    --muted: #a39b90;
    --line: #3a3732;
    --accent: #e0835c;
    --accent-text: #1b1a18;
    --danger: #f2827a;
    --banner: #3b3220;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 0 1rem; }
.center-text { text-align: center; }

.screen { min-height: 100vh; max-width: 760px; margin: 0 auto; padding-bottom: 6rem; }
.screen.center { display: flex; align-items: center; justify-content: center; padding: 1rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.narrow { width: 100%; max-width: 420px; }
.card h1 { margin-bottom: .5rem; }

label { display: block; margin: .9rem 0; font-weight: 600; font-size: .95rem; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
label.check { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-weight: 400; }
label.check .hint { flex-basis: 100%; }
input, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .7rem;
  width: 100%;
  margin-top: .3rem;
}
input[type="checkbox"] { width: auto; margin: 0; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .55rem 1rem;
  cursor: pointer;
  background: transparent;
  color: var(--text);
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary.small { padding: .4rem .9rem; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.ghost { padding: .4rem .6rem; color: var(--accent); }
.danger-text { color: var(--danger) !important; }
form .primary { width: 100%; margin-top: .5rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1em; margin: .3rem 0; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem .75rem;
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar-actions { display: flex; gap: .15rem; align-items: center; }

.toolbar { padding: .75rem 1rem 0; }
.toolbar input { margin: 0; }

.note-list { list-style: none; margin: 0; padding: .75rem 1rem; display: grid; gap: .6rem; }
.note-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  cursor: pointer;
}
.note-item:hover { border-color: var(--accent); }
.note-item .t { font-weight: 700; overflow-wrap: anywhere; }
.note-item .s {
  color: var(--muted); font-size: .9rem; margin-top: .15rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.note-item .m { color: var(--muted); font-size: .78rem; margin-top: .35rem; }

.fab {
  position: fixed; right: 1.25rem; bottom: max(1.25rem, env(safe-area-inset-bottom));
  width: 3.5rem; height: 3.5rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  font-size: 1.8rem; line-height: 1; padding: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}

.banner { background: var(--banner); padding: .7rem 1rem; font-size: .9rem; display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.editor { padding: 1rem; }
.ed-title { font-size: 1.3rem; font-weight: 700; border: none; background: transparent; padding: .2rem 0; margin: 0; }
.ed-title:focus { outline: none; }
#ed-meta { margin: .1rem 0 .6rem; }
.ed-body { min-height: 45vh; resize: vertical; line-height: 1.7; background: var(--card); }
.editor input:disabled, .editor textarea:disabled { opacity: .8; }

.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; margin-top: .75rem; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.thumb .rm {
  position: absolute; top: 4px; right: 4px;
  width: 1.8rem; height: 1.8rem; padding: 0; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; font-size: 1rem; line-height: 1;
}
.thumb .badge { position: absolute; left: 4px; bottom: 4px; font-size: .7rem; background: rgba(0,0,0,.6); color: #fff; padding: 0 .35rem; border-radius: 4px; }
.add-photo {
  display: inline-block; margin-top: .75rem; padding: .55rem 1rem;
  border: 1px dashed var(--accent); border-radius: 8px; color: var(--accent);
  cursor: pointer; font-weight: 600;
}
.trash-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }

.settings { padding: 1rem; display: grid; gap: 1rem; }

.viewer {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

.modal {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-box {
  background: var(--card); border-radius: var(--radius); padding: 1.25rem;
  width: 100%; max-width: 480px; max-height: 85vh; overflow: auto;
}
#modal-body { white-space: pre-wrap; overflow-wrap: anywhere; }
#modal-body .preview-title { font-weight: 700; font-size: 1.1rem; margin-bottom: .4rem; }
#modal-body .preview-body { font-size: .95rem; background: var(--bg); border-radius: 8px; padding: .6rem .75rem; }
.modal-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.modal-buttons button { border-color: var(--line); }
.modal-buttons button.primary { border-color: transparent; }

.toast {
  position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 999px;
  font-size: .9rem; max-width: 90vw;
}
