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

:root,
[data-theme="dark"] {
  --bg: #100f0c;
  --surface: #1c1a16;
  --text: #ede6d9;
  --text-secondary: #9e9588;
  --text-tertiary: #6b6459;
  --border: #2e2a24;
  --bar-track: #1e1b16;
  --bar-track-border: #2a2620;
  --toggle-bg: #252219;
  --grain-opacity: 0.028;
}

[data-theme="light"] {
  --bg: #f8f4ec;
  --surface: #ffffff;
  --text: #1c1810;
  --text-secondary: #6b6254;
  --text-tertiary: #9e9588;
  --border: #e0d8ca;
  --bar-track: #ede6d9;
  --bar-track-border: #ddd5c5;
  --toggle-bg: #f0ebe2;
  --grain-opacity: 0.015;
}

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  transition: background-color 0.5s ease, color 0.3s ease;
  overflow-x: hidden;
}

.page {
  width: 100%;
  max-width: 520px;
  padding: 2rem 1.5rem 3rem;
  position: relative;
  z-index: 1;
}

/* -------- HEADER -------- */
header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 3rem;
}

h1 {
  font-family: 'Fraunces', serif;
  font-weight: 400;
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  line-height: 1.3;
  color: var(--text);
  font-optical-sizing: auto;
}

h1 .name {
  font-weight: 700;
  font-style: italic;
}

/* -------- THEME TOGGLE -------- */
.theme-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--toggle-bg);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background-color 0.3s, border-color 0.3s, transform 0.2s;
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.theme-toggle:hover { transform: scale(1.08); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* -------- ENERGY SECTION -------- */
.energy-section {
  margin-bottom: 2.5rem;
  position: relative;
}

.energy-section::before {
  content: '';
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 140%;
  height: 350%;
  background: radial-gradient(
    ellipse,
    hsla(var(--energy-h), var(--energy-s), var(--energy-l), 0.07) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: -1;
  transition: background 1s;
}

.energy-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
}

.energy-value {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-size: clamp(5rem, 15vw, 8rem);
  line-height: 1;
  color: hsl(var(--energy-h), var(--energy-s), var(--energy-l));
  display: block;
  margin-bottom: 1rem;
  letter-spacing: -0.04em;
  font-optical-sizing: auto;
  transition: color 0.5s;
}

.energy-track {
  width: 100%;
  height: clamp(28px, 5vw, 40px);
  border-radius: 999px;
  background: var(--bar-track);
  border: 1px solid var(--bar-track-border);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
  position: relative;
  overflow: hidden;
  transition: background-color 0.3s, border-color 0.3s;
}

.energy-fill {
  height: 100%;
  border-radius: 999px;
  width: 0%;
  background: linear-gradient(
    180deg,
    hsla(var(--energy-h), var(--energy-s), calc(var(--energy-l) + 12%), 1) 0%,
    hsl(var(--energy-h), var(--energy-s), var(--energy-l)) 100%
  );
  box-shadow:
    0 0 20px hsla(var(--energy-h), var(--energy-s), var(--energy-l), 0.35),
    0 0 50px hsla(var(--energy-h), var(--energy-s), var(--energy-l), 0.12);
  position: relative;
  overflow: hidden;
  transition: width 1.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.energy-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: -50%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.13), transparent);
  animation: shimmer 4s ease-in-out 2s infinite;
}

/* -------- MOOD SECTION -------- */
.mood-section {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: 1rem;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  transition: background-color 0.3s, border-color 0.3s;
}

.mood-orb-wrap {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
}

.mood-orb {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 38% 38%,
    hsla(var(--mood-h), var(--mood-s), calc(var(--mood-l) + 22%), 1) 0%,
    hsl(var(--mood-h), var(--mood-s), var(--mood-l)) 70%
  );
  box-shadow:
    0 0 16px hsla(var(--mood-h), var(--mood-s), var(--mood-l), 0.4),
    0 0 40px hsla(var(--mood-h), var(--mood-s), var(--mood-l), 0.12);
  animation: orb-pulse var(--orb-pulse-speed, 3.5s) ease-in-out infinite;
}

.mood-content {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.mood-label {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--text);
}

.mood-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* -------- WORK STRESS SECTION -------- */
.stress-section {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: 1rem;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  transition: background-color 0.3s, border-color 0.3s;
}

.stress-bars-wrap {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stress-bars {
  display: flex;
  flex-direction: column-reverse;
  gap: 3px;
  width: 32px;
}

.stress-bar {
  height: 5px;
  border-radius: 2.5px;
  background: var(--border);
  transition: background-color 0.6s, box-shadow 0.6s;
}

.stress-bar.active {
  background: hsl(var(--stress-h), var(--stress-s), var(--stress-l));
  box-shadow: 0 0 8px hsla(var(--stress-h), var(--stress-s), var(--stress-l), 0.35);
}

.stress-section.is-overwhelmed .stress-bar.active {
  animation: stress-pulse 1.5s ease-in-out infinite;
}

.stress-content {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stress-label {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--text);
}

.stress-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* -------- ANXIETY SECTION -------- */
.anxiety-section {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: 1rem;
  border: 1px solid var(--border);
  margin-bottom: 1.25rem;
  transition: background-color 0.3s, border-color 0.3s;
}

.anxiety-rings-wrap {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  position: relative;
}

.anxiety-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid hsl(var(--anxiety-h), var(--anxiety-s), var(--anxiety-l));
  opacity: 0;
  animation: ripple var(--anxiety-speed, 3s) ease-out infinite;
}

.anxiety-ring:nth-child(2) { animation-delay: calc(var(--anxiety-speed, 3s) * -0.33); }
.anxiety-ring:nth-child(3) { animation-delay: calc(var(--anxiety-speed, 3s) * -0.66); }

.anxiety-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 40%,
    hsla(var(--anxiety-h), var(--anxiety-s), calc(var(--anxiety-l) + 15%), 1),
    hsl(var(--anxiety-h), var(--anxiety-s), var(--anxiety-l))
  );
  box-shadow: 0 0 10px hsla(var(--anxiety-h), var(--anxiety-s), var(--anxiety-l), 0.4);
}

.anxiety-content {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.anxiety-label {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.2rem;
  color: var(--text);
}

.anxiety-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* -------- MESSAGE -------- */
.message-section {
  display: none;
  margin-bottom: 1.25rem;
}

.message-card {
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border-radius: 1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-tertiary);
  transition: background-color 0.3s, border-color 0.3s;
}

.message {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text);
  font-weight: 400;
}

/* -------- META -------- */
.meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  transition: border-color 0.3s;
}

.meta-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex-shrink: 0;
  transition: background-color 0.3s;
}

.updated {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* -------- ANIMATIONS -------- */
@keyframes shimmer {
  0% { left: -50%; }
  50%, 100% { left: 120%; }
}

@keyframes orb-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.07); opacity: 0.85; }
}

@keyframes ripple {
  0% { transform: scale(0.3); opacity: 0.6; }
  100% { transform: scale(1.15); opacity: 0; }
}

@keyframes stress-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* -------- GRAIN OVERLAY -------- */
.grain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  opacity: var(--grain-opacity);
  mix-blend-mode: overlay;
}

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