:root {
  --bg-dark: #090d16;
  --card-bg: rgba(18, 24, 38, 0.75);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #64748b;
  
  --orange: #f97316;
  --orange-light: #fb923c;
  --orange-glow: rgba(249, 115, 22, 0.45);
  --orange-track: rgba(249, 115, 22, 0.12);
  
  --blue: #38bdf8;
  --indigo: #6366f1;
  --emerald: #10b981;
  --rose: #f43f5e;
  
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  position: relative;
  overflow-x: hidden;
  padding: 16px;
  -webkit-font-smoothing: antialiased;
}

/* Ambient glow orbs - GPU accelerated with optimized blur */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(60px);
  -webkit-filter: blur(60px);
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  pointer-events: none;
  z-index: 0;
  opacity: 0.22;
  will-change: transform;
}

.glow-orange {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(249, 115, 22, 0.45) 0%, transparent 70%);
  top: 10%;
  right: -80px;
}

.glow-blue {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.25) 0%, transparent 70%);
  bottom: 5%;
  left: -80px;
}

.tracker-app {
  width: 100%;
  max-width: 560px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-bottom: 40px;
}

/* Header */
.tracker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  transition: all 0.2s ease;
}

.back-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.nav-center {
  text-align: center;
}

.app-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.live-clock {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  font-family: monospace;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid rgba(249, 115, 22, 0.35);
  color: #fdba74;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn-pill:hover {
  background: rgba(249, 115, 22, 0.25);
  color: #ffedd5;
  transform: scale(1.02);
}

.icon-btn-pill.settings-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
}

.icon-btn-pill.settings-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

/* Date Navigator */
.date-navigator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 8px 16px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.nav-arrow-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.nav-arrow-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.current-date-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.date-label {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.date-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.btn-return-today {
  margin-top: 6px;
  background: rgba(249, 115, 22, 0.2);
  border: 1px solid rgba(249, 115, 22, 0.4);
  color: #ffedd5;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 12px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: all 0.2s ease;
}

.btn-return-today:hover {
  background: rgba(249, 115, 22, 0.4);
  color: #fff;
  transform: translateY(-1px);
}

.btn-return-today.hidden {
  display: none;
}

/* Historical Mode */
body.historical-view .ambient-glow {
  opacity: 0.15; /* Dim the background glows */
  filter: grayscale(80%);
}

body.historical-view .dial-card {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(13, 19, 33, 0.85); /* Slightly darker/tinted */
}

/* 24-Hour Circular Dial */
.dial-container {
  display: flex;
  justify-content: center;
}

.dial-card {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 28px;
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.dial-wrapper {
  position: relative;
  width: 330px;
  height: 330px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.dial-svg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
}

/* SVG Elements */
.dial-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 22px;
}

.dial-tick {
  stroke: rgba(255, 255, 255, 0.15);
  stroke-width: 1.5px;
}

.dial-tick-major {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 2.5px;
}

.dial-hour-text {
  fill: var(--text-sub);
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
}

.dial-hour-text.major {
  fill: var(--text-muted);
  font-weight: 700;
}

/* Sleep Arc */
.sleep-arc {
  fill: none;
  stroke: var(--orange);
  stroke-width: 22px;
  stroke-linecap: round;
  stroke-linejoin: round;
  shape-rendering: geometricPrecision;
  transition: stroke 0.3s ease;
}

.sleep-arc.active-session {
  stroke: #ff9800;
  animation: arc-pulse 2s infinite alternate ease-in-out;
}

@keyframes arc-pulse {
  0% { opacity: 0.88; stroke-width: 22px; }
  100% { opacity: 1; stroke-width: 23px; }
}

/* Time Indicator */
.indicator-hand {
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1.5px;
  stroke-dasharray: 2 4;
}

.indicator-beacon {
  fill: #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
}

/* Center Content */
.dial-center-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 210px;
  height: 210px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(13, 19, 33, 0.95) 0%, rgba(9, 13, 22, 0.9) 100%);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.status-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.status-tag.awake {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.status-tag.sleeping {
  background: rgba(249, 115, 22, 0.2);
  color: #fed7aa;
  border: 1px solid rgba(249, 115, 22, 0.5);
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.3);
  animation: pulse 1.8s infinite;
}

.center-timer {
  font-family: var(--font-heading);
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  line-height: 1.1;
  margin: 2px 0;
}

.center-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  max-width: 170px;
}

/* Start / Stop Button */
.btn-sleep-action {
  border: none;
  outline: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.btn-sleep-action.start-mode {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(249, 115, 22, 0.4);
}

.btn-sleep-action.start-mode:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 25px rgba(249, 115, 22, 0.6);
}

.btn-sleep-action.stop-mode {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(14, 165, 233, 0.45);
}

.btn-sleep-action.stop-mode:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 25px rgba(14, 165, 233, 0.65);
}

