:root {
  --bg: #fbf8f4;
  --surface: #ffffff;
  --ink: #4a4458;
  --muted: #7f778c;
  --line: #ece6ea;
  --soft: #f4eff2;
  --pink: #e8a5b4;
  --lav: #c9c1e0;
  --mint: #bfe3cf;
  --peach: #f6cdb5;
  --sky: #bcd3ea;
  --accent: #d98ea0;
  --accent-ink: #ffffff;
  --r: 3px;
  --tabs-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1c24; --surface: #29252f; --ink: #ece6f0; --muted: #9a93a6;
    --line: #3a3541; --soft: #322d39; --accent: #e8a5b4; --accent-ink: #2a2230;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }
button, a, .scale, .cal-col { touch-action: manipulation; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }
h2:first-child { margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: baseline; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-en { font-size: 19px; font-weight: 600; letter-spacing: .02em; }
.brand-jp { font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.week-badge { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

main { max-width: 640px; margin: 0 auto; padding: 4px 18px 32px; }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.tabs a.on { color: var(--accent); }

/* generic */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: #c46a7d; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 22px; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=time], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--lav); }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* home */
.today-head { margin: 8px 0 18px; }
.today-head .date { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.today-head .sub { color: var(--muted); margin-top: 2px; }
.report { display: block; }
.h2-row { display: flex; justify-content: space-between; align-items: baseline; }
.h2-row a { font-size: 14px; color: var(--accent); padding: 8px 0 8px 16px; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.report-item .lbl { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.report-item .val { font-variant-numeric: tabular-nums; color: var(--ink); }
.bar { height: 6px; background: var(--soft); margin-top: 4px; }
.bar > i { display: block; height: 100%; }
.note-preview { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.thumbs { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; }
.thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: var(--r); flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--surface); cursor: pointer; user-select: none;
}
.chip .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.done { background: var(--soft); }
.chip:active { transform: scale(.97); }

.glance { display: grid; grid-template-columns: 92px repeat(7, 1fr); gap: 3px; align-items: center; font-size: 12px; }
.glance .h { text-align: center; color: var(--muted); font-size: 11px; line-height: 1.2; }
.glance .h.today { color: var(--accent); font-weight: 600; }
.glance .n { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.glance .c { height: 22px; background: var(--soft); display: flex; align-items: center; justify-content: center; font-size: 11px; font-variant-numeric: tabular-nums; }
.glance a.c { cursor: pointer; }

/* day log */
.day-nav {
  position: sticky; top: var(--top-h, 50px); z-index: 9; display: flex; align-items: center; justify-content: space-between;
  margin: 0 -18px 12px; padding: 4px 10px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.day-nav .icon-btn { width: 44px; height: 44px; font-size: 26px; }
.day-nav .w .saved { color: var(--accent); }
.day-nav .mid { text-align: center; }
.day-nav .mid .d { font-size: 18px; font-weight: 600; }
.day-nav .mid .w { font-size: 13px; color: var(--muted); }
.day-nav input[type=date] { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.metric { padding: 10px 0; border-bottom: 1px solid var(--line); }
.metric:last-child { border-bottom: 0; }
.metric .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; min-height: 24px; }
.metric .head .clear { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 0 0 10px; cursor: pointer; }
.metric .head .v { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 2ch; text-align: right; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.scale button {
  height: 40px; border: 0; background: var(--soft); cursor: pointer; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; padding: 0;
}
.scale button.on { color: var(--ink); }
.num-input { display: flex; align-items: center; gap: 8px; }
.num-input input { max-width: 140px; font-variant-numeric: tabular-nums; }
.save-state { font-size: 12px; color: var(--muted); text-align: right; height: 16px; }
.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.photo-grid img, .photo-add { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--r); display: block; cursor: pointer; }
.photo-add { border: 1px dashed var(--line); background: none; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 26px; }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.link-btn { border: 0; background: none; color: var(--muted); padding: 12px 0; cursor: pointer; font-size: 14px; }
.add-row select { width: 120px; flex: none; }

/* charts */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--soft); color: var(--ink); font-weight: 600; }
.chart-big { margin: 14px 0 6px; }
.chart-big svg, .spark svg { display: block; width: 100%; }
.chart-big .title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart-big .title b { font-size: 17px; }
.chart-big .readout { font-size: 13px; color: var(--muted); min-height: 18px; margin-top: 4px; text-align: center; font-variant-numeric: tabular-nums; }
.chart-big svg { touch-action: pan-y; }
.spark.nodata { opacity: .55; padding-bottom: 12px; }
.spark-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.spark { padding: 10px 12px; cursor: pointer; }
.spark.on { border-color: var(--lav); box-shadow: inset 0 0 0 1px var(--lav); }
.spark .lbl { display: flex; justify-content: space-between; font-size: 13px; }
.spark .lbl .v { font-variant-numeric: tabular-nums; color: var(--muted); }
svg text { fill: var(--muted); font-size: 11px; font-family: inherit; }
svg .grid { stroke: var(--line); stroke-width: 1; }

/* intake calendar */
.cal { display: grid; grid-template-columns: 34px repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.cal-head { display: contents; }
.cal-head > div { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--line); font-size: 13px; }
.cal-head > div .w { display: block; font-size: 11px; color: var(--muted); }
.cal-head > div.today { color: var(--accent); font-weight: 600; }
.cal-hours { position: relative; }
.cal-hours span { position: absolute; right: 4px; transform: translateY(-50%); font-size: 10px; color: var(--muted); }
.cal-col { position: relative; border-left: 1px solid var(--line); cursor: copy; }
.cal-col .hl { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); opacity: .6; }
.cal-col .now { position: absolute; left: 0; right: 0; border-top: 1.5px solid var(--accent); z-index: 1; }
.cal-col .ev {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 0; border: 0; background: none;
  cursor: pointer; z-index: 2; padding: 0; display: flex; align-items: center; justify-content: center;
}
.cal-col .ev::after { content: ""; position: absolute; inset: -10px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* settings */
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row.archived { opacity: .5; }
.swatch-btn { width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer; flex: none; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatches button.on { border-color: var(--ink); }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(40, 32, 48, .35); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; background: var(--bg);
  border-top-left-radius: 6px; border-top-right-radius: 6px; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
.sheet h3 { margin: 0 0 14px; font-size: 17px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet .actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.viewer { position: fixed; inset: 0; background: rgba(20, 16, 24, .92); z-index: 60; display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer .bar2 { display: flex; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
.viewer .bar2 .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r); z-index: 70;
  display: flex; gap: 14px; align-items: center; font-size: 14px; max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--pink); font-weight: 600; cursor: pointer; padding: 0; }

/* login */
.login { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.login .jp { font-size: 40px; letter-spacing: .12em; }
.login .en { color: var(--muted); letter-spacing: .2em; margin-bottom: 26px; }
body.anon .tabs, body.anon .top { display: none; }
.h2-row h2 { margin: 28px 0 10px; }

/* symbols: outlined shapes in the item's colour */
.sym { display: inline-flex; flex: none; }
.sym svg { width: 100%; height: 100%; overflow: visible; }
.sym-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.sym-grid button { height: 44px; border: 1px solid transparent; border-radius: var(--r); background: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.sym-grid button.on { border-color: var(--ink); background: var(--surface); }

/* iOS Safari: date/time inputs keep an intrinsic min width and overflow their container */
input[type=date], input[type=datetime-local], input[type=time] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%;
}
input::-webkit-date-and-time-value { text-align: left; min-height: 1.45em; }

/* exercise */
.stack { display: flex; flex-direction: column; gap: 10px; }
.session { display: block; }
.session .hr { font-variant-numeric: tabular-nums; }
.ex-lines { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.ex-lines .row { gap: 8px; }
.ex-lines .muted { font-variant-numeric: tabular-nums; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.two .field, .three .field { margin-bottom: 0; }
.card > .field:last-child, .card > .two:last-child { margin-bottom: 0; }
.ex-list { padding: 4px 16px; }
.ex-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.ex-row .clear { border: 0; background: none; color: var(--muted); font-size: 20px; padding: 0 0 0 12px; cursor: pointer; }
.ex-inputs { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.ex-inputs input { width: 58px; text-align: center; font-variant-numeric: tabular-nums; padding: 8px 4px; }
.ex-inputs .unit { min-width: 26px; font-size: 13px; }
.block-seg { display: flex; width: 100%; }
.block-seg button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 4px; }

/* settings sections */
details.section { margin-top: 22px; }
details.section > summary {
  list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 0 10px;
  font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: '›'; margin-left: auto; font-size: 20px; line-height: 1; transition: transform .15s; }
details.section[open] > summary::after { transform: rotate(90deg); }
.list-row .up { width: 36px; height: 36px; font-size: 16px; }
.day-label { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.day-label.today { color: var(--accent); font-weight: 600; }
