: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%; }
}



/* ---- Planet Putt ---- */
canvas { image-rendering: pixelated; }
:root { --bg: #05040f; --panel: #1a1640; --card: #28225e; --border: rgba(255,255,255,0.18); --muted: #b8b4f0; --accent: #ffd451; --accent-dark: #c79a1a; }
.hud-title, .hud-stat, .hud-btns { background: rgba(26,22,64,0.85); border: 1px solid var(--border); border-radius: 14px; }
.icon-btn { border-radius: 10px; }
#modal { background: rgba(5,4,20,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, #2a2470, #17134a); }
#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); }
.btn.alt { box-shadow: 0 3px 0 #a59e85; }
.btn.wide { justify-content: center; margin-top: 6px; }
.big-score { font-size: 26px; font-weight: 800; color: var(--accent); margin: 4px 0; }
.toast { border: none; border-radius: 14px; }
.card.mode { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card.mode > div { min-width: 0; }
.card.mode .btn { flex: none; }
.trail { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; margin: 6px 0 8px; }
.lvl { font: inherit; font-weight: 800; background: rgba(255,255,255,0.08); color: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 4px 0 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; touch-action: manipulation; }
.lvl small { font-size: 8px; min-height: 10px; letter-spacing: 0; }
.lvl.done { background: rgba(255,212,81,0.16); border-color: rgba(255,212,81,0.5); }
.lvl:disabled { opacity: 0.4; cursor: not-allowed; }
.how { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.how > div { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.06); border-radius: 12px; padding: 5px 8px; font-size: 14px; }
.how img.px { width: 36px; height: 36px; flex: none; }
.how span img.px { width: 18px; height: 18px; vertical-align: -4px; }
.sc-wrap { overflow-x: auto; margin: 8px 0; }
.scorecard { border-collapse: collapse; width: 100%; font-size: 14px; text-align: center; }
.scorecard th { text-align: left; color: var(--muted); font-weight: 700; padding: 2px 6px 2px 0; font-size: 12px; white-space: nowrap; }
.scorecard td { padding: 3px 2px; border-bottom: 1px solid rgba(255,255,255,0.08); font-weight: 800; }
.scorecard td.hn { color: var(--muted); font-weight: 700; font-size: 11px; border-bottom: none; padding-top: 8px; }
#banner { position: fixed; left: 50%; top: 22%; transform: translateX(-50%); z-index: 4; pointer-events: none; text-align: center;
  background: rgba(26,22,64,0.88); border: 1px solid var(--border); border-radius: 16px; padding: 10px 20px; transition: opacity 0.5s; white-space: nowrap; }
#banner b { display: block; font-size: 20px; color: #ffe69a; }
#banner small { color: var(--muted); font-size: 14px; font-weight: 700; }
#banner.out { opacity: 0; }
@media (max-width: 480px) { #hud .hud-stat { flex: 1; } #banner b { font-size: 17px; } }
