/* ─── Variables ─────────────────────────────── */
:root {
  /* Citrus Noir palette */
  --bg:          #0d0d0d;
  --surface:     #161616;
  --surface-2:   #1e1e1e;
  --surface-3:   #272727;

  --lime:        #e8ff4d;
  --lime-glow:   rgba(232, 255, 77, 0.22);
  --lime-dim:    rgba(232, 255, 77, 0.10);
  --coral:       #ff5533;
  --coral-dim:   rgba(255, 85, 51, 0.12);
  --teal:        #4dffd4;

  --text:        #f0ede8;
  --text-muted:  #6a6a6a;
  --text-sub:    #3d3d3d;

  --border:      #222222;
  --border-hi:   #303030;

  --radius:      22px;
  --radius-sm:   13px;
  --radius-pill: 100px;

  /* Safe-area insets */
  --sa-top:    env(safe-area-inset-top,    0px);
  --sa-right:  env(safe-area-inset-right,  0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left:   env(safe-area-inset-left,   0px);
}

/* ─── Reset ─────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ─── Body ──────────────────────────────────── */
body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--bg);
  font-family: 'Outfit', sans-serif;
  color: var(--text);
  padding:
    calc(clamp(16px, 3vw, 36px) + var(--sa-top))
    calc(clamp(16px, 3vw, 36px) + var(--sa-right))
    calc(clamp(16px, 3vw, 36px) + var(--sa-bottom))
    calc(clamp(16px, 3vw, 36px) + var(--sa-left));
  position: relative;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

/* ─── Background Blobs ──────────────────────── */
.bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.18;
  animation: drift 14s ease-in-out infinite alternate;
  will-change: transform;
}
.blob-1 {
  width: clamp(260px, 38vw, 500px);
  height: clamp(260px, 38vw, 500px);
  background: var(--lime);
  top: -14%; left: -10%;
  animation-delay: 0s;
}
.blob-2 {
  width: clamp(220px, 32vw, 440px);
  height: clamp(220px, 32vw, 440px);
  background: var(--coral);
  bottom: -10%; right: -8%;
  animation-delay: -5s;
}
.blob-3 {
  width: clamp(180px, 26vw, 360px);
  height: clamp(180px, 26vw, 360px);
  background: var(--teal);
  top: 44%; left: 54%;
  animation-delay: -10s;
}
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(36px, 22px) scale(1.07); }
}

/* ─── Card ──────────────────────────────────── */
.container {
  position: relative;
  z-index: 1;

  /* Fluid width: snug on mobile, roomy on desktop */
  width: clamp(320px, 94vw, 580px);

  /* Fluid padding */
  padding:
    clamp(28px, 5vw, 46px)
    clamp(22px, 4.5vw, 42px)
    clamp(22px, 4vw, 36px);

  background: var(--surface);
  border-radius: clamp(22px, 3.5vw, 34px);
  border: 1px solid var(--border-hi);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.035),
    0 32px 80px rgba(0,0,0,0.55),
    0 8px 24px rgba(0,0,0,0.35);
}

/* Subtle lime-to-teal gradient rim */
.container::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  background: linear-gradient(
    135deg,
    rgba(232,255,77,0.18) 0%,
    transparent 45%,
    rgba(77,255,212,0.10) 100%
  );
  z-index: -1;
  pointer-events: none;
}

/* ─── Header ────────────────────────────────── */
.header {
  text-align: center;
  margin-bottom: clamp(22px, 4vw, 32px);
}
.emoji-badge {
  display: block;
  font-size: clamp(40px, 8vw, 58px);
  line-height: 1;
  margin-bottom: clamp(8px, 1.5vw, 12px);
  animation: bounce 2.8s ease-in-out infinite;
  filter: drop-shadow(0 0 18px rgba(232,255,77,0.5));
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}
h1 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1;
  background: linear-gradient(140deg, #ffffff 10%, var(--lime) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  margin-top: 7px;
  font-size: clamp(13px, 2vw, 15px);
  color: var(--text-muted);
  font-weight: 300;
}

/* ─── Mood Section ──────────────────────────── */
.mood-section {
  margin-bottom: clamp(16px, 3vw, 24px);
}
.field-label {
  display: block;
  font-size: clamp(10px, 1.4vw, 11px);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: clamp(8px, 1.5vw, 12px);
}
.mood-pills {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(6px, 1.2vw, 10px);
  margin-bottom: clamp(12px, 2vw, 16px);
}
.pill {
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-pill);
  padding: clamp(8px, 1.4vw, 11px) clamp(14px, 2.5vw, 18px);
  font-size: clamp(13px, 1.9vw, 14px);
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  min-height: 40px;
  touch-action: manipulation;
}
.pill:hover {
  border-color: var(--lime);
  color: var(--lime);
  transform: translateY(-1px);
}
.pill.active {
  background: var(--lime);
  border-color: var(--lime);
  color: #0d0d0d;
  font-weight: 600;
  box-shadow: 0 0 22px var(--lime-glow);
}

