/* =================================================================
   Save Pet — style.css
   Design language: candy-bright glassmorphism, rounded everything,
   soft shadows. Built mobile-first; scales up for tablet/desktop.
   ================================================================= */

:root {
  --honey: #FFB627;
  --honey-dark: #E0980A;
  --meadow: #3AC7C0;
  --meadow-dark: #2A9C96;
  --blossom: #FF6B9D;
  --blossom-dark: #E14F82;
  --ink: #22283A;
  --cream: #FFF8ED;
  --leaf: #3AAE60;
  --danger: #FF5D5D;

  --bg-grad-1: #8FE3E0;
  --bg-grad-2: #FFD9A0;
  --bg-grad-3: #FFB0C9;

  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-blur: 18px;

  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 26px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 8px rgba(34, 40, 58, 0.12);
  --shadow-md: 0 8px 24px rgba(34, 40, 58, 0.18);
  --shadow-lg: 0 16px 40px rgba(34, 40, 58, 0.24);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2) 55%, var(--bg-grad-3));
  background-attachment: fixed;
}
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
.hidden { display: none !important; }

/* ---------------- splash screen ---------------- */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  background: linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2) 55%, var(--bg-grad-3));
  transition: opacity 0.5s ease;
}
.splash--done { opacity: 0; pointer-events: none; }
.splash-logo { font-size: 2.2rem; font-weight: 800; color: var(--ink); text-shadow: 0 2px 0 rgba(255,255,255,0.5); }
.splash-logo span { color: var(--blossom); }
.splash-bar { width: 180px; height: 8px; border-radius: var(--radius-pill); background: rgba(255,255,255,0.5); overflow: hidden; }
.splash-bar-fill { width: 40%; height: 100%; background: var(--honey); border-radius: var(--radius-pill); animation: splashLoad 1.1s ease-in-out infinite; }
@keyframes splashLoad { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
.splash-tip { font-size: 0.9rem; opacity: 0.75; font-weight: 600; }

/* ---------------- app shell ---------------- */
.app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
.screen { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#screen-menu, #screen-game { overflow: hidden; }

/* ---------------- ad slots ---------------- */
.ad-slot {
  flex: 0 0 auto;
  min-height: 50px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.25);
  position: relative;
}
.ad-slot--placeholder::before {
  content: "";
}
.ad-label {
  font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(34,40,58,0.35); font-weight: 700;
}
.ad-slot ins.adsbygoogle { width: 100%; }

/* ---------------- buttons ---------------- */
.btn {
  border: none; border-radius: var(--radius-pill);
  padding: 14px 22px; font-size: 1rem; font-weight: 700;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  width: 100%;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, var(--honey), var(--honey-dark)); color: var(--ink); }
.btn-secondary { background: rgba(255,255,255,0.75); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink); opacity: 0.7; box-shadow: none; }
.btn-lg { padding: 18px 24px; font-size: 1.15rem; }
.btn-icon {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.65); box-shadow: var(--shadow-sm);
  font-size: 1.3rem; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.btn-icon:active { transform: scale(0.92); }
.btn-icon-sm { width: 30px; height: 30px; border-radius: 50%; border: none; background: rgba(0,0,0,0.08); font-size: 0.8rem; }
.badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--blossom); color: #fff; font-size: 0.6rem; font-weight: 800;
  border-radius: var(--radius-pill); padding: 2px 6px; box-shadow: var(--shadow-sm);
}

