/* ==============================================
   COMPONENTS
   Reusable UI pieces built from tokens.
   No page-specific positioning here.
   ============================================== */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--fg);
  background: var(--sky);
  line-height: 1.6;
}

/* ── Typography helpers ── */
.font-hand { font-family: var(--font-hand); }
.muted     { color: var(--muted); }
.small     { font-size: var(--text-sm); }

/* ── Spacing helpers ── */
.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mt-2 { margin-top:    var(--sp-2); }
.mt-3 { margin-top:    var(--sp-3); }
.mt-4 { margin-top:    var(--sp-4); }

/* ── Stack / Row layout ── */
.stack > * + * { margin-top: var(--sp-3); }
.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px 22px;
  border: none;
  border-radius: var(--r-full);
  font-family: var(--font-hand);
  font-size: var(--text-lg);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition:
    transform var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-fast) var(--ease-gentle);
  background: var(--grass-dark);
  color: #fff;
  box-shadow: 0 3px 0 #2d5a20, var(--shadow-sm);
}
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 0 #2d5a20, var(--shadow-md);
}
.btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #2d5a20;
}

.btn--ghost {
  background: transparent;
  color: var(--fg);
  border: 2px solid var(--grass-dark);
  box-shadow: none;
}
.btn--ghost:hover {
  background: rgba(78, 128, 64, 0.1);
  box-shadow: none;
}
.btn--ghost:active {
  transform: translateY(1px);
}

.btn--warm {
  background: var(--warm);
  box-shadow: 0 3px 0 #c07030, var(--shadow-sm);
  color: var(--fg);
}
.btn--warm:hover {
  box-shadow: 0 5px 0 #c07030, var(--shadow-md);
}

/* ── Form fields ── */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.field > span,
.field > label {
  font-family: var(--font-hand);
  font-size: var(--text-lg);
  color: var(--fg-light);
}

input[type="text"],
input[type="password"],
input[type="datetime-local"],
input:not([type]) {
  background: var(--parchment);
  border: 2px solid var(--parchment-dk);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--fg);
  transition: border-color var(--dur-fast) var(--ease-gentle);
  outline: none;
  width: 100%;
}
input:focus {
  border-color: var(--grass-dark);
  box-shadow: 0 0 0 3px rgba(78, 128, 64, 0.15);
}

.form-stack {
  display: grid;
  gap: var(--sp-3);
}

/* ── Error message ── */
.error {
  color: var(--wax);
  font-size: var(--text-sm);
  font-family: var(--font-hand);
}

/* ── Speech bubble (login) ── */
.speech-bubble {
  position: relative;
  background: var(--parchment);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-md);
  border: 2px solid var(--parchment-dk);
}
/* tail pointing down-left toward rabbit */
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -18px;
  left: 28px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 8px solid transparent;
  border-top: 20px solid var(--parchment);
  filter: drop-shadow(0 2px 2px var(--shadow));
}
.speech-bubble::before {
  content: '';
  position: absolute;
  bottom: -22px;
  left: 26px;
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 10px solid transparent;
  border-top: 24px solid var(--parchment-dk);
}
.speech-bubble h2 {
  font-family: var(--font-hand);
  font-size: var(--text-xl);
  margin: 0 0 var(--sp-3);
  color: var(--fg);
}

/* ── Letter card ── */
.letter-card {
  position: relative;
  background: var(--parchment);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-5);
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--parchment-dk);
  /* faint ruled lines */
  background-image:
    repeating-linear-gradient(
      transparent,
      transparent 27px,
      rgba(122, 106, 85, 0.12) 28px
    );
  background-size: 100% 28px;
  min-height: 320px;
}

/* Wax seal overlay */
.seal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: var(--parchment);
  border-radius: var(--r-lg);
  z-index: 10;
  cursor: pointer;
  transition: opacity var(--dur-med) var(--ease-gentle);
}
.seal svg {
  width: 120px;
  height: 120px;
  filter: drop-shadow(0 4px 12px rgba(176, 52, 26, 0.4));
}
.seal p {
  font-family: var(--font-hand);
  font-size: var(--text-lg);
  color: var(--muted);
  margin: var(--sp-2) 0 0;
}
.seal:hover svg {
  transform: scale(1.05);
  transition: transform var(--dur-fast) var(--ease-spring);
}
.seal--melting {
  animation: seal-melt var(--dur-slow) var(--ease-gentle) forwards;
}

/* Letter salutation */
.letter-salutation {
  font-family: var(--font-hand);
  font-size: var(--text-3xl);
  color: var(--fg);
  margin: 0 0 var(--sp-3);
  font-weight: 400;
  line-height: 1.2;
}
.letter-body {
  font-family: var(--font-body);
  font-size: var(--text-md);
  color: var(--fg-light);
  line-height: 1.8;
  margin: 0 0 var(--sp-3);
}
.signature {
  font-family: var(--font-hand);
  font-size: var(--text-2xl);
  color: var(--muted);
  font-style: italic;
  margin: var(--sp-3) 0;
}

/* Letter panels (unfolding) */
.letter-panels {
  display: grid;
  gap: 0;
}
.letter-panel {
  overflow: hidden;
  transform-origin: top center;
}
.letter-panel--folded {
  transform: perspective(600px) rotateX(-90deg);
  opacity: 0;
}
.letter-panel--unfolding {
  animation: panel-unfold var(--dur-slow) var(--ease-out) forwards;
  animation-delay: calc(var(--panel-index, 0) * 350ms);
}

