:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1c1c1c;
  --border: #3b434e;
  --accent: #c8ff00;
  --accent-dim: rgba(200,255,0,0.12);
  --accent2: #ff4d4d;
  --text: #f0f0f0;
  --muted: #9aa4af;
  --radius: 14px;
  --toast-bg: #c8ff00;
  --toast-fg: #000;
}
.light {
  --bg: #f6f7f1;
  --surface: #ffffff;
  --surface2: #edf1e4;
  --border: #c8d0b6;
  --accent: #4f7f00;
  --accent-dim: rgba(94,142,0,0.14);
  --accent2: #e63030;
  --text: #141810;
  --muted: #55604f;
  --toast-bg: #243511;
  --toast-fg: #f5f9ef;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  line-height: 1.45;
  transition: background 0.3s, color 0.3s;
}

/* ── STICKY HEADER WRAPPER ── */
.app-header-sticky {
  position: sticky;
  top: 0;
  z-index: 110;
  background: var(--bg);
}

/* ── TOP BAR ── */
.topbar {
  position: relative;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  gap: 10px;
}

.topbar-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  flex: 1 1 0;
  min-width: 120px;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.topbar-actions { display: flex; gap: 8px; }

.topbar-icon-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.icon-label {
  font-size: 0.52rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  text-transform: uppercase;
  transition: color 0.2s;
}

.icon-label.active { color: var(--accent); }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  animation: pulse-wake 2s ease-in-out infinite;
}
@keyframes pulse-wake {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200,255,0,0.5); }
  50%       { box-shadow: 0 0 0 6px rgba(200,255,0,0); }
}
.light .icon-btn.active {
  background: var(--accent);
  color: #f5f9ef;
  border-color: var(--accent);
  animation: pulse-wake-light 2s ease-in-out infinite;
}
@keyframes pulse-wake-light {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0,0,0,0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(0,0,0,0); }
}

/* ── TABS ── */
.tabs {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1;
}
.tab {
  flex: 1;
  padding: 12px 6px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab.active { color: var(--accent); border-color: var(--accent); }

/* ── PAGES ── */
.page {
  display: none;
  padding: 16px;
  max-width: 920px;
  margin: 0 auto;
}
.page.active { display: block; }

/* ── SESSION DATE HEADER ── */
.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.session-date {
  font-family: 'Space Mono', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.session-progress {
  font-family: 'Space Mono', monospace;
  font-size: 0.78rem;
  color: var(--accent);
}

/* ── OVERALL PROGRESS BAR ── */
.overall-bar-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.overall-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.overall-label span:last-child { font-family: 'Space Mono', monospace; color: var(--accent); }
.bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(.4,2,.6,1);
}

/* ── EXERCISE CARDS ── */
.exercises { display: flex; flex-direction: column; gap: 12px; }

.pair-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 2px -2px;
}

.pair-title {
  font-family: 'Space Mono', monospace;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.pair-hint {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.ex-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.3s;
}
.ex-card.all-done { border-color: var(--accent); }

.ex-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px;
}
.ex-num {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--muted);
  min-width: 22px;
}
.ex-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
}
.ex-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.ex-pair-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: 'Space Mono', monospace;
  font-size: 0.62rem;
  line-height: 1;
}
.ex-check {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  flex-shrink: 0;
  transition: background 0.3s, border-color 0.3s;
}
.ex-card.all-done .ex-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}

.ex-series {
  display: flex;
  gap: 8px;
  padding: 2px 14px 14px 48px;
  flex-wrap: wrap;
}

.serie-btn {
  flex: 1;
  min-width: 80px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
}
.serie-btn span {
  display: block;
  font-size: 0.62rem;
  margin-top: 2px;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
}
.serie-btn.done {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.serie-btn:active { transform: scale(0.94); }

/* ── EXERCISE DESC ── */
.ex-desc-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 14px 0 48px;
  background: var(--surface2);
  border-top: 0px solid var(--border);
}
.ex-card.open .ex-desc-body {
  max-height: 120px;
  padding: 12px 14px 12px 48px;
  border-top: 1px solid var(--border);
}
.ex-desc-text {
  font-size: 0.82rem;
  color: var(--text);
  opacity: 0.9;
  line-height: 1.6;
}
.light .ex-desc-text { color: #3f4638; }
.ex-muscle-tag {
  display: inline-block;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  letter-spacing: 0.04em;
}
.ex-expand-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.15rem;
  padding: 0 2px;
  cursor: pointer;
  transition: transform 0.25s ease, color 0.2s;
  flex-shrink: 0;
  line-height: 1;
}
.ex-card.open .ex-expand-btn { transform: rotate(180deg); color: var(--accent); }

