:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text2: #777;
  --accent: #4ade80;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
  font-size: 16px;
}

/* ── Layout ── */
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; position: relative; }

.view {
  display: none; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(80px + var(--safe-bottom));
  padding-top: calc(64px + var(--safe-top));
}
.view.active { display: block; }

/* ── Header ── */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: calc(64px + var(--safe-top)); padding-top: var(--safe-top);
  background: rgba(10,10,10,0.9); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 20px; padding-right: 16px;
}
.header h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: calc(65px + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: rgba(22,22,22,0.95); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; background: none; border: none;
  cursor: pointer; color: var(--text2); font-size: 10px; font-weight: 500;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 22px; line-height: 1; }

/* ── Cards ── */
.card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 16px; margin-bottom: 12px;
}
.card-title {
  font-size: 11px; color: var(--text2); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 14px;
}

/* ── Buttons ── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 15px 20px; border-radius: 14px; border: none;
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s; width: 100%;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-icon {
  width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,0.1);
  border: none; cursor: pointer; font-size: 18px; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}

/* ── Stats ── */
.stats-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 8px; text-align: center;
}
.stat-value { font-size: 20px; font-weight: 700; line-height: 1.2; }
.stat-value.green { color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text2); margin-top: 3px; }

/* ── Section header ── */
.section-header { font-size: 24px; font-weight: 700; padding: 20px 0 4px; letter-spacing: -0.5px; }
.section-sub { font-size: 14px; color: var(--text2); margin-bottom: 18px; }

/* ── Chart ── */
.chart-wrap { position: relative; height: 180px; }
.chart-placeholder {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: var(--text2); font-size: 14px; text-align: center;
  padding: 20px;
}

/* ── Photo slots ── */
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-slot {
  aspect-ratio: 3/4; border-radius: var(--radius);
  border: 2px dashed var(--border); overflow: hidden; position: relative;
  cursor: pointer; background: var(--surface2);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; transition: border-color 0.2s;
}
.photo-slot:active { opacity: 0.8; }
.photo-slot.has { border-style: solid; border-color: var(--accent); }
.photo-slot img, .photo-slot video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.slot-icon { font-size: 32px; }
.slot-label { font-size: 12px; color: var(--text2); text-align: center; line-height: 1.3; }
.slot-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.75)); padding: 8px 6px 6px;
  font-size: 11px; color: #fff; text-align: center; font-weight: 500;
}

/* ── Inputs ── */
.input-group { margin-bottom: 14px; }
.input-label { font-size: 13px; color: var(--text2); display: block; margin-bottom: 6px; }
.input-field {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; font-size: 20px; font-weight: 600;
  color: var(--text); outline: none; -webkit-appearance: none;
  transition: border-color 0.2s;
}
.input-field:focus { border-color: var(--accent); }

/* ── Toggle section ── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-top: 1px solid var(--border); cursor: pointer;
}
.toggle-row-label { font-size: 15px; font-weight: 500; }
.chevron { font-size: 20px; color: var(--text2); transition: transform 0.25s; display: inline-block; }
.chevron.open { transform: rotate(90deg); }
.toggle-body { display: none; padding-top: 12px; }
.toggle-body.open { display: block; }

/* ── Timelapse ── */
.tl-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.tl-tab {
  padding: 11px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text2); font-size: 14px;
  font-weight: 600; cursor: pointer; text-align: center; transition: all 0.2s;
}
.tl-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }

.tl-frame {
  width: 100%; aspect-ratio: 3/4; border-radius: var(--radius); overflow: hidden;
  background: var(--surface2); position: relative; margin-bottom: 12px;
}
.tl-frame img { width: 100%; height: 100%; object-fit: cover; }
.tl-badge {
  position: absolute; bottom: 12px; left: 12px;
  background: rgba(0,0,0,0.65); padding: 4px 12px; border-radius: 20px;
  font-size: 13px; font-weight: 600; color: #fff;
}

.tl-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.tl-play {
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent);
  border: none; cursor: pointer; font-size: 20px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.tl-slider {
  flex: 1; -webkit-appearance: none; height: 4px;
  border-radius: 2px; background: var(--border); outline: none; cursor: pointer;
}
.tl-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
  box-shadow: 0 0 0 4px rgba(74,222,128,0.2);
}
.speed-row { display: flex; align-items: center; gap: 6px; }
.speed-chip {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text2); font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.speed-chip.active { background: var(--surface2); color: var(--text); border-color: var(--text2); }

/* ── History ── */
.hist-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border);
  padding: 12px; margin-bottom: 8px;
}
.hist-thumbs { display: flex; gap: 4px; flex-shrink: 0; }
.hist-thumb {
  width: 46px; height: 62px; border-radius: 8px; object-fit: cover;
  background: var(--surface2); display: flex; align-items: center;
  justify-content: center; font-size: 18px; overflow: hidden;
}
.hist-thumb img { width: 100%; height: 100%; object-fit: cover; }
.hist-info { flex: 1; min-width: 0; }
.hist-date { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.hist-stats { display: flex; gap: 12px; flex-wrap: wrap; }
.hist-stat { font-size: 13px; color: var(--text2); }
.hist-stat strong { color: var(--text); }
.badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.badge {
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-g { background: rgba(74,222,128,0.15); color: var(--accent); }
.badge-o { background: rgba(245,158,11,0.15); color: var(--warning); }

/* ── Empty state ── */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text2);
}
.empty-icon { font-size: 56px; display: block; margin-bottom: 14px; }
.empty p { font-size: 15px; line-height: 1.6; }