/* Legend */
.dial-legend {
  display: flex;
  gap: 16px;
  margin-top: 18px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.current-time { background: #fff; box-shadow: 0 0 6px rgba(255, 255, 255, 0.8); }
.legend-dot.night { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.legend-dot.nap { background: var(--blue); box-shadow: 0 0 6px var(--blue); }

/* Metrics Section */
.metrics-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.metric-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.total-metric {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
}

.metric-icon-box {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-icon-box.orange {
  background: rgba(249, 115, 22, 0.18);
  color: #fb923c;
}

.metric-icon-box.blue {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
}

.metric-icon-box.amber {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.metric-data {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-value {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.total-metric .metric-value { color: #34d399; }
.night-metric .metric-value { color: #fb923c; }
.nap-metric .metric-value { color: #38bdf8; }

/* Sleep Log List */
.log-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 20px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.log-header h2 {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
}

.log-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 10px;
  border-radius: 999px;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  padding: 24px;
  color: var(--text-sub);
  font-size: 0.88rem;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  transition: all 0.2s ease;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
}

.session-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-badge-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 8px var(--blue);
}

.session-badge-dot.night {
  background: var(--orange);
  box-shadow: 0 0 8px var(--orange);
}

.session-times {
  display: flex;
  flex-direction: column;
}

.session-range {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
}

.session-type-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.session-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.session-duration {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  color: #fdba74;
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.session-action-btn,
.session-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-sub);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.session-edit-btn:hover {
  color: #fdba74;
  background: rgba(249, 115, 22, 0.12);
}

.session-delete-btn:hover {
  color: var(--rose);
  background: rgba(244, 63, 94, 0.1);
}

.settings-helper-text {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 6px;
}

/* Footer */
.tracker-footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 10px;
}

.footer-legal-link {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.footer-legal-link:hover {
  color: var(--orange);
  text-decoration: underline;
}

.footer-sub {
  opacity: 0.6;
}

/* Legal Modal */
.modal-card.legal-modal {
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.legal-content {
  overflow-y: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
  color: #cbd5e1;
}

.legal-content h4 {
  font-family: var(--font-heading);
  color: #fff;
  font-size: 0.98rem;
  margin-bottom: 2px;
}

.legal-content .contact-line {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  background: #131926;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.form-row input,
.form-row select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
}

.form-row select option {
  background: #131926;
  color: #fff;
}

.form-row input:focus,
.form-row select:focus {
  border-color: var(--orange);
}

.form-row select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: rgba(255, 255, 255, 0.02);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-border);
  transition: .3s;
  border-radius: 20px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: .3s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: rgba(249, 115, 22, 0.2);
  border-color: rgba(249, 115, 22, 0.5);
}

input:checked + .toggle-slider:before {
  transform: translateX(16px);
  background-color: var(--orange);
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--card-border);
  color: #fff;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--orange);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

/* Custom Time Picker Component */
.time-picker-wrapper {
  width: 100%;
}

.time-picker-control {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 4px 8px;
  transition: border-color 0.2s, background 0.2s;
}

.time-picker-control:focus-within {
  border-color: var(--orange);
  background: rgba(255, 255, 255, 0.09);
}

.time-select {
  background: transparent !important;
  border: none !important;
  color: #fff !important;
  font-family: var(--font-heading) !important;
  font-size: 1.05rem !important;
  font-weight: 700 !important;
  padding: 6px 4px !important;
  outline: none !important;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  text-align: center;
  text-align-last: center;
  min-width: 40px;
}

.time-select option {
  background: #131926;
  color: #fff;
  font-size: 0.95rem;
}

.time-colon {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-muted);
  user-select: none;
  line-height: 1;
  padding: 0 1px;
}

.time-ampm-btn {
  margin-left: auto;
  background: rgba(249, 115, 22, 0.16);
  border: 1px solid rgba(249, 115, 22, 0.4);
  color: #fdba74;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.time-ampm-btn:hover {
  background: rgba(249, 115, 22, 0.32);
  color: #fff;
}

.time-ampm-btn.hidden {
  display: none !important;
}

/* Clock Format Toggle Group in Settings */
.clock-format-toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.format-option {
  cursor: pointer;
  display: block;
}

.format-option input {
  display: none;
}

.format-option-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  transition: all 0.2s;
  text-align: center;
}

.format-option input:checked + .format-option-box {
  background: rgba(249, 115, 22, 0.15);
  border-color: rgba(249, 115, 22, 0.5);
  box-shadow: 0 0 14px rgba(249, 115, 22, 0.2);
}

.format-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: #fff;
  margin-bottom: 2px;
}

.format-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: monospace;
}

.format-option input:checked + .format-option-box .format-preview {
  color: #fdba74;
}

.settings-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 6px 0;
}

@media (max-width: 480px) {
  .metrics-section {
    grid-template-columns: 1fr;
  }
  .dial-wrapper {
    width: 290px;
    height: 290px;
  }
}
