:root {
  --magenta: #ec4899;
  --cyan: #22d3ee;
  --violet: #a855f7;
  --gold: #fbbf24;
  --mint: #86efac;
  --rose: #fb7185;
  --bg-deep: #1e0a3c;
  --bg-mid: #4c1d95;
  --bg-edge: #06051a;
  --warn: #ff5577;
  --frame: rgba(255, 255, 255, 0.18);
  --frame-bright: rgba(255, 255, 255, 0.45);
  --text: #f8fafc;
  --text-dim: rgba(248, 250, 252, 0.65);
  --font: 'SF Mono', 'Menlo', 'Consolas', monospace;
  --glow: rgba(236, 72, 153, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-edge);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0.05em;
}

body {
  background:
    radial-gradient(ellipse 70% 50% at 50% 35%, var(--bg-mid) 0%, var(--bg-deep) 50%, var(--bg-edge) 100%);
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

#scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: screen;
  animation: scanShift 8s linear infinite;
  z-index: 4;
}

@keyframes scanShift {
  0%   { transform: translateY(0); }
  100% { transform: translateY(4px); }
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.7) 100%);
  z-index: 5;
}

/* HUD */
#hud-top {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 0;
  font-size: 11px;
  text-transform: uppercase;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: bold;
  letter-spacing: 0.25em;
  text-shadow: 0 0 12px var(--glow);
  background: linear-gradient(90deg, var(--gold), var(--rose), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 13px;
}

.brand .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--rose);
  box-shadow: 0 0 12px var(--rose), 0 0 24px var(--magenta);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.85); }
}

.hud-right {
  display: flex;
  gap: 8px;
}

.hud-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--frame-bright);
  color: var(--text);
  font-family: var(--font);
  font-size: 10px;
  letter-spacing: 0.18em;
  padding: 7px 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-transform: uppercase;
  border-radius: 4px;
  transition: background 0.15s, transform 0.1s;
}

.hud-btn:active { transform: scale(0.94); }
.hud-btn:hover  { background: rgba(255, 255, 255, 0.18); }

.hud-btn .count {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 9px;
}

#gallery-btn[data-attention="true"] {
  border-color: var(--rose);
  animation: hudFlash 1s ease-in-out infinite;
}

#gallery-btn.flash {
  animation: hudShake 0.4s ease-in-out 3;
}

@keyframes hudFlash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.5); }
  50%      { box-shadow: 0 0 16px 4px rgba(251, 113, 133, 0.7); }
}

@keyframes hudShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

#sound-btn .ico-off { display: none; }
#sound-btn[data-muted="true"] .ico-on { display: none; }
#sound-btn[data-muted="true"] .ico-off { display: inline; }

/* Pet meta unter HUD */
.pet-meta {
  position: relative;
  z-index: 10;
  text-align: center;
  font-size: 11px;
  padding: 6px 0 0;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

.pet-meta #pet-name {
  color: var(--text);
  font-weight: bold;
  text-shadow: 0 0 10px var(--glow);
}

.pet-meta .sep { opacity: 0.4; margin: 0 4px; }

/* Stats */
#stats {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  padding: 12px 22px 0;
}

.stat-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  margin-bottom: 4px;
  color: var(--text-dim);
}

.stat-val { color: var(--text); font-weight: bold; }

.bar {
  height: 7px;
  border: 1px solid var(--frame);
  background: rgba(255, 255, 255, 0.05);
  position: relative;
  overflow: hidden;
  border-radius: 3px;
}

.bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  box-shadow: 0 0 8px var(--glow);
  transition: width 0.4s ease, background 0.4s ease;
  border-radius: 2px;
}

.stat[data-stat="hunger"] .bar-fill { background: linear-gradient(90deg, var(--gold), var(--rose)); }
.stat[data-stat="energy"] .bar-fill { background: linear-gradient(90deg, var(--mint), var(--cyan)); }
.stat[data-stat="happiness"] .bar-fill { background: linear-gradient(90deg, var(--rose), var(--magenta)); }
.stat[data-stat="cleanliness"] .bar-fill { background: linear-gradient(90deg, var(--cyan), var(--violet)); }

.stat[data-low="true"] .bar-fill {
  background: var(--warn) !important;
  box-shadow: 0 0 12px rgba(255, 85, 119, 0.8);
  animation: barBlink 0.8s ease-in-out infinite;
}

.stat[data-low="true"] .stat-label {
  color: var(--warn);
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes barBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* Message */
#message {
  position: absolute;
  bottom: 142px;
  left: 0;
  right: 0;
  z-index: 10;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(251, 191, 36, 0.7);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#message.show { opacity: 1; transform: translateY(0); }

/* Actions */
#actions {
  position: relative;
  z-index: 10;
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 14px 16px 18px;
}

.action {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--frame-bright);
  color: var(--text);
  font-family: var(--font);
  font-size: 9px;
  letter-spacing: 0.18em;
  padding: 12px 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s, transform 0.1s, border-color 0.2s;
}

.action:hover { background: rgba(255, 255, 255, 0.14); }
.action:active { transform: scale(0.95); background: rgba(255, 255, 255, 0.22); }

.action[disabled] { opacity: 0.3; cursor: not-allowed; }

.action[data-action="feed"]  { border-color: rgba(251, 191, 36, 0.5); }
.action[data-action="play"]  { border-color: rgba(236, 72, 153, 0.5); }
.action[data-action="clean"] { border-color: rgba(34, 211, 238, 0.5); }
.action[data-action="sleep"] { border-color: rgba(168, 85, 247, 0.5); }

.action .ico {
  font-size: 26px;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.4));
}

