:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1f232c;
  --line: #2b303b;
  --text: #e8eaee;
  --muted: #9aa3b2;
  --accent: #f2c14e;
  --accent-ink: #1a1405;
  --good: #4cc38a;
  --warn: #f2a33a;
  --bad: #ef5d5d;
  --info: #6aa8ff;
  --radius: 14px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(15, 17, 21, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font-weight: 700; letter-spacing: 0.3px; }
.iconbtn { color: var(--muted); font-size: 22px; padding: 4px 8px; }

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

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--panel); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; gap: 2px;
}
.tabbar a .ti { font-size: 16px; }
.tabbar a.active { color: var(--accent); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 0 0 12px;
}
.card.flat { background: transparent; }
.card h2 + p, .card h3 + p { margin-top: -2px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.good { background: var(--good); color: #062014; border-color: var(--good); }
.btn.bad { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 72px; font-size: 20px; border-radius: 16px; }
.btn[disabled] { opacity: 0.45; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
input[type="range"] { padding: 0; accent-color: var(--accent); }
.field { margin-bottom: 10px; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
}
.pill.good { color: var(--good); border-color: rgba(76, 195, 138, 0.4); }
.pill.warn { color: var(--warn); border-color: rgba(242, 163, 58, 0.4); }
.pill.bad { color: var(--bad); border-color: rgba(239, 93, 93, 0.4); }
.pill.accent { color: var(--accent); border-color: rgba(242, 193, 78, 0.45); }
.pill.info { color: var(--info); border-color: rgba(106, 168, 255, 0.4); }

.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; border: 1px solid; }
.banner.green { border-color: rgba(76, 195, 138, 0.4); background: rgba(76, 195, 138, 0.08); }
.banner.amber { border-color: rgba(242, 163, 58, 0.5); background: rgba(242, 163, 58, 0.1); }
.banner.red { border-color: rgba(239, 93, 93, 0.5); background: rgba(239, 93, 93, 0.1); }
.banner.info { border-color: rgba(106, 168, 255, 0.4); background: rgba(106, 168, 255, 0.08); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.kpi .v { font-size: 22px; font-weight: 700; }
.kpi .l { font-size: 12px; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.rowlink { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text); }

.progress { height: 6px; background: var(--panel2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

/* session logging */
.ex { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.ex.done { border-color: rgba(76, 195, 138, 0.45); }
.ex .dose { color: var(--accent); font-weight: 600; }
.ex details summary { color: var(--muted); font-size: 13px; cursor: pointer; margin: 4px 0; }
.setrow { display: grid; grid-template-columns: 54px 1fr 1fr 1fr 48px; gap: 6px; align-items: center; margin-top: 6px; }
.setrow.noload { grid-template-columns: 54px 1fr 1fr 48px; }
.setrow .lbl { font-size: 12px; color: var(--muted); line-height: 1.2; }
.setrow input, .setrow select { min-height: 40px; padding: 6px 8px; text-align: center; }
.setrow .chk { width: 44px; height: 40px; min-height: 0; border-radius: 10px; padding: 0; font-size: 18px; }
.setrow.logged input, .setrow.logged select { border-color: rgba(76, 195, 138, 0.45); color: var(--good); }
.setrow.logged .chk { background: var(--good); color: #062014; border-color: var(--good); }
.setrow.extra .lbl { color: var(--warn); }
.colhead { display: grid; grid-template-columns: 54px 1fr 1fr 1fr 48px; gap: 6px; font-size: 11px; color: var(--muted); text-align: center; margin-top: 8px; }
.colhead.noload { grid-template-columns: 54px 1fr 1fr 48px; }

.checkline { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checkline:last-child { border-bottom: 0; }
.checkline input { margin-top: 2px; flex: none; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.seg button { min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.counter { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.counter .score { text-align: center; font-size: 34px; font-weight: 800; margin: 6px 0; }

/* placement diagram */
.board-wrap { position: relative; width: 100%; }
.board-svg { width: 100%; height: auto; display: block; touch-action: none; }
.board-mini { width: 100%; max-width: 280px; height: auto; display: block; }

/* media */
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.thumbs .t { position: relative; border-radius: 10px; overflow: hidden; background: #000; aspect-ratio: 1; }
.thumbs .t img, .thumbs .t video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .t .badge { position: absolute; left: 4px; bottom: 4px; }

.measure-stage { position: relative; width: 100%; background: #000; border-radius: 12px; overflow: hidden; }
.measure-stage video { width: 100%; height: 60vh; max-height: 560px; object-fit: contain; display: block; }
.measure-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

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

.spark { width: 100%; height: 48px; display: block; }

.timeline .card { position: relative; }
.timeline .when { color: var(--muted); font-size: 13px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 90vw; z-index: 20;
}
#toast.show { opacity: 1; }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.lock { color: var(--muted); }
