:root {
  --bg: #0e1315;
  --surface: #161d20;
  --surface-2: #1e272b;
  --line: #2a3539;
  --text: #e9eef0;
  --muted: #8fa0a6;
  --accent: #2fc0ac;
  --accent-ink: #062521;
  --warn: #f2b84b;
  --danger: #ef6a5f;
  --pr: #ffcf4a;
  --c3: #8fb4ff;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f6f6; --surface: #ffffff; --surface-2: #eef2f2; --line: #d9e1e2;
    --text: #13201f; --muted: #5d6f73; --accent: #138a7b; --accent-ink: #ffffff;
    --warn: #a86b00; --danger: #c43c31; --pr: #b88700; --c3: #3d6fd6;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; }
#topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line);
}
#topbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -0.01em; }
#topbar .sub { color: var(--muted); font-size: 13px; }
#main { padding: 14px 16px calc(var(--nav-h) + var(--safe-b) + 110px); }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* nav */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
#nav a {
  flex: 1; max-width: 128px; height: var(--nav-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; color: var(--muted);
  text-decoration: none; font-size: 12px;
}
#nav a .ico { font-size: 18px; line-height: 1; }
#nav a.on { color: var(--accent); }

/* building blocks */
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
h2:first-child { margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.hl { border-color: var(--accent); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.right { text-align: right; }
.center { text-align: center; }
.spacer { height: 10px; }
.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.tag.accent { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.tag.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.tag.pr { background: color-mix(in srgb, var(--pr) 22%, transparent); color: var(--pr); font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.list-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.list-item:last-child { border-bottom: 0; }
.chev { color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* buttons & inputs */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 12px; padding: 11px 14px; min-height: 44px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active, .btn:active { transform: scale(0.98); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.block, .btn.block { width: 100%; }
button.small { min-height: 34px; padding: 6px 10px; font-size: 14px; border-radius: 10px; }
button.icon { width: 44px; padding: 0; }
button:disabled { opacity: .45; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; font-size: 16px; width: 100%; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; margin: 0; }
.check input { width: 22px; height: 22px; min-height: 0; }

/* session */
.ex-head { display: flex; align-items: flex-start; gap: 8px; }
.ex-head h3 { margin: 0; font-size: 17px; }
.target { font-size: 13px; color: var(--muted); margin-top: 2px; }
.lasttime { font-size: 13px; color: var(--muted); margin-top: 8px; }
.hint { font-size: 13px; margin-top: 6px; padding: 7px 10px; border-radius: 10px; background: var(--surface-2); }
.hint.up { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.sets { margin: 10px 0 4px; }
.set {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); margin-bottom: 6px; width: 100%; text-align: left; min-height: 40px;
  border: 0; font-size: 15px;
}
.set .n { width: 22px; color: var(--muted); font-size: 13px; }
.set.wu { opacity: .7; }
.entry { display: grid; grid-template-columns: 1.35fr 1fr 0.9fr; gap: 8px; margin-top: 8px; }
.entry .lbl { font-size: 11px; color: var(--muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.stepper { display: flex; }
.stepper input { text-align: center; border-radius: 0; padding: 10px 2px; min-width: 0; }
.stepper button { min-width: 36px; padding: 0; border-radius: 0; }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.entry-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.done-badge { color: var(--accent); font-size: 13px; }

/* timer */
#timer {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 25;
  max-width: 640px; margin: 0 auto; padding: 0 10px 8px;
}
#timer .box {
  background: var(--surface); border: 1px solid var(--accent); border-radius: 16px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.35); position: relative; overflow: hidden;
}
#timer .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
#timer .time { font-size: 30px; font-weight: 750; font-variant-numeric: tabular-nums; min-width: 92px; }
#timer .box.done { border-color: var(--warn); }
#timer .box.done .time { color: var(--warn); }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b));
}
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.picker-list { max-height: 50vh; overflow: auto; }

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 70px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }

/* sync pill */
.sync { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.sync.pending { color: var(--warn); }

/* charts */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.hbar { display: grid; grid-template-columns: 96px 1fr 30px; gap: 8px; align-items: center; font-size: 13px; margin-bottom: 6px; }
.hbar .track { background: var(--surface-2); border-radius: 6px; height: 14px; position: relative; overflow: hidden; }
.hbar .fill { background: var(--accent); height: 100%; border-radius: 6px; }
.hbar .zone { position: absolute; top: 0; bottom: 0; border-left: 1px dashed var(--muted); border-right: 1px dashed var(--muted); opacity: .6; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.scroll-x { overflow-x: auto; }

/* login */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; }
.login h1 { font-size: 26px; margin-bottom: 4px; }

/* keep grid cells (and date pickers) from overflowing narrow screens */
.grid2 > *, .grid3 > *, .entry > * { min-width: 0; }
input[type="date"] { min-width: 0; -webkit-appearance: none; appearance: none; }
.check input[type="radio"] { width: 22px; height: 22px; min-height: 0; flex: none; }

/* 1-10 scale */
.scale { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
.scale button { min-height: 40px; padding: 0; border-radius: 9px; font-size: 15px; font-variant-numeric: tabular-nums; }
.scale button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.scale-ends { display: flex; justify-content: space-between; margin-top: 4px; }
.chip { display: inline-block; min-width: 26px; text-align: center; padding: 2px 6px; border-radius: 8px; background: var(--surface-2); font-size: 13px; font-variant-numeric: tabular-nums; }
