/* Kokorozashi — washi paper & sumi ink, with a vermilion seal accent. Mobile first. */

:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe9de;
  --ink: #1f1c18;
  --ink-2: #5b554c;
  --ink-3: #8a8378;
  --line: #e2dacb;
  --accent: #c8372d;        /* shu-iro vermilion */
  --accent-ink: #fbf6ee;
  --accent-soft: #f6dfd9;
  --good: #3f7a4f;
  --track: #e8e1d3;
  --cat-health: #2f7d6d;
  --cat-finance: #a67a1f;
  --cat-relationships: #b8466f;
  --cat-work: #3b679c;
  --cat-learning: #7356a8;
  --cat-personal: #82654b;
  --shadow: 0 1px 2px rgb(40 30 20 / .06), 0 4px 16px rgb(40 30 20 / .06);
  --radius: 16px;
  --serif: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1c19;
    --surface-2: #272420;
    --ink: #f1ece3;
    --ink-2: #b9b1a4;
    --ink-3: #857e73;
    --line: #34302a;
    --accent: #e0574a;
    --accent-ink: #1a0f0d;
    --accent-soft: #3a211d;
    --good: #7cbf8c;
    --track: #322e28;
    --cat-health: #6cc0ad;
    --cat-finance: #d9b25c;
    --cat-relationships: #e48aab;
    --cat-work: #82abdc;
    --cat-learning: #b39ae0;
    --cat-personal: #c4a68a;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; letter-spacing: .01em; }

/* ---- Seal logo ---- */
.seal {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent-ink) 35%, transparent);
  font-family: var(--serif); font-weight: 700; font-size: 22px; line-height: 1;
}
.seal > span { transform: translateY(-1px); }
.seal--hero { width: 112px; height: 112px; border-radius: 26px; font-size: 70px;
  box-shadow: inset 0 0 0 4px color-mix(in srgb, var(--accent-ink) 35%, transparent), var(--shadow);
  transform: rotate(-3deg); }

/* ---- Login ---- */
.login {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px 16px; text-align: center;
}
.login__title { font-size: 34px; margin-top: 18px; }
.login__tagline { color: var(--ink-2); margin: 0 0 18px; }
.login__button { min-height: 44px; }
.login__error { color: var(--accent); max-width: 32ch; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand__name { font-family: var(--serif); font-weight: 700; font-size: 19px; }
.topbar__actions { position: relative; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); padding: 0;
  background: var(--surface-2); overflow: hidden; cursor: pointer; display: grid; place-items: center;
  font-weight: 600;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.menu {
  position: absolute; right: 0; top: 46px; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px;
}
.menu__who { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line);
  margin-bottom: 6px; overflow-wrap: anywhere; }