/* ── Mushroom easter egg ── */
.mushroom-wrap {
  position: absolute;
  bottom: var(--sp-3);
  right: var(--sp-3);
  width: 48px;
  height: 60px;
}
.mushroom {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  user-select: none;
  z-index: 10;
  transition: transform var(--dur-fast) var(--ease-gentle);
}
.mushroom:hover {
  animation: sway var(--dur-med) ease-in-out;
}
.mushroom.dragging {
  cursor: grabbing;
  transition: none;
}
.lab-btn {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  z-index: 5;
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease-gentle);
  text-decoration: none;
}
.lab-btn.revealed { opacity: 1; }

/* ── Timer display ── */
.timer {
  display: flex;
  justify-content: center;
  gap: var(--sp-3);
  margin: var(--sp-4) 0;
  flex-wrap: wrap;
}
.timer-unit {
  background: var(--parchment);
  border: 2px solid var(--parchment-dk);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  min-width: 90px;
  text-align: center;
  box-shadow: var(--shadow-sm), 0 3px 0 var(--parchment-dk);
}
.timer-number {
  display: block;
  font-family: var(--font-hand);
  font-size: clamp(2rem, 7vw, 3.5rem);
  font-weight: 700;
  color: var(--fg);
  line-height: 1;
}
.timer-label {
  display: block;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-top: var(--sp-1);
}

/* ── Wooden sign (countdown title) ── */
.wooden-sign {
  background: #c8a060;
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-5);
  position: relative;
  box-shadow: 0 4px 0 #8a6030, var(--shadow-md);
  display: inline-block;
}
.wooden-sign::before,
.wooden-sign::after {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 60%;
  background: #a07040;
  border-radius: 3px;
  box-shadow: 0 3px 0 #7a5020;
}
.wooden-sign::before { left: -10px; }
.wooden-sign::after  { right: -10px; }
.wooden-sign h2 {
  font-family: var(--font-hand);
  font-size: var(--text-2xl);
  color: #3a2010;
  margin: 0;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.2);
}

/* ── Countdown form inline ── */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
  align-items: flex-end;
  margin-top: var(--sp-3);
}
.inline-form label {
  font-family: var(--font-hand);
  font-size: var(--text-md);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.inline-form input {
  min-width: 160px;
}

/* ── Scene skeleton (shared across pages) ── */
.scene {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

/* Sky gradient */
.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    #87ceeb 0%,
    #b8d9f0 35%,
    #dff0d8 65%,
    #c8e8a0 100%
  );
}

/* Cloud layer */
.cloud-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
}
.cloud {
  position: absolute;
  opacity: 0.85;
}

/* Background trees (blurred for depth) */
.trees-bg {
  position: absolute;
  bottom: 35%;
  left: 0;
  right: 0;
  height: 40%;
  overflow: visible;
}
.tree-blob {
  position: absolute;
  border-radius: 50% 50% 40% 40%;
  filter: blur(4px);
  opacity: 0.7;
}

/* Grass layers */
.grass-far {
  position: absolute;
  bottom: 32%;
  left: 0;
  right: 0;
  height: 12%;
  background: var(--grass-light);
  border-radius: 60% 60% 0 0 / 40% 40% 0 0;
}
.grass-mid {
  position: absolute;
  bottom: 18%;
  left: 0;
  right: 0;
  height: 18%;
  background: var(--grass);
  border-radius: 50% 50% 0 0 / 30% 30% 0 0;
}
.grass-near {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22%;
  background: var(--grass-dark);
}

/* Plant layer (mouse-reactive) */
.plants-layer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 35%;
  pointer-events: none;
}
.plant {
  position: absolute;
  bottom: 0;
  transform-origin: bottom center;
  transition: transform var(--dur-fast) var(--ease-gentle);
}
.plant.swaying {
  animation: plant-sway 3s ease-in-out infinite;
}

/* Deer positioning */
.deer-wrap {
  position: absolute;
  bottom: 20%;
  pointer-events: none;
}

/* Butterflies layer */
.butterflies-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.butterfly {
  position: absolute;
  pointer-events: none;
}
.butterfly svg {
  width: 40px;
  height: 30px;
}

/* ── Login character ── */
.login-character {
  position: fixed;
  bottom: var(--sp-4);
  left: var(--sp-5);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
  z-index: 100;
  max-width: 340px;
}
.login-character .rabbit-svg {
  width: 80px;
  height: 112px;
  margin-left: var(--sp-3);
  animation: rabbit-settle var(--dur-slow) var(--ease-spring) both;
}

/* ── Subtle footer ── */
.site-footer {
  position: fixed;
  bottom: var(--sp-2);
  right: var(--sp-4);
  font-family: var(--font-hand);
  font-size: var(--text-sm);
  color: var(--muted);
  z-index: 50;
  pointer-events: none;
  opacity: 0.7;
}

/* ── Auth-wall card (countdown fallback) ── */
.auth-wall {
  background: var(--parchment);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  max-width: 400px;
  margin: var(--sp-6) auto;
  text-align: center;
  box-shadow: var(--shadow-md);
  font-family: var(--font-hand);
}
.auth-wall h2 {
  font-size: var(--text-2xl);
  margin: 0 0 var(--sp-3);
}

/* ── Lab card ── */
.lab-card {
  background: var(--parchment);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--parchment-dk);
}
.lab-card h2 {
  font-family: var(--font-hand);
  font-size: var(--text-2xl);
  margin: 0 0 var(--sp-3);
}
.lab-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--sp-2);
}
.lab-list a {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-hand);
  font-size: var(--text-lg);
  color: var(--grass-dark);
  text-decoration: none;
  padding: var(--sp-2) 0;
  transition: gap var(--dur-fast) var(--ease-gentle);
}
.lab-list a:hover { gap: var(--sp-3); }
