/* style.css — Tamagotchi Virtual Pet */

/* ============ RESET & BASE ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --shell-pink: #f8b4d9;
  --shell-pink-dark: #e88fc5;
  --shell-pink-darker: #d06aa8;
  --shell-purple: #c084fc;
  --shell-teal: #67e8f9;
  --shell-teal-dark: #22d3ee;
  --screen-bg: #c5d8a4;
  --screen-bg-night: #7a8f6a;
  --screen-border: #5c6b4a;
  --text-dark: #2d2b3d;
  --text-light: #f8f0ff;
  --btn-bg: #e879a8;
  --btn-hover: #d35f91;
  --btn-active: #b8477a;
  --stat-hunger: #ff8fab;
  --stat-happy: #ffd166;
  --stat-energy: #67e8f9;
  --stat-health: #7bc47f;
  --bg-gradient-start: #fce4ec;
  --bg-gradient-end: #f3e5f5;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Courier New', monospace;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dark);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body.night-mode {
  --bg-gradient-start: #1a1a2e;
  --bg-gradient-end: #16213e;
  --screen-bg: #7a8f6a;
}

/* ============ LOADING SCREEN ============ */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: linear-gradient(135deg, #fce4ec, #f3e5f5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-egg {
  width: 60px;
  height: 80px;
  background: #f5e6d0;
  border: 3px solid #4a3728;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  position: relative;
  animation: egg-bounce 0.6s ease-in-out infinite alternate;
}

.loading-egg::before,
.loading-egg::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: #e8b4d8;
  border-radius: 50%;
}

.loading-egg::before {
  top: 25px;
  left: 12px;
}

.loading-egg::after {
  top: 35px;
  right: 10px;
}

@keyframes egg-bounce {
  from { transform: translateY(0) rotate(-3deg); }
  to { transform: translateY(-10px) rotate(3deg); }
}

.loading-text {
  margin-top: 20px;
  font-size: 1.1rem;
  color: var(--text-dark);
}

.loading-text::after {
  content: '';
  animation: loading-dots 1.5s steps(1) infinite;
}

@keyframes loading-dots {
  0%  { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
}

/* ============ INTRO / NAMING SCREEN ============ */
#intro-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  min-height: 100vh;
}

#intro-screen.active {
  display: flex;
}

.intro-title {
  font-size: 2rem;
  font-weight: bold;
  color: var(--shell-pink-darker);
  margin-bottom: 0.5rem;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.1);
}

.intro-subtitle {
  font-size: 0.9rem;
  color: #888;
  margin-bottom: 2rem;
}

.intro-egg-container {
  width: 100px;
  height: 130px;
  margin-bottom: 2rem;
  position: relative;
}

.intro-egg {
  width: 80px;
  height: 100px;
  background: #f5e6d0;
  border: 3px solid #4a3728;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  margin: 0 auto;
  position: relative;
  animation: egg-bounce 0.8s ease-in-out infinite alternate;
}

.intro-egg::before,
.intro-egg::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: #e8b4d8;
  border-radius: 50%;
}

.intro-egg::before {
  top: 30px;
  left: 15px;
}

.intro-egg::after {
  top: 45px;
  right: 12px;
}

.intro-prompt {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-dark);
}

#pet-name-input {
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  padding: 0.6rem 1rem;
  border: 3px solid var(--shell-pink-dark);
  border-radius: 12px;
  background: #fff;
  color: var(--text-dark);
  text-align: center;
  width: 220px;
  outline: none;
  transition: border-color 0.2s;
}

#pet-name-input:focus {
  border-color: var(--shell-purple);
}

.intro-start-btn {
  margin-top: 1.5rem;
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: bold;
  padding: 0.7rem 2rem;
  border: none;
  border-radius: 30px;
  background: linear-gradient(135deg, var(--shell-pink), var(--shell-purple));
  color: white;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 15px rgba(200, 100, 200, 0.3);
}

.intro-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(200, 100, 200, 0.4);
}

.intro-start-btn:active {
  transform: translateY(0);
}

.intro-start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============ GAME CONTAINER ============ */
#game-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  width: 100%;
  max-width: 420px;
}

#game-screen.active {
  display: flex;
}

