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

:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface-2: #1a2235;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #00B0B9;
  --accent-2: #7C4DFF;
  --trees: #2dd4a0;
  --creatures: #a78bfa;
  --flora: #fbbf24;
  --storms: #f87171;
  --terrain: #38bdf8;
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.nav-btn {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
}

.nav-btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.dream-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  padding: 8px 20px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  letter-spacing: 0.01em;
}

.dream-btn:hover {
  opacity: 0.9;
  transform: scale(1.03);
}

.dream-btn.active {
  box-shadow: 0 0 24px rgba(0, 176, 185, 0.35);
}

main {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 28px;
  padding: 28px 0 40px;
  min-height: calc(100vh - 80px);
}

.canvas-container {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
  min-height: 500px;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.tooltip {
  position: absolute;
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  pointer-events: none;
  transition: opacity 0.2s;
  backdrop-filter: blur(12px);
  z-index: 10;
  max-width: 220px;
  line-height: 1.5;
}

.tooltip.hidden {
  opacity: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sleep-score {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.05);
}

.score-ring {
  position: relative;
  width: 120px;
  height: 120px;
}

.score-ring svg {
  width: 100%;
  height: 100%;
}

.score-value {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-value span {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.score-value small {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.legend {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  border: 1px solid rgba(255,255,255,0.05);
}

.legend h3 {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.legend-items {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.legend-item {
  display: grid;
  grid-template-columns: 20px 1fr;
  grid-template-rows: auto auto;
  gap: 4px 12px;
  align-items: center;
  cursor: pointer;
  padding: 4px 0;
  transition: opacity 0.2s;
}

.legend-item:hover {
  opacity: 0.85;
}

.legend-icon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  grid-row: 1 / 3;
}

.legend-icon.trees { background: var(--trees); }
.legend-icon.creatures { background: var(--creatures); }
.legend-icon.flora { background: var(--flora); }
.legend-icon.storms { background: var(--storms); }
.legend-icon.terrain { background: var(--terrain); }

.legend-text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.legend-text strong {
  font-size: 0.88rem;
  font-weight: 500;
}

.metric-val {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.legend-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 1s ease;
  width: 0%;
}

.trees-bg { background: var(--trees); }
.creatures-bg { background: var(--creatures); }
.flora-bg { background: var(--flora); }
.storms-bg { background: var(--storms); }
.terrain-bg { background: var(--terrain); }

.insight-card {
  background: linear-gradient(135deg, rgba(0,176,185,0.1), rgba(124,77,255,0.08));
  border: 1px solid rgba(0,176,185,0.2);
  border-radius: var(--radius);
  padding: 20px;
}

.insight-card p {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
}

.week-strip {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  border: 1px solid rgba(255,255,255,0.05);
}

.week-strip h3 {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.week-dots {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.day-dot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  transition: transform 0.15s;
}

.day-dot:hover {
  transform: scale(1.08);
}

.day-dot .dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.08);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.day-dot.active .dot {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(0,176,185,0.3);
}

.day-dot .day-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Dream mode overlay */
body.dream-mode {
  background: #050810;
}

body.dream-mode .canvas-container {
  box-shadow: 0 0 60px rgba(124,77,255,0.15), 0 0 120px rgba(0,176,185,0.08);
}

body.dream-mode .panel {
  opacity: 0.15;
  pointer-events: none;
  transition: opacity 0.8s;
}

body.dream-mode header {
  opacity: 0.4;
  transition: opacity 0.8s;
}

body.dream-mode header .dream-btn {
  opacity: 1;
}

body.dream-mode main {
  grid-template-columns: 1fr;
}

body.dream-mode .canvas-container {
  min-height: calc(100vh - 120px);
}

/* Responsive */
@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
  }

  .canvas-container {
    min-height: 380px;
  }
}

@media (max-width: 480px) {
  header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .dream-btn {
    order: 3;
    width: 100%;
    text-align: center;
  }
}
