:root {
  --edge: 28px;
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  --green: #7dff9a; --green2: #2fd35d; --ink: #0f1020; --panel: rgba(18, 20, 40, 0.92);
  --font: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Heiti TC", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #1b1d3a; color: #fff; font-family: var(--font);
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
}
canvas#c {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none;
}
button { font-family: inherit; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; user-select: none; }
.hidden { display: none !important; }
.edge-guard { position: fixed; top: 0; bottom: 0; width: calc(var(--edge) + var(--sl)); z-index: 60; touch-action: none; }
.edge-guard.left { left: 0; } .edge-guard.right { right: 0; width: calc(var(--edge) + var(--sr)); }
body:not(.touch) .edge-guard { pointer-events: none; }

/* ---------- 畫面 ---------- */
.screen { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px calc(var(--edge) + 12px); }
.screen.dim { background: rgba(8, 8, 24, 0.62); }
#menu { background: linear-gradient(180deg, rgba(20, 18, 50, 0.15), rgba(20, 18, 50, 0.55)); }
.menu-wrap { text-align: center; max-width: 560px; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 10px; }
.logo .l1 {
  font-size: clamp(44px, 11vw, 92px); font-weight: 900; letter-spacing: 0.06em; color: var(--green);
  text-shadow: 4px 4px 0 #134d26, 8px 8px 0 #0c0d1e, 0 0 26px rgba(120, 255, 150, 0.55);
  transform: rotate(-2deg);
}
.logo .l2 { font: 800 clamp(12px, 2.6vw, 18px) monospace; letter-spacing: 0.42em; color: #ffd27a; text-shadow: 2px 2px 0 #4a1d10; }
.tag { margin: 6px auto 18px; max-width: 460px; line-height: 1.6; color: #e6e2ff; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6); font-size: clamp(13px, 2.4vw, 16px); }
.menu-btns { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.best { margin-top: 14px; color: #c9c4ef; font-size: 14px; }
.best b { color: #ffd27a; font-size: 18px; }
button.big, button.ghost {
  min-width: 220px; padding: 12px 26px; font-size: 20px; font-weight: 900; letter-spacing: 0.1em; border: 0; color: #08240f;
  background: var(--green); box-shadow: 0 5px 0 #198a3a, 0 8px 18px rgba(0, 0, 0, 0.4); border-radius: 6px;
}
button.big:active, button.ghost:active { transform: translateY(3px); box-shadow: 0 2px 0 #198a3a; }
button.ghost { background: rgba(255, 255, 255, 0.12); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); font-size: 17px; padding: 10px 22px; outline: 2px solid rgba(255, 255, 255, 0.25); }
a.more {
  position: fixed; right: calc(var(--edge) + var(--sr) + 14px); bottom: calc(var(--sb) + 14px);
  color: #ffd27a; text-decoration: none; font-weight: 800; font-size: 15px; padding: 8px 14px; border-radius: 20px;
  background: rgba(10, 10, 30, 0.55); border: 1px solid rgba(255, 210, 122, 0.45);
}
a.more.inline { position: static; display: inline-block; margin-top: 14px; }
.panel {
  background: var(--panel); border: 2px solid rgba(125, 255, 154, 0.35); border-radius: 10px; padding: 18px 22px 20px;
  text-align: center; max-width: 520px; width: 100%; max-height: calc(100% - 8px); overflow: auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.panel h2 { margin: 0 0 4px; color: var(--green); font-size: 26px; letter-spacing: 0.15em; text-shadow: 3px 3px 0 #134d26; }
.panel .note { color: #cfcaf0; font-size: 14px; line-height: 1.6; margin: 4px 0; }
.how p { margin: 6px 0; font-size: 15px; }
kbd { display: inline-block; padding: 1px 7px; border-radius: 4px; background: #2d3058; border-bottom: 3px solid #14162e; font: 700 13px monospace; color: #ffd27a; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; max-width: 400px; }
.row > span { font-weight: 700; }
.seg { display: flex; gap: 4px; }
.seg button { padding: 7px 12px; border-radius: 5px; border: 0; background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 700; font-size: 14px; }
.seg button.on { background: var(--green); color: #08240f; }
.res { width: 100%; max-width: 320px; }
.res p { display: flex; justify-content: space-between; margin: 5px 0; font-size: 16px; }
.res b { color: #ffd27a; }
.res .total { border-top: 1px dashed rgba(255, 255, 255, 0.3); padding-top: 8px; font-size: 22px; }
.res .total b { color: var(--green); }
.newbest { justify-content: center !important; color: #ff7ab6; font-weight: 900; animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
#loading { background: #1b1d3a; z-index: 80; }
.spin { width: 48px; height: 48px; border: 6px solid rgba(125, 255, 154, 0.25); border-top-color: var(--green); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud button, #hud .zone { pointer-events: auto; }
#stats { position: absolute; left: calc(var(--edge) + var(--sl) + 8px); top: calc(var(--st) + 8px); display: flex; gap: 14px; }
.stat { display: flex; flex-direction: column; text-shadow: 2px 2px 0 #000; }
.stat span { font-size: 11px; color: #c9c4ef; }
.stat b { font: 900 20px monospace; color: #fff; }
#hScore { color: var(--green); }
#top { position: absolute; left: 50%; top: calc(var(--st) + 6px); transform: translateX(-50%); text-align: center; }
#hTime { font: 900 28px monospace; text-shadow: 3px 3px 0 #000; }
#hTime.low { color: #ff6060; animation: pulse 0.5s infinite alternate; }
#hWanted { font-size: 15px; letter-spacing: 2px; color: #ffd24a; text-shadow: 2px 2px 0 #000; min-height: 18px; }
#hWanted i { font-style: normal; color: rgba(255, 255, 255, 0.25); }
#btnPause {
  position: absolute; right: calc(var(--edge) + var(--sr) + 8px); top: calc(var(--st) + 8px); width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5); background: rgba(10, 10, 30, 0.5); display: flex; align-items: center; justify-content: center; gap: 6px;
}
#btnPause i { width: 6px; height: 18px; background: #fff; border-radius: 2px; }
#bars { position: absolute; left: calc(var(--edge) + var(--sl) + 8px); top: calc(var(--st) + 56px); display: flex; flex-direction: column; gap: 5px; }
.bar { display: flex; align-items: center; gap: 6px; font-size: 11px; text-shadow: 1px 1px 0 #000; }
.bar span { width: 56px; color: #ddd; }
.bar div { width: 130px; height: 9px; background: rgba(0, 0, 0, 0.5); border: 1px solid rgba(255, 255, 255, 0.3); }
.bar i { display: block; height: 100%; width: 100%; transform-origin: left; }
.shield i { background: #4fc3ff; } .heat i { background: #ff9a3c; } .energy i { background: var(--green); }
.heat.over i { background: #ff3030; animation: pulse 0.25s infinite alternate; }
.energy.full i { background: #fff; box-shadow: 0 0 10px var(--green); }
#toast {
  position: absolute; left: 50%; top: 24%; transform: translate(-50%, 0); font-size: clamp(22px, 5vw, 38px); font-weight: 900; color: #ffd27a;
  text-shadow: 3px 3px 0 #5a1a08, 0 0 18px rgba(255, 180, 80, 0.6); white-space: nowrap; opacity: 0; transition: opacity 0.2s;
}
#toast.show { opacity: 1; animation: pop 0.3s; }
@keyframes pop { from { transform: translate(-50%, 0) scale(1.5); } }
#fps { position: absolute; right: calc(var(--edge) + var(--sr) + 64px); top: calc(var(--st) + 18px); font: 12px monospace; color: #9f9; text-shadow: 1px 1px 0 #000; }

/* ---------- 手機操作 ---------- */
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .pc-only { display: none; }
.zone { position: absolute; bottom: calc(var(--sb) + 18px); width: 170px; height: 170px; border-radius: 50%; touch-action: none; }
#stickZone { left: calc(var(--edge) + var(--sl) + 14px); }
#aimZone { right: calc(var(--edge) + var(--sr) + 14px); }
.zone .base { position: absolute; left: 50%; top: 50%; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; border: 3px dashed rgba(125, 255, 154, 0.55); background: rgba(10, 30, 20, 0.28); }
.zone .knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(125, 255, 154, 0.75); box-shadow: 0 0 14px rgba(125, 255, 154, 0.6); }
#aimZone .base { border-color: rgba(255, 140, 140, 0.6); background: rgba(40, 10, 10, 0.25); }
#aimZone .knob { background: rgba(255, 120, 120, 0.8); box-shadow: 0 0 14px rgba(255, 90, 90, 0.6); }
.zone.active .base { border-style: solid; }
.zone .hint { position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); text-align: center; white-space: nowrap; text-shadow: 2px 2px 0 #000; transition: opacity 0.4s; }
.zone .hint b { display: block; font-size: 15px; color: #fff; }
.zone .hint small { font-size: 11px; color: #cfd; }
.zone.used .hint { opacity: 0; }
#tbtns { position: absolute; right: calc(var(--edge) + var(--sr) + 196px); bottom: calc(var(--sb) + 22px); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.tbtn { width: 78px; height: 62px; border-radius: 14px; border: 2px solid rgba(255, 255, 255, 0.55); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; }
.tbtn b { font-size: 16px; } .tbtn small { font-size: 9px; opacity: 0.8; }
.tbtn.bomb { background: rgba(40, 170, 80, 0.55); }
.tbtn.beam { background: rgba(60, 140, 200, 0.55); }
.tbtn.beam.on { background: rgba(120, 220, 255, 0.85); }
.tbtn.mega { background: rgba(200, 255, 210, 0.85); color: #08240f; animation: pulse 0.5s infinite alternate; }
.tbtn.mega.off { background: rgba(60, 60, 60, 0.4); color: #999; animation: none; }
.tbtn:active { transform: scale(0.94); }
/* 直式手機：按鈕排成一列放在右邊圓盤上方 */
@media (orientation: portrait) {
  .zone { width: 150px; height: 150px; }
  .zone .base { width: 116px; height: 116px; margin: -58px 0 0 -58px; }
  #tbtns { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(var(--sb) + 196px); flex-direction: row; }
  #top { left: auto; right: calc(var(--edge) + var(--sr) + 62px); transform: none; text-align: right; }
  #hTime { font-size: 22px; }
  #stats { gap: 9px; } .stat b { font-size: 16px; }
  .zone .hint small { display: none; }
  .tbtn { width: 68px; height: 56px; }
  #bars .bar div { width: 90px; }
}
@media (max-height: 420px) {
  .zone { width: 140px; height: 140px; bottom: calc(var(--sb) + 10px); }
  .zone .base { width: 110px; height: 110px; margin: -55px 0 0 -55px; }
  #tbtns { right: calc(var(--edge) + var(--sr) + 164px); bottom: calc(var(--sb) + 10px); gap: 6px; }
  .tbtn { width: 70px; height: 50px; }
  .panel { padding: 12px 18px; gap: 7px; }
  .logo .l1 { font-size: 48px; }
  .tag { margin: 2px auto 8px; }
  button.big { padding: 9px 22px; font-size: 18px; }
  button.ghost { padding: 7px 18px; font-size: 15px; }
}

/* ---------- 手機直拿：請轉橫向 ---------- */
#rotate { display: none; position: fixed; inset: 0; z-index: 90; background: #14152c; color: #fff; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px; }
body.touch.portrait #rotate { display: flex; }
#rotate b { font-size: 22px; color: var(--green); letter-spacing: 0.08em; }
#rotate small { font-size: 14px; color: #cfcaf0; }
#rotate .phone { width: 54px; height: 92px; border: 4px solid var(--green); border-radius: 10px; position: relative; animation: rot 2s ease-in-out infinite; }
#rotate .phone i { position: absolute; left: 50%; bottom: 6px; width: 10px; height: 4px; margin-left: -5px; background: var(--green); border-radius: 2px; }
@keyframes rot { 0%, 25% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }

/* ---------- 選單擴充 ---------- */
.mrow { display: flex; gap: 10px; }
.mrow button.ghost { min-width: 150px; }
.panel.huge { max-width: 860px; }
.sub-title { align-self: flex-start; font-weight: 900; color: #ffd27a; margin-top: 4px; }
.coins { color: #cfcaf0; } .coins b { color: #ffd27a; font-size: 20px; }
#stageList { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; width: 100%; }
.stage { text-align: left; padding: 10px 12px; border-radius: 8px; border: 2px solid rgba(125, 255, 154, 0.4); background: rgba(255, 255, 255, 0.06); color: #fff; position: relative; }
.stage:hover { background: rgba(125, 255, 154, 0.12); }
.stage .sn { font-size: 12px; color: #9fd4ff; } .stage .st { font-size: 20px; font-weight: 900; color: var(--green); }
.stage .ss { font-size: 12px; color: #cfcaf0; margin-bottom: 4px; }
.stage .tags i { font-style: normal; font-size: 11px; padding: 1px 6px; border-radius: 9px; background: rgba(255, 255, 255, 0.14); margin-right: 4px; }
.stage .tags i.c { background: #2fd35d; color: #08240f; }
.stage ul { margin: 6px 0 4px; padding: 0; list-style: none; font-size: 12px; color: #ddd; }
.stage li.ok { color: #7dff9a; }
.stage .best { font-size: 12px; color: #ffd27a; }
.stage.locked { opacity: 0.45; border-color: rgba(255, 255, 255, 0.2); cursor: not-allowed; }
.stage .lock { font-size: 11px; color: #ffb0b0; margin-top: 4px; }
.stage.clear { border-color: #ffd27a; }
.slist { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.06); text-align: left; }
.srow.eq { outline: 2px solid var(--green); }
.srow .si { display: flex; flex-direction: column; } .srow .si b { font-size: 16px; } .srow .si small { font-size: 12px; color: #cfcaf0; }
.pips { color: var(--green); letter-spacing: 2px; font-size: 13px; } .pips i { font-style: normal; color: rgba(255, 255, 255, 0.25); }
.buy { min-width: 96px; padding: 7px 10px; border-radius: 6px; border: 0; background: #ffd27a; color: #2a1a00; font-weight: 900; }
.buy:disabled { background: rgba(255, 255, 255, 0.15); color: #aaa; }
#dexList { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; width: 100%; }
.dcard { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); }
.dcard .dic { width: 56px; height: 64px; image-rendering: pixelated; }
.dcard b { color: var(--green); } .dcard small { font-size: 11px; color: #cfcaf0; line-height: 1.4; } .dcard i { font-style: normal; font-size: 12px; color: #ffd27a; }
.dcard.unk b { color: #888; }
.res.missions p { font-size: 14px; color: #ccc; } .res.missions p.ok { color: #7dff9a; }
.res.missions .unlock { color: #ffd27a; justify-content: center; font-weight: 900; }
.res .coin b { color: #ffd27a; }

/* ---------- HUD 擴充 ---------- */
#combo { position: absolute; left: 50%; top: calc(var(--st) + 64px); transform: translateX(-50%); font: 900 22px monospace; color: #ff7ab6; text-shadow: 2px 2px 0 #000, 0 0 12px rgba(255, 120, 180, 0.7); opacity: 0; transition: opacity 0.2s; white-space: nowrap; }
#combo.show { opacity: 1; } #combo.pop { animation: pop 0.25s; }
#mHud { position: absolute; right: calc(var(--edge) + var(--sr) + 8px); top: calc(var(--st) + 62px); display: flex; flex-direction: column; gap: 2px; font-size: 11px; text-align: right; text-shadow: 1px 1px 0 #000; }
#mHud div { display: flex; gap: 6px; justify-content: flex-end; color: #ddd; } #mHud b { color: #ffd27a; min-width: 48px; } #mHud .ok { color: #7dff9a; } #mHud .ok b { color: #7dff9a; }
#bossBar { position: absolute; left: 50%; bottom: calc(var(--sb) + 14px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; width: min(420px, 60vw); }
#bossBar span { font-weight: 900; color: #ff6060; text-shadow: 2px 2px 0 #000; letter-spacing: 0.1em; }
#bossBar div { width: 100%; height: 10px; background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 255, 255, 0.4); }
#bossBar i { display: block; height: 100%; width: 100%; background: linear-gradient(#ff7060, #c02020); transform-origin: left; }
#wBox { position: absolute; left: calc(var(--edge) + var(--sl) + 8px); top: calc(var(--st) + 120px); font-size: 11px; text-shadow: 1px 1px 0 #000; }
#wBox span { display: block; font-weight: 900; color: #b0ffd0; } #wBox div { width: 130px; height: 6px; background: rgba(0, 0, 0, 0.5); margin: 2px 0; }
#wBox i { display: block; height: 100%; width: 100%; background: #b0ffd0; transform-origin: left; } #wBox small { color: #aaa; }
.tbtn { position: relative; overflow: hidden; }
#tBombCd { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; background: rgba(0, 0, 0, 0.55); transform-origin: bottom; transform: scaleY(0); pointer-events: none; }
body.touch #bossBar { bottom: calc(var(--sb) + 6px); width: 26vw; left: 42%; }
body.touch #mHud { top: calc(var(--st) + 60px); }
@media (max-height: 420px) { #mHud { font-size: 10px; } #combo { font-size: 17px; top: calc(var(--st) + 54px); } .stage .ss, .stage ul { display: none; } }
.slist { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