/* ── RESET BTN ── */
.reset-row {
  display: flex;
  justify-content: center;
  margin-top: 12px;
  margin-bottom: 14px;
  gap: 8px;
  flex-wrap: wrap;
}
.reset-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  padding: 9px 20px;
  min-height: 38px;
  border-radius: 99px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.reset-row-top { margin-bottom: 8px; }
.reset-row-bottom { margin-top: 18px; margin-bottom: 8px; }
.reset-btn:hover { border-color: color-mix(in srgb, var(--accent) 70%, var(--border)); color: color-mix(in srgb, var(--accent) 82%, var(--text)); }
.reset-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

/* ── PROGRESS PAGE ── */
.stat-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}
.stat-val {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem;
  color: var(--accent);
  line-height: 1;
}
.stat-lbl {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.stat-box.goal-hit {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.stat-box.goal-hit .stat-lbl {
  color: var(--accent);
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.chart-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
}
.chart-wrap { position: relative; height: 180px; }

/* ── MEALS PAGE ── */
.plan-layout {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.plan-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.meal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.meal-grid-training {
  margin-top: 0;
}

.meal-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 2px;
}

.meal-card,
.meal-notes {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 15px;
}

.meal-day-title,
.meal-notes-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
}

.meal-block {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.meal-block:last-child { margin-bottom: 0; }
.meal-block:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.meal-block-title {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.meal-list {
  list-style: disc;
  padding-left: 18px;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.55;
}

.meal-list li { margin-bottom: 4px; }
.meal-list li:last-child { margin-bottom: 0; }

.meal-notes { margin-top: 0; }

.plan-subblock {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
}

.plan-subblock-title {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.plan-note {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.variant-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.variant-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.45;
}

.variant-subblock .meal-list {
  margin-top: 8px;
}

.variant-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.45;
}

.day-pill,
.day-pill-placeholder {
  min-width: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--border);
}

.day-pill-force {
  background: rgba(200,255,0,0.14);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 70%, var(--border));
}

.day-pill-cardio {
  background: rgba(80,140,255,0.16);
  color: #9dc5ff;
  border-color: rgba(128,174,255,0.6);
}

.light .day-pill-cardio {
  background: rgba(41,102,187,0.12);
  color: #2a5a9a;
  border-color: rgba(42,90,154,0.35);
}

.day-pill-placeholder {
  border-color: transparent;
  color: transparent;
}

body:not(.light) .tab:hover,
body:not(.light) .ex-expand-btn:hover,
body:not(.light) .import-btn:hover,
body:not(.light) .export-btn:hover {
  color: color-mix(in srgb, var(--accent) 80%, var(--text));
  border-color: color-mix(in srgb, var(--accent) 65%, var(--border));
}

@media (min-width: 860px) {
  .meal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .meal-grid-training {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── HISTORY ── */
.history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-date { font-family: 'Space Mono', monospace; font-size: 0.75rem; color: var(--muted); }
.history-val { font-family: 'Space Mono', monospace; font-size: 0.82rem; color: var(--accent); }
.history-val.incomplete { color: var(--accent2); }
.history-bar {
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  margin-top: 8px;
  overflow: hidden;
}
.history-bar-fill { height: 100%; background: var(--accent); border-radius: 99px; }

/* ── EMPTY STATE ── */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.7;
}
.empty-icon { font-size: 2rem; margin-bottom: 8px; }

/* ── DATA EXPORT/IMPORT ── */
.data-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.data-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 10px;
  border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.01em;
  text-align: center;
  user-select: none;
}
.export-btn {
  background: var(--accent-dim);
  border: 1.5px solid var(--accent);
  color: var(--accent);
}
.export-btn:active { opacity: 0.7; transform: scale(0.97); }
.import-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--muted);
}
.import-btn:active { opacity: 0.7; transform: scale(0.97); }
.file-input-hidden { display: none; }

/* ── COMPLETE TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 12px 24px;
  border-radius: 99px;
  border: 1px solid var(--border);
  z-index: 999;
  transition: transform 0.35s cubic-bezier(.4,2,.6,1);
  white-space: nowrap;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── CONFIRM DIALOG ── */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dialog-backdrop.show { display: flex; }
.dialog {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.dialog-title {
  font-family: 'Space Mono', monospace;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
}
.dialog-text {
  margin-top: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
}
.dialog-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.dialog-btn {
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-family: 'DM Sans', sans-serif;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}
.dialog-btn-cancel { color: var(--muted); }
.dialog-btn-danger {
  border-color: var(--accent2);
  color: var(--accent2);
}

@media (min-width: 560px) {
  .stat-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 20px;
  }

  .data-actions {
    flex-direction: row;
  }
}

@media (min-width: 1024px) {
  .page {
    max-width: 1000px;
    padding: 22px;
  }

  .exercises,
  .reset-row-top,
  .reset-row-bottom,
  .overall-bar-wrap,
  .session-header {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
  }

  .chart-wrap {
    height: 210px;
  }
}
