:root {
  --bg: #fff8f0;
  --surface: #ffffff;
  --text: #2b2118;
  --muted: #8a7b6e;
  --primary: #ff6b4a;
  --primary-ink: #ffffff;
  --accent: #ffc93c;
  --good: #3ec98b;
  --border: #f0e2d4;
  --shadow: 0 6px 20px rgba(120, 70, 30, 0.12);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1612;
    --surface: #2a221c;
    --text: #f6ece2;
    --muted: #b3a394;
    --primary: #ff7b5c;
    --border: #3b3029;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1612;
  --surface: #2a221c;
  --text: #f6ece2;
  --muted: #b3a394;
  --primary: #ff7b5c;
  --border: #3b3029;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.screen { display: flex; flex-direction: column; gap: 16px; animation: fade 0.25s ease; }

h1, h2 { margin: 0; line-height: 1.15; }
h1 { font-size: 1.8rem; text-align: center; margin-top: 16px; }
h2 { font-size: 1.25rem; text-align: center; }
.sub { margin: 0; text-align: center; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  padding: 14px 20px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow); }
.btn-big { font-size: 1.4rem; padding: 22px; }
.btn-big:disabled { opacity: 1; background: var(--good); color: #fff; box-shadow: none; }
.btn-ghost { background: var(--surface); color: var(--text); border: 2px solid var(--border); }
.btn-link { background: none; color: var(--muted); font-weight: 600; }
.btn-icon {
  font: inherit; font-size: 1.4rem; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); cursor: pointer;
}
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

/* ---------- setup ---------- */
.species-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.species, .chip {
  font: inherit; color: var(--text);
  background: var(--surface); border: 3px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 18px 8px; cursor: pointer; font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s;
}
.species:active, .chip:active { transform: scale(0.95); }
.species.active, .chip.active { border-color: var(--primary); transform: scale(1.03); }
.species-emoji { font-size: 3.2rem; }
.name-field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 0.9rem; }
.name-field input {
  font: inherit; font-size: 1.1rem; color: var(--text);
  padding: 14px 16px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface);
}

/* ---------- home ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pet-title { font-size: 1.4rem; font-weight: 800; }
.pet-stage { color: var(--muted); font-size: 0.9rem; }
.streak {
  background: var(--surface); border-radius: 999px; padding: 8px 14px;
  font-size: 1.2rem; box-shadow: var(--shadow); white-space: nowrap;
}

.bubble {
  position: relative; background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); text-align: center; min-height: 3.2em;
  display: flex; align-items: center; justify-content: center;
}
.bubble::after {
  content: ""; position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  border: 10px solid transparent; border-top-color: var(--surface); border-bottom: 0;
}

.pet-wrap { display: flex; justify-content: center; padding: 12px 0 4px; }
.pet {
  --scale: 1;
  position: relative; width: 190px; height: 190px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 60%, var(--accent) 0%, transparent 70%);
  animation: idle 2.4s ease-in-out infinite;
}
.pet-emoji { font-size: calc(110px * var(--scale)); line-height: 1; transition: font-size 0.4s; }
.pet-accessory { position: absolute; top: 6px; right: 14px; font-size: 2.4rem; transform: rotate(14deg); }
.pet-mood {
  position: absolute; bottom: 8px; left: 10px; font-size: 1.9rem;
  background: var(--surface); border-radius: 50%; width: 48px; height: 48px;
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.pet[data-mood="sad"] { animation: sway 3s ease-in-out infinite; filter: saturate(0.6); }
.pet[data-mood="sleepy"] { animation: sway 4s ease-in-out infinite; filter: saturate(0.4) brightness(0.9); }
.pet[data-mood="ecstatic"] { animation: hop 0.9s ease-in-out infinite; }
.pet.dance { animation: dance 0.9s ease-in-out 2; }
.pet.droop { animation: droop 1.2s ease-in-out 1; }

.level { display: flex; flex-direction: column; gap: 6px; }
.level-row { display: flex; justify-content: space-between; font-size: 0.95rem; color: var(--muted); }
.level-row b { color: var(--text); }
.xp-bar { height: 14px; background: var(--border); border-radius: 999px; overflow: hidden; }
.xp-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.6s cubic-bezier(.2,.8,.2,1.2);
}

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.dot {
  width: 36px; height: 36px; border-radius: 50%; background: var(--border);
  display: grid; place-items: center; font-size: 1.1rem;
}
.day.done .dot { background: var(--good); }
.day.today .dname { color: var(--text); font-weight: 800; }

/* ---------- excuses ---------- */
.excuse-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.chip { padding: 14px 8px; font-size: 0.95rem; text-align: center; }
.chip-emoji { font-size: 1.8rem; }

