:root {
  --bg: #0d0f12;
  --surface: #161a20;
  --surface2: #1f242c;
  --border: #2a313b;
  --text: #eef1f5;
  --muted: #8b95a3;
  --accent: #b6f23a;
  --accent-ink: #11160a;
  --good: #4ade80;
  --mid: #facc15;
  --bad: #f87171;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(13, 15, 18, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: .2px; }
.logo { margin-right: 4px; }
.beta { font-size: 11px; font-weight: 600; color: var(--accent-ink); background: var(--accent); padding: 2px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }
.conn { font-size: 14px; color: var(--muted); }
.conn.ok { color: var(--good); }
.conn.bad { color: var(--bad); }

main { padding: 8px 16px 24px; max-width: 640px; margin: 0 auto; }
h1 { font-size: 24px; margin: 12px 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
p { margin: 6px 0 12px; }
code { background: var(--surface2); padding: 1px 5px; border-radius: 5px; }

.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin: 14px 0;
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input, select {
  display: block; width: 100%; margin-top: 6px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; font: inherit; font-size: 16px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.btn {
  display: block; width: 100%; border: 0; border-radius: 14px;
  padding: 15px; font: inherit; font-weight: 700; font-size: 16px;
  background: var(--surface2); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .4; }
.btn + .btn { margin-top: 10px; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.row-btns { display: flex; gap: 10px; }
.row-btns .btn { margin: 0; }

/* pose slots */
.poses { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.pose {
  position: relative; aspect-ratio: 3 / 4; overflow: hidden;
  background: var(--surface); border: 1.5px dashed var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; cursor: pointer;
}
.pose.filled { border-style: solid; border-color: var(--accent); }
.pose svg { width: 46%; opacity: .55; }
.pose .lbl { font-size: 13px; font-weight: 600; margin-top: 8px; padding: 0 6px; }
.pose .sub { font-size: 11px; color: var(--muted); }
.pose img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pose .tag {
  position: absolute; left: 8px; bottom: 8px; z-index: 2;
  background: rgba(0,0,0,.65); padding: 3px 8px; border-radius: 8px; font-size: 12px;
}
.pose .x {
  position: absolute; right: 6px; top: 6px; z-index: 2; width: 30px; height: 30px;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 16px;
}

/* results */
.score-head { display: flex; gap: 16px; align-items: center; }
.ring {
  --v: 50; flex: none; width: 92px; height: 92px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--v) * 1%), var(--surface2) 0);
  display: grid; place-items: center;
}
.ring > div {
  width: 74px; height: 74px; border-radius: 50%; background: var(--surface);
  display: grid; place-items: center; font-size: 26px; font-weight: 800;
}
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }

.muscle { padding: 10px 0; border-bottom: 1px solid var(--border); }
.muscle:last-child { border-bottom: 0; }
.muscle-top { display: flex; align-items: center; gap: 10px; }
.muscle-name { flex: 1; font-weight: 600; }
.bar { height: 8px; background: var(--surface2); border-radius: 8px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 8px; background: var(--accent); }
.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.pill.good { background: rgba(74,222,128,.15); color: var(--good); }
.pill.mid { background: rgba(250,204,21,.15); color: var(--mid); }
.pill.bad { background: rgba(248,113,113,.15); color: var(--bad); }
.pill.na { background: var(--surface2); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.chip { background: var(--surface2); border: 1px solid var(--border); padding: 5px 10px; border-radius: 999px; font-size: 13px; }
.chip.accent { border-color: var(--accent); color: var(--accent); }
.warn { background: rgba(250,204,21,.1); border: 1px solid rgba(250,204,21,.35); color: var(--mid); padding: 12px; border-radius: 12px; margin-bottom: 12px; }
.err { background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.35); color: var(--bad); padding: 12px; border-radius: 12px; margin: 12px 0; }

/* rating */
.stars { display: flex; gap: 6px; margin: 4px 0 12px; }
.star { background: none; border: 0; font-size: 36px; line-height: 1; color: var(--surface2); padding: 0 2px; cursor: pointer; -webkit-text-stroke: 1px var(--border); }
.star.on { color: #facc15; -webkit-text-stroke: 0; }

/* scan photos (stored on the phone) */
.scan-photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 12px; }
.scan-photos:empty { display: none; }
.scan-photos figure { margin: 0; }
.scan-photos img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; display: block; }
.scan-photos figcaption { font-size: 10px; color: var(--muted); text-align: center; margin-top: 2px; }

/* character */
.char { display: flex; gap: 14px; align-items: center; }
.char svg { width: 90px; flex: none; }
.stat { display: grid; grid-template-columns: 90px 1fr 32px; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0; }
.stat .bar { margin: 0; }