/* ---------------- glass surfaces ---------------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

/* ---------------- menu screen ---------------- */
#screen-menu { display: flex; align-items: center; justify-content: center; padding: 20px; position: relative; }
.menu-card { padding: 32px 26px; width: 100%; max-width: 380px; text-align: center; display: flex; flex-direction: column; gap: 18px; }
.game-title { font-size: 2.4rem; font-weight: 800; }
.game-title span { color: var(--blossom); }
.game-tagline { font-weight: 600; opacity: 0.65; margin-top: -10px; }
.menu-stats { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.7); border-radius: var(--radius-pill);
  padding: 8px 16px; font-weight: 800; font-size: 0.95rem; box-shadow: var(--shadow-sm);
  border: none;
}
.stat-pill--action { background: linear-gradient(135deg, var(--blossom), var(--blossom-dark)); color: #fff; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; }
.menu-row { display: flex; gap: 10px; }
.menu-row .btn-secondary { font-size: 0.9rem; padding: 12px 10px; }
.menu-row--icons { justify-content: center; gap: 16px; }

.install-banner {
  position: absolute; left: 16px; right: 16px; bottom: calc(16px + var(--safe-bottom));
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--ink); color: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  font-size: 0.85rem; font-weight: 600;
}
.install-banner span { flex: 1; }
.install-banner #btn-install { width: auto; padding: 8px 16px; background: var(--honey); color: var(--ink); box-shadow: none; }

.update-banner {
  position: fixed; left: 16px; right: 16px; top: calc(16px + var(--safe-top)); z-index: 500;
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--ink); color: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  font-size: 0.85rem; font-weight: 600;
}
.update-banner span { flex: 1; }
.update-banner button { width: auto; padding: 8px 16px; background: var(--meadow); color: var(--ink); box-shadow: none; }