.bust {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
}
.bust.pop { animation: pop 0.35s cubic-bezier(.2,.8,.2,1.3); }
.bust-head { display: flex; gap: 12px; align-items: flex-start; }
.bust-pet { font-size: 2.8rem; line-height: 1; }
.bust-talk { margin: 0; font-size: 1.05rem; font-weight: 600; }
.plan { background: var(--bg); border-radius: 14px; padding: 12px 14px; }
.plan-title { font-weight: 800; color: var(--primary); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.06em; }
.plan ul { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- fx ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px;
  font-weight: 700; max-width: calc(100% - 32px); text-align: center;
  transition: transform 0.3s cubic-bezier(.2,.8,.2,1.2); z-index: 11;
}
.toast.show { transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-16px) scale(1.04, 0.96); } }
@keyframes sway { 0%, 100% { transform: rotate(-4deg) translateY(4px); } 50% { transform: rotate(4deg) translateY(4px); } }
@keyframes dance {
  0% { transform: rotate(0) scale(1); }
  25% { transform: rotate(-14deg) scale(1.12); }
  50% { transform: rotate(14deg) scale(1.18) translateY(-12px); }
  75% { transform: rotate(-8deg) scale(1.08); }
  100% { transform: rotate(0) scale(1); }
}
@keyframes droop { 0%, 100% { transform: none; } 50% { transform: translateY(14px) scale(0.92); } }
@keyframes pop { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- coach mode: dark, gritty, loud ---------- */
.top-right { display: flex; align-items: center; gap: 10px; }
.coach-head, .btn-sound { display: none; }

body.coach-mode {
  --bg: #0e0e0e;
  --surface: #1a1a1a;
  --text: #f2f2f2;
  --muted: #a3a3a3;
  --primary: #d7261e;
  --primary-ink: #ffffff;
  --accent: #d7261e;
  --border: #333333;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  --coach-font: Impact, "Haettenschweiler", "Arial Narrow Bold", "Arial Black", sans-serif;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 14px, transparent 14px 28px),
    radial-gradient(ellipse at top, #2a0d0b 0%, var(--bg) 60%);
  background-color: var(--bg);
  background-attachment: fixed;
  animation: shake 0.35s ease 1;
}
body.coach-mode h2,
body.coach-mode .btn-primary,
body.coach-mode .plan-title { font-family: var(--coach-font); text-transform: uppercase; letter-spacing: 0.04em; }
body.coach-mode .chip { border-color: #2a2a2a; }
body.coach-mode .chip.active { border-color: var(--primary); }
body.coach-mode .plan { background: #0e0e0e; border-left: 4px solid var(--primary); }
body.coach-mode .bust-head { opacity: 0.85; font-size: 0.9rem; }
body.coach-mode .bust-pet { font-size: 1.8rem; }
body.coach-mode .bust-talk { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
body.coach-mode .coach-head { display: flex; gap: 14px; align-items: center; }
body.coach-mode .btn-sound { display: block; }

.btn-sound {
  background: var(--surface); color: var(--text); border: 2px solid var(--primary);
  font-family: var(--coach-font); text-transform: uppercase; letter-spacing: 0.06em;
}

.coach-avatar {
  flex: none; position: relative; width: 84px; height: 84px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #3a3a3a, #111);
  border: 3px solid var(--primary); box-shadow: 0 0 0 4px rgba(215, 38, 30, 0.25);
  display: grid; place-items: center; overflow: hidden;
}
.coach-avatar img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) contrast(1.2); mix-blend-mode: luminosity; }
.coach-avatar::after { /* red grit tint over photos */
  content: ""; position: absolute; inset: 0; background: rgba(215, 38, 30, 0.18); pointer-events: none;
}
.badge-skull { font-size: 2.6rem; line-height: 1; }
.badge-fire { position: absolute; top: 4px; right: 6px; font-size: 1.1rem; }
.badge-ribbon {
  position: absolute; bottom: 10px; left: -6px; right: -6px; transform: rotate(-8deg);
  background: var(--primary); color: #fff; text-align: center;
  font-family: var(--coach-font); font-size: 0.62rem; letter-spacing: 0.08em; padding: 2px 0;
}
.coach-avatar-big { width: 132px; height: 132px; margin: 0 auto; }
.coach-avatar-big .badge-skull { font-size: 4.2rem; }
.coach-avatar-big .badge-fire { font-size: 1.8rem; }
.coach-avatar-big .badge-ribbon { font-size: 0.9rem; bottom: 18px; }

.coach-tag { font-family: var(--coach-font); color: var(--primary); letter-spacing: 0.1em; font-size: 0.85rem; }
.coach-quote {
  margin: 4px 0 2px; font-family: var(--coach-font); text-transform: uppercase;
  font-size: 1.25rem; line-height: 1.15; color: var(--text);
}
.coach-quote::before { content: "“"; color: var(--primary); }
.coach-quote::after { content: "”"; color: var(--primary); }
.coach-attr { color: var(--muted); font-size: 0.85rem; font-style: italic; }

.coach-overlay {
  position: fixed; inset: 0; z-index: 9; overflow-y: auto;
  background: rgba(8, 8, 8, 0.985);
  display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  animation: fade 0.25s ease;
}
.coach-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.coach-title { font-family: var(--coach-font); color: var(--primary); font-size: 1.1rem; letter-spacing: 0.06em; }
.coach-quote-big { font-size: 1.9rem; }
.coach-overlay .coach-attr { margin-top: -8px; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.coach-finisher {
  font-family: var(--coach-font); color: var(--primary); text-transform: uppercase;
  font-size: 1.05rem; letter-spacing: 0.04em;
}
.coach-finisher-big { font-size: 1.5rem; }
.coach-finisher.pulse { animation: pulse 0.5s ease 2; }

/* "Now playing" equalizer on the sound button */
.btn-sound.playing::after {
  content: ""; display: inline-block; width: 18px; height: 12px; margin-left: 10px; vertical-align: middle;
  background: linear-gradient(var(--primary), var(--primary)) 0 100% / 4px 40% no-repeat,
              linear-gradient(var(--primary), var(--primary)) 7px 100% / 4px 90% no-repeat,
              linear-gradient(var(--primary), var(--primary)) 14px 100% / 4px 60% no-repeat;
  animation: eq 0.6s steps(3) infinite;
}
@keyframes eq { 50% { transform: scaleY(0.4); } }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* YouTube sound-bite player (Shorts are vertical) */
.yt-slot { display: flex; justify-content: center; }
.yt-slot iframe {
  width: min(100%, 260px); height: auto; aspect-ratio: 9 / 16; max-height: 55vh;
  border: 2px solid var(--primary); border-radius: 14px; background: #000;
}
/* Keep the takeover's buttons in view with a player open; margin:auto centers without clipping the top. */
.coach-overlay { align-items: flex-start; }
.coach-card { margin: auto; }
.coach-overlay .yt-slot iframe { max-height: 36vh; }
