/* ===================================================================
   Digimon Prototype — Iteration 1
   Mobile-first responsive styling.
   =================================================================== */
:root {
  --bg-0: #0b0f2a;
  --bg-1: #1a1440;
  --bg-2: #25206b;
  --accent: #ffd23f;
  --accent-2: #7fe0ff;
  --text: #eef2ff;
  --text-dim: #aab4d6;
  --danger: #ff5d6c;
  --ok: #4ade80;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  --radius: 18px;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: #fff;
  background:
    radial-gradient(1200px 700px at 85% -10%, rgba(47,124,255,0.20), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(255,210,63,0.12), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 60%, var(--bg-2));
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* subtle starfield dots */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 60% 15%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 80% 40%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 40% 70%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 90% 80%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 10% 85%, rgba(255,255,255,0.3), transparent);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  width: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 18px;
}

.stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: stageIn 0.4s ease;
}
.stage.hidden { display: none; }

@keyframes stageIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  padding: 26px 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

/* ---------- typography ---------- */
.title {
  font-size: clamp(2.4rem, 9vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 14px 0 6px;
}
.title span { color: var(--accent); -webkit-text-fill-color: var(--accent); }

.tagline {
  color: var(--accent-2);
  font-weight: 600;
  font-size: 1.02rem;
  margin-bottom: 10px;
}
.intro { color: var(--text-dim); font-size: 0.96rem; line-height: 1.5; margin-bottom: 22px; }

.subtitle { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
.help { color: var(--text-dim); font-size: 0.92rem; margin-bottom: 18px; }
.eyebrow { color: var(--accent-2); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ---------- buttons ---------- */
.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 22px;
  font-size: 1.02rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #f7971e, var(--accent));
  color: #17132e;
  box-shadow: 0 8px 24px rgba(255, 210, 63, 0.30);
}
.btn-primary:hover { box-shadow: 0 10px 30px rgba(255, 210, 63, 0.45); }

.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: #dce3ff;
  border: 1px solid var(--card-border);
}
.btn-ghost:hover { background: rgba(255,255,255,0.14); }

.btn-danger {
  background: rgba(255, 93, 108, 0.14);
  color: var(--danger);
  border: 1px solid rgba(255, 93, 108, 0.4);
}
.btn-warn { background: rgba(255, 193, 7, 0.16); color: #ffd23f; border: 1px solid rgba(255,193,7,0.4); }

.btn-block { width: 100%; margin-top: 10px; }
.btn-big { padding: 16px 28px; font-size: 1.15rem; }

.link-btn {
  background: none; border: none; color: var(--text-dim);
  margin-top: 16px; cursor: pointer; font-size: 0.9rem; font-family: inherit;
}
.link-btn:hover { color: #fff; }

/* ---------- name input ---------- */
#name-form { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
input[type="text"] {
  padding: 15px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--card-border);
  background: rgba(0,0,0,0.28);
  color: #fff;
  font-size: 1.05rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
  text-align: center;
}
input[type="text"]::placeholder { color: #6c7499; }
input[type="text"]:focus { border-color: var(--accent); }

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: -4px;
}
.field-error.hidden { display: none; }
.input-invalid { border-color: var(--danger) !important; }

/* ---------- egg scene ---------- */
.egg-scene {
  position: relative;
  width: 160px;
  height: 210px;
  margin: 30px auto 20px;
}
.egg-shape {
  position: absolute;
  inset: 0;
  width: 130px;
  height: 178px;
  margin: auto;
  filter: drop-shadow(0 18px 26px rgba(0,0,0,0.5));
  animation: eggFloat 2.6s ease-in-out infinite;
}
@keyframes eggFloat {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-10px) rotate(2deg); }
}
.egg-top {
  position: absolute; top: 0; left: 50%;
  transform: translateX(-50%);
  width: 66px; height: 78px;
  background: linear-gradient(180deg, #7fe0ff, #3f87dd);
  border-radius: 60% 60% 40% 40%;
  z-index: 2;
  animation: eggPulse 2.6s ease-in-out infinite;
}
.egg-bottom {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  width: 104px; height: 118px;
  background: linear-gradient(180deg, #4a7bd8, #2b4fae);
  border-radius: 42% 42% 50% 50%;
}
.egg-bottom::after {
  content: ""; position: absolute; top: 14px; left: 26px;
  width: 16px; height: 26px; border-radius: 50%;
  background: rgba(255,255,255,0.35); filter: blur(2px);
}
@keyframes eggPulse {
  0%,100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}
.egg-glow {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  width: 120px; height: 22px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(127,224,255,0.35), transparent);
  filter: blur(4px);
  animation: glowPulse 1.6s ease-in-out infinite;
}
@keyframes glowPulse { 0%,100%{opacity:.5; transform:translateX(-50%) scale(1);} 50%{opacity:.9; transform:translateX(-50%) scale(1.15);} }

.countdown {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(255,210,63,0.4);
  letter-spacing: 0.04em;
}
.hatch-hint { color: var(--text-dim); margin-top: 10px; font-size: 0.95rem; }

/* ---------- hatch animation ---------- */
.hatch-anim { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.hatch-anim.hidden { display: none; }
.burst {
  position: absolute; top: 50%; left: 50%;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  animation: burst 1s ease-out forwards;
}
.b1{ --tx:-120px; --ty:-90px; } .b2{ --tx:120px; --ty:-70px; }
.b3{ --tx:-110px; --ty:80px; } .b4{ --tx:130px; --ty:90px; }
@keyframes burst {
  from { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  to   { opacity: 0; transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.2); }
}
.spin-ring {
  position:absolute; top:50%; left:50%; width:220px; height:220px;
  transform: translate(-50%,-50%);
  border: 3px solid rgba(127,224,255,0.5);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: translate(-50%,-50%) rotate(360deg); } }
@keyframes flashPulse { 0%{background:rgba(255,210,63,0);} 50%{background:rgba(255,210,63,0.35);} 100%{background:rgba(255,210,63,0);} }
body.hatching { animation: flashPulse 1s ease; }

/* ---------- companion ---------- */
.digi-stage { position: relative; width: 100%; height: 250px; display: flex; align-items: center; justify-content: center; }
.digi-wrap { position: relative; width: 200px; height: 200px; }
.digi-creature {
  width: 100%; height: 100%;
  animation: digiBounce 2.4s ease-in-out infinite;
  filter: drop-shadow(0 16px 22px rgba(0,0,0,0.45));
}
@keyframes digiBounce {
  0%,100% { transform: translateY(0) scale(1.02); }
  50%     { transform: translateY(-12px) scale(0.98); }
}
.digi-creature svg { width: 100%; height: 100%; overflow: visible; }
.digi-creature.blink { animation: blinkAnim 4s ease infinite; }
@keyframes blinkAnim { 0%,90%,100%{transform:scaleY(1);} 93%{transform:scaleY(0.06);} 96%{transform:scaleY(1);} }
.digi-wrap.wobble { animation: wobble 0.4s ease; }
@keyframes wobble { 0%{transform:scale(1) rotate(0);} 30%{transform:scale(1.12) rotate(-4deg);} 60%{transform:scale(1.05) rotate(3deg);} 100%{transform:scale(1) rotate(0);} }

.speech-bubble {
  position: absolute;
  top: 8px; right: 6%;
  background: #fff; color: #1d1a33;
  padding: 10px 14px; border-radius: 14px;
  font-weight: 700; font-size: 0.95rem;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  animation: pop 0.25s ease;
}
.speech-bubble::after {
  content:""; position:absolute; bottom:-8px; left:24px;
  border-left:9px solid transparent; border-right:9px solid transparent; border-top:9px solid #fff;
}
.speech-bubble.hidden { display:none; }
@keyframes pop { from { transform: scale(0.6); opacity:0; } to { transform: scale(1); opacity:1; } }

.message-strip {
  margin: 4px auto 14px;
  padding: 10px 18px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 30px;
  color: var(--accent-2);
  font-weight: 600;
  animation: pop 0.25s ease;
}
.message-strip.hidden { display:none; }

/* ---------- actions ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  margin-top: 6px;
}
.act-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px 8px;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.act-btn:active { transform: scale(0.94); background: rgba(255,255,255,0.13); }
.act-btn .act-icon { font-size: 1.7rem; }
.act-btn span { font-size: 0.9rem; }

/* ---------- menu / debug ---------- */
.menu-inner, .error-inner { text-align: left; }
.menu-stat { display:flex; justify-content:space-between; padding: 9px 0; border-bottom:1px solid var(--card-border); font-size:0.92rem; }
.menu-stat b { font-weight:600; word-break: break-all; text-align:right; }

.debug-grid { display:grid; grid-template-columns:1fr; gap:6px; margin: 14px 0; }
.dbitem { display:flex; justify-content:space-between; gap:12px; padding:7px 10px; background:rgba(0,0,0,0.22); border-radius:8px; font-size:0.82rem; }
.dbitem span { color: var(--text-dim); }
.dbitem b { font-weight:600; word-break:break-all; text-align:right; }

.debug-controls { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin:12px 0; }
.debug-controls .btn { padding: 11px 8px; font-size:0.9rem; }
.debug-controls #db-reset { grid-column: span 2; }

.event-log { margin-top: 6px; }
.event-log h3 { font-size:0.78rem; letter-spacing:0.1em; color:var(--text-dim); margin-bottom:8px; }
.event-log ul { list-style:none; max-height:200px; overflow-y:auto; }
.event-log li {
  font-family: ui-monospace, monospace;
  font-size:0.8rem;
  display:flex; justify-content:space-between;
  padding:5px 8px;
  border-bottom:1px solid var(--card-border);
  color:#cfd6f2;
}
.event-log li time { color:var(--text-dim); font-size:0.75rem; }

/* ---------- stage 2: status bar + mood ---------- */
.status-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
  margin: 2px auto 12px;
}
.stat-pill {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 7px 6px;
  font-weight: 700;
}
.stat-pill .stat-icon { font-size: 1rem; }
.stat-pill .stat-val { font-size: 0.95rem; color: #fff; }
.stat-pill.low .stat-val { color: var(--danger); }

.mood-chip {
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.45);
  border: 1px solid var(--card-border);
  color: var(--accent-2);
  font-size: 0.78rem; font-weight: 700;
  padding: 4px 12px; border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}