/* ---------------- screen header (level select / settings / achievements / howto) ---------------- */
.screen-header {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  position: sticky; top: 0; z-index: 5;
  background: rgba(255,255,255,0.35);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.screen-header h2 { flex: 1; font-size: 1.15rem; font-weight: 800; }

/* ---------------- level select ---------------- */
.world-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; scrollbar-width: none; }
.world-tabs::-webkit-scrollbar { display: none; }
.world-tab {
  flex: 0 0 auto; border: none; border-radius: var(--radius-pill);
  padding: 8px 14px; font-size: 0.8rem; font-weight: 700;
  background: rgba(255,255,255,0.6); color: var(--ink); white-space: nowrap;
}
#level-grid { padding: 4px 16px 24px; }
.world-section { margin-bottom: 22px; }
.world-heading { font-weight: 800; font-size: 1rem; margin: 10px 4px; opacity: 0.8; }
.world-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.level-btn {
  aspect-ratio: 1; border: none; border-radius: var(--radius-md);
  background: rgba(255,255,255,0.75); box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.level-btn:active { transform: scale(0.94); }
.level-btn .level-num { font-weight: 800; font-size: 1.05rem; }
.level-btn .level-stars { font-size: 0.65rem; color: var(--honey-dark); letter-spacing: 1px; }
.level-btn.completed { background: linear-gradient(135deg, rgba(58,199,192,0.35), rgba(58,199,192,0.15)); }
.level-btn.locked { background: rgba(34,40,58,0.08); opacity: 0.55; }
.level-btn .lock-icon { font-size: 1.2rem; }

/* ---------------- game screen ---------------- */
#screen-game { display: flex; flex-direction: column; }
.hud-top {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  padding-top: calc(12px + var(--safe-top));
  position: relative; z-index: 3;
}
.hud-center { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.hud-level-label { font-weight: 800; font-size: 0.85rem; opacity: 0.75; }
.hud-timer-row { display: flex; align-items: center; gap: 10px; }
.ink-bar { flex: 1; height: 10px; border-radius: var(--radius-pill); background: rgba(255,255,255,0.5); overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.15); }
.ink-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--meadow), var(--meadow-dark)); border-radius: var(--radius-pill); transition: width 0.15s linear; }
.ink-fill.ink-low { background: linear-gradient(90deg, var(--danger), #c73c3c); animation: pulseLow 0.6s infinite; }
@keyframes pulseLow { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.hud-timer { font-weight: 800; font-size: 1rem; min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.hud-hearts { font-size: 1.1rem; letter-spacing: 2px; }

.canvas-wrap { flex: 1 1 auto; position: relative; min-height: 0; }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.hud-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; padding-bottom: calc(12px + var(--safe-bottom));
}
.hud-coins { pointer-events: none; }

#screen-game.flash-hit .canvas-wrap::after {
  content: ""; position: absolute; inset: 0; background: rgba(255, 60, 60, 0.28); pointer-events: none;
  animation: flashHit 0.2s ease-out;
}
@keyframes flashHit { from { opacity: 1; } to { opacity: 0; } }

/* ---------------- modals ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 20, 35, 0.45);
  padding: 20px;
}
.modal {
  width: 100%; max-width: 340px; padding: 28px 24px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.modal h2 { font-size: 1.4rem; font-weight: 800; }
.modal-settings-quick { display: flex; justify-content: center; gap: 18px; font-size: 0.85rem; font-weight: 600; }
.modal-settings-quick label { display: flex; align-items: center; gap: 6px; }

.result-icon { font-size: 3rem; }
.result-stars { font-size: 2rem; letter-spacing: 6px; color: rgba(255,255,255,0.5); }
.result-stars .star.filled { color: var(--honey); text-shadow: 0 2px 6px rgba(224,152,10,0.5); }
.result-sub { font-weight: 600; opacity: 0.8; }
.result-badge {
  display: inline-block; align-self: center; background: rgba(255,182,39,0.25); color: var(--honey-dark);
  padding: 6px 14px; border-radius: var(--radius-pill); font-weight: 800; font-size: 0.8rem;
}
.result-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

#modal-rewarded-body, #modal-interstitial .modal { font-weight: 700; }

/* ---------------- settings screen ---------------- */
.settings-list { padding: 12px 16px 40px; display: flex; flex-direction: column; gap: 6px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(255,255,255,0.55); border-radius: var(--radius-md); padding: 14px 16px;
}
.settings-row label { font-weight: 700; font-size: 0.95rem; }
.settings-row input[type="range"] { width: 130px; }
.switch { position: relative; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; z-index: 1; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: rgba(34,40,58,0.2); border-radius: var(--radius-pill); transition: background 0.2s; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.2s; }
.switch input:checked ~ .track { background: var(--meadow); }
.switch input:checked ~ .thumb { transform: translateX(20px); }
.settings-danger { color: var(--danger); }

/* ---------------- achievements ---------------- */
.achievements-list { padding: 12px 16px 40px; display: flex; flex-direction: column; gap: 10px; }
.achievement-item {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius-md);
  background: rgba(255,255,255,0.4); opacity: 0.55;
}
.achievement-item.unlocked { opacity: 1; background: rgba(255,255,255,0.75); }
.ach-icon { font-size: 1.6rem; }
.ach-text { flex: 1; }
.ach-name { font-weight: 800; font-size: 0.95rem; }
.ach-desc { font-size: 0.78rem; opacity: 0.7; }
.ach-check { color: var(--leaf); font-weight: 800; font-size: 1.2rem; }

/* ---------------- how to play ---------------- */
.howto-content { padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 16px; max-width: 480px; margin: 0 auto; }
.howto-step { display: flex; gap: 14px; align-items: flex-start; background: rgba(255,255,255,0.55); border-radius: var(--radius-md); padding: 14px; }
.howto-step .num {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; background: var(--honey);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.howto-step p { font-size: 0.9rem; font-weight: 600; line-height: 1.4; }

/* ---------------- toasts ---------------- */
.toast-container {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center; width: 90%; max-width: 360px;
}
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius-pill);
  font-weight: 700; font-size: 0.85rem; box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(10px); transition: opacity 0.25s ease, transform 0.25s ease;
  display: flex; align-items: center; gap: 10px; text-align: left;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--achievement { background: linear-gradient(135deg, var(--honey), var(--honey-dark)); color: var(--ink); border-radius: var(--radius-md); }
.toast-icon { font-size: 1.4rem; }
.toast-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.8; }
.toast-sub { font-size: 0.95rem; }

/* ---------------- responsive ---------------- */
@media (min-width: 700px) {
  .menu-card { max-width: 420px; }
  .world-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (orientation: landscape) and (max-height: 500px) {
  .menu-card { padding: 18px 24px; gap: 10px; }
  .game-title { font-size: 1.6rem; }
  .hud-top { padding-top: calc(8px + var(--safe-top)); }
  .splash-logo { font-size: 1.6rem; }
}

@media (min-width: 900px) {
  .app { max-width: 560px; margin: 0 auto; box-shadow: var(--shadow-lg); }
}

/* ---------------- reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
