:root {
  color-scheme: dark;
  --page: #0a0a0c;
  --surface: #131317;
  --surface-2: #1c1c22;
  --surface-3: #26262e;
  --ink: #f5f5f2;
  --ink-2: #b8b8b2;
  --muted: #7c7c78;
  --grid: #232329;
  --baseline: #34343c;
  --volt: #d4ff4f;
  --volt-dim: #a8cc3f;
  --volt-ink: #10120a;
  --blue: #3987e5;
  --good: #4ade80;
  --danger: #f87171;
  --border: rgba(255,255,255,0.07);
  --border-hi: rgba(255,255,255,0.12);
  --r: 20px;
  --r-s: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  background: var(--page); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(420px 320px at 85% -60px, rgba(212,255,79,0.07), transparent 70%),
    radial-gradient(500px 400px at -10% 20%, rgba(57,135,229,0.06), transparent 70%);
}
.view { position: relative; z-index: 1; padding: 24px 18px calc(130px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.page-head p { margin-top: 5px; font-size: 13.5px; }
h2 { font-size: 13px; color: var(--muted); margin-bottom: 14px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }
.msg { font-size: 13px; min-height: 18px; margin-top: 12px; color: var(--good); }

.icon { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.28em; }

.card {
  position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0) 40%), var(--surface);
  border: 1px solid var(--border); border-radius: var(--r); padding: 20px; margin-bottom: 16px;
}

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px; border-radius: 16px; border: 1px solid var(--border-hi);
  background: var(--surface-2); color: var(--ink); font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform .12s ease, opacity .12s ease; letter-spacing: 0.01em;
}
.btn.primary { background: var(--volt); border-color: transparent; color: var(--volt-ink); box-shadow: 0 8px 28px -10px rgba(212,255,79,0.45); }
.btn.ghost { background: transparent; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .35; box-shadow: none; }

/* ---------- auth ---------- */
.auth-view { display: flex; align-items: center; justify-content: center; min-height: 92vh; }
.auth-card { width: 100%; max-width: 340px; text-align: center; }
.auth-logo {
  width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 24px;
  background: var(--volt); color: var(--volt-ink); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 14px 44px -12px rgba(212,255,79,0.5);
}
.auth-logo .icon { width: 38px; height: 38px; stroke-width: 2; }
.auth-card h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.auth-card > p { margin: 8px 0 26px; font-size: 13.5px; }
.auth-card input {
  width: 100%; padding: 15px 16px; margin-bottom: 12px; border-radius: 16px;
  border: 1px solid var(--border-hi); background: var(--surface); color: var(--ink); font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--volt-dim); }

