:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #5f6b7a;
  --line: #dde3e0;
  --accent: #198754;
  --accent-soft: #e3f2ea;
  --warn: #b35c00;
  --warn-soft: #fff4e2;
  --bad: #c0392b;
  --input: #f7f9f8;
  --phase: #198754;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --card: #1a211e;
    --text: #e6ebe8;
    --muted: #96a29c;
    --line: #2c3632;
    --accent: #3fbf7f;
    --accent-soft: #1c3329;
    --warn: #f0a650;
    --warn-soft: #33270f;
    --bad: #ef6b5b;
    --input: #141a17;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412;
  --card: #1a211e;
  --text: #e6ebe8;
  --muted: #96a29c;
  --line: #2c3632;
  --accent: #3fbf7f;
  --accent-soft: #1c3329;
  --warn: #f0a650;
  --warn-soft: #33270f;
  --bad: #ef6b5b;
  --input: #141a17;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 6px 0; }
ul { margin: 4px 0; padding-left: 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.title { font-weight: 700; font-size: 18px; }
.sync { display: flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px; cursor: pointer; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--accent); }
.dot.pending { background: var(--warn); }
.dot.err { background: var(--bad); }

main { max-width: 560px; margin: 0 auto; padding: 12px 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}
.card.accent { border-left: 4px solid var(--phase); }

.daynav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.daynav .label { text-align: center; }
.daynav .label b { display: block; font-size: 16px; }
.iconbtn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; }
.iconbtn:disabled { opacity: .35; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }

.phase-chip { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--phase); color: #fff; font-size: 12px; font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--phase); }

.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field span { font-size: 13px; color: var(--muted); }
input[type=number], input[type=text], input[type=password], input[type=date], input[type=time], textarea {
  width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--input);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.check:first-of-type { border-top: 0; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.box { flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); display: grid; place-items: center; margin-top: 1px; }
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.check .t { display: block; }
.check .h { display: block; font-size: 13px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.block { width: 100%; }

.steps-num { font-size: 13px; color: var(--muted); }
.meter { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin: 6px 0 2px; }
.meter > i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-right: 4px; }
.tag.rest { background: var(--line); color: var(--muted); }
.tag.weigh { background: var(--warn-soft); color: var(--warn); }

.week-day { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.week-day:first-child { border-top: 0; }
.week-day.today .wd b { color: var(--accent); }
.wd { text-align: center; line-height: 1.2; }
.wd b { display: block; font-size: 17px; }
.wd span { font-size: 12px; color: var(--muted); }
.marks { display: flex; gap: 4px; }
.mark { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 700; border: 1.5px solid var(--line); color: var(--muted); }
.mark.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.mark.miss { border-color: var(--bad); color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--input); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat .good { color: var(--accent); }
.stat .bad { color: var(--bad); }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--accent); }
.chart .goal { stroke: var(--warn); stroke-dasharray: 4 4; stroke-width: 1.5; }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td, table.list th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: right; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; border-top: 0; }
table.list td:first-child, table.list th:first-child { text-align: left; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button { flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: 0; color: var(--muted); font-size: 11px; padding: 4px 0; cursor: pointer; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); font-weight: 600; }

#overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; text-align: center; }
.timer-phase { font-size: 28px; font-weight: 800; }
.timer-time { font-size: 80px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 8px 0; }
.timer-next { color: var(--muted); }
.timer-round { color: var(--muted); margin-top: 4px; }
.timer-btns { display: flex; gap: 12px; margin-top: 28px; }
#overlay.brisk { background: var(--accent-soft); }
#overlay.brisk .timer-phase { color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 99px; font-size: 14px; z-index: 30; max-width: calc(100% - 32px); }

.login { max-width: 360px; margin: 10vh auto 0; }
.notice { background: var(--warn-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
