/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-input: #21262d;
  --text: #e6edf3;
  --text-muted: #9ea7b1;
  --accent: #22c55e;
  --accent-dim: rgba(34, 197, 94, 0.15);
  --danger: #f85149;
  --border: #30363d;
  --nav-height: 64px;
  --stage-fed: #8b949e;
  --stage-sugar: #58a6ff;
  --stage-fat: #f0883e;
  --stage-ketosis: #22c55e;
  --stage-deep: #a371f7;
  --stage-autophagy: #e3b341;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  position: relative;
}

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

/* === Offline Banner === */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 4px 0;
  font-size: 13px;
  z-index: 1000;
  transition: transform 0.3s;
}
.offline-banner.hidden {
  transform: translateY(-100%);
}

/* === Screens === */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding-bottom: var(--nav-height);
}
.screen.active {
  display: flex;
  flex-direction: column;
}
.screen-content {
  flex: 1;
  padding: 20px 16px 24px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.screen-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* === Timer Screen === */
.date-display {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 16px;
}

.timer-ring-container {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 0 auto 20px;
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.progress-ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 753.98;
  stroke-dashoffset: 753.98;
  transition: stroke-dashoffset 1s linear, stroke 0.5s;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-time {
  display: block;
  font-size: 48px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}

.timer-label {
  display: block;
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.stage-indicator {
  text-align: center;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.stage-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--stage-fed);
}

.target-info {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
  min-height: 20px;
}

/* === Buttons === */
.btn-primary {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 20px;
  padding: 16px 24px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 50px;
  background: var(--accent);
  color: #000;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:active {
  transform: scale(0.96);
}
.btn-primary.stopping {
  background: var(--danger);
  color: #fff;
}

.btn-secondary {
  display: inline-block;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-danger {
  display: inline-block;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 16px;
}

.btn-small {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #000;
  cursor: pointer;
}

/* === Presets === */
.presets-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.preset-chip {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.preset-chip.active {
  border-color: var(--accent);
  color: #fff;
  background: rgba(34, 197, 94, 0.25);
}

.custom-preset {
  text-align: center;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.custom-preset label {
  font-size: 14px;
  color: var(--text-muted);
}
.custom-preset input {
  width: 60px;
  padding: 6px 8px;
  font-size: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-align: center;
}

.hidden {
  display: none !important;
}

/* === Celebration pulse === */
@keyframes celebrate {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 20px rgba(34, 197, 94, 0); }
}
.celebrating .progress-ring-fg {
  filter: drop-shadow(0 0 8px var(--accent));
}

/* === Calendar === */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 16px;
  font-weight: 600;
}

.calendar-grid {
  margin-bottom: 16px;
}

.calendar-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-card);
}
.calendar-day.empty {
  background: transparent;
}
.calendar-day.completed {
  background: var(--accent);
  color: #000;
  font-weight: 700;
}
.calendar-day.partial {
  background: #e3b341;
  color: #000;
  font-weight: 700;
}
.calendar-day.today {
  border: 2px solid var(--accent);
}

/* === Stats === */
.stats-bar {
  display: flex;
  justify-content: space-around;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px 8px;
  margin-bottom: 16px;
}
.stat {
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* === Fast List === */
.fast-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fast-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: 10px;
}
.fast-item-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fast-item-date {
  font-size: 14px;
  font-weight: 600;
}
.fast-item-times {
  font-size: 12px;
  color: var(--text-muted);
}
.fast-item-right {
  text-align: right;
}
.fast-item-duration {
  font-size: 16px;
  font-weight: 700;
}
.fast-item-status {
  font-size: 12px;
}
.fast-item-status.met {
  color: var(--accent);
}
.fast-item-status.missed {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 15px;
}

/* === Settings === */
.settings-group {
  margin-bottom: 24px;
}
.settings-group h3 {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.settings-group select,
.settings-group input[type="time"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  margin-bottom: 8px;
  -webkit-appearance: none;
}
.settings-group input[type="number"] {
  width: 80px;
  padding: 8px;
  font-size: 15px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  cursor: pointer;
  margin-bottom: 10px;
}
.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.about p {
  font-size: 14px;
  margin-bottom: 4px;
}
.muted {
  color: var(--text-muted);
}

/* === Bottom Nav === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 8px 16px;
  transition: color 0.2s;
}
.nav-btn.active {
  color: var(--accent);
}
.nav-btn svg {
  width: 24px;
  height: 24px;
}

/* === Light Mode === */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --bg-card: #f6f8fa;
    --bg-input: #eaeef2;
    --text: #1f2328;
    --text-muted: #656d76;
    --border: #d0d7de;
    --accent: #168039;
    --accent-dim: rgba(22, 128, 57, 0.1);
  }
}