.mood-chip.hidden { display: none; }

/* Mood-linked motion. Base bounce on .digi-creature already exists; here we
   ONLY retune speed/amplitude so the creature "feels" its mood. */
.digi-wrap[data-mood="HAPPY"] .digi-creature { animation: digiBounce 2.2s ease-in-out infinite; }
.digi-wrap[data-mood="EXCITED"] .digi-creature { animation: digiExcited 0.6s ease-in-out infinite; }
.digi-wrap[data-mood="SAD"] svg { filter: drop-shadow(0 8px 12px rgba(0,0,0,0.5)) saturate(0.8); }
.digi-wrap[data-mood="SAD"] .digi-creature { animation: digiSad 3.2s ease-in-out infinite; }
.digi-wrap[data-mood="HUNGRY"] .digi-creature { animation: digiHungry 3s ease-in-out infinite; }
.digi-wrap[data-mood="TIRED"] .digi-creature { animation: digiTired 3.4s ease-in-out infinite; }
.digi-wrap[data-mood="SLEEPING"] .digi-creature,
.digi-wrap.asleep .digi-creature { animation: digiSleep 4s ease-in-out infinite; opacity: 0.92; }
.digi-wrap.asleep svg { filter: drop-shadow(0 10px 14px rgba(0,0,0,0.5)) brightness(0.96); }