/* workout */
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin: 12px 0; overflow: hidden; }
.day summary { list-style: none; padding: 14px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.day summary::-webkit-details-marker { display: none; }
.day summary b { display: block; }
.day[open] summary { border-bottom: 1px solid var(--border); }
.ex { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.ex:last-child { border-bottom: 0; }
.ex-top { display: flex; justify-content: space-between; gap: 10px; }
.ex-sets { color: var(--accent); font-weight: 700; white-space: nowrap; }

/* weekly workout */
.wday { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.wday.today { border-color: var(--accent); }
.wday.rest { padding: 10px 14px; opacity: .6; }
.wday-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.wday-head b { font-size: 16px; }
.wday-head span { color: var(--accent); font-size: 13px; font-weight: 600; text-align: right; }
.wday.rest .wday-head span { color: var(--muted); }
.wday:not(.rest) .wday-head { margin-bottom: 6px; }
.wex { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; }
.wex b { white-space: nowrap; color: var(--text); }

/* food */
.photo-drop {
  display: grid; place-items: center; min-height: 150px; margin-bottom: 12px;
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface2);
  color: var(--text); font-size: 15px; overflow: hidden; cursor: pointer;
}
.photo-drop img { width: 100%; max-height: 300px; object-fit: cover; }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.macro { background: var(--surface2); border-radius: 12px; padding: 10px; text-align: center; }
.macro b { display: block; font-size: 17px; }
.big-kcal { font-size: 34px; font-weight: 800; }
.log-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.log-item:last-child { border-bottom: 0; }
.log-item .info { flex: 1; }
.del { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px; }

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

/* camera */
.cam { position: fixed; inset: 0; z-index: 40; background: #000; overflow: hidden; }
.cam video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam video.mirror { transform: scaleX(-1); }
.cam-guide {
  position: absolute; inset: 14% 0 22%; display: flex; justify-content: center; pointer-events: none;
}
.cam-guide svg { height: 100%; width: 94%; overflow: visible; }
.cam-guide svg * { fill: rgba(182, 242, 58, .06); stroke: rgba(182, 242, 58, .95); stroke-width: .7; stroke-dasharray: 2.5 1.5; }
.cam-top {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 24px;
  background: linear-gradient(rgba(0,0,0,.75), transparent);
}
.cam-title { flex: 1; text-align: center; text-shadow: 0 1px 3px #000; }
.cam-title b { font-size: 18px; display: block; }
.cam-title div { font-size: 14px; color: #dfe5ec; }
.cam-btn { width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0; background: rgba(0,0,0,.5); color: #fff; font-size: 18px; }
.cam-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 24px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}
.cam-thumbs { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; min-height: 64px; }
.cam-thumbs div {
  width: 48px; height: 64px; border-radius: 8px; border: 2px solid rgba(255,255,255,.35); overflow: hidden;
  background: rgba(255,255,255,.08); display: grid; place-items: center; font-size: 10px; color: #ccc;
}
.cam-thumbs div.cur { border-color: var(--accent); }
.cam-thumbs img { width: 100%; height: 100%; object-fit: cover; }
.cam-controls { display: flex; align-items: center; justify-content: space-between; }
.cam-timer { width: 76px; color: #ddd; font-size: 12px; margin: 0; }
.cam-timer select { padding: 6px; font-size: 14px; margin-top: 2px; background: rgba(0,0,0,.5); }
.shutter {
  width: 78px; height: 78px; border-radius: 50%; border: 5px solid #fff; background: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,0,0,.3);
}
.shutter.stop { background: var(--bad); border-radius: 22px; }
.cam-hint { text-align: center; color: #ddd; font-size: 13px; margin-top: 10px; text-shadow: 0 1px 2px #000; }
.cam-count {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 140px; font-weight: 900; color: #fff; text-shadow: 0 4px 24px rgba(0,0,0,.8);
}
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .35s; }
.cam-flash.on { opacity: .85; transition: none; }

/* tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(22, 26, 32, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; font-weight: 600;
  padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbar button span { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--accent); }
.tabbar button.active span { filter: none; opacity: 1; }

/* loading + toast */
.loading {
  position: fixed; inset: 0; z-index: 50; background: rgba(13,15,18,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  text-align: center; padding: 24px;
}
.loading[hidden] { display: none; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid var(--surface2); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-size: 18px; font-weight: 700; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--surface2); border: 1px solid var(--border); padding: 12px 14px; border-radius: 12px;
  text-align: center; font-weight: 600;
}
.toast[hidden] { display: none; }
