:root {
  --bg: #10163a;
  --panel: #101638;
  --card: #1c2858;
  --border: #f4f0e0;
  --text: #f3f0e2;
  --muted: #a8b0d8;
  --accent: #f8d848;
  --accent-dark: #b89818;
  --sea: #3aa8d8;
  --pos: #8be07a;
  --neg: #ff8a7a;
  --warn: #f8b860;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.hidden { display: none !important; }
canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; image-rendering: pixelated; touch-action: none; }

/* ---- Top bar ---- */
#hud { position: fixed; top: calc(6px + env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; align-items: center; gap: 6px; z-index: 3; flex-wrap: wrap; }
.hud-title, .hud-stat, .hud-btns { background: rgba(16,22,56,0.9); border: 2px solid var(--border); border-radius: 4px; }
.hud-title { font-weight: 800; font-size: 17px; padding: 6px 10px; }
.hud-stat { padding: 2px 10px; text-align: center; min-width: 58px; }
.hud-stat small { display: block; color: var(--muted); font-size: 10px; }
.hud-stat b { font-size: 15px; white-space: nowrap; }
#stat-money { color: var(--accent); }
.stars { color: var(--accent); letter-spacing: 1px; }
.hud-btns { margin-left: auto; display: flex; padding: 1px; }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; padding: 5px 6px; border-radius: 3px; text-decoration: none; line-height: 1; touch-action: manipulation; }
.icon-btn:hover { background: rgba(255,255,255,0.1); }

