:root {
  --bg: #0b1210;
  --bg-2: #101a17;
  --glass: rgba(16, 26, 23, 0.72);
  --glass-strong: rgba(14, 22, 20, 0.9);
  --line: rgba(160, 220, 180, 0.14);
  --line-strong: rgba(160, 220, 180, 0.28);
  --text: #e9f1ec;
  --muted: #9db3a7;
  --ivy: #66c27a;
  --ivy-bright: #8ee69c;
  --ivy-deep: #2f6f43;
  --amber: #f6b04a;
  --steel: #8a98a3;
  --danger: #ef6b5b;
  --radius: 18px;
  --font-ui: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

.hidden { display: none !important; }

/* ---------- Icons ---------- */
.ico { width: 18px; height: 18px; flex: none; color: currentColor; }
.ico.big { width: 30px; height: 30px; color: var(--ivy-bright); }
.ico.glow { color: var(--ivy-bright); filter: drop-shadow(0 0 6px rgba(142, 230, 156, 0.7)); }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 10;
}
.hud-left, .hud-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; pointer-events: auto; }
.hud-right { justify-content: flex-end; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}
.level-chip { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; line-height: 1.1; }
.level-chip span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ivy-bright); font-weight: 600; }
.level-chip small { font-size: 14px; color: var(--text); font-weight: 500; }

.inventory { display: flex; gap: 8px; }
.inv {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: transform .2s, border-color .2s;
}
.inv .ico { width: 20px; height: 20px; }
.inv.key .ico { color: var(--amber); }
.inv.bomb .ico { color: #c9d3da; }
.inv.compass .ico { color: #7fd4ff; }
.inv.lantern .ico { color: #f6c25a; }
.inv.empty { opacity: 0.4; }
.inv.pop { animation: pop .45s cubic-bezier(.2,1.6,.4,1); border-color: var(--ivy-bright); }
.inv .bar { position: absolute; left: 8px; right: 8px; bottom: 4px; height: 3px; border-radius: 2px; background: rgba(127, 212, 255, .25); overflow: hidden; }
.inv .bar i { display: block; height: 100%; background: #7fd4ff; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--glass);
  color: var(--text);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .1s;
}
.icon-btn:hover { background: rgba(40, 64, 54, 0.8); border-color: var(--line-strong); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.on { border-color: var(--ivy); color: var(--ivy-bright); }
.icon-btn.off { opacity: .5; }
.icon-btn.off::after { content: ""; position: absolute; width: 22px; height: 2px; background: currentColor; transform: rotate(-45deg); border-radius: 1px; }
#btn-music { position: relative; }

/* ---------- Toasts ---------- */
#toast-wrap {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px;
  border-radius: 14px;
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
  font-weight: 500;
  font-size: 15px;
  animation: toastIn .35s cubic-bezier(.2,1.2,.4,1) both;
  text-align: center;
}
.toast.good { border-color: rgba(142, 230, 156, .55); }
.toast.good .ico { color: var(--ivy-bright); }
.toast.warn { border-color: rgba(246, 176, 74, .55); }
.toast.warn .ico { color: var(--amber); }
.toast.out { animation: toastOut .35s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* ---------- Screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  overflow-y: auto;
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(102, 194, 122, 0.10), transparent 60%),
    radial-gradient(900px 600px at 90% 90%, rgba(47, 111, 67, 0.18), transparent 60%),
    rgba(6, 10, 9, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn .35s ease both;
  touch-action: auto;
}
#screen-title { background: radial-gradient(1200px 800px at 75% 30%, rgba(102, 194, 122, 0.12), transparent 60%), rgba(6, 10, 9, 0.55); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(520px, 100%);
  padding: 34px 32px 28px;
  border-radius: 26px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  box-shadow: 0 30px 80px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.04);
  text-align: center;
  animation: rise .45s cubic-bezier(.2,1,.3,1) both;
}
.panel.wide { width: min(860px, 100%); }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } to { opacity: 1; transform: none; } }

h1, h2 { font-family: var(--font-display); font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: clamp(28px, 4vw, 38px); margin-bottom: 14px; }
.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ivy-bright);
}
.muted { color: var(--muted); line-height: 1.6; margin: 0 0 18px; }