/* ─── Custom Mood Input ─────────────────────── */
.custom-mood-wrap {
  position: relative;
}
#customMood {
  width: 100%;
  padding: clamp(12px, 2vw, 15px) 44px clamp(12px, 2vw, 15px) clamp(14px, 2.5vw, 18px);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  font-size: 16px; /* ≥16px prevents iOS Safari auto-zoom */
  font-family: 'Outfit', sans-serif;
  font-weight: 400;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
}
#customMood:focus {
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(232,255,77,0.10);
}
#customMood::placeholder {
  color: var(--text-sub);
}
.input-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  pointer-events: none;
  opacity: 0.35;
}

/* ─── CTA Button ────────────────────────────── */
#getJokeBtn {
  width: 100%;
  padding: clamp(14px, 2.5vw, 18px) 20px;
  background: var(--lime);
  color: #0d0d0d;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Syne', sans-serif;
  font-size: clamp(14px, 2.2vw, 16px);
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  margin-bottom: clamp(16px, 3vw, 22px);
  min-height: 52px;
  touch-action: manipulation;
  box-shadow: 0 4px 28px rgba(232,255,77,0.28);
}
#getJokeBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 36px rgba(232,255,77,0.42);
  background: #f0ff6a;
}
#getJokeBtn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 14px rgba(232,255,77,0.2);
}
#getJokeBtn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
#getJokeBtn.loading .btn-text::after {
  content: '...';
}
.btn-icon {
  font-size: clamp(16px, 2.5vw, 20px);
  animation: spin-slow 4s linear infinite;
}
@keyframes spin-slow {
  to { transform: rotate(360deg); }
}

/* ─── Joke Box ──────────────────────────────── */
.joke-box {
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  min-height: clamp(100px, 18vw, 130px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(18px, 3vw, 28px);
  text-align: center;
  margin-bottom: clamp(16px, 3vw, 22px);
  overflow: hidden;
  transition: border-color 0.35s, background 0.35s, box-shadow 0.35s;
  position: relative;
}
/* Decorative corner accent */
.joke-box::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(232,255,77,0.04) 0%, transparent 55%);
  pointer-events: none;
  border-radius: inherit;
}
.joke-box.has-joke {
  border-color: rgba(232,255,77,0.45);
  background: var(--lime-dim);
  box-shadow: inset 0 0 32px rgba(232,255,77,0.06), 0 0 0 1px rgba(232,255,77,0.18);
}
.joke-placeholder {
  text-align: center;
  color: var(--text-sub);
}
.placeholder-icon {
  font-size: clamp(28px, 5vw, 38px);
  margin-bottom: 8px;
  opacity: 0.45;
}
.joke-placeholder p {
  font-size: clamp(13px, 2vw, 14px);
}
#jokeText {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(15px, 2.5vw, 18px);
  font-style: italic;
  line-height: 1.68;
  color: var(--text);
  font-weight: 400;
  overflow-wrap: anywhere;
  word-break: break-word;
}
#jokeText.hidden        { display: none; }
.joke-placeholder.hidden { display: none; }

/* ─── Rating ────────────────────────────────── */
.rating-section {
  margin-bottom: clamp(12px, 2.5vw, 18px);
  text-align: center;
  opacity: 0.3;
  pointer-events: none;
  transition: opacity 0.35s;
}
.rating-section.active {
  opacity: 1;
  pointer-events: all;
}
.rating-label {
  font-size: clamp(10px, 1.4vw, 11px);
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--text-muted);
  margin-bottom: clamp(8px, 1.5vw, 12px);
  font-weight: 600;
}
.ratings {
  display: flex;
  justify-content: center;
  gap: clamp(8px, 1.5vw, 12px);
}
.rate-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  padding: clamp(8px, 1.5vw, 12px) clamp(12px, 2vw, 16px);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  min-width: 72px;
  min-height: 56px;
  flex: 1 1 0;
  max-width: 120px;
  touch-action: manipulation;
  color: var(--text-muted);
}
.rate-btn:hover {
  border-color: var(--lime);
  transform: translateY(-2px);
  color: var(--text);
}
.rate-btn.selected {
  background: var(--lime-dim);
  border-color: rgba(232,255,77,0.5);
  box-shadow: 0 0 0 1px rgba(232,255,77,0.25);
  color: var(--lime);
}
.rate-emoji { font-size: clamp(18px, 3vw, 24px); }
.rate-label { font-size: clamp(10px, 1.4vw, 12px); font-weight: 500; }

