/* ===== RESET & ROOT ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0A0A0F;
  --surface: #13131A;
  --card: #1C1C27;
  --card2: #22222F;
  --border: #2E2E3E;
  --accent: #C8FF00;
  --accent-dim: #8FAF00;
  --accent-glow: rgba(200,255,0,0.15);
  --text: #FFFFFF;
  --text-2: #9999AA;
  --text-3: #555566;
  --success: #00E87A;
  --danger: #FF4D6D;
  --warn: #FFB800;
  --radius: 16px;
  --radius-sm: 10px;
  --tab-h: 70px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ===== SCROLLABLE CONTENT ===== */
.scroll-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 16px);
}
.scroll-content.no-tab { padding-bottom: 24px; }

/* ===== AUTH SCREEN ===== */
#screen-auth {
  background: var(--bg);
  align-items: center;
  justify-content: center;
  gap: 0;
}
.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 48px;
}
.auth-logo img { width: 72px; height: 72px; border-radius: 18px; }
.auth-logo h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.auth-logo h1 span { color: var(--accent); }
.auth-logo p { color: var(--text-2); font-size: 14px; }

.pin-dots {
  display: flex;
  gap: 16px;
  margin-bottom: 40px;
}
.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all 0.15s;
}
.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.pin-dot.error {
  background: var(--danger);
  border-color: var(--danger);
  animation: shake 0.35s;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 280px;
}
.pin-key {
  height: 72px;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.pin-key:active { transform: scale(0.93); background: var(--card2); }
.pin-key.del { font-size: 20px; color: var(--text-2); }
.pin-key.empty { visibility: hidden; }

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  flex-shrink: 0;
}
.topbar-title { font-size: 22px; font-weight: 800; }
.topbar-title span { color: var(--accent); }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--card);
  border: none;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.1s;
}
.icon-btn:active { transform: scale(0.9); }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: color 0.15s;
  padding: 8px 4px 0;
}
.nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active .nav-icon {
  filter: drop-shadow(0 0 6px var(--accent));
}

/* ===== CARDS ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}
.card-sm { padding: 14px; }
.card-accent {
  background: var(--accent);
  color: #000;
}
.card-accent .text-2 { color: rgba(0,0,0,0.6); }

/* ===== HOME SCREEN ===== */
.greeting { font-size: 13px; color: var(--text-2); margin-bottom: 2px; }
.greeting-name { font-size: 24px; font-weight: 800; margin-bottom: 20px; }

.today-card {
  background: var(--accent);
  color: #000;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}
.today-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  background: rgba(0,0,0,0.15);
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 8px;
}
.today-day-name { font-size: 28px; font-weight: 900; letter-spacing: -1px; margin-bottom: 4px; }
.today-meta { font-size: 13px; opacity: 0.7; margin-bottom: 18px; }
.btn-start {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: #000;
  color: var(--accent);
  border: none;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: opacity 0.1s;
}
.btn-start:active { opacity: 0.8; }
.rest-day-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  text-align: center;
}
.rest-day-icon { font-size: 48px; margin-bottom: 8px; }
.rest-day-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.rest-day-sub { font-size: 13px; color: var(--text-2); }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  margin-top: 6px;
}
.section-title { font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-2); }
.section-link { font-size: 12px; color: var(--accent); font-weight: 600; cursor: pointer; }

/* PR cards row */
.pr-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}
.pr-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.pr-card-label { font-size: 11px; color: var(--text-2); margin-bottom: 4px; font-weight: 600; }
.pr-card-value { font-size: 22px; font-weight: 900; color: var(--accent); }
.pr-card-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ===== WORKOUT SCREEN (day view) ===== */
.workout-header {
  background: var(--surface);
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.workout-header-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.back-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--card);
  border: none;
  color: var(--text);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.workout-header-title { font-size: 20px; font-weight: 800; flex: 1; }
.workout-timer {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}
.workout-timer-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: 1px; }
.btn-finish {
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--success);
  color: #000;
  border: none;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