/* Theme overrides */
html.theme-light {
  --bg: #ffffff;
  --bg-card: #f6f8fa;
  --bg-input: #eaeef2;
  --text: #1f2328;
  --text-muted: #656d76;
  --border: #d0d7de;
  --accent: #168039;
  --accent-dim: rgba(22, 128, 57, 0.1);
}
html.theme-dark {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-input: #21262d;
  --text: #e6edf3;
  --text-muted: #9ea7b1;
  --border: #30363d;
  --accent-dim: rgba(34, 197, 94, 0.15);
}

/* === PRO Badge === */
.pro-badge {
  position: fixed;
  top: 10px;
  right: 12px;
  z-index: 200;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  border: 1.5px solid #e3b341;
  border-radius: 12px;
  background: transparent;
  color: #e3b341;
  cursor: pointer;
  transition: all 0.2s;
}
.pro-badge:active {
  transform: scale(0.94);
}
.pro-badge.pro-active {
  background: #e3b341;
  color: #000;
  border-color: #e3b341;
}

/* === Upgrade Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden {
  display: none !important;
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.modal-small {
  max-width: 300px;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}
.modal-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.modal-features {
  list-style: none;
  text-align: left;
  margin: 0 0 20px;
  padding: 0;
}
.modal-features li {
  font-size: 14px;
  padding: 5px 0;
  padding-left: 22px;
  position: relative;
}
.modal-features li::before {
  content: '\2713';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 700;
}
.btn-upgrade {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  border: none;
  border-radius: 50px;
  background: #22c55e;
  color: #000;
  cursor: pointer;
  transition: transform 0.15s;
  margin-bottom: 10px;
}
.btn-upgrade:active {
  transform: scale(0.96);
}
.btn-restore-link {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
  text-decoration: underline;
}

/* === Restore Input === */
.restore-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 18px;
  font-family: monospace;
  text-align: center;
  letter-spacing: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  margin-bottom: 8px;
}
.restore-msg {
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 10px;
}

/* === Upgrade Banner (History) === */
.upgrade-banner {
  text-align: center;
  padding: 16px 14px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 10px;
  margin-top: 4px;
}
.upgrade-banner p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.btn-upgrade-inline {
  display: inline-block;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  border: 1.5px solid #e3b341;
  border-radius: 20px;
  background: transparent;
  color: #e3b341;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-upgrade-inline:active {
  transform: scale(0.96);
}

/* === Responsive === */
@media (max-width: 360px) {
  .timer-time {
    font-size: 40px;
  }
  .timer-ring-container {
    width: 220px;
    height: 220px;
  }
}

@media (min-width: 600px) {
  .screen-content {
    padding: 32px 24px;
  }
}

/* Light mode contrast fixes - must be after base definitions */
@media (prefers-color-scheme: light) {
  .pro-badge { color: #7a5a00; border-color: #7a5a00; }
  .pro-badge.pro-active { background: #7a5a00; color: #fff; border-color: #7a5a00; }
  .preset-chip.active { color: #0d5a22; }
  .nav-btn.active { color: #168039; }
  .btn-primary { color: #fff; }
  .btn-small { color: #fff; }
  .btn-upgrade { color: #fff; }
  .stat-value { color: #168039; }
  .calendar-day.completed { color: #fff; background: #168039; }
  .fast-item-status.met { color: #168039; }
}
html.theme-light .pro-badge { color: #7a5a00; border-color: #7a5a00; }
html.theme-light .pro-badge.pro-active { background: #7a5a00; color: #fff; border-color: #7a5a00; }
html.theme-light .preset-chip.active { color: #0d5a22; }
html.theme-light .nav-btn.active { color: #168039; }