/* ── Camera overlay ── */
.camera-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000; display: none; flex-direction: column;
}
.camera-overlay.active { display: flex; }
.camera-preview-wrap { flex: 1; position: relative; overflow: hidden; }
#cam-video { width: 100%; height: 100%; object-fit: cover; transition: transform 0.2s; }
#cam-video.mirror { transform: scaleX(-1); }

.cam-top {
  position: absolute; top: calc(16px + var(--safe-top)); left: 0; right: 0;
  display: flex; justify-content: center; gap: 8px;
}
.cam-mode-btn {
  padding: 7px 18px; border-radius: 20px; border: none; font-size: 14px;
  font-weight: 600; cursor: pointer; background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.6);
}
.cam-mode-btn.active { background: rgba(255,255,255,0.9); color: #000; }

.rec-badge {
  position: absolute; top: calc(16px + var(--safe-top)); left: 16px;
  display: none; align-items: center; gap: 5px;
  background: rgba(0,0,0,0.6); padding: 4px 10px; border-radius: 20px;
}
.rec-badge.show { display: flex; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }
.rec-time { font-size: 13px; color: #fff; font-weight: 600; }

.cam-controls {
  padding: 24px 32px calc(24px + var(--safe-bottom));
  background: rgba(0,0,0,0.8);
  display: flex; align-items: center; justify-content: space-between;
}
.cam-shutter {
  width: 72px; height: 72px; border-radius: 50%; background: #fff;
  border: 4px solid rgba(255,255,255,0.4); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
  transition: transform 0.1s;
}
.cam-shutter:active { transform: scale(0.88); }

/* ── Toast ── */
.toast {
  position: fixed; top: calc(72px + var(--safe-top)); left: 16px; right: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 16px; font-size: 14px; font-weight: 500; z-index: 400;
  transform: translateY(-12px); opacity: 0; transition: all 0.3s; text-align: center;
  pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.ok { border-color: var(--accent); color: var(--accent); }
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ── Delta ── */
#weight-delta { font-size: 13px; color: var(--text2); margin-bottom: 12px; min-height: 18px; }

/* ── Named slots grid ── */
.slots-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px;
}
.slot-named {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; transition: opacity 0.15s;
}
.slot-named:active { opacity: 0.7; }
.slot-thumb {
  width: 100%; aspect-ratio: 3/4; border-radius: 10px;
  background: var(--surface2); border: 2px dashed var(--border);
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.slot-named.has .slot-thumb {
  border: 2px solid var(--accent); border-style: solid;
}
.slot-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot-thumb .add-plus {
  font-size: 28px; color: var(--text2); line-height: 1; font-weight: 300;
}
.slot-name {
  font-size: 12px; color: var(--text2); font-weight: 600;
  text-align: center; letter-spacing: 0.2px;
}
.slot-named.has .slot-name { color: var(--accent); }
.photo-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.75); color: #fff;
  border: none; font-size: 11px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.count-pill {
  float: right; font-size: 11px; color: var(--text2); font-weight: 600;
  background: var(--surface2); padding: 2px 10px; border-radius: 20px;
  letter-spacing: 0; text-transform: none; margin-top: -3px;
}

/* ── Timer overlay (countdown) ── */
.timer-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 140px; font-weight: 800; color: #fff;
  text-shadow: 0 0 40px rgba(0,0,0,0.9);
  pointer-events: none; opacity: 0;
}
.timer-overlay.show { opacity: 1; }
@keyframes pulseCount {
  0%   { transform: scale(1.6); opacity: 0; }
  20%  { transform: scale(1);   opacity: 1; }
  100% { transform: scale(0.6); opacity: 0; }
}

/* ── Timer toggle button ── */
.cam-timer-btn {
  position: absolute; top: calc(16px + var(--safe-top)); right: 16px;
  padding: 7px 14px; border-radius: 20px; border: none;
  font-size: 13px; font-weight: 700; cursor: pointer;
  background: rgba(0,0,0,0.55); color: rgba(255,255,255,0.6);
  display: flex; align-items: center; gap: 4px;
}
.cam-timer-btn.active { background: rgba(74,222,128,0.95); color: #000; }

/* ── Slot label in camera ── */
.cam-slot-label {
  position: absolute; top: calc(16px + var(--safe-top)); left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px; border-radius: 22px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 15px; font-weight: 700;
  letter-spacing: 0.3px; pointer-events: none;
  display: none;
}

/* ── History num badge (multi photo) ── */
.hist-thumb { position: relative; }
.num-badge {
  position: absolute; bottom: 2px; right: 2px;
  background: rgba(74,222,128,0.95); color: #000;
  font-size: 9px; font-weight: 800; padding: 1px 5px; border-radius: 8px;
  line-height: 1.3;
}

/* ── Persistence hint ── */
.hint-card {
  background: rgba(74,222,128,0.06);
  border: 1px solid rgba(74,222,128,0.3);
  border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
  font-size: 13px; line-height: 1.5; color: var(--text);
}
.hint-card strong { color: var(--accent); }

/* ── Settings / Profile ── */
.user-id-box {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px; word-break: break-all;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
  margin-top: 10px; color: var(--accent);
  letter-spacing: 0.5px;
}

.sync-pill {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; background: var(--text2);
  transition: background 0.3s, box-shadow 0.3s;
}
.sync-pill.sync-ok      { background: var(--accent);  box-shadow: 0 0 8px rgba(74,222,128,0.6); }
.sync-pill.sync-pending { background: var(--warning); animation: pulse-pill 1.4s infinite; }
.sync-pill.sync-err     { background: var(--danger); }
.sync-pill.sync-off     { background: var(--text2); }
@keyframes pulse-pill {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.85); }
}

/* ── Misc ── */
.mt-8 { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.label-sm { font-size: 13px; color: var(--text2); }