/* Exercise list item */
.exercise-item {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.exercise-item.active-ex { border-color: var(--accent); }
.exercise-item-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  gap: 12px;
}
.exercise-check {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  color: transparent;
  transition: all 0.2s;
}
.exercise-check.done { border-color: var(--success); background: var(--success); color: #000; }
.exercise-check.in-progress { border-color: var(--accent); }
.exercise-item-name { font-size: 16px; font-weight: 700; flex: 1; }
.exercise-item-sets { font-size: 12px; color: var(--text-2); }
.chevron { font-size: 12px; color: var(--text-3); transition: transform 0.2s; }
.exercise-item.expanded .chevron { transform: rotate(180deg); }

/* Exercise expand panel */
.exercise-panel {
  display: none;
  padding: 0 16px 16px;
  flex-direction: column;
  gap: 12px;
}
.exercise-item.expanded .exercise-panel { display: flex; }

.pr-banner {
  background: var(--card2);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pr-banner-left label { font-size: 10px; color: var(--text-2); letter-spacing: 1px; text-transform: uppercase; display: block; }
.pr-banner-left .pr-val { font-size: 20px; font-weight: 900; color: var(--accent); }
.pr-banner-right { text-align: right; }
.pr-banner-right label { font-size: 10px; color: var(--text-2); letter-spacing: 1px; text-transform: uppercase; display: block; }
.pr-banner-right .ws-val { font-size: 16px; font-weight: 700; color: var(--text); }

/* Set logger */
.set-log-header {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 36px;
  gap: 8px;
  font-size: 11px;
  color: var(--text-2);
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 0 2px;
}
.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 36px;
  gap: 8px;
  align-items: center;
}
.set-num { font-size: 12px; color: var(--text-2); text-align: center; font-weight: 700; }
.set-input {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  padding: 8px 6px;
  width: 100%;
  -moz-appearance: textfield;
}
.set-input::-webkit-outer-spin-button,
.set-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.set-input:focus { outline: none; border-color: var(--accent); }
.set-done-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.set-done-btn.logged { background: var(--success); border-color: var(--success); color: #000; }

.btn-add-set {
  padding: 10px;
  border-radius: 10px;
  background: var(--card2);
  border: 1px dashed var(--border);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  width: 100%;
  transition: all 0.15s;
}
.btn-add-set:active { border-color: var(--accent); color: var(--accent); }

/* ===== CAMERA SCREEN ===== */
.camera-container {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  flex-shrink: 0;
}
#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#camera-canvas { display: none; }
#camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}
.camera-overlay {
  position: absolute;
  bottom: 12px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 16px;
}
.camera-shutter {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent);
  border: 4px solid rgba(255,255,255,0.3);
  cursor: pointer;
  transition: transform 0.1s;
  box-shadow: 0 0 20px rgba(200,255,0,0.4);
}
.camera-shutter:active { transform: scale(0.9); }
.camera-retake {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  align-self: center;
  display: none;
}

.camera-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.btn-identify {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-identify.show { display: flex; }
.btn-lens {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-lens:active { background: var(--card2); }

/* Identify results */
.identify-results {
  margin-top: 14px;
}
.result-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.result-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; font-weight: 700; }
.result-machine { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.result-confidence { font-size: 12px; color: var(--success); font-weight: 600; }

.match-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.match-item:last-child { border-bottom: none; }
.match-name { font-size: 15px; font-weight: 600; }
.match-cat { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.btn-add-match {
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn-add-new {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius);
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}

/* Camera permission error */
.camera-error {
  background: var(--card);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
}
.camera-error-icon { font-size: 48px; margin-bottom: 12px; }
.camera-error-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.camera-error-desc { font-size: 14px; color: var(--text-2); }

/* ===== HISTORY SCREEN ===== */
.history-day {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.history-day-name { font-size: 16px; font-weight: 700; }
.history-day-date { font-size: 12px; color: var(--text-2); }
.history-stat-row {
  display: flex;
  gap: 16px;
}
.history-stat { text-align: center; }
.history-stat-val { font-size: 18px; font-weight: 800; color: var(--accent); }
.history-stat-label { font-size: 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.5px; }
.history-exercises { margin-top: 10px; }
.history-ex-tag {
  display: inline-block;
  background: var(--card2);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin: 3px 3px 3px 0;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-2);
}
.empty-state-icon { font-size: 56px; margin-bottom: 12px; }
.empty-state-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state-sub { font-size: 14px; }

/* ===== SETTINGS SCREEN ===== */
.settings-group { margin-bottom: 24px; }
.settings-group-title { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-2); margin-bottom: 8px; padding: 0 4px; }
.setting-row {
  background: var(--card);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  cursor: pointer;
}
.setting-row:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.setting-row:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.setting-row:only-of-type { border-radius: var(--radius); }
.setting-row:active { background: var(--card2); }
.setting-label { font-size: 15px; font-weight: 500; }
.setting-value { font-size: 14px; color: var(--text-2); }
.setting-arrow { font-size: 12px; color: var(--text-3); }

/* Toggle */
.toggle {
  width: 44px; height: 26px;
  background: var(--border);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  width: 20px; height: 20px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px; left: 3px;
  transition: transform 0.2s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(18px); }

/* Settings input */
.settings-input {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  padding: 12px 16px;
  width: 100%;
  margin-top: 8px;
}
.settings-input:focus { outline: none; border-color: var(--accent); }
.settings-input::placeholder { color: var(--text-3); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  padding: 24px 20px;
  padding-bottom: calc(24px + var(--safe-b));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-title { font-size: 20px; font-weight: 800; margin-bottom: 16px; }
.modal-input {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 12px 16px;
  width: 100%;
  margin-bottom: 10px;
}
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-input::placeholder { color: var(--text-3); }
.modal-textarea {
  height: 80px;
  resize: none;
  font-family: inherit;
}
.btn-modal-confirm {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 8px;
}
.btn-modal-confirm:active { opacity: 0.85; }
.btn-modal-cancel {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 15px;
  cursor: pointer;
  margin-top: 4px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 200;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  border: 1px solid var(--border);
}
.toast.pr-toast { background: var(--accent); color: #000; border-color: transparent; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== SPINNER ===== */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== UTILS ===== */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-accent { color: var(--accent); }
.text-2 { color: var(--text-2); }
.text-sm { font-size: 13px; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.loading { opacity: 0.5; pointer-events: none; }