.menu__who span { color: var(--ink-3); font-size: 13px; }
.menu__item { width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.menu__item:hover { background: var(--surface-2); }

/* ---- Content ---- */
.content { max-width: 1200px; margin: 0 auto; padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
.summary { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.stat { flex: 1 1 0; min-width: 96px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 14px; }
.stat__value { font-family: var(--serif); font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 999px; margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; cursor: pointer; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; } }

/* ---- Goal card ---- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
  cursor: pointer; transition: transform .12s ease, border-color .12s ease; text-align: left;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.card:active { transform: scale(.99); }
.card:focus-visible, .btn:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card__top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card__title { font-size: 17px; line-height: 1.35; overflow-wrap: anywhere; }
.card__meta { color: var(--ink-3); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }
.card__meta .overdue { color: var(--accent); }
.card__numbers { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.card__current { font-family: var(--serif); font-size: 30px; font-weight: 700; line-height: 1; }
.card__unit { color: var(--ink-2); }
.card__target { color: var(--ink-3); margin-left: auto; font-size: 14px; }
.card__actions { display: flex; gap: 8px; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge--done { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }

/* Progress bar: rounded data-end, recessive track */
.progress { display: flex; align-items: center; gap: 10px; }
.progress__track { flex: 1; height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.progress__fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width .4s ease; }
.progress__fill.is-done { background: var(--good); }
.progress__pct { font-size: 13px; color: var(--ink-2); min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: 10px;
  cursor: pointer; font-weight: 500; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn--small { padding: 6px 12px; min-height: 34px; font-size: 14px; }
.btn--danger { color: var(--accent); }
.btn--desktop { display: none; }
@media (min-width: 640px) { .btn--desktop { display: inline-block; } .fab { display: none !important; } }
.icon-btn { border: 0; background: none; font-size: 18px; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }

.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent); cursor: pointer;
}

/* ---- Empty state ---- */
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty__glyph { font-family: var(--serif); font-size: 84px; color: color-mix(in srgb, var(--accent) 30%, var(--bg)); line-height: 1; }

/* ---- Dialogs: bottom sheet on phones, centered card on larger screens ---- */
.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0;
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgb(20 15 10 / .45); backdrop-filter: blur(2px); }
.sheet[open] { display: flex; flex-direction: column; animation: sheet-in .2s ease-out; }
.sheet > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 640px) {
  .sheet { max-width: 520px; margin: auto; border-radius: 20px; }
  .sheet--wide { max-width: 680px; }
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 8px; }
.sheet__head h2 { font-size: 20px; overflow-wrap: anywhere; }
.sheet__body { padding: 8px 16px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.sheet__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--ink-2); border: 0; padding: 0; margin: 0; min-width: 0; }
.field legend { padding: 0; margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--ink-3); }
.field input, .field textarea, .field select {
  font: 16px var(--sans); color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row .field--unit { grid-column: span 2; }
@media (min-width: 640px) { .row { grid-template-columns: 1fr 1fr 110px; } .row .field--unit { grid-column: auto; } }
.segmented { flex-direction: row; display: flex; gap: 0; background: var(--surface-2); border-radius: 10px; padding: 3px; flex-wrap: wrap; }
.segmented legend { width: 100%; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }
.group-only { display: flex; flex-direction: column; gap: 14px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.form-error { color: var(--accent); margin: 0; font-size: 14px; }

/* ---- Detail ---- */
.detail__desc { color: var(--ink-2); margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail__log { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface-2); padding: 12px; border-radius: 14px; }
.detail__log .field { flex: 1 1 120px; }
.detail__log .field--note { flex: 3 1 180px; }
.detail__toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.detail__toolbar .spacer { flex: 1; }
.history { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.history li { display: flex; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 14px; align-items: baseline; }
.history__value { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 5em; }
.history__note { color: var(--ink-2); flex: 1; overflow-wrap: anywhere; }
.history__date { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 4px 0 0; }

/* ---- Chart ---- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 180px; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 11px; font-family: var(--sans); }
.chart .target-line { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: color-mix(in srgb, var(--accent) 10%, transparent); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; }
.chart .tooltip {
  position: absolute; top: 0; pointer-events: none; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap;
}

/* ---- Groups ---- */
.card__eyebrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: -6px; }
.card__parent { color: var(--ink-3); font-size: 13px; overflow-wrap: anywhere; }

/* Category chip: coloured dot + label (colour never carries the meaning alone) */
.cat {
  --cat: var(--ink-3);
  align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--ink-2);
  padding: 2px 9px 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--cat) 14%, transparent);
}
.cat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cat); }
.cat[data-category="health"] { --cat: var(--cat-health); }
.cat[data-category="finance"] { --cat: var(--cat-finance); }
.cat[data-category="relationships"] { --cat: var(--cat-relationships); }
.cat[data-category="work"] { --cat: var(--cat-work); }
.cat[data-category="learning"] { --cat: var(--cat-learning); }
.cat[data-category="personal"] { --cat: var(--cat-personal); }
.next-up { margin: 0; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.next-up strong { color: var(--ink); font-weight: 600; }
.children { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); cursor: default; }
.child { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 2px; border-bottom: 1px solid var(--line); }
.child.is-archived { opacity: .55; }
.check {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; padding: 0;
  border: 1.5px solid var(--ink-3); border-radius: 7px; background: none; color: var(--surface);
  font-size: 14px; font-weight: 700; line-height: 1; cursor: pointer;
}
.check.is-done { background: var(--good); border-color: var(--good); }
.check--static { cursor: default; border-style: dashed; }
.check--static.is-done { border-style: solid; }
.check:focus-visible, .child__title:focus-visible, .crumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.child__title {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: none; border: 0; padding: 8px 0; text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.child__title:hover { color: var(--accent); }
.child.is-done .child__title { color: var(--ink-3); }
.child__side { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.child__move { display: flex; }
.child__move .icon-btn { width: 32px; height: 32px; font-size: 15px; }
.child__move .icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.add-item { display: flex; gap: 8px; align-items: flex-end; }
.add-item .field { flex: 1; }
.link-btn { align-self: flex-start; }
.crumb { align-self: flex-start; background: none; border: 0; padding: 0; color: var(--ink-3); font-size: 13px; cursor: pointer; overflow-wrap: anywhere; text-align: left; }
.crumb:hover { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px); z-index: 50;
}