/* ---------- home ---------- */
.hero { display: flex; align-items: center; gap: 22px; }
.ring-wrap { position: relative; width: 118px; height: 118px; flex: none; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-bg { stroke: var(--surface-3); }
.ring-fg { stroke: var(--volt); transition: stroke-dashoffset .8s ease; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center b { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.ring-center span { font-size: 10px; color: var(--muted); margin-top: 2px; }
.hero-stats { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.hs { display: flex; flex-direction: column; }
.hs b { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.hs b em { font-style: normal; font-size: 13px; color: var(--muted); font-weight: 600; margin-left: 3px; }
.hs span { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.hs b .up { color: var(--volt); }

#chart { width: 100%; display: block; }
.chart-tip {
  position: fixed; transform: translate(-50%, -130%); background: var(--surface-3);
  border: 1px solid var(--border-hi); border-radius: 10px; padding: 7px 12px; font-size: 12px;
  color: var(--ink); pointer-events: none; white-space: nowrap; z-index: 30;
}
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick .btn.span2 { grid-column: 1 / -1; }

/* ---------- weigh ---------- */
.shoot-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 30px 12px; border: 1.5px dashed var(--baseline);
  border-radius: var(--r-s); color: var(--ink-2); font-size: 15px; font-weight: 600; cursor: pointer; margin-bottom: 14px;
}
.shoot-btn .icon { width: 30px; height: 30px; color: var(--volt); }
.preview img { width: 100%; border-radius: 12px; margin-bottom: 12px; }
.weight-input-row { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.weight-input-row input {
  flex: 1; padding: 14px; font-size: 26px; font-weight: 800; text-align: center; letter-spacing: -0.02em;
  border-radius: 16px; border: 1px solid var(--border-hi); background: var(--surface-2); color: var(--ink);
}
.weight-input-row input:focus { outline: none; border-color: var(--volt-dim); }
.unit { color: var(--muted); font-weight: 600; }
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 2px; border-bottom: 1px solid var(--grid); font-size: 14.5px;
}
.list-row:last-child { border-bottom: none; }
.list-row .d { color: var(--muted); font-size: 13px; }
.list-row b { font-weight: 700; }
.delta-down { color: var(--good); font-size: 12px; font-weight: 700; margin-left: 6px; }
.delta-up { color: var(--danger); font-size: 12px; font-weight: 700; margin-left: 6px; }

/* ---------- photos ---------- */
.slot-tabs { display: flex; gap: 8px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 4px; }
.slot-tab { flex: 1; padding: 10px; border-radius: 11px; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.slot-tab.active { background: var(--surface-3); color: var(--ink); }
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.photo-cell { position: relative; border-radius: 14px; overflow: hidden; aspect-ratio: 3/4; border: 2px solid transparent; }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell .pd { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; padding: 4px 6px; background: linear-gradient(transparent, rgba(0,0,0,.75)); color: var(--ink-2); }
.photo-cell.selected { border-color: var(--volt); }
.photo-cell .sel-badge { position: absolute; top: 5px; right: 5px; background: var(--volt); color: var(--volt-ink); width: 20px; height: 20px; border-radius: 50%; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; }

/* ---------- camera / compare modals ---------- */
.modal { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ghost { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .38; pointer-events: none; }
.cam-tip { position: absolute; top: calc(24px + env(safe-area-inset-top)); left: 24px; right: 24px; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 4px #000; }
.cam-bar { position: absolute; bottom: calc(30px + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; align-items: center; justify-content: space-around; }
.cam-btn { width: 52px; height: 52px; border-radius: 50%; border: none; background: rgba(255,255,255,.14); color: #fff; font-size: 19px; backdrop-filter: blur(8px); }
.cam-shutter { width: 76px; height: 76px; border-radius: 50%; background: #fff; border: 5px solid rgba(255,255,255,.3); }
.cam-shutter:active { transform: scale(.9); }

#compare-modal { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); gap: 16px; background: rgba(10,10,12,.97); }
.compare-wrap { position: relative; width: 100%; max-width: 480px; aspect-ratio: 3/4; border-radius: 16px; overflow: hidden; }
.compare-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#cmp-b-clip { position: absolute; inset: 0; overflow: hidden; }
#cmp-handle { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--volt); left: 50%; box-shadow: 0 0 10px rgba(212,255,79,.5); }
.cmp-label { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 8px; backdrop-filter: blur(6px); }
.cmp-label.right { left: auto; right: 10px; }
#cmp-range { width: 100%; max-width: 480px; accent-color: var(--volt); }
#compare-modal .btn { max-width: 480px; }

/* ---------- train ---------- */
.ex-list { display: flex; flex-direction: column; }
.ex-row { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--grid); }
.ex-row:last-child { border-bottom: none; }
.ex-num { width: 34px; height: 34px; flex: none; border-radius: 11px; background: var(--surface-3); color: var(--volt); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; }
.ex-info { flex: 1; }
.ex-info b { display: block; font-size: 15px; font-weight: 700; }
.ex-info span { font-size: 12px; color: var(--muted); }
.ex-target { font-size: 13px; font-weight: 700; color: var(--ink-2); }

.sets-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 14px 0 4px; }
.set-btn { padding: 15px 8px; border-radius: 14px; border: 1px solid var(--border-hi); background: var(--surface-2); color: var(--ink); font-size: 15px; font-weight: 800; }
.set-btn.active { background: var(--volt); border-color: transparent; color: var(--volt-ink); }
details.manual { margin-top: 2px; }
details.manual summary { list-style: none; cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px 0; }
details.manual summary::-webkit-details-marker { display: none; }

/* ---------- train session ---------- */
#train-modal { background: #000; justify-content: flex-start; }
#train-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform: scaleX(-1); }
#train-skeleton { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.train-shade { position: absolute; inset: 0; background: linear-gradient(rgba(0,0,0,.55), transparent 22%, transparent 62%, rgba(0,0,0,.65)); pointer-events: none; }
.train-hud-top {
  position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 18px; right: 18px;
  display: flex; align-items: flex-start; justify-content: space-between;
}
.train-meta b { display: block; font-size: 21px; font-weight: 800; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.train-meta span { font-size: 12.5px; color: rgba(255,255,255,.75); }
#train-close { width: 40px; height: 40px; border-radius: 50%; border: none; background: rgba(255,255,255,.16); color: #fff; font-size: 17px; backdrop-filter: blur(8px); }
.train-count {
  position: absolute; right: 22px; top: 50%; transform: translateY(-50%);
  text-align: right; color: #fff; text-shadow: 0 2px 10px rgba(0,0,0,.55);
}
.train-count b { font-size: 74px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; color: var(--volt); }
.train-count span { font-size: 17px; font-weight: 600; color: rgba(255,255,255,.8); }
.tm-meter { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.7); margin-top: 6px; }
.meter { position: relative; width: 132px; height: 8px; margin: 12px 0 0 auto; border-radius: 4px; background: rgba(255,255,255,.18); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: #fff; border-radius: 4px; transition: width .1s linear; }
.meter i.hit { background: var(--volt); }
.meter .meter-mark { position: absolute; top: -2px; bottom: -2px; left: 89%; width: 2px; background: var(--volt); border-radius: 1px; }

.pref-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 2px; font-size: 14px; color: var(--ink-2); }
.seg { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 12px; border: none; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 700; }
.seg button.on { background: var(--surface-3); color: var(--volt); }

.week-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.wk { text-align: center; }
.wk b { display: block; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; color: var(--volt); }
.wk span { font-size: 11px; color: var(--muted); }
#train-hint {
  position: absolute; left: 18px; right: 18px; bottom: calc(108px + env(safe-area-inset-bottom));
  text-align: center; color: #fff; font-size: 16px; font-weight: 600; text-shadow: 0 1px 6px rgba(0,0,0,.7); min-height: 22px;
}
#train-hint.warn { color: #ffd166; }
.train-progress { position: absolute; left: 18px; right: 18px; bottom: calc(88px + env(safe-area-inset-bottom)); height: 4px; border-radius: 2px; background: rgba(255,255,255,.18); overflow: hidden; }
.train-progress i { display: block; height: 100%; width: 0; background: var(--volt); border-radius: 2px; transition: width .3s ease; }
.train-bar { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); left: 0; right: 0; display: flex; justify-content: center; gap: 14px; }
.train-bar .tbtn { padding: 13px 26px; border-radius: 26px; border: none; background: rgba(255,255,255,.14); color: #fff; font-size: 14px; font-weight: 700; backdrop-filter: blur(10px); }

.train-overlay {
  position: absolute; inset: 0; z-index: 5; background: rgba(10,10,12,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 32px; text-align: center;
}
.train-overlay h3 { font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.train-overlay .big { font-size: 84px; font-weight: 800; letter-spacing: -0.04em; color: var(--volt); line-height: 1.1; }
.train-overlay p { color: var(--ink-2); font-size: 15px; max-width: 300px; }
.train-overlay .btn { max-width: 300px; margin-top: 14px; }
.demo-canvas {
  width: 210px; height: 260px; border-radius: 18px;
  background: radial-gradient(140px 170px at 50% 45%, rgba(212,255,79,0.08), transparent 75%), var(--surface);
  border: 1px solid var(--border);
}
.demo-canvas.sm { width: 150px; height: 186px; }
.demo-name { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; }
.sum-list { width: 100%; max-width: 320px; margin-top: 8px; }
.sum-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--grid); font-size: 14.5px; }
.sum-row:last-child { border-bottom: none; }
.sum-row .ok { color: var(--volt); font-weight: 700; }

/* ---------- tabbar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; z-index: 40;
  background: rgba(15,15,18,.86); backdrop-filter: blur(18px); border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
#tabbar button {
  flex: 1; padding: 7px 0 5px; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; border-radius: 12px;
  font-family: inherit;
}
#tabbar button .icon { width: 22px; height: 22px; }
#tabbar button span { font-size: 10px; font-weight: 600; }
#tabbar button.active { color: var(--volt); }

.app-ver { text-align: center; color: var(--muted); font-size: 11px; margin-top: 22px; letter-spacing: 0.04em; }

#update-bar {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; z-index: 70; cursor: pointer;
  background: var(--surface-3); border: 1px solid var(--border-hi); border-radius: 22px;
  padding: 11px 18px; font-size: 13.5px; box-shadow: 0 10px 34px rgba(0,0,0,.55);
  animation: slideDown .35s ease;
}
#update-bar b { color: var(--volt); font-weight: 800; }
@keyframes slideDown { from { transform: translate(-50%, -140%); } to { transform: translate(-50%, 0); } }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--border-hi); color: var(--ink);
  padding: 11px 20px; border-radius: 22px; font-size: 14px; font-weight: 600; z-index: 60; max-width: 86vw; text-align: center;
  box-shadow: 0 10px 34px rgba(0,0,0,.5);
}
