:root {
  --bg: #0f1720;
  --surface: #17222e;
  --surface2: #1f2d3b;
  --line: #2a3a4b;
  --text: #e8eef2;
  --muted: #93a4b3;
  --accent: #2dd4bf;
  --accent-dim: #14463f;
  --warn: #f59e0b;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(15,23,32,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { color: var(--accent); font-size: 20px; letter-spacing: -3px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.sync { background: none; border: 0; color: var(--muted); font-size: 22px; padding: 4px 8px; }
.sync.spin { animation: spin .8s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.iconbtn { background: none; border: 0; color: var(--muted); font-size: 20px; padding: 4px 6px; }
.iconbtn:active { color: var(--accent); }

/* layout */
main { padding: 14px; max-width: 720px; margin: 0 auto; }
h2 { font-size: 16px; margin: 18px 0 8px; color: var(--text); }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 12px 0;
}
.card .ex-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .ex-head .name { font-weight: 600; }
.card .ex-head .tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.card .target { color: var(--muted); font-size: 13px; margin: 2px 0 6px; }
.card .last { color: var(--accent); font-size: 13px; margin-bottom: 8px; }
.note { color: var(--muted); font-size: 13px; font-style: italic; margin-top: 6px; }

/* set rows */
.set-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.set-row .n { width: 22px; color: var(--muted); font-size: 13px; }
.stepper { display: flex; align-items: center; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: 1; }
.stepper button { width: 54px; height: 48px; border: 0; background: transparent; color: var(--text); font-size: 24px; }
.stepper button:active { background: var(--accent-dim); }
.stepper input { flex: 1; min-width: 0; height: 48px; border: 0; background: transparent; color: var(--text); text-align: center; font-size: 17px; font-variant-numeric: tabular-nums; }
.stepper .unit { color: var(--muted); font-size: 12px; padding-right: 10px; }
.set-row .wt { flex: none; width: 118px; }
.set-row .wt button { width: 38px; height: 44px; font-size: 20px; }
.set-row .wt input { height: 44px; font-size: 16px; }
.set-row .wt .unit { font-size: 11px; padding-right: 6px; }
.wt-add { flex: none; height: 44px; padding: 0 12px; border-radius: 10px; border: 1px dashed var(--line); background: transparent; color: var(--muted); font-size: 13px; }
.wt-add:active { color: var(--accent); border-color: var(--accent); }
.row-timer { flex: none; width: 44px; height: 48px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface2); color: var(--text); font-size: 18px; }
.row-timer:active { background: var(--accent-dim); }

/* warm-up tick-off */
.kv.warm { cursor: pointer; user-select: none; -webkit-user-select: none; }
.warm-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.warm-check { flex: none; width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; color: transparent; }
.kv.warm.done .warm-check { background: var(--accent); border-color: var(--accent); color: #06231f; }
.kv.warm.done .warm-name { text-decoration: line-through; color: var(--muted); }

/* sticky save bar */
.save-bar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom) + 8px);
  margin: 16px -14px 0; padding: 8px 14px 4px;
  background: linear-gradient(to top, var(--bg) 55%, transparent); }

.btn { display: block; width: 100%; padding: 14px; border: 0; border-radius: 12px; font-size: 16px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #06231f; }
.btn.primary:active { filter: brightness(.92); }
.btn.ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--line); }
.btn + .btn { margin-top: 10px; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.pill { padding: 9px 14px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); color: var(--text); font-size: 14px; }
.pill.active { background: var(--accent); color: #06231f; border-color: var(--accent); }

.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }

input, select { font-size: 16px; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2); color: var(--text); }
.field.logdate { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; }
.field.logdate label { margin: 0; flex: none; }
.field.logdate input { width: auto; flex: 1; min-width: 0; padding: 10px 12px; color-scheme: dark; }

.banner { padding: 10px 14px; background: var(--accent-dim); color: var(--accent); font-size: 14px; text-align: center; }
.banner.warn { background: #3a2a08; color: var(--warn); }

/* bottom tabs */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: rgba(15,23,32,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; padding: 12px 4px; background: none; border: 0; color: var(--muted); font-size: 13px; }
.tab.active { color: var(--accent); }

.toast {
  position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface2); color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.hidden { display: none !important; }

/* markdown */
.md h1 { font-size: 22px; margin: 6px 0 12px; }
.md h2 { font-size: 18px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.md h3 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 15px; }
.md table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface2); }
.md code { background: var(--surface2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md pre { background: var(--surface2); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 4px 12px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md a { word-break: break-word; }

/* timer / stopwatch sheet */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end;
  background: rgba(0,0,0,.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.sheet-card { width: 100%; max-width: 720px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.seg { display: flex; flex: 1; background: var(--surface2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg-btn { flex: 1; padding: 8px 0; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg-btn.active { background: var(--accent); color: #06231f; }
.sheet-close { flex: none; width: 38px; height: 38px; border: 0; border-radius: 999px; background: var(--surface2); color: var(--muted); font-size: 16px; }
.timer-display { text-align: center; font-size: 64px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: 1px; margin: 18px 0 14px; color: var(--text); }
.timer-display.done { color: var(--accent); animation: pulse .6s ease-in-out 3; }
@keyframes pulse { 50% { opacity: .35; } }
.timer-presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.preset { padding: 9px 16px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.preset.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.timer-controls { display: flex; gap: 10px; }
.timer-controls .btn { margin-top: 0; }
