/* =================================================================
   Sleep Animal - Circular Sleep Timeline Builder
   Primary: #4A3F8A (Deep Indigo)
   ================================================================= */

:root {
  --primary: #4A3F8A;
  --primary-dark: #3a3170;
  --primary-light: #7B6FBF;
  --primary-glow: rgba(74, 63, 138, 0.35);
  --accent: #C8A2E8;
  --accent-glow: rgba(200, 162, 232, 0.3);
  --bg: #0a0a1a;
  --bg-2: #0e0e24;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.10);
  --border: rgba(255, 255, 255, 0.10);
  --border-focus: rgba(74, 63, 138, 0.5);
  --text: #e8edf5;
  --text-muted: rgba(232, 237, 245, 0.55);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.08);

  /* Animal colors */
  --bear: #C08B5C;
  --lion: #E8A838;
  --wolf: #7B8CDE;
  --dolphin: #5BC0BE;

  /* Activity colors */
  --clr-sleep: #5B6ABF;
  --clr-nap: #8B7BDE;
  --clr-caffeine: #D4915C;
  --clr-exercise: #5BBF7B;
  --clr-screen: #BF5B5B;
  --clr-work: #BFA95B;
  --clr-meal: #BF8B5B;
  --clr-relax: #5BBFB8;
}

[data-theme="light"] {
  --bg: #f0f0ff;
  --bg-2: #e8e8f8;
  --surface: rgba(255, 255, 255, 0.75);
  --surface-hover: rgba(255, 255, 255, 0.92);
  --border: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(74, 63, 138, 0.6);
  --text: #1a1a2e;
  --text-muted: rgba(26, 26, 46, 0.55);
  --glass: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(0, 0, 0, 0.07);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(74, 63, 138, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(200, 162, 232, 0.10) 0%, transparent 55%),
    radial-gradient(ellipse at 50% 50%, rgba(91, 192, 190, 0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

[data-theme="light"] body::before {
  background:
    radial-gradient(ellipse at 20% 10%, rgba(74, 63, 138, 0.08) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(200, 162, 232, 0.06) 0%, transparent 55%);
}

/* Starfield */
.stars {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.stars span {
  position: absolute;
  width: 2px; height: 2px;
  background: #fff;
  border-radius: 50%;
  animation: twinkle var(--dur, 3s) ease-in-out infinite var(--delay, 0s);
  opacity: 0.4;
}
[data-theme="light"] .stars { opacity: 0; }

@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 0.8; transform: scale(1.2); }
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -40px; left: 0;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  z-index: 999;
  border-radius: 0 0 8px 0;
  font-weight: 600;
}
.skip-link:focus { top: 0; }

/* App Loader */
.app-loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: opacity 0.4s, visibility 0.4s;
}
.app-loader.hidden { opacity: 0; visibility: hidden; }
.loader-spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Ad Banners */
.ad-banner {
  width: 100%;
  text-align: center;
  padding: 8px 0;
  background: var(--bg-2);
  position: relative;
  z-index: 1;
}

/* Container */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 40px;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.app-title {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.app-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  position: relative;
}
.icon-btn {
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  color: var(--text);
}
.icon-btn:hover { background: var(--surface-hover); border-color: var(--border-focus); }

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  z-index: 100;
  min-width: 160px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.lang-menu.hidden { display: none; }
.lang-option {
  padding: 7px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text);
  text-align: left;
  transition: all 0.15s;
  white-space: nowrap;
}
.lang-option:hover { background: var(--surface-hover); border-color: var(--border); }
.lang-option.active { background: var(--primary-glow); border-color: var(--primary); color: var(--primary-light); }

/* Screens */
.screen { display: none; }
.screen.active { display: block; animation: fadeInUp 0.35s ease; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Start Screen ===== */
.start-hero {
  text-align: center;
  padding: 32px 0 24px;
}
.hero-icon {
  font-size: 5rem;
  margin-bottom: 16px;
  display: block;
  filter: drop-shadow(0 0 24px rgba(200, 162, 232, 0.5));
}
.hero-title {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--accent), var(--dolphin));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}
.hero-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto 24px;
}

.info-strip {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.info-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 7px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.animals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}
.animal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: all 0.2s;
  backdrop-filter: blur(12px);
}
.animal-card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
.animal-emoji { font-size: 2rem; margin-bottom: 8px; }
.animal-name {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.animal-card[data-animal="bear"] .animal-name { color: var(--bear); }
.animal-card[data-animal="lion"] .animal-name { color: var(--lion); }
.animal-card[data-animal="wolf"] .animal-name { color: var(--wolf); }
.animal-card[data-animal="dolphin"] .animal-name { color: var(--dolphin); }
.animal-desc {
  font-size: 0.77rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.disclaimer {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 52px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 20px var(--primary-glow);
  width: 100%;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px var(--primary-glow);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ===== Timeline Builder Screen ===== */
.timeline-header {
  text-align: center;
  margin-bottom: 20px;
}
.timeline-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.timeline-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Activity Palette */
.activity-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}
.activity-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 30px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  min-height: 44px;
  backdrop-filter: blur(8px);
  user-select: none;
  -webkit-user-select: none;
}
.activity-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}
.activity-btn.selected {
  border-color: var(--activity-color, var(--primary-light));
  background: color-mix(in srgb, var(--activity-color, var(--primary)) 20%, transparent);
  box-shadow: 0 2px 12px color-mix(in srgb, var(--activity-color, var(--primary)) 30%, transparent);
}
.activity-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Clock */
.clock-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.clock-container {
  position: relative;
  width: min(85vw, 380px);
  height: min(85vw, 380px);
}
.clock-svg {
  width: 100%;
  height: 100%;
}
.clock-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.clock-center-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 4px;
}
.clock-center-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  max-width: 100px;
  display: block;
}