/* ─── Actions ───────────────────────────────── */
.actions {
  display: flex;
  gap: clamp(8px, 1.5vw, 12px);
  margin-bottom: clamp(10px, 2vw, 16px);
}
.action-btn {
  flex: 1;
  padding: clamp(12px, 2vw, 15px);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hi);
  font-family: 'Outfit', sans-serif;
  font-size: clamp(13px, 1.9vw, 14px);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  min-height: 48px;
  touch-action: manipulation;
}
.action-btn.continue {
  background: #252a00;
  color: #e8ff4d;
  border-color: rgba(232,255,77,0.5);
  font-weight: 600;
}
.action-btn.continue:hover {
  background: var(--lime);
  color: #0d0d0d;
  border-color: var(--lime);
  box-shadow: 0 4px 18px rgba(232,255,77,0.28);
}
.action-btn.stop {
  background: #2a2222;
  color: #f0ede8;
  border-color: #3d3030;
}
.action-btn.stop:hover {
  background: var(--coral-dim);
  border-color: rgba(255,85,51,0.55);
  color: var(--coral);
}

/* ─── Message ───────────────────────────────── */
#message {
  text-align: center;
  font-size: clamp(12px, 1.7vw, 13px);
  color: var(--text-muted);
  min-height: 20px;
}
#message.success {
  color: var(--lime);
  font-weight: 500;
}

/* ─── Transitions ───────────────────────────── */
@keyframes pop-in {
  0%   { transform: scale(0.91); opacity: 0; }
  60%  { transform: scale(1.025); }
  100% { transform: scale(1);   opacity: 1; }
}
.pop-in {
  animation: pop-in 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* ─── Mobile: reduce blur cost ──────────────── */
@media (max-width: 480px) {
  .blob {
    filter: blur(65px);
    opacity: 0.14;
  }
  body {
    align-items: flex-start; /* allow scroll on very small/short viewports */
  }
}

/* ─── Short landscape phones ────────────────── */
@media (max-height: 560px) and (orientation: landscape) {
  body { align-items: flex-start; }
  .header { margin-bottom: 14px; }
  .emoji-badge {
    font-size: 30px;
    margin-bottom: 4px;
    animation: none;
  }
  .joke-box { min-height: 76px; }
}

/* ─── Reduced motion ────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .blob, .btn-icon, .emoji-badge { animation: none; }
}

/* ─── Light mode ────────────────────────────── */
@media (prefers-color-scheme: light) {
  :root {
    --bg:        #f0ede6;
    --surface:   #ffffff;
    --surface-2: #f7f4ef;
    --surface-3: #ece9e2;
    --text:      #1a1625;
    --text-muted:#888888;
    --text-sub:  #c2bfb8;
    --border:    #e0ddd6;
    --border-hi: #d4d0c8;
    --lime-dim:  rgba(180, 160, 0, 0.10);
  }
  .container {
    box-shadow: 0 8px 56px rgba(0,0,0,0.10), 0 2px 12px rgba(0,0,0,0.06);
  }
  h1 {
    background: linear-gradient(140deg, #1a1625 0%, #5a4200 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  #getJokeBtn {
    background: #1a1625;
    color: var(--lime);
    box-shadow: 0 4px 24px rgba(26,22,37,0.2);
  }
  #getJokeBtn:hover {
    background: #2d2040;
    box-shadow: 0 8px 32px rgba(26,22,37,0.3);
  }
  .pill {
    background: var(--surface-2);
    color: var(--text-muted);
  }
  .pill.active {
    background: #1a1625;
    border-color: #1a1625;
    color: var(--lime);
    box-shadow: none;
  }
  #customMood { background: var(--surface-2); color: var(--text); }
  .joke-box   { background: var(--surface-2); }
  .rate-btn   { background: var(--surface-2); }
  .action-btn.continue { background: #1a1625; color: #e8ff4d; border-color: #3a3050; }
  .action-btn.continue:hover { background: #2d2040; color: #e8ff4d; }
  .action-btn.stop { background: #ede9e2; color: #1a1625; border-color: #ccc8c0; }
  .action-btn.stop:hover { background: #fde8e4; border-color: rgba(255,85,51,0.5); color: var(--coral); }
  .blob-1 { background: #ffd700; }
  .blob-2 { background: #ffb347; }
  .blob-3 { background: #87ceeb; }
}