/* ============ TAMAGOTCHI DEVICE SHELL ============ */
.device {
  background: linear-gradient(145deg, var(--shell-pink), var(--shell-pink-dark));
  border-radius: 50% 50% 45% 45% / 55% 55% 45% 45%;
  padding: 24px 20px 30px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.15),
    inset 0 2px 4px rgba(255,255,255,0.4),
    inset 0 -2px 4px rgba(0,0,0,0.1);
  position: relative;
  width: 100%;
  max-width: 340px;
}

.device::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  background: var(--shell-teal);
  border-radius: 50%;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}

/* ============ SCREEN ============ */
.screen-frame {
  background: var(--screen-border);
  border-radius: 16px;
  padding: 6px;
  margin-top: 16px;
}

.screen {
  background: var(--screen-bg);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1 / 1;
}

body.night-mode .screen {
  background: var(--screen-bg-night);
}

#pet-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Status bar overlay on screen */
.screen-status {
  position: absolute;
  top: 6px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 0.6rem;
  color: #3d4a2f;
  pointer-events: none;
}

body.night-mode .screen-status {
  color: #c5d8a4;
}

.pet-name-display {
  font-weight: bold;
  font-size: 0.7rem;
}

.pet-age-display {
  font-size: 0.65rem;
}

/* Night mode indicator */
.night-indicator {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.7rem;
  pointer-events: none;
}

/* Evolution notification */
.evolution-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: flash-in 0.3s ease;
}

.evolution-overlay.active {
  display: flex;
}

.evolution-text {
  font-size: 1rem;
  font-weight: bold;
  color: var(--shell-pink-darker);
  text-align: center;
  margin-bottom: 8px;
}

.evolution-stage {
  font-size: 0.8rem;
  color: #666;
}

