/* =============================================
   SOMNUS — Sleep Quality Analyzer
   Aesthetic: Deep Night / Celestial Minimal
   Font: Cormorant Garamond (display) + DM Sans (body)
   ============================================= */

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

:root {
  --bg:           #080c14;
  --bg-card:      #0e1420;
  --bg-card2:     #121926;
  --bg-input:     #0a0f1a;
  --border:       rgba(130, 160, 220, 0.10);
  --border-hover: rgba(130, 160, 220, 0.22);
  --accent:       #7eb8f7;
  --accent-dim:   rgba(126, 184, 247, 0.15);
  --accent-glow:  rgba(126, 184, 247, 0.08);
  --gold:         #c9a96e;
  --gold-dim:     rgba(201, 169, 110, 0.15);
  --text-primary: #dde4f0;
  --text-sec:     #8a96aa;
  --text-dim:     #4a5568;
  --success:      #6ec9a0;
  --warning:      #c9a96e;
  --danger:       #e07070;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body:    'DM Sans', sans-serif;
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    20px;
  --radius-xl:    28px;
  --transition:   0.22s ease;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- STARS ---- */
.stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.star {
  position: absolute;
  border-radius: 50%;
  background: white;
  animation: twinkle var(--dur) ease-in-out infinite;
  opacity: 0;
}
@keyframes twinkle {
  0%, 100% { opacity: 0; }
  50% { opacity: var(--op); }
}

/* ---- LAYOUT ---- */
.app-wrapper {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

/* ---- HEADER ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.75rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.moon-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
  opacity: 0.9;
}
.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text-primary);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.streak-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--gold-dim);
  border: 1px solid rgba(201,169,110,0.25);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--gold);
  letter-spacing: 0.02em;
}
.streak-fire { font-size: 10px; }
.settings-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  cursor: pointer;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.settings-btn svg { width: 16px; height: 16px; }
.settings-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }

/* ---- SETTINGS PANEL ---- */
.settings-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  animation: slideDown 0.2s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.settings-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.settings-desc {
  font-size: 13px;
  color: var(--text-sec);
  margin-bottom: 1rem;
}
.ideal-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ideal-input {
  width: 80px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
  transition: var(--transition);
}
.ideal-input:focus { border-color: var(--accent); }
.ideal-unit { font-size: 13px; color: var(--text-sec); }
.save-btn {
  background: var(--accent-dim);
  border: 1px solid rgba(126,184,247,0.25);
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.save-btn:hover { background: rgba(126,184,247,0.22); }

/* ---- SECTION ---- */
.section { margin-bottom: 2.5rem; }

.section-header { margin-bottom: 1.5rem; }
.section-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 300;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  line-height: 1.15;
  margin-bottom: 6px;
}
.section-sub {
  font-size: 14px;
  color: var(--text-sec);
  font-style: italic;
}

/* ---- FORM CARD ---- */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2rem 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group { display: flex; flex-direction: column; gap: 8px; }

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sec);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.label-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.text-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 300;
  outline: none;
  transition: var(--transition);
  -moz-appearance: textfield;
}
.text-input::-webkit-inner-spin-button,
.text-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.text-input:focus { border-color: rgba(126,184,247,0.4); background: rgba(126,184,247,0.03); }
.text-input::placeholder { color: var(--text-dim); }
.input-unit {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--text-dim);
  min-width: 20px;
}
.input-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 16px;
  display: block;
}

/* ---- SLIDER ---- */
.slider-track {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slider-cap {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 12px;
  text-align: center;
}
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-card);
  box-shadow: 0 0 0 1px rgba(126,184,247,0.4);
  cursor: pointer;
  transition: transform 0.15s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-card);
  cursor: pointer;
}
.slider-desc-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  padding: 0 2px;
}

/* ---- TOGGLES ---- */
.toggle-group {
  display: flex;
  gap: 8px;
}
.toggle-btn {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  color: var(--text-sec);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.02em;
}
.toggle-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.toggle-btn.active {
  background: var(--accent-dim);
  border-color: rgba(126,184,247,0.3);
  color: var(--accent);
  font-weight: 500;
}

