/* ===== TOKENS ===== */
:root {
  --emerald: #00c27a;
  --emerald-2: #0a7a52;
  --crimson: #f0284a;
  --gold: #ffcc4d;
  --ink: #031a13;
  --text: #f4fff9;
  --muted: #a9d6c4;
  --glass: rgba(6, 40, 30, 0.55);
  --glass-border: rgba(255, 255, 255, 0.16);
  --radius: 20px;
  --grad: linear-gradient(135deg, #00c27a 0%, #0fa3a0 45%, #f0284a 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Outfit', system-ui, sans-serif;
  color: var(--text);
  background: url('bg.jpg') center/cover no-repeat;
  background-color: var(--ink);
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
}
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background-image: linear-gradient(180deg, rgba(3, 26, 19, 0.55) 0%, rgba(3, 26, 19, 0.35) 45%, rgba(20, 3, 12, 0.7) 100%);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: none;
}
.bg-overlay {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(circle at 50% 40%, transparent 30%, rgba(0, 0, 0, 0.45) 100%);
}
.num { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }

/* ===== LAYOUT ===== */
.app {
  position: relative; z-index: 1;
  max-width: 480px; margin: 0 auto;
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
.screen {
  position: absolute; inset: 0;
  width: 100%; min-height: 100%;
  display: none; flex-direction: column;
  overflow: hidden;
}
.screen.active { display: flex; animation: screenIn .35s ease; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.content { flex: 1; padding: 18px; display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ===== GLASS ===== */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ===== BUTTONS ===== */
.btn {
  font: inherit; font-weight: 700; color: var(--text);
  border: none; border-radius: 16px; padding: 16px 20px;
  cursor: pointer; transition: transform .15s, box-shadow .2s, filter .2s;
  width: 100%; font-size: 1.05rem;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--grad); box-shadow: 0 8px 24px rgba(0, 194, 122, 0.4); }
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 10px 30px rgba(240, 40, 74, 0.45); }
.btn-glass { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--glass-border); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.btn-glass:hover { background: rgba(255, 255, 255, 0.15); }
.btn-lg { font-size: 1.3rem; padding: 20px; }
.btn-back {
  font: inherit; font-size: 1.4rem; color: var(--text);
  width: 42px; height: 42px; flex-shrink: 0;
  border-radius: 12px; border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.08); cursor: pointer;
}

/* ===== WELCOME ===== */
.welcome-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.hero-logo { width: 140px; height: 140px; border-radius: 34px; box-shadow: 0 0 40px rgba(0, 194, 122, .6); animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px) rotate(-3deg); } }
.title { font-size: 2.6rem; font-weight: 800; letter-spacing: 1px; text-shadow: 0 0 20px rgba(0, 194, 122, .7); }
.title span { background: linear-gradient(90deg, var(--gold), var(--crimson)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.card-stack { width: 100%; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.glass-card { padding: 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); border-left: 3px solid var(--emerald); }
.glass-card:nth-child(2) { border-color: var(--gold); }
.glass-card:nth-child(3) { border-color: var(--crimson); }
.glass-card p { color: var(--muted); font-size: .9rem; margin-top: 2px; }

/* ===== TOPBAR ===== */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  margin: 12px 12px 0; padding: 10px 12px; border-radius: 18px;
  background: rgba(4, 30, 22, 0.78);
}
.mini-logo { width: 36px; height: 36px; border-radius: 10px; }
.topbar-title { flex: 1; font-weight: 800; font-size: 1.15rem; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: 999px; background: rgba(255, 204, 77, .15); border: 1px solid rgba(255, 204, 77, .4); font-weight: 700; max-width: 45%; }

/* ===== HOME ===== */
.stats { display: flex; padding: 16px; gap: 8px; }
.stat { flex: 1; min-width: 0; text-align: center; }
.stat small { color: var(--muted); display: block; }
.stat b { font-size: 1.5rem; display: block; }
.menu { display: flex; flex-direction: column; gap: 12px; margin-top: auto; margin-bottom: 20px; }

/* ===== LEVELS ===== */
.levels-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-bottom: 20px; }
.level-card {
  position: relative; overflow: hidden;
  aspect-ratio: 1; border-radius: 18px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--glass); border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .15s;
}
.level-card:active { transform: scale(.94); }
.level-card b { font-size: 1.6rem; }
.level-card small { color: var(--gold); font-size: .75rem; }
.level-card.done { border-color: var(--emerald); box-shadow: inset 0 0 20px rgba(0, 194, 122, .35); }
.level-card.locked { opacity: .45; cursor: default; }

/* ===== SHOP ===== */
.shop-list, .ach-list { display: flex; flex-direction: column; gap: 12px; padding-bottom: 20px; }
.shop-item, .ach-item { display: flex; align-items: center; gap: 14px; padding: 14px; flex-wrap: wrap; }
.swatch { width: 54px; height: 54px; border-radius: 16px; flex-shrink: 0; box-shadow: 0 0 18px rgba(255, 255, 255, .2); }
.info { flex: 1; min-width: 0; }
.info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info small { color: var(--muted); }
.shop-item .btn { width: auto; padding: 10px 16px; font-size: .9rem; white-space: nowrap; }
.ach-icon { font-size: 1.8rem; width: 48px; text-align: center; filter: grayscale(1); opacity: .5; }
.ach-item.got .ach-icon { filter: none; opacity: 1; }
.ach-item.got { border-color: var(--gold); }

/* ===== GAME ===== */
.game-screen { padding: 10px; gap: 10px; }
.hud { position: relative; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: rgba(4, 30, 22, 0.8); }
.hud-item { min-width: 0; text-align: center; }
.hud-item.grow { flex: 1; }
.hud-item small { display: block; color: var(--muted); font-size: .7rem; }
.hud-item b { display: block; font-size: 1.15rem; }
.progress { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .12); overflow: hidden; margin-top: 3px; }
.progress div { height: 100%; width: 0; background: var(--grad); transition: width .2s; }
.canvas-wrap { flex: 1; position: relative; overflow: hidden; border-radius: 22px; border: 1px solid var(--glass-border); min-height: 0; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.toast {
  position: absolute; left: 50%; top: 90px; z-index: 6;
  transform: translateX(-50%) scale(.8); opacity: 0;
  padding: 8px 18px; border-radius: 999px; font-weight: 700;
  background: rgba(4, 30, 22, .85); border: 1px solid var(--gold);
  transition: all .25s; pointer-events: none; white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) scale(1); }

/* ===== MODAL ===== */
.modal {
  position: absolute; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(2, 14, 10, .7);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.modal.hidden { display: none; }
.modal-card { width: 100%; padding: 26px; text-align: center; background: rgba(6, 40, 30, .92); animation: screenIn .3s ease; }
.modal-card h2 { font-size: 1.8rem; margin-bottom: 8px; background: linear-gradient(90deg, var(--emerald), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.modal-card p { color: var(--muted); margin-bottom: 18px; line-height: 1.5; word-wrap: break-word; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