@keyframes flash-in {
  0% { opacity: 0; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* Death overlay */
.death-overlay {
  position: absolute;
  inset: 0;
  background: rgba(50, 50, 50, 0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.death-overlay.active {
  display: flex;
}

.death-text {
  font-size: 0.9rem;
  color: #ddd;
  text-align: center;
  margin-bottom: 10px;
  line-height: 1.4;
}

.death-restart-btn {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  padding: 0.4rem 1.2rem;
  border: 2px solid #aaa;
  border-radius: 20px;
  background: transparent;
  color: #ddd;
  cursor: pointer;
  transition: all 0.2s;
}

.death-restart-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: #fff;
  color: #fff;
}

/* ============ DEVICE BUTTONS ============ */
.device-buttons {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  padding: 0 12px;
}

.device-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--shell-pink-darker);
  background: linear-gradient(145deg, #f5a0c0, #e080a0);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-dark);
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
  -webkit-tap-highlight-color: transparent;
}

.device-btn:active {
  transform: scale(0.92);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.device-btn.center-btn {
  width: 52px;
  height: 52px;
  font-size: 1.3rem;
}

/* ============ STAT BARS ============ */
.stats-panel {
  width: 100%;
  max-width: 340px;
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.6);
  border-radius: 10px;
  padding: 6px 10px;
}

body.night-mode .stat-item {
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
}

.stat-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.stat-bar-container {
  flex: 1;
  height: 10px;
  background: rgba(0,0,0,0.1);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.stat-bar {
  height: 100%;
  border-radius: 5px;
  transition: width 0.5s ease;
}

.stat-bar.hunger { background: var(--stat-hunger); }
.stat-bar.happiness { background: var(--stat-happy); }
.stat-bar.energy { background: var(--stat-energy); }
.stat-bar.health { background: var(--stat-health); }

.stat-bar.low {
  animation: bar-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes bar-pulse {
  from { opacity: 1; }
  to { opacity: 0.5; }
}

.stat-value {
  font-size: 0.6rem;
  min-width: 22px;
  text-align: right;
  font-weight: bold;
}

/* ============ ACTION BUTTONS ============ */
.actions-panel {
  width: 100%;
  max-width: 340px;
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.action-btn {
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  font-weight: bold;
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--shell-pink), var(--shell-pink-dark));
  color: white;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
  transform: scale(0.95);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.action-btn.play-btn {
  background: linear-gradient(135deg, var(--stat-happy), #f0b840);
}

.action-btn.sleep-btn {
  background: linear-gradient(135deg, var(--stat-energy), #40c8e0);
}

.action-btn.clean-btn {
  background: linear-gradient(135deg, #b8e6b8, #7bc47f);
}

.action-btn.medicine-btn {
  background: linear-gradient(135deg, var(--stat-health), #4caf50);
}

/* ============ MINI-GAME OVERLAY ============ */
.minigame-overlay {
  position: absolute;
  inset: 0;
  background: var(--screen-bg);
  z-index: 20;
  display: none;
}

body.night-mode .minigame-overlay {
  background: var(--screen-bg-night);
}

.minigame-overlay.active {
  display: block;
}

#minigame-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.minigame-score {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.7rem;
  font-weight: bold;
  color: #3d4a2f;
  pointer-events: none;
}

body.night-mode .minigame-score {
  color: #c5d8a4;
}

.minigame-exit {
  position: absolute;
  top: 6px;
  left: 8px;
  font-family: 'Courier New', monospace;
  font-size: 0.6rem;
  padding: 2px 8px;
  border: 1px solid #3d4a2f;
  border-radius: 8px;
  background: transparent;
  color: #3d4a2f;
  cursor: pointer;
}

body.night-mode .minigame-exit {
  border-color: #c5d8a4;
  color: #c5d8a4;
}

/* ============ TOOLBAR ============ */
.toolbar {
  width: 100%;
  max-width: 340px;
  margin-top: 14px;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.toolbar-btn {
  font-family: 'Courier New', monospace;
  font-size: 0.65rem;
  padding: 5px 12px;
  border: 2px solid rgba(0,0,0,0.1);
  border-radius: 14px;
  background: rgba(255,255,255,0.5);
  color: var(--text-dark);
  cursor: pointer;
  transition: all 0.15s;
}

body.night-mode .toolbar-btn {
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  border-color: rgba(255,255,255,0.15);
}

.toolbar-btn:hover {
  background: rgba(255,255,255,0.8);
}

.toolbar-btn.active {
  background: var(--shell-pink);
  color: white;
  border-color: var(--shell-pink-dark);
}

/* ============ SAVE/LOAD MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}

body.night-mode .modal {
  background: #2d2b3d;
  color: var(--text-light);
}

.modal-title {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 1rem;
  text-align: center;
}

.modal textarea {
  width: 100%;
  height: 100px;
  font-family: 'Courier New', monospace;
  font-size: 0.65rem;
  padding: 8px;
  border: 2px solid #ddd;
  border-radius: 8px;
  resize: vertical;
  margin-bottom: 0.8rem;
}

body.night-mode .modal textarea {
  background: #1a1a2e;
  border-color: #444;
  color: var(--text-light);
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-btn {
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  padding: 6px 16px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.1s;
}

.modal-btn:active {
  transform: scale(0.95);
}

.modal-btn.primary {
  background: linear-gradient(135deg, var(--shell-pink), var(--shell-purple));
  color: white;
}

.modal-btn.secondary {
  background: #eee;
  color: var(--text-dark);
}

body.night-mode .modal-btn.secondary {
  background: #444;
  color: var(--text-light);
}

.modal-btn.danger {
  background: #e74c3c;
  color: white;
}

.modal-status {
  text-align: center;
  font-size: 0.7rem;
  margin-top: 0.5rem;
  min-height: 1em;
}

/* ============ TOAST NOTIFICATIONS ============ */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(45, 43, 61, 0.9);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  white-space: nowrap;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.2s forwards;
  pointer-events: auto;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-10px); }
}

/* ============ CONFETTI / PARTICLES ============ */
.particle-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translateY(-20px) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(100vh) rotate(720deg);
  }
}

.sparkle-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #ffd700;
  border-radius: 50%;
  animation: sparkle-pop 0.6s ease-out forwards;
}

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

/* ============ RESPONSIVE ============ */
@media (max-width: 420px) {
  body {
    justify-content: flex-start;
    padding-top: 0.5rem;
  }

  .device {
    max-width: 300px;
    padding: 20px 16px 26px;
  }

  .stats-panel {
    max-width: 300px;
  }

  .actions-panel {
    max-width: 300px;
  }

  .toolbar {
    max-width: 300px;
  }

  .action-btn {
    font-size: 0.7rem;
    padding: 6px 10px;
  }
}

@media (max-width: 360px) {
  .device {
    max-width: 280px;
    padding: 18px 14px 22px;
  }

  .device-btn {
    width: 38px;
    height: 38px;
    font-size: 0.95rem;
  }

  .device-btn.center-btn {
    width: 46px;
    height: 46px;
  }
}

/* ============ ACCESSIBILITY ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ SOUND TOGGLE ============ */
.sound-indicator {
  font-size: 0.7rem;
  opacity: 0.7;
}
