/* ── Theme ── */
:root {
  --bg: #1a1a2e;
  --text: #e0e0e0;
  --text-muted: #9a9ab0;
  --accent: #e94560;
  --card-bg: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --spacing: 1.5rem;
  --pig-pink: #f4a4b8;
  --pig-dark: #e8899f;
  --pig-snout: #e8899f;
  --pig-nostril: #c46b82;
  --pig-cheek: rgba(255, 130, 160, 0.35);
  --bubble-bg: rgba(40, 40, 70, 0.95);
  --bubble-border: rgba(255, 255, 255, 0.15);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf9f6;
    --text: #2d2d2d;
    --text-muted: #6b6b6b;
    --accent: #c62368;
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.08);
    --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --pig-pink: #ffb6c8;
    --pig-dark: #f19cb0;
    --pig-snout: #f19cb0;
    --pig-nostril: #d47a92;
    --pig-cheek: rgba(255, 130, 160, 0.3);
    --bubble-bg: #ffffff;
    --bubble-border: rgba(0, 0, 0, 0.12);
  }
}

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

/* ── Body ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Main ── */
main {
  max-width: 600px;
  width: 100%;
  padding: var(--spacing);
  text-align: center;
}

/* ── Brand ── */
.brand {
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
}

/* ── Pig Scene ── */
.pig-scene {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 2rem;
  padding-top: 7rem;
}

/* ── Speech Bubble ── */
.speech-bubble {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: var(--bubble-bg);
  border: 2px solid var(--bubble-border);
  border-radius: 18px;
  padding: 0.5rem 1rem;
  box-shadow: var(--card-shadow);
  min-width: 3rem;
  max-width: 260px;
  word-break: break-word;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.4;
  opacity: 1;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.speech-bubble #bubble-text {
  white-space: pre-line;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 12px solid var(--bubble-border);
}

.speech-bubble::before {
  content: "";
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid var(--bubble-bg);
  z-index: 1;
}

.speech-bubble.hidden {
  transform: translateX(-50%) scale(0);
  opacity: 0;
  pointer-events: none;
}

.speech-bubble.pop-in {
  animation: pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes pop-in {
  0%   { transform: translateX(-50%) scale(0); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ── Pig ── */
.pig {
  position: relative;
  width: 160px;
  height: 160px;
}

.head {
  position: absolute;
  width: 140px;
  height: 130px;
  background: var(--pig-pink);
  border-radius: 50%;
  top: 20px;
  left: 10px;
}

/* ── Ears ── */
.ear {
  position: absolute;
  width: 45px;
  height: 40px;
  background: var(--pig-dark);
  border-radius: 50% 50% 20% 20%;
  z-index: 0;
}

.ear-left {
  top: 8px;
  left: 12px;
  transform: rotate(-20deg);
}

.ear-right {
  top: 8px;
  right: 12px;
  transform: rotate(20deg);
}

/* ── Eyes ── */
.eye {
  position: absolute;
  width: 10px;
  height: 12px;
  background: #2d2d2d;
  border-radius: 50%;
  top: 42px;
}

.eye-left {
  left: 35px;
}

.eye-right {
  right: 35px;
}

/* ── Snout ── */
.snout {
  position: absolute;
  width: 60px;
  height: 40px;
  background: var(--pig-snout);
  border-radius: 50%;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
}

.nostril {
  position: absolute;
  width: 10px;
  height: 12px;
  background: var(--pig-nostril);
  border-radius: 50%;
  top: 50%;
  transform: translateY(-50%);
}

.nostril-left {
  left: 14px;
}

.nostril-right {
  right: 14px;
}

/* ── Cheeks ── */
.cheek {
  position: absolute;
  width: 25px;
  height: 16px;
  background: var(--pig-cheek);
  border-radius: 50%;
  top: 62px;
}

.cheek-left {
  left: 12px;
}

.cheek-right {
  right: 12px;
}

/* ── Mouth ── */
.mouth {
  position: absolute;
  width: 20px;
  height: 8px;
  border-bottom: 2.5px solid var(--pig-nostril);
  border-radius: 0 0 50% 50%;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
}

/* ── Tail ── */
.tail {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 3px solid var(--pig-dark);
  border-radius: 50%;
  border-left-color: transparent;
  border-bottom-color: transparent;
  right: -8px;
  top: 70px;
  transform: rotate(-30deg);
}

/* ── Input ── */
#pig-input {
  width: 100%;
  max-width: 300px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#pig-input::placeholder {
  color: var(--text-muted);
}

#pig-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

/* ── 404 page ── */
.error-code {
  font-size: clamp(4rem, 15vw, 8rem);
  font-weight: 800;
  color: var(--accent);
}

.error-message {
  margin: var(--spacing) 0;
}

.home-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.home-link:hover,
.home-link:focus-visible {
  border-bottom-color: var(--accent);
}

/* ── Responsive ── */
@media (max-width: 400px) {
  .pig {
    width: 130px;
    height: 130px;
  }

  .head {
    width: 115px;
    height: 108px;
    top: 16px;
    left: 8px;
  }

  .ear {
    width: 38px;
    height: 34px;
  }

  .ear-left  { left: 8px; }
  .ear-right { right: 8px; }

  .eye      { top: 36px; }
  .eye-left { left: 28px; }
  .eye-right{ right: 28px; }

  .snout {
    width: 50px;
    height: 34px;
  }

  #pig-input {
    max-width: 260px;
  }
}