/* ---- ANALYZE BUTTON ---- */
.analyze-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  background: linear-gradient(135deg, rgba(126,184,247,0.18), rgba(126,184,247,0.08));
  border: 1px solid rgba(126,184,247,0.3);
  border-radius: var(--radius-lg);
  padding: 15px;
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.25s ease;
  margin-top: 0.5rem;
}
.analyze-btn svg { width: 16px; height: 16px; transition: transform 0.2s; }
.analyze-btn:hover {
  background: linear-gradient(135deg, rgba(126,184,247,0.28), rgba(126,184,247,0.14));
  border-color: rgba(126,184,247,0.5);
  box-shadow: 0 0 24px rgba(126,184,247,0.12);
}
.analyze-btn:hover svg { transform: translateX(3px); }
.analyze-btn:active { transform: scale(0.99); }

/* ---- RESULT SECTION ---- */
.result-section { animation: fadeUp 0.4s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.result-date {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text-sec);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.back-btn svg { width: 14px; height: 14px; }
.back-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }

/* ---- SCORE CARD ---- */
.score-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 1rem;
}
.score-orbit {
  position: relative;
  flex-shrink: 0;
  width: 160px;
  height: 160px;
}
.score-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg {
  fill: none;
  stroke: rgba(126,184,247,0.08);
  stroke-width: 6;
}
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 427.26;
  stroke-dashoffset: 427.26;
  transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 0 6px rgba(126,184,247,0.4));
}
.score-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-number {
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 300;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.02em;
}
.score-denom {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}
.score-right { flex: 1; }
.sleep-type {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 300;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.score-grade {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid;
}
.grade-excellent { color: var(--success); border-color: rgba(110,201,160,0.3); background: rgba(110,201,160,0.08); }
.grade-good      { color: var(--accent);  border-color: rgba(126,184,247,0.3); background: rgba(126,184,247,0.08); }
.grade-fair      { color: var(--gold);    border-color: rgba(201,169,110,0.3); background: rgba(201,169,110,0.08); }
.grade-poor      { color: var(--danger);  border-color: rgba(224,112,112,0.3); background: rgba(224,112,112,0.08); }

/* ---- STATS GRID ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  text-align: center;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- INSIGHT CARD ---- */
.insight-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 2px solid rgba(126,184,247,0.4);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 1.25rem 1.5rem;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.insight-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--accent);
  opacity: 0.7;
  margin-top: 2px;
}
.insight-icon svg { width: 100%; height: 100%; }
.insight-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-sec);
}

/* ---- EDGE NOTICE ---- */
.edge-notice {
  background: rgba(201,169,110,0.06);
  border: 1px solid rgba(201,169,110,0.2);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--gold);
  line-height: 1.6;
  margin-bottom: 1rem;
  font-style: italic;
}

/* ---- TREND SECTION ---- */
.trend-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.trend-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 300;
  color: var(--text-primary);
}
.trend-meta {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- DEBT BANNER ---- */
.debt-banner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-sec);
  line-height: 1.5;
  margin-bottom: 1rem;
}
.debt-banner strong { color: var(--danger); font-weight: 500; }
.debt-banner .debt-ok { color: var(--success); }

/* ---- CHART ---- */
.chart-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.5rem 1.5rem 1rem;
  margin-bottom: 1rem;
}
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 100px;
  margin-bottom: 8px;
}
.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}
.bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.bar.today { box-shadow: 0 0 10px rgba(126,184,247,0.3); }
.bar-score-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.chart-labels {
  display: flex;
  gap: 8px;
}
.chart-label {
  flex: 1;
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.chart-label.today { color: var(--accent); }

/* ---- TREND STATS ---- */
.trend-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.trend-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}
.trend-stat-val {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.trend-stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- EMPTY STATE ---- */
.empty-trend {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-dim);
  font-size: 14px;
  font-style: italic;
}

/* ---- FOOTER ---- */
.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}
.footer em { font-family: var(--font-display); font-style: italic; opacity: 0.7; }

/* ---- RESPONSIVE ---- */
@media (max-width: 500px) {
  .score-card { flex-direction: column; align-items: flex-start; gap: 1.25rem; }
  .score-orbit { width: 130px; height: 130px; }
  .score-number { font-size: 38px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-card { padding: 1.5rem 1.25rem; }
  .section-title { font-size: 28px; }
}
