:root {
  --bg: #f5f0e8;
  --text: #1a1a1a;
  --text-muted: #5c5348;
  --accent: #2d6a4f;
  --candle-body: #e8dcc8;
  --candle-shadow: rgba(0, 0, 0, 0.12);
  --flame-glow: rgba(255, 180, 60, 0.35);
}

[data-theme="dark"] {
  --bg: #12141a;
  --text: #f0ebe3;
  --text-muted: #a89f94;
  --accent: #7ec8a3;
  --candle-body: #c9b89a;
  --candle-shadow: rgba(0, 0, 0, 0.45);
  --flame-glow: rgba(255, 200, 80, 0.25);
}

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

html,
body {
  margin: 0;
  min-height: 100vh;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  transition: background 0.6s ease, color 0.6s ease;
  overflow-x: hidden;
}

main {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem 4rem;
}

.writing-scene {
  position: relative;
  width: min(92vw, 720px);
  min-height: 280px;
}

.text-lines {
  position: relative;
  z-index: 1;
  padding-top: 3.5rem;
}

.line {
  display: flex;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 0.08em;
  margin: 0.15em 0;
  min-height: 1.2em;
}

.letter {
  font-size: clamp(2.4rem, 8vw, 4.2rem);
  font-weight: 700;
  line-height: 1.1;
  color: transparent;
  opacity: 0;
  transform: translateY(6px);
  transition: color 0.15s ease, opacity 0.2s ease, transform 0.2s ease;
}

.letter.written {
  color: var(--text);
  opacity: 1;
  transform: translateY(0);
}

.turtle {
  position: absolute;
  width: 110px;
  height: auto;
  z-index: 2;
  pointer-events: none;
  transform-origin: center center;
  transition: left 0.35s ease, top 0.35s ease, transform 0.35s ease;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

.turtle.walking-away {
  transition: left 1.1s ease-in, top 0.9s ease-in, transform 0.35s ease;
}

.candle-btn {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 10;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 12px;
  transition: transform 0.2s ease, background 0.3s ease;
}

.candle-btn:hover {
  transform: scale(1.05);
}

.candle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.candle-btn.lit {
  background: radial-gradient(circle at 50% 20%, var(--flame-glow) 0%, transparent 70%);
}

.candle-svg {
  width: 56px;
  height: 110px;
  display: block;
  filter: drop-shadow(0 4px 10px var(--candle-shadow));
}

.candle-body {
  fill: var(--candle-body);
  transition: fill 0.6s ease;
}

.candle-wick {
  fill: #3a3028;
}

.flame-group {
  opacity: 0;
  transform-origin: 50% 100%;
  transform: scale(0.4);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.candle-btn.lit .flame-group {
  opacity: 1;
  transform: scale(1);
  animation: flicker 1.8s ease-in-out infinite;
}

.flame-outer {
  fill: #ff9a2e;
}

.flame-inner {
  fill: #ffe566;
}

.flame-core {
  fill: #fff8d6;
}

@keyframes flicker {
  0%,
  100% {
    transform: scale(1) rotate(-1deg);
  }
  25% {
    transform: scale(1.04, 0.96) rotate(1deg);
  }
  50% {
    transform: scale(0.97, 1.03) rotate(-2deg);
  }
  75% {
    transform: scale(1.02, 0.98) rotate(0.5deg);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .candle-btn {
    top: 0.75rem;
    right: 0.75rem;
  }

  .candle-svg {
    width: 44px;
    height: 88px;
  }

  .turtle {
    width: 80px;
  }
}
