@font-face {
  font-family: "DSEG7";
  src: url("fonts/DSEG7Classic-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: block;
}

:root {
  --paper: #E9EDEA;
  --surface: #F5F7F5;
  --ink: #1C2420;
  --ink-2: #5A6660;
  --line: #CAD2CD;
  --lcd: #C3CFBA;
  --lcd-edge: #A9B7A0;
  --seg: #1A2519;
  --ghost: rgba(26, 37, 25, 0.075);
  --accent: #2B57C4;
  --accent-ink: #FFFFFF;
  --toward: #2B57C4;
  --away: #5A6660;
  --danger: #B3261E;
  --raw: #1C2420;
  --train: #2C7A57;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141917;
    --surface: #1C2320;
    --ink: #E2E8E4;
    --ink-2: #94A09A;
    --line: #2F3934;
    --lcd: #22302A;
    --lcd-edge: #0F1512;
    --seg: #B9F0C8;
    --ghost: rgba(185, 240, 200, 0.07);
    --accent: #7D9CF2;
    --accent-ink: #0E1530;
    --toward: #8EA9F5;
    --away: #94A09A;
    --danger: #F2827A;
    --raw: #E2E8E4;
    --train: #6CC79A;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.35; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: 0.01em; }
h1 { font-size: 17px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }

.top, main { max-width: 560px; margin: 0 auto; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 0;
}

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; background: none; border-radius: 50%;
  color: var(--ink-2);
  margin-right: -10px;
}

main { padding: 0 16px 40px; }

/* ---------- entry ---------- */

.entry { padding-top: 4px; }

.date-nav {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  margin: 0 -8px 10px;
}

.nav-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; background: none; border-radius: 50%;
}

.date-label {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  padding: 8px 0;
}
.date-rel { font-size: 13px; font-weight: 500; color: var(--accent); }
.date-rel:empty { display: none; }
.date-label input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: 0; padding: 0;
}

/* the scale display */
.lcd {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 10px;
  padding: 18px 18px 16px 14px;
  background: var(--lcd);
  border-radius: 16px;
  box-shadow:
    inset 0 2px 0 rgba(0, 0, 0, 0.10),
    inset 0 0 0 1px var(--lcd-edge),
    inset 0 10px 24px rgba(0, 0, 0, 0.10);
}
.lcd-ghost, .lcd-input {
  font-family: "DSEG7", monospace;
  font-weight: 700;
  font-size: clamp(56px, 19vw, 84px);
  line-height: 1;
  letter-spacing: 0.02em;
}
.lcd-digits { position: relative; flex: 1; min-width: 0; display: flex; }
.lcd-ghost {
  position: absolute;
  right: 0;
  bottom: 0;
  color: var(--ghost);
  pointer-events: none;
  user-select: none;
}
.lcd-input {
  position: relative;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--seg);
  caret-color: var(--seg);
  text-align: right;
  outline: none;
}
.lcd-input::placeholder { color: transparent; }
.lcd:focus-within { box-shadow:
    inset 0 2px 0 rgba(0, 0, 0, 0.10),
    inset 0 0 0 2px var(--accent),
    inset 0 10px 24px rgba(0, 0, 0, 0.10); }
.lcd-unit {
  flex: none;
  width: 1.6em;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--seg);
  padding-bottom: 2px;
}

.clothes-seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 10px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.clothes-seg button {
  min-height: 42px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink-2);
  font-size: 15px;
}
.clothes-seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 650; }
.clothes-hint {
  margin: 8px 2px 0;
  font-size: 13px;
  color: var(--ink);
}

.status {
  margin: 8px 2px 0;
  min-height: 1.6em;
  font-size: 14px;
  color: var(--ink-2);
}
.status.error { color: var(--danger); }

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}
.stepper button {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px;
  font-weight: 600;
  user-select: none;
  -webkit-user-select: none;
}
.stepper button:active { background: var(--line); }

.extra { margin-top: 14px; }
.extra summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  font-size: 15px;
  color: var(--ink-2);
  cursor: pointer;
}
.extra summary::-webkit-details-marker { display: none; }
.extra summary::before {
  content: "";
  width: 7px; height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  margin-right: 4px;
}
.extra[open] summary::before { transform: rotate(45deg); }
.extra-body { display: grid; gap: 12px; padding: 2px 0 6px; }