/* Clock segment hover/active */
.clock-segment {
  cursor: pointer;
  transition: opacity 0.15s;
}
.clock-segment:hover {
  opacity: 0.85;
}
.clock-segment.filled {
  filter: drop-shadow(0 0 4px rgba(255,255,255,0.15));
}

/* Hour labels on clock */
.clock-hour-label {
  font-size: 11px;
  fill: var(--text-muted);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

[data-theme="light"] .clock-hour-label {
  fill: rgba(26, 26, 46, 0.5);
}

/* Legend */
.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 16px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Stats */
.timeline-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  backdrop-filter: blur(8px);
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary-light);
}
.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Timeline actions */
.timeline-actions {
  display: flex;
  gap: 12px;
}
.timeline-actions .btn { flex: 1; }

/* ===== Result Screen ===== */
.result-hero {
  text-align: center;
  padding: 28px 0 20px;
}
.result-animal-emoji {
  font-size: 5rem;
  display: block;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 30px var(--accent-glow));
  animation: floatAnimal 3s ease-in-out infinite;
}
@keyframes floatAnimal {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.result-type-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
}
.result-animal-name {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
}
.result-animal-name.bear { color: var(--bear); }
.result-animal-name.lion { color: var(--lion); }
.result-animal-name.wolf { color: var(--wolf); }
.result-animal-name.dolphin { color: var(--dolphin); }

.result-percentage {
  display: inline-block;
  padding: 6px 18px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  margin-bottom: 16px;
}

.result-description {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.7;
  max-width: 500px;
  margin: 0 auto 24px;
}

/* Comparison clocks */
.comparison-clocks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
.comparison-item {
  text-align: center;
}
.comparison-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.comparison-clock {
  width: 100%;
  max-width: 160px;
  margin: 0 auto;
}
.comparison-clock svg {
  width: 100%;
  height: auto;
}

/* Section titles */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Traits */
.traits-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}
.trait-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 8px 16px;
  font-size: 0.82rem;
  color: var(--text);
  backdrop-filter: blur(12px);
}

/* Sleep Tips */
.tips-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 28px;
}
.tip-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.88rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  backdrop-filter: blur(12px);
  line-height: 1.5;
}
.tip-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

/* Schedule */
.schedule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
  backdrop-filter: blur(12px);
}
.schedule-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.schedule-item:last-child { border-bottom: none; }
.schedule-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.schedule-icon.wake { background: rgba(232, 168, 56, 0.15); }
.schedule-icon.peak { background: rgba(74, 63, 138, 0.15); }
.schedule-icon.exercise { background: rgba(91, 192, 190, 0.15); }
.schedule-icon.wind { background: rgba(200, 162, 232, 0.15); }
.schedule-icon.sleep { background: rgba(123, 140, 222, 0.15); }
.schedule-text {
  color: var(--text);
  font-weight: 500;
}

/* Share */
.share-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.share-btn {
  flex: 1;
  min-width: 120px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
}
.share-btn:hover { background: var(--surface-hover); transform: translateY(-1px); }
.share-btn.twitter { background: #000; color: #fff; border-color: #000; }
.share-btn.twitter:hover { background: #1a1a1a; }

/* Moon decoration */
.moon {
  position: fixed;
  top: 60px; right: -30px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f5f3ce, #e8d88e, #c8a84e);
  box-shadow: 0 0 60px rgba(245, 243, 206, 0.15), 0 0 120px rgba(245, 243, 206, 0.08);
  pointer-events: none;
  z-index: 0;
  opacity: 0.25;
}
[data-theme="light"] .moon { opacity: 0.08; }

/* Related Tests */
.related-tests { width: 100%; max-width: 420px; margin: 24px auto 0; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.1); }
.related-tests h3 { font-size: 16px; color: var(--text-muted); margin-bottom: 12px; text-align: center; }
.related-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.related-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; background: var(--card-bg, rgba(255,255,255,0.05)); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; text-decoration: none; color: var(--text-main, #fff); transition: transform 0.2s, border-color 0.2s; }
.related-card:hover { transform: translateY(-2px); border-color: var(--card-color, var(--accent, #6c5ce7)); }
.related-emoji { font-size: 28px; }
.related-name { font-size: 12px; font-weight: 600; text-align: center; color: var(--text-muted); }
[data-theme="light"] .related-tests { border-top-color: rgba(0,0,0,0.1); }
[data-theme="light"] .related-card { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.1); }
[data-theme="light"] .related-card:hover { background: rgba(0,0,0,0.06); }
.percentile-stat { text-align: center; margin: 16px auto 0; font-size: 13px; color: var(--text-muted); max-width: 420px; }
.percentile-stat strong { color: var(--accent, #6c5ce7); font-size: 15px; }

/* Responsive */
@media (max-width: 400px) {
  .animals-grid { grid-template-columns: 1fr; }
  .hero-title { font-size: 1.5rem; }
  .result-animal-emoji { font-size: 4rem; }
  .result-animal-name { font-size: 1.6rem; }
  .comparison-clocks { grid-template-columns: 1fr; }
  .activity-btn { padding: 6px 10px; font-size: 0.78rem; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pulseSegment {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
