:root {
  color-scheme: light;
  --bg: #f1f0ec; --surface: #fcfcfb; --surface-2: #f4f3ef; --border: #e2e1da;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7b7a74;
  --series: #2a78d6; --accent: #1f63b8; --on-accent: #ffffff;
  --good: #1a7a48; --warn: #9a6200; --crit: #c0392b;
  --good-bg: #e3f3ea; --warn-bg: #fbf0d9; --crit-bg: #fbe6e3;
  --grid: #e6e5df;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #30302d;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e85;
    --series: #3987e5; --accent: #3987e5; --on-accent: #ffffff;
    --good: #4cc38a; --warn: #e2a336; --crit: #f07b6e;
    --good-bg: #12301f; --warn-bg: #33270e; --crit-bg: #3a1a16;
    --grid: #2a2a28;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #30302d;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e85;
  --series: #3987e5; --accent: #3987e5; --on-accent: #ffffff;
  --good: #4cc38a; --warn: #e2a336; --crit: #f07b6e;
  --good-bg: #12301f; --warn-bg: #33270e; --crit-bg: #3a1a16;
  --grid: #2a2a28;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 48px 16px; color: var(--muted); text-align: center; }

.shell { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 92px); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.top h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.top .sub { color: var(--text-2); font-size: 14px; }
.datenav { display: flex; align-items: center; gap: 4px; }
.datenav button { min-height: 40px; border-radius: 12px; padding: 0 10px; white-space: nowrap; }
.datenav button.icon { width: 40px; padding: 0; font-size: 20px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); margin-bottom: 10px; }
.card h3 { font-size: 17px; font-weight: 650; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.sec { color: var(--text-2); }

button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 0 14px; min-height: 44px; cursor: pointer; font-weight: 550; }
button { white-space: nowrap; }
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.ghost { background: transparent; }
button.danger { color: var(--crit); }
button.block { width: 100%; }
button:disabled { opacity: 0.55; }
button.icon { width: 44px; padding: 0; }

input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); padding: 8px 12px; }
textarea { min-height: 72px; resize: vertical; }
input[type="checkbox"] { width: 24px; min-height: 24px; height: 24px; accent-color: var(--accent); }
input[type="range"] { padding: 0; min-height: 32px; accent-color: var(--accent); border: 0; background: transparent; }
input:focus-visible, button:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label { display: grid; gap: 4px; font-size: 13.5px; color: var(--text-2); }
label .lv { display: flex; justify-content: space-between; }
label.check { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--text); min-height: 44px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.banner { border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; font-weight: 550; border: 1px solid transparent; }
.banner.good { background: var(--good-bg); color: var(--good); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.crit { background: var(--crit-bg); color: var(--crit); }
.banner small { display: block; font-weight: 400; color: var(--text-2); margin-top: 2px; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile .k { font-size: 12.5px; color: var(--text-2); }
.tile .v { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.tile .d { font-size: 12.5px; color: var(--muted); }

.meter { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; position: relative; }
.meter > i { display: block; height: 100%; background: var(--series); border-radius: 6px; }
.meter > b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text-2); }

.chips { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.chip { min-height: 40px; border-radius: 20px; padding: 0 2px; background: var(--surface); font-size: 14.5px; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-left: 6px; vertical-align: middle; opacity: 0.7; }

.ex { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.ex:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.ex .target { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ex .last { font-size: 13.5px; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.ex .hint { font-size: 13.5px; color: var(--good); margin-top: 2px; font-weight: 550; }
.sets { display: grid; gap: 8px; margin-top: 10px; }
.setrow { display: grid; grid-template-columns: 28px 1fr 14px 1fr 24px; align-items: center; gap: 8px; }
.setrow.nokg { grid-template-columns: 28px 1fr 24px; }
.setrow .n { color: var(--muted); font-size: 13.5px; text-align: center; }
.setrow input { text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.setrow .x { color: var(--muted); text-align: center; }
.setrow .ok { color: var(--good); font-weight: 700; text-align: center; }
.unit { position: relative; }
.unit input { padding-right: 56px; }
.unit[data-u="kg"] input, .unit[data-u="sn"] input, .unit[data-u="m"] input { padding-right: 36px; }
.unit::after { content: attr(data-u); position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12.5px; pointer-events: none; }
details { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 8px; }
details summary { cursor: pointer; color: var(--text-2); font-size: 14px; min-height: 32px; display: flex; align-items: center; }
details p, details li { font-size: 14.5px; color: var(--text-2); }
details ul { margin: 6px 0 0; padding-left: 20px; }
details.plain { border: 0; margin: 0; padding: 0; }

.list { display: grid; gap: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .name { overflow-wrap: anywhere; }
.item .nums { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13.5px; }
.thumb { width: 48px; height: 48px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); }
.preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; display: block; }
.photos figcaption { font-size: 12px; color: var(--text-2); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12.5px; padding: 6px 4px; border-bottom: 1px solid var(--border); }
td { padding: 8px 4px; border-bottom: 1px solid var(--border); }
td.r, th.r { text-align: right; }
.scroll { overflow-x: auto; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 8px; padding: 4px 8px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -130%); font-variant-numeric: tabular-nums; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .axis { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .band { fill: var(--text-2); opacity: 0.12; }
.chart .bar { fill: var(--series); }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .target { stroke: var(--text-2); stroke-width: 1; }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--border); padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px); z-index: 10; }
nav.tabs .in { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
nav.tabs button { border: 0; background: transparent; min-height: 52px; padding: 4px 0; border-radius: 12px; font-size: 11.5px; font-weight: 550; color: var(--muted); display: grid; justify-items: center; gap: 2px; }
nav.tabs button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav.tabs button[aria-current="page"] { color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14.5px; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 30; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; }
#timer { position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 88px); z-index: 20; background: var(--accent); color: var(--on-accent); border-radius: 24px; padding: 10px 16px; font-weight: 700; font-variant-numeric: tabular-nums; box-shadow: 0 6px 20px rgba(0,0,0,0.25); cursor: pointer; }

.auth { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 72px) 20px 40px; }
.auth h1 { font-size: 28px; margin-bottom: 4px; }
.auth form { display: grid; gap: 12px; margin-top: 24px; }
.err { color: var(--crit); font-size: 14.5px; }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } button:active { transform: none; } }

.est { display: grid; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.est:last-child { border-bottom: 0; padding-bottom: 0; }
.estnums { display: grid; grid-template-columns: 1fr 1fr 1fr 44px; gap: 8px; align-items: end; }
.estnums input { text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