/* Splash */
#splash {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: radial-gradient(ellipse at 50% 40%, rgba(76, 29, 149, 0.95), rgba(6, 5, 26, 0.98));
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease;
}

#splash.hide {
  opacity: 0;
  pointer-events: none;
}

.splash-inner {
  text-align: center;
  padding: 0 32px;
  max-width: 420px;
}

.logo {
  font-size: 44px;
  font-weight: bold;
  letter-spacing: 0.4em;
  background: linear-gradient(90deg, var(--gold), var(--rose), var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(251, 191, 36, 0.4);
  margin-bottom: 8px;
  animation: logoShine 4s ease-in-out infinite;
  background-size: 200% auto;
}

@keyframes logoShine {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

.tag {
  font-size: 10px;
  letter-spacing: 0.4em;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.intro {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 28px;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  letter-spacing: 0;
  opacity: 0.95;
}

#start-btn {
  width: 100%;
  background: linear-gradient(90deg, var(--magenta), var(--violet));
  border: none;
  color: white;
  font-family: var(--font);
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.25em;
  padding: 18px;
  cursor: pointer;
  box-shadow: 0 0 32px rgba(236, 72, 153, 0.6);
  transition: transform 0.1s, box-shadow 0.2s;
  border-radius: 8px;
}

#start-btn:active {
  transform: scale(0.97);
  box-shadow: 0 0 18px rgba(236, 72, 153, 0.4);
}

.hint {
  margin-top: 20px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  line-height: 1.6;
}

/* Hatch flash */
@keyframes flash {
  0%   { opacity: 0; }
  40%  { opacity: 0.85; }
  100% { opacity: 0; }
}

#stage.hatch::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  animation: flash 0.6s ease-out;
}

/* ——— Galerie ——— */

#gallery {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#gallery.show {
  pointer-events: auto;
  opacity: 1;
}

.gallery-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(76, 29, 149, 0.92), rgba(6, 5, 26, 0.96));
  backdrop-filter: blur(8px);
}

.gallery-inner {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.gallery-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--frame);
}

.gallery-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.25em;
  color: var(--text);
}

.gallery-title .g-castle {
  font-size: 22px;
  color: var(--gold);
  text-shadow: 0 0 10px var(--gold);
}

#gallery-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px;
  align-content: start;
}

@media (min-width: 480px) {
  #gallery-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 720px) {
  #gallery-grid { grid-template-columns: repeat(5, 1fr); }
}

.pet-card {
  --p: rgba(255,255,255,0.1);
  --s: rgba(255,255,255,0.06);
  --a: rgba(255,255,255,0.4);
  background: linear-gradient(180deg, var(--p) 0%, var(--s) 100%);
  border: 1.5px solid var(--frame);
  padding: 12px 8px;
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  position: relative;
  aspect-ratio: 0.95;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

.pet-card[data-discovered="true"] {
  border-color: var(--a);
  box-shadow: 0 0 20px -8px var(--p), inset 0 0 30px -10px var(--p);
}

.pet-card[data-discovered="true"]:active { transform: scale(0.96); }

.pet-card[data-discovered="false"] {
  opacity: 0.55;
  background: rgba(255, 255, 255, 0.04);
  cursor: not-allowed;
}

.pet-card[data-active="true"] {
  border-width: 2px;
  border-color: var(--gold);
  box-shadow: 0 0 24px rgba(251, 191, 36, 0.6), inset 0 0 30px -10px var(--p);
}

.pet-card[data-rarity="rare"] {
  background: linear-gradient(180deg, var(--p), var(--s)),
              repeating-linear-gradient(45deg, rgba(255,255,255,0.05) 0 4px, transparent 4px 12px);
}

.pet-card[data-rarity="legendary"] {
  background: linear-gradient(180deg, var(--p), var(--s)),
              repeating-linear-gradient(45deg, rgba(251,191,36,0.15) 0 4px, transparent 4px 14px);
}

.pet-card[data-rarity="legendary"][data-discovered="true"]::before {
  content: '★';
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 12px;
  color: var(--gold);
  text-shadow: 0 0 8px var(--gold);
}

.pet-card[data-attention="true"] {
  animation: cardAttention 0.9s ease-in-out infinite;
}

@keyframes cardAttention {
  0%, 100% {
    box-shadow: 0 0 8px rgba(255, 85, 119, 0.4), inset 0 0 30px -10px var(--p);
    border-color: rgba(255, 85, 119, 0.5);
  }
  50% {
    box-shadow: 0 0 24px rgba(255, 85, 119, 0.9), inset 0 0 30px -10px var(--p);
    border-color: var(--warn);
  }
}

.pet-emoji {
  font-size: 38px;
  line-height: 1;
  filter: drop-shadow(0 0 10px var(--a));
  margin-bottom: 6px;
}

.pet-emoji.locked {
  font-size: 38px;
  opacity: 0.5;
  filter: none;
  color: var(--text-dim);
}

.pet-card-name {
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.15em;
  color: var(--text);
  margin-bottom: 2px;
}

.pet-card-species {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.pet-card .attn {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 18px;
  height: 18px;
  background: var(--warn);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px var(--warn);
  animation: pulse 0.9s ease-in-out infinite;
}

.pet-card .active-mark {
  position: absolute;
  top: 6px;
  right: 8px;
  color: var(--gold);
  font-size: 14px;
  text-shadow: 0 0 10px var(--gold);
}

.pet-card.egg-slot {
  background: rgba(255, 255, 255, 0.05);
  border-style: dashed;
  border-color: var(--frame-bright);
  cursor: default;
}

.pet-card.egg-slot.available {
  cursor: pointer;
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.4);
  animation: pulse 1.4s ease-in-out infinite;
}

#gallery-close {
  font-size: 14px;
  padding: 6px 12px;
}