/* Title */
.title-layout {
  display: grid;
  grid-template-columns: auto minmax(0, 520px);
  gap: clamp(28px, 6vw, 80px);
  align-items: center;
  max-width: 1100px;
}
.hero-card {
  position: relative;
  width: clamp(200px, 26vw, 300px);
  aspect-ratio: 260 / 520;
  border-radius: 24px;
  overflow: hidden;
  background: #efe8d8;
  box-shadow: 0 40px 90px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.08);
  transform: rotate(-2.5deg);
  animation: float 6s ease-in-out infinite;
}
.hero-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-card::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 70%, rgba(11,18,16,.35));
  pointer-events: none;
}
.hero-tag {
  position: absolute; left: 14px; bottom: 14px; z-index: 1;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(11, 18, 16, 0.78);
  color: var(--ivy-bright);
  font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  white-space: nowrap;
}
@keyframes float { 0%,100% { transform: rotate(-2.5deg) translateY(0); } 50% { transform: rotate(-1.5deg) translateY(-10px); } }

.title-copy h1 {
  font-size: clamp(56px, 9vw, 112px);
  line-height: 0.92;
  margin-bottom: 22px;
}
.title-copy h1 em {
  font-style: italic;
  background: linear-gradient(120deg, var(--ivy-bright), #c8f5b8 50%, var(--ivy));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.lede { color: var(--muted); font-size: clamp(16px, 1.6vw, 18px); line-height: 1.65; margin: 0 0 30px; max-width: 46ch; }

/* Buttons */
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; }
.btn-row.center { justify-content: center; margin-top: 26px; }
.btn-col { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: rgba(30, 48, 41, 0.75);
  color: var(--text);
  font: 600 16px var(--font-ui);
  padding: 14px 26px;
  min-height: 48px;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .12s, background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { background: rgba(44, 70, 58, 0.9); border-color: rgba(160,220,180,.45); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .icon-btn:focus-visible, .level-card:focus-visible { outline: 2px solid var(--ivy-bright); outline-offset: 3px; }
.btn.primary {
  background: linear-gradient(180deg, #7fd892, #4ea763);
  border-color: transparent;
  color: #07130c;
  box-shadow: 0 10px 30px rgba(102, 194, 122, .35), inset 0 1px 0 rgba(255,255,255,.35);
}
.btn.primary:hover { background: linear-gradient(180deg, #92e6a4, #58b46d); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* How to play */
.how-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  text-align: left;
  margin-top: 10px;
}
.how-item {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px;
  border-radius: 16px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.how-item p { margin: 0; color: var(--muted); line-height: 1.5; font-size: 15px; }
.how-item b { color: var(--text); font-weight: 600; }
.kbd-row { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; color: var(--muted); }
kbd {
  display: inline-grid; place-items: center;
  min-width: 28px; height: 28px; padding: 0 7px;
  border-radius: 7px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.14);
  border-bottom-width: 3px;
  font: 600 13px var(--font-ui);
  color: var(--text);
}

/* Level select */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.level-card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 18px 16px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(102,194,122,.08), rgba(255,255,255,.02));
  color: var(--text);
  font-family: var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition: transform .15s, border-color .2s, background .2s;
}
.level-card:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--line-strong); }
.level-card .num { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1; color: var(--ivy-bright); }
.level-card .nm { font-weight: 600; font-size: 15px; }
.level-card .meta { font-size: 12px; color: var(--muted); }
.level-card .mini-stars { display: flex; gap: 2px; margin-top: 4px; }
.level-card .mini-stars .ico { width: 14px; height: 14px; color: rgba(255,255,255,.15); }
.level-card .mini-stars .ico.on { color: var(--amber); }
.level-card:disabled { cursor: not-allowed; opacity: .45; }
.level-card .lock { position: absolute; top: 14px; right: 14px; width: 18px; height: 18px; color: var(--muted); }

/* Intro */
.intro-items { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.intro-items .pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  font-size: 14px; font-weight: 500;
}
.intro-items .pill .ico { width: 18px; height: 18px; }
.intro-items .pill.key .ico { color: var(--amber); }
.intro-items .pill.bomb .ico { color: #c9d3da; }
.intro-items .pill.compass .ico { color: #7fd4ff; }
.intro-items .pill.lantern .ico { color: #f6c25a; }
.intro-items .pill.marker .ico { color: var(--ivy-bright); }

/* Complete */
.stars { display: flex; justify-content: center; gap: 10px; margin: 6px 0 22px; }
.stars .ico { width: 46px; height: 46px; color: rgba(255,255,255,.1); }
.stars .ico.on { color: var(--amber); filter: drop-shadow(0 0 14px rgba(246,176,74,.55)); animation: starIn .5s cubic-bezier(.2,1.6,.4,1) both; }
.stars .ico.on:nth-child(2) { animation-delay: .15s; }
.stars .ico.on:nth-child(3) { animation-delay: .3s; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: none; opacity: 1; } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats div {
  padding: 14px 8px;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.stats small { display: block; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.stats b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Touch ---------- */
#touch {
  position: fixed;
  left: 0; right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  z-index: 15;
  pointer-events: none;
}
.action-prompt {
  position: fixed;
  left: 0; top: 0;
  z-index: 16;
  display: inline-flex; align-items: center; gap: 8px;
  height: 46px;
  padding: 0 16px 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(246, 176, 74, .7);
  background: rgba(30, 20, 10, 0.86);
  color: #ffe2b0;
  font: 600 15px var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 0 0 0 rgba(246, 176, 74, .5), 0 10px 30px rgba(0,0,0,.45);
  animation: promptPulse 1.4s ease-in-out infinite;
  touch-action: none;
  will-change: transform;
}
.action-prompt .ico { width: 22px; height: 22px; color: #ffcf8a; }
.action-prompt .key-hint { min-width: 0; height: 22px; font-size: 11px; background: rgba(255,255,255,.1); color: #ffe2b0; border-color: rgba(255,226,176,.3); }
.action-prompt:active { background: rgba(246, 176, 74, .4); }
.action-prompt.no-bomb { border-color: rgba(255,255,255,.2); color: var(--muted); animation: none; cursor: default; }
.action-prompt.no-bomb .ico { color: var(--muted); }
.action-prompt.no-bomb .key-hint { display: none; }
.is-touch .action-prompt .key-hint { display: none; }
.is-touch .action-prompt { height: 52px; font-size: 16px; padding: 0 20px 0 14px; }
@keyframes promptPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(246, 176, 74, .45), 0 10px 30px rgba(0,0,0,.45); }
  50% { box-shadow: 0 0 0 10px rgba(246, 176, 74, 0), 0 10px 30px rgba(0,0,0,.45); }
}

.swipe-hint {
  position: absolute;
  left: 50%; bottom: 120px;
  transform: translateX(-50%);
  width: min(300px, 80vw);
  padding: 18px 18px 14px;
  border-radius: 20px;
  background: var(--glass-strong);
  border: 1px solid var(--line-strong);
  text-align: center;
  animation: rise .4s ease both;
}
.swipe-hint p { margin: 10px 0 0; font-size: 14px; color: var(--muted); line-height: 1.45; }
.swipe-demo { position: relative; height: 54px; border-radius: 12px; background: rgba(255,255,255,.04); overflow: hidden; }
.swipe-demo .finger {
  position: absolute; top: 50%; left: 18%;
  width: 26px; height: 26px; margin-top: -13px;
  border-radius: 50%;
  background: rgba(142, 230, 156, .85);
  box-shadow: 0 0 0 6px rgba(142, 230, 156, .18), 0 0 20px rgba(142,230,156,.6);
  animation: swipeDemo 1.6s ease-in-out infinite;
}
@keyframes swipeDemo { 0% { left: 18%; opacity: 0; } 15% { opacity: 1; } 70% { left: 72%; opacity: 1; } 100% { left: 72%; opacity: 0; } }

/* Install */
.install-btn {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 22px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(102, 194, 122, .1);
  color: var(--ivy-bright);
  font: 600 14px var(--font-ui);
  cursor: pointer;
}
.install-btn:hover { background: rgba(102, 194, 122, .2); }
.install-tip { margin: 22px 0 0; font-size: 14px; color: var(--muted); line-height: 1.5; max-width: 44ch; }
.install-tip b { color: var(--text); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .title-layout { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 22px; }
  .hero-card { width: 150px; }
  .hero-tag { left: 10px; bottom: 10px; font-size: 9px; letter-spacing: .08em; }
  .lede { margin-left: auto; margin-right: auto; }
  .title-copy .btn-row { justify-content: center; }
  .install-tip { margin-left: auto; margin-right: auto; }
  #toast-wrap { bottom: 120px; }
  .panel { padding: 26px 18px 22px; }
  .level-chip small { font-size: 13px; }
  #hud { flex-direction: column; align-items: stretch; }
  .hud-left { justify-content: space-between; }
  .hud-right { justify-content: flex-end; }
  .hud-right .inventory { margin-right: auto; }
  .chip, .inv, .icon-btn { height: 36px; }
  .icon-btn { width: 36px; }
}
@media (max-width: 420px) {
  .hud-left .chip:not(.level-chip) { padding: 0 10px; }
  .stats b { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