/* ---- Buttons ---- */
.btn { font: inherit; background: var(--accent); color: #2a2000; border: 2px solid #3a2a00; border-radius: 4px; padding: 7px 12px; font-weight: 800; cursor: pointer;
  box-shadow: 0 3px 0 var(--accent-dark); display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; touch-action: manipulation; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn.cant, .btn:disabled { background: #4e5470; color: #aab0c8; box-shadow: 0 3px 0 #33384c; border-color: #262a3a; cursor: not-allowed; }
.btn.big { font-size: 18px; padding: 11px 16px; justify-content: center; width: 100%; margin-top: 12px; }
.btn.wide { width: 100%; }
.btn.small { padding: 4px 9px; font-size: 12px; background: #d9d2b8; box-shadow: 0 2px 0 #a59e85; }
.btn.alt { background: #d9d2b8; box-shadow: 0 3px 0 #a59e85; }
.btn.gather-btn { background: #48b0e8; box-shadow: 0 3px 0 #2878a8; color: #08203a; }
.btn.gather-btn:disabled { background: #4e5470; color: #aab0c8; box-shadow: 0 3px 0 #33384c; border-color: #262a3a; cursor: not-allowed; }
.btn.open-btn { background: #68c858; box-shadow: 0 3px 0 #3a8a30; color: #0c2a08; }
.btn .cost { background: rgba(0,0,0,0.15); border-radius: 3px; padding: 1px 6px; font-size: 13px; white-space: nowrap; }
.link { background: none; border: none; color: var(--muted); cursor: pointer; text-decoration: underline; font: inherit; font-size: 13px; padding: 0; }
.close-x { display: block; margin: 14px auto 0; }

/* ---- Menus ---- */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 12px; }
#modal-box { background: var(--panel); border: 3px solid var(--border); border-radius: 6px; box-shadow: 0 0 0 3px #101638, 0 10px 40px rgba(0,0,0,0.5);
  padding: 18px 20px; max-width: 560px; width: 100%; max-height: 92vh; max-height: 92dvh; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; -webkit-user-select: text; user-select: text; }
#modal-box h2 { margin: 0 0 8px; color: #f8e8b0; }
#modal-box h3 { margin: 14px 0 6px; color: #f8e8b0; font-size: 16px; }
#modal-box ol { padding-left: 20px; line-height: 1.5; }
#modal-box p { margin: 6px 0; }
.card { background: var(--card); border: 1px solid rgba(244,240,224,0.25); border-radius: 4px; padding: 10px 12px; margin-bottom: 8px; }
.card small, .up-info small, .spot small, .nm small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg) !important; } .warn { color: var(--warn); }
.wallet { color: var(--accent); font-weight: 800; }
.row { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; padding: 3px 0; }
.row.total { border-top: 1px solid rgba(255,255,255,0.25); margin-top: 6px; padding-top: 6px; font-size: 17px; font-weight: 800; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid rgba(244,240,224,0.25); border-radius: 4px; padding: 2px 8px; margin: 2px; font-size: 13px; }
img.px { image-rendering: pixelated; vertical-align: middle; }
.tag { display: inline-block; background: rgba(255,255,255,0.08); border-radius: 3px; padding: 1px 6px; margin: 2px 3px 0 0; font-size: 11px; color: var(--text); white-space: nowrap; }
.lock, .maxed { font-weight: 800; font-size: 13px; color: var(--muted); white-space: nowrap; }
.maxed { color: var(--accent); }
.have { font-size: 12px; color: var(--pos); font-weight: 700; padding: 3px 4px; }

.upgrade, .spot { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.upgrade .em, .spot .em { font-size: 26px; }
.up-info { flex: 1; min-width: 0; }
.spot-head { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 0; }
.spot.locked { opacity: 0.75; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.seg { font: inherit; font-size: 13px; font-weight: 700; background: #2a3668; color: var(--text); border: 2px solid rgba(244,240,224,0.3); border-radius: 4px; padding: 5px 10px; cursor: pointer; touch-action: manipulation; }
.seg.on { background: var(--sea); color: #04182a; border-color: var(--border); }
.seg:disabled { opacity: 0.45; cursor: not-allowed; }
.segs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.opt-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.opt-row > span:first-child { width: 96px; font-weight: 700; font-size: 14px; }
.meter { flex: 1; min-width: 80px; height: 10px; background: rgba(255,255,255,0.12); }
.meter div { height: 100%; }

.nm { flex: 1; min-width: 150px; font-weight: 700; }
.legend { color: var(--accent); font-size: 11px; }

#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; pointer-events: none; width: min(92vw, 420px); }
.toast { background: var(--accent); color: #2a2000; border: 3px solid #3a2a00; border-radius: 4px; padding: 9px 14px; box-shadow: 0 6px 20px rgba(0,0,0,0.4); transition: opacity 0.5s, transform 0.5s; text-align: center; }
.toast.out { opacity: 0; transform: translateY(-10px); }

/* Phones */
@media (max-width: 700px), (max-height: 500px) {
  .hud-title { display: none; }
  .hud-stat { padding: 1px 6px; min-width: 0; }
  .hud-stat small { font-size: 9px; }
  .hud-stat b { font-size: 13px; }
  #hud { gap: 4px; left: 4px; right: 4px; top: calc(4px + env(safe-area-inset-top)); }
    .btn { padding: 6px 9px; font-size: 14px; }
  #modal-box { padding: 14px; }
}
@media (max-width: 480px) {
  .upgrade, .spot { flex-wrap: wrap; }
  .upgrade .btn, .spot .btn { width: 100%; }
  .main-btns .btn { flex: 1 1 45%; }
}



/* ---- Sky Hopper ---- */
.hud-btns { margin-left: auto; }
.hud-title { margin-right: 0; }
canvas { image-rendering: pixelated; }
:root { --panel: #1c2358; --card: #2a3478; --border: rgba(255,255,255,0.18); --muted: #b4c0f0; --accent: #ffd451; --accent-dark: #c79a1a; }
.hud-title, .hud-stat, .hud-btns { background: rgba(28,35,88,0.85); border: 1px solid var(--border); border-radius: 14px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.icon-btn { border-radius: 10px; }
#modal { background: rgba(5,8,30,0.55); }
#modal-box { border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); background: linear-gradient(180deg, #252e70, #181e4c); }
#modal-box h2, #modal-box h3 { color: #ffe69a; }
.btn { border: none; border-radius: 12px; box-shadow: 0 3px 0 var(--accent-dark), 0 6px 14px rgba(0,0,0,0.2); }
.btn:active { box-shadow: 0 1px 0 var(--accent-dark); }
.big-score { font-size: 26px; font-weight: 800; color: var(--accent); margin: 4px 0; }
.skins { display: flex; flex-wrap: wrap; gap: 6px; }
.btn.skin { flex: 1 1 28%; justify-content: center; background: #d9d2f0; box-shadow: 0 3px 0 #9a94b8; font-size: 13px; padding: 6px 8px; }
.btn.skin.on { background: var(--accent); }
.btn.skin:disabled { background: #4e5470; color: #aab0c8; box-shadow: 0 3px 0 #33384c; }
.skin .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #4a2040; display: inline-block; }
#hint { position: fixed; left: 0; right: 0; bottom: calc(14px + env(safe-area-inset-bottom)); text-align: center; color: #fff; font-weight: 800; font-size: 14px; text-shadow: 0 2px 4px rgba(0,0,0,0.6); pointer-events: none; z-index: 2; }
.toast { border: none; border-radius: 14px; }
/* level editor */
.ed-bar { position: fixed; left: 8px; right: 8px; z-index: 3; display: flex; align-items: center; gap: 6px; background: rgba(28,35,88,0.9); border: 1px solid var(--border); border-radius: 14px; padding: 5px 6px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#ed-top { top: calc(6px + env(safe-area-inset-top)); }
#ed-top .btn.small { background: var(--accent); box-shadow: 0 2px 0 var(--accent-dark); font-size: 13px; }
.ed-h { margin-left: auto; color: var(--muted); font-weight: 800; font-size: 13px; padding-right: 4px; }
#ed-tools { bottom: calc(6px + env(safe-area-inset-bottom)); flex-wrap: wrap; justify-content: center; gap: 3px; }
.ed-tool { font: inherit; background: rgba(255,255,255,0.08); color: #fff; border: 2px solid transparent; border-radius: 10px; padding: 2px 0; width: 46px; display: flex; flex-direction: column; align-items: center; cursor: pointer; touch-action: manipulation; }
.ed-tool span { font-size: 17px; line-height: 1.2; }
.ed-tool small { font-size: 9px; color: var(--muted); }
.ed-tool.on { border-color: var(--accent); background: rgba(255,212,81,0.18); }
.lvls { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; max-height: 46vh; overflow-y: auto; }
.lvl { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.07); border-radius: 12px; padding: 6px 8px; }
.lvl-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lvl-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl-info small { color: var(--muted); font-size: 11px; }
.lvl-btns { display: flex; gap: 4px; }
.lvl-btns .btn.small { font-size: 15px; padding: 4px 7px; }
textarea.code { width: 100%; box-sizing: border-box; font: 12px monospace; border-radius: 10px; border: 1px solid var(--border); background: #10163a; color: #fff; padding: 8px; resize: vertical; word-break: break-all; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: 13px; color: var(--muted); }
.field input { font: inherit; font-size: 16px; border-radius: 10px; border: 1px solid var(--border); background: #10163a; color: #fff; padding: 8px; }
#modal-box .btn.wide { justify-content: center; margin-top: 8px; }