@keyframes digiExcited {
  0%,100% { transform: translateY(0) scale(1.05) rotate(0); }
  25% { transform: translateY(-10px) scale(1.08) rotate(-3deg); }
  50% { transform: translateY(-18px) scale(1.1) rotate(0); }
  75% { transform: translateY(-10px) scale(1.08) rotate(3deg); }
}
@keyframes digiSad {
  0%,100% { transform: translateY(0) scale(0.98); }
  50% { transform: translateY(6px) scale(0.96); }
}
@keyframes digiHungry {
  0%,100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.02); }
}
@keyframes digiTired {
  0%,100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(3px) scale(0.99); }
}
@keyframes digiSleep {
  0%,100% { transform: translateY(0) rotate(-2deg) scale(0.98); }
  50% { transform: translateY(-4px) rotate(-2deg) scale(0.96); }
}

/* ---------- stage 2: debug additions ---------- */
.debug-panel h3 {
  font-size:0.78rem; letter-spacing:0.12em; color:var(--text-dim);
  margin: 12px 0 4px; text-transform: uppercase;
}
.db-nowrap { white-space: nowrap; }
.db-bars { display:flex; flex-direction:column; gap:6px; margin:4px 0 6px; }
.bar-row { display:flex; align-items:center; gap:8px; font-size:0.8rem; }
.bar-row span { width: 84px; color: var(--text-dim); text-transform: capitalize; }
.bar-row .bar {
  flex:1; height: 10px; background: rgba(0,0,0,0.28);
  border-radius: 6px; overflow: hidden;
}
.bar-row .bar-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.25s ease;
}
.bar-row b { font-weight:600; width:34px; text-align:right; font-size:0.78rem; }
.sim-tools { margin: 6px 0 4px; }
.sim-row { display:grid; grid-template-columns:repeat(auto-fit, minmax(84px, 1fr)); gap:6px; margin-bottom:6px; }
.sim-row .btn { padding: 10px 6px; font-size:0.78rem; }
@media (min-width: 768px) { .sim-row .btn { font-size:0.86rem; } }

/* ---------- error ---------- */
.error-inner { text-align:center; }
.error-icon { font-size:2.4rem; margin-bottom:8px; }
#error-msg { color: var(--text-dim); margin-bottom:18px; font-size:0.95rem; }

/* =================================================
   Desktop layout — use the extra width nicely.
   ================================================= */
@media (min-width: 768px) {
  #app { max-width: 720px; padding: 24px 32px; }

  .digi-stage { height: 320px; }
  .digi-wrap { width: 250px; height: 250px; }

  .actions { max-width: 460px; gap: 18px; }
  .act-btn { padding: 18px 10px; }
  .act-btn .act-icon { font-size: 2.1rem; }
  .act-btn span { font-size: 1rem; }

  .debug-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: 32px 30px; }
}

@media (min-width: 1100px) {
  #app { max-width: 860px; }
}

/* Landscape phones (short viewport) */
@media (max-height: 520px) and (orientation: landscape) {
  .egg-scene { margin: 6px auto; height: 150px; }
  .egg-shape { width: 90px; height: 120px; }
  .digi-stage { height: 180px; }
  .digi-wrap { width: 150px; height: 150px; }
  .countdown { font-size: 1.4rem; }
  .title { font-size: 2rem; }
}