:root {
  --bg: #efece4;
  --paper: #f7f6f2;
  --ink: #1a1916;
  --muted: #5e5a53;
  --line: #e0dbd2;
  --green: #1f6b4a;
  --green-ink: #ffffff;
  --green-soft: #e5f3ec;
  --amber: #8a5a12;
  --amber-soft: #f8efd8;
  --red: #8f3d32;
  --shadow: 0 1px 0 rgba(26, 25, 22, 0.04);
  color-scheme: light;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }

#app {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(92px + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 5;
}
.tabbar a {
  text-decoration: none;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.tabbar a.active { color: var(--green); background: var(--green-soft); }

h1 { font-size: 28px; line-height: 1.1; margin: 0 0 4px; letter-spacing: -0.03em; }
h2 { font-size: 18px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.lede { color: var(--muted); margin-bottom: 16px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.stack { display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 8px; }
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--muted); font-size: 12px; }

label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 16px;
}
textarea { min-height: 72px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 44px; }
.check input { width: 20px; height: 20px; }

.btn, .tabbar a, .chip {
  min-height: 44px;
}
.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--green);
  color: var(--green-ink);
  font-weight: 700;
}
.btn.secondary { background: var(--green-soft); color: var(--green); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; }

.chip {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
}
.chip.on { background: var(--green); color: white; border-color: var(--green); }

.alert {
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0;
}
.alert.bad { background: #f8e6e3; color: var(--red); }
.note { font-size: 13px; color: var(--muted); }

.bar {
  height: 8px;
  background: #e7e2d8;
  border-radius: 99px;
  overflow: hidden;
}
.bar span { display: block; height: 100%; background: var(--green); }
.bar.warn span { background: var(--amber); }
.bar.over span { background: var(--red); }
.micro { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; margin-bottom: 8px; font-size: 14px; }

.search-hit, .log-row, .lift {
  width: 100%;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.lift.done { background: var(--green-soft); }
.set {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: white;
  padding: 8px 10px;
  font-weight: 650;
}
.set.on { background: var(--green); color: white; border-color: var(--green); }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #141210;
  border-radius: 16px;
  overflow: hidden;
}
.stage video, .stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.reps {
  font-size: 56px;
  line-height: 1;
  letter-spacing: -0.04em;
}
.photo-preview { width: 100%; border-radius: 12px; max-height: 240px; object-fit: cover; background: #ddd; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 26px; }
}