.field { display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); }
.field input {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
}
.field-input { position: relative; display: block; }
.field-input input { padding-right: 44px; }
.field-input .unit {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-2);
}

.primary {
  display: block;
  width: 100%;
  height: 54px;
  margin-top: 14px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 650;
}
.primary:active { filter: brightness(0.92); }

.text-btn {
  border: 0; background: none;
  min-height: 44px;
  padding: 0 4px;
  color: var(--ink-2);
  font-size: 15px;
}
.text-btn.danger { color: var(--danger); }
#deleteBtn { display: block; margin: 6px auto 0; }
#deleteBtn[hidden] { display: none; }

.small-btn {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
}
.small-btn.wide { width: 100%; }

/* ---------- training entry ---------- */

.train {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.train-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.train-title { font-size: 15px; font-weight: 650; }
.train-note { font-size: 12px; color: var(--ink-2); }
.train-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.train-seg button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 15px;
}
.train-seg button[aria-pressed="true"] {
  border-color: var(--train);
  background: color-mix(in srgb, var(--train) 14%, var(--surface));
  color: var(--ink);
  font-weight: 650;
  box-shadow: inset 0 0 0 1px var(--train);
}

/* ---------- notice ---------- */

.notice {
  margin-top: 22px;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 10px 10px 0;
  font-size: 14px;
}
.notice p { margin: 0 0 6px; }
.notice-actions { display: flex; gap: 12px; align-items: center; }

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 26px;
  border-top: 1px solid var(--line);
}
.stat {
  display: flex;
  flex-direction: column;
  padding: 12px 0 14px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.stat:nth-child(odd) { padding-right: 12px; border-right: 1px solid var(--line); }
.stat:nth-child(even) { padding-left: 14px; }
.s-label { font-size: 13px; color: var(--ink-2); }
.s-val { font-size: 24px; font-weight: 650; line-height: 1.3; }
.s-val small { font-size: 14px; font-weight: 500; margin-left: 3px; color: var(--ink-2); }
.s-val.muted { font-size: 17px; color: var(--ink-2); font-weight: 500; padding: 4px 0 2px; }
.s-sub { font-size: 13px; color: var(--ink-2); }
.s-link {
  align-self: flex-start;
  border: 0; background: none; padding: 0;
  min-height: 32px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}
.stats-note { margin: 8px 0 0; font-size: 12.5px; color: var(--ink-2); }
.toward { color: var(--toward); }
.away { color: var(--away); }

/* ---------- chart ---------- */

.chart-sec { margin-top: 30px; }
.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.seg button {
  border: 0; background: none;
  min-height: 34px;
  padding: 0 9px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

.chart {
  position: relative;
  margin-top: 12px;
  min-height: 230px;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { fill: var(--ink-2); font-size: 11px; }
.chart .raw-line { fill: none; stroke: var(--raw); stroke-opacity: 0.28; stroke-width: 1.2; }
.chart .raw-dot { fill: var(--raw); fill-opacity: 0.55; }
.chart .raw-dot.clothed { fill: var(--paper); fill-opacity: 1; stroke: var(--raw); stroke-opacity: 0.7; stroke-width: 1.4; }
.chart .ma-line { fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.chart .goal-line { stroke: var(--ink); stroke-opacity: 0.55; stroke-width: 1.4; stroke-dasharray: 5 4; }
.chart .goal-t { fill: var(--ink-2); font-size: 11px; }
.chart .last-dot { fill: var(--raw); stroke: var(--paper); stroke-width: 2; }
.chart .train-mark { fill: var(--train); }
.chart .train-mark.lv1 { fill-opacity: 0.5; }
.chart .guide { stroke: var(--ink-2); stroke-width: 1; }
.chart .hl { fill: var(--paper); stroke: var(--ink); stroke-width: 2; }
.chart .empty {
  display: grid;
  place-items: center;
  min-height: 230px;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  color: var(--ink-2);
  font-size: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}
.tip {
  position: absolute;
  top: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  line-height: 1.45;
  white-space: nowrap;
  pointer-events: none;
}
.tip b { font-size: 15px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-2);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-raw { stroke: var(--raw); stroke-opacity: 0.28; stroke-width: 1.2; }
.lg-dot { fill: var(--raw); fill-opacity: 0.55; }
.lg-train1 { fill: var(--train); fill-opacity: 0.5; }
.lg-train2 { fill: var(--train); }
.lg-clothed { fill: var(--paper); stroke: var(--raw); stroke-opacity: 0.7; stroke-width: 1.4; }
.legend span[hidden] { display: none; }
.lg-ma { stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; }
.lg-goal { stroke: var(--ink); stroke-opacity: 0.55; stroke-width: 1.4; stroke-dasharray: 4 3; }

/* ---------- training analysis ---------- */

.training-sec { margin-top: 30px; }
.training-sec h3 { margin: 14px 0 8px; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.training-sec .help { margin-top: 8px; }

.cmp { display: grid; gap: 6px; }
.cmp-row {
  display: grid;
  grid-template-columns: 6.6em 1fr 4.6em 2.6em;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.cmp-row.is-sub { font-size: 13px; color: var(--ink-2); }
.cmp-row.is-sub .cmp-label { padding-left: 1em; }
.cmp-bar {
  position: relative;
  height: 14px;
  background: linear-gradient(var(--line), var(--line)) center / 1px 100% no-repeat;
}
.cmp-bar i {
  position: absolute;
  top: 2px; bottom: 2px;
  border-radius: 2px;
  background: var(--ink-2);
}
.cmp-row.is-train .cmp-bar i { background: var(--train); }
.cmp-row.is-sub .cmp-bar i { background: var(--train); opacity: 0.5; }
.cmp-val { text-align: right; font-weight: 650; }
.cmp-val small { font-size: 11px; font-weight: 500; color: var(--ink-2); margin-left: 1px; }
.cmp-row.is-sub .cmp-val { font-weight: 500; }
.cmp-n { text-align: right; font-size: 12px; color: var(--ink-2); }
.verdict { margin: 10px 0 0; font-size: 14px; }

.wk {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  font-size: 14px;
}
.wk.fat { grid-template-columns: max-content minmax(0, 1fr) max-content max-content; }
.wk-row { display: contents; }
.wk-row > span {
  padding: 7px 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  white-space: nowrap;
}
.wk-row > span + span { padding-left: 12px; }
.wk-head > span { font-size: 12px; color: var(--ink-2); border-top: 0; padding-top: 0; }
.wk-row > span:nth-child(n+3) { text-align: right; }
.wk-row small { font-size: 12px; color: var(--ink-2); }
.wk-row small.toward { color: var(--toward); }
.wk-train { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.wk-marks { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.wk-marks i { display: block; width: 5px; border-radius: 1px; background: var(--train); }
.wk-marks i.lv1 { height: 6px; opacity: 0.5; }
.wk-marks i.lv2 { height: 12px; }
.muted { color: var(--ink-2); }

/* ---------- history ---------- */

.history { margin-top: 30px; }
.history h2 { margin-bottom: 6px; }
.empty-text { color: var(--ink-2); font-size: 14px; margin: 6px 0; }

.month { border-top: 1px solid var(--line); }
.month summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  font-weight: 600;
  cursor: pointer;
}
.month summary::-webkit-details-marker { display: none; }
.month summary .m-avg { font-size: 13px; font-weight: 500; color: var(--ink-2); }

.row {
  display: grid;
  grid-template-columns: 3.4em 1fr auto auto;
  align-items: baseline;
  gap: 0 12px;
  width: 100%;
  padding: 9px 4px;
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  background: none;
  text-align: left;
}
.row.sel { background: var(--surface); border-radius: 8px; }
.r-day { font-weight: 600; }
.r-day small { font-size: 12px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.r-w { font-size: 17px; font-weight: 600; }
.r-w small { font-size: 12px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.r-w.none { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.r-train { color: var(--train); font-weight: 600; }
.r-train.lv1 { font-weight: 500; }
.r-diff { font-size: 14px; min-width: 3.4em; text-align: right; }
.r-fat { font-size: 13px; color: var(--ink-2); min-width: 3.6em; text-align: right; }
.r-memo {
  grid-column: 2 / -1;
  font-size: 13px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- settings sheet ---------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  margin: auto auto 0;
  padding: 6px 18px calc(18px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--paper);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(10, 14, 12, 0.45); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 4px;
}
.sheet-group {
  display: grid;
  gap: 10px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.sheet-group:last-child { border-bottom: 0; }
.sheet-group .primary { margin-top: 2px; }
.help { margin: 0; font-size: 13px; color: var(--ink-2); }
.help.strong { color: var(--ink); font-weight: 600; }
.help.version { margin-top: 4px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
