:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #2b2620;
  --ink-soft: #6f665a;
  --ink-faint: #a39a8c;
  --line: #e7dfd0;
  --accent: #b5562f;
  --accent-soft: #f3e2d6;
  --work: #eef2ee;
  --work-ink: #3d5a48;
  --shadow: 0 1px 2px rgba(60, 45, 25, .06), 0 6px 18px rgba(60, 45, 25, .06);
  --radius: 16px;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a16;
    --paper: #26221d;
    --ink: #eee6d8;
    --ink-soft: #b9ae9d;
    --ink-faint: #85796a;
    --line: #3a342c;
    --accent: #e08a5f;
    --accent-soft: #3d2a20;
    --work: #222b25;
    --work-ink: #a9c9b4;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------- ログイン ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.brand { font-family: var(--serif); font-size: 34px; letter-spacing: .12em; }
.login-sub { color: var(--ink-soft); margin: 8px 0 28px; font-size: 14px; }
.login-card input {
  width: 100%; padding: 14px 16px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--paper); color: var(--ink); margin-bottom: 12px;
}
.login-card .btn-primary { width: 100%; }
.error { color: var(--accent); font-size: 14px; min-height: 1.4em; margin: 10px 0 0; }

/* ---------- 本体 ---------- */
.app { max-width: 620px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--bg);
}
.nav {
  width: 44px; height: 44px; border: none; background: transparent; font-size: 30px; line-height: 1;
  color: var(--ink-soft); border-radius: 50%;
}
.nav:active { background: var(--accent-soft); }
.nav.small { width: 36px; height: 36px; font-size: 24px; }
.date-btn { border: none; background: transparent; display: flex; flex-direction: column; align-items: center; padding: 4px 12px; border-radius: 12px; }
.date-btn:active { background: var(--accent-soft); }
.date-md { font-family: var(--serif); font-size: 28px; letter-spacing: .06em; }
.date-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-top: 12px; border: 1px solid var(--line); }
.card-label { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; letter-spacing: .04em; }
.save-state { font-size: 12px; color: var(--ink-faint); }
.save-state.dirty { color: var(--accent); }
.tag { font-size: 11px; background: var(--work); color: var(--work-ink); padding: 2px 8px; border-radius: 99px; }

textarea {
  width: 100%; border: none; outline: none; resize: none; background: transparent; color: var(--ink);
  font-family: var(--serif); font-size: 17px; line-height: 1.8; min-height: 110px; padding: 0;
}
textarea::placeholder { color: var(--ink-faint); }
.row-end { display: flex; justify-content: flex-end; margin-top: 8px; }
.btn-primary {
  border: none; background: var(--accent); color: #fff; padding: 11px 26px; border-radius: 99px;
  font-size: 15px; font-weight: 600; letter-spacing: .06em;
}
.btn-primary:active { opacity: .85; }
.btn-primary:disabled { background: var(--line); color: var(--ink-soft); cursor: default; }

.work { background: var(--work); border-color: transparent; }
.work-body { white-space: pre-wrap; font-size: 14px; line-height: 1.75; color: var(--ink); overflow-wrap: anywhere; }
.work-body.empty { color: var(--ink-faint); font-size: 13px; }

/* ---------- 過去 ---------- */
.past { margin-top: 28px; }
.past-title { font-family: var(--serif); font-weight: normal; font-size: 16px; color: var(--ink-soft); letter-spacing: .08em; margin: 0 0 4px; }
.past-empty { color: var(--ink-faint); font-size: 13px; line-height: 1.7; padding: 8px 0; }
.year {
  position: relative; padding: 14px 0 14px 18px; border-left: 2px solid var(--line); margin-left: 6px;
}
.year::before {
  content: ""; position: absolute; left: -6px; top: 20px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
}
.year-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.year-num { font-family: var(--serif); font-size: 20px; }
.year-ago { font-size: 12px; color: var(--ink-faint); }
.year-memo { font-family: var(--serif); font-size: 16px; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }
.year-memo.empty { color: var(--ink-faint); font-family: var(--sans); font-size: 13px; }
details.year-work { margin-top: 8px; }
details.year-work summary { font-size: 12px; color: var(--work-ink); cursor: pointer; list-style: none; }
details.year-work summary::-webkit-details-marker { display: none; }
details.year-work summary::before { content: "▸ "; }
details.year-work[open] summary::before { content: "▾ "; }
details.year-work .work-body { background: var(--work); border-radius: 10px; padding: 10px 12px; margin-top: 6px; }
.go-day { border: none; background: none; color: var(--ink-faint); font-size: 12px; padding: 0; margin-left: auto; }

/* ---------- カレンダー ---------- */
.calendar { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.cal-head { display: flex; align-items: center; justify-content: space-between; font-family: var(--serif); font-size: 17px; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.cal-week { font-size: 11px; color: var(--ink-faint); margin: 6px 0 2px; }
.cal-grid button {
  position: relative; aspect-ratio: 1 / 1; border: none; background: transparent; border-radius: 10px; font-size: 14px; max-height: 48px;
}
.cal-grid button:active { background: var(--accent-soft); }
.cal-grid button.is-today { font-weight: 700; color: var(--accent); }
.cal-grid button.is-selected { background: var(--accent); color: #fff; }
.cal-grid button .dots { position: absolute; left: 0; right: 0; bottom: 5px; display: flex; justify-content: center; gap: 3px; }
.cal-grid button .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.cal-grid button .dots i.w { background: var(--work-ink); }
.cal-grid button.is-selected .dots i { background: #fff; }
.link { border: none; background: none; color: var(--ink-soft); font-size: 13px; text-decoration: underline; padding: 8px; }
.calendar .link { display: block; margin: 4px auto 0; }

.foot { text-align: center; margin-top: 36px; }

/* ---------- 日／月の切り替え ---------- */
.tabs {
  display: flex; gap: 4px; width: 160px; margin: calc(10px + env(safe-area-inset-top)) auto 0;
  background: var(--line); padding: 3px; border-radius: 99px;
}
.tab { flex: 1; border: none; background: transparent; padding: 7px 0; border-radius: 99px; font-size: 14px; color: var(--ink-soft); }
.tab.is-on { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.topbar { padding-top: 6px; }
.date-btn.static { cursor: default; }
.date-btn.static:active { background: transparent; }

/* ---------- 元のメモ ---------- */
details.raw { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
details.raw summary { font-size: 12px; color: var(--ink-faint); cursor: pointer; list-style: none; }
details.raw summary::-webkit-details-marker { display: none; }
details.raw summary::before { content: "▸ "; }
details.raw[open] summary::before { content: "▾ "; }
.raw-body { white-space: pre-wrap; font-size: 13px; line-height: 1.7; color: var(--ink-soft); margin-top: 6px; overflow-wrap: anywhere; }

/* ---------- 月 ---------- */
.calendar { margin-top: 4px; }
.cal-grid button:disabled { opacity: .3; }
.cal-legend { display: flex; justify-content: center; gap: 16px; font-size: 11px; color: var(--ink-faint); margin-top: 6px; }
.cal-legend i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 5px; vertical-align: middle; }
.cal-legend i.w { background: var(--work-ink); }
.month-memo textarea { min-height: 220px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; }
.org-state { font-size: 12px; color: var(--ink-faint); line-height: 1.5; }
.org-state.pending { color: var(--accent); }
.org-state.done { color: var(--work-ink); }
