* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d1626; font-family: 'Kanit', system-ui, sans-serif; color: #fff; user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- buttons ---------- */
.btn { border: none; border-radius: 14px; padding: 12px 22px; font-size: 18px; font-weight: 600; color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:disabled { filter: grayscale(1) brightness(.7); cursor: not-allowed; }
.btn.big { font-size: 24px; padding: 16px 30px; }
.btn.small { font-size: 15px; padding: 8px 14px; }
.btn-green { background: linear-gradient(#4cd964, #22a447); }
.btn-blue { background: linear-gradient(#3fa9f5, #1f6fc4); }
.btn-gold { background: linear-gradient(#ffd23f, #e09a00); color: #3a2400; }
.btn-dark { background: linear-gradient(#34496e, #1e2c48); }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; z-index: 10; }
.overlay { background: rgba(5,10,25,.72); justify-content: center; z-index: 30; backdrop-filter: blur(3px); }
.panel-bg { background: radial-gradient(ellipse at 50% 30%, #1d3a6a, #0b1428 75%); }
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; }
.topbar h2 { margin: 0; font-size: 26px; text-shadow: 0 3px 0 #000; }
/* level / xp */
.lvl-badge { display: flex; align-items: center; gap: 10px; background: rgba(10,20,40,.7); border: 2px solid #3fa9f566; border-radius: 20px; padding: 6px 14px; font-size: 18px; }
.xpbar { display: inline-block; width: 110px; height: 9px; border-radius: 5px; background: #0b1424; overflow: hidden; vertical-align: middle; }
.xpbar.big { width: 100%; height: 14px; border-radius: 7px; flex: 1; }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3fa9f5, #8fe0ff); border-radius: inherit; transition: width .8s ease-out; }
.res-xp { width: 100%; background: #0d1830; border-radius: 12px; padding: 10px 16px; }
.xp-line { display: flex; align-items: center; gap: 12px; }
.xp-gain { color: #8fe0ff; white-space: nowrap; }
.levelup { margin-top: 8px; text-align: center; color: #ffd23f; font-weight: 700; line-height: 1.6; animation: pop .4s; }
.levelup small { display: block; color: #fff; font-weight: 400; }

/* armory */
.arm-left { flex: 1 1 360px; }
.arm-list { flex: 2 1 460px; min-height: 0; }
.lvl-row { display: flex; align-items: center; gap: 14px; }
.lvl-big { font-size: 38px; font-weight: 800; color: #ffd23f; text-shadow: 0 3px 0 #8a5000; white-space: nowrap; }
.lvl-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
#arm-preview { width: 100%; max-height: 250px; object-fit: contain; background: radial-gradient(ellipse at 50% 80%, #2d5a8a, #13203a 70%); border-radius: 12px; }
.wslots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.wslot { min-height: 96px; border-radius: 12px; border: 2px dashed #2d4d80; background: #0d1830; color: #fff; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px; }
.wslot.on { border-style: solid; border-color: var(--c); box-shadow: 0 0 12px color-mix(in srgb, var(--c) 45%, transparent); }
.wslot.locked { opacity: .5; cursor: default; }
.wslot canvas { width: 64px; height: 48px; }
.wlist { display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.wcard { display: flex; gap: 12px; align-items: center; background: #0d1830; border: 2px solid #1f3558; border-radius: 14px; padding: 10px; }
.wcard.owned { border-color: color-mix(in srgb, var(--c) 60%, #1f3558); }
.wcard.locked { opacity: .55; }
.wcard .wicon { width: 80px; height: 62px; flex: none; background: radial-gradient(circle at 50% 70%, #24426e, #0b1424 75%); border-radius: 10px; }
.winfo { flex: 1; min-width: 0; }
.winfo b { font-size: 17px; }
.wkind { font-size: 11px; background: #2d4d80; border-radius: 6px; padding: 1px 6px; margin-left: 4px; vertical-align: middle; }
.tiers { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.tiers i { width: 14px; height: 7px; border-radius: 3px; background: #2a3a5a; }
.winfo small { display: block; color: #9fb8d8; }
.wstats { font-size: 12.5px; margin-top: 3px; color: #dfe8f5; }
.wstats .nx { color: #6ee06e; }
.wact { display: flex; flex-direction: column; gap: 6px; flex: none; width: 118px; }
.wact .btn { padding: 7px 8px; font-size: 14px; }
.lockmsg { text-align: center; color: #ff8a8a; font-weight: 700; font-size: 14px; }
.coins { background: rgba(10,20,40,.7); border: 2px solid #ffd23f55; border-radius: 20px; padding: 6px 16px; font-weight: 700; font-size: 18px; min-width: 110px; text-align: center; }

.logo { margin-top: 4vh; text-align: center; }
.logo h1 { margin: 0; font-size: clamp(56px, 11vw, 120px); font-weight: 800; letter-spacing: 4px; line-height: 1;
  color: #ffd23f; text-shadow: 0 6px 0 #a05a00, 0 12px 20px rgba(0,0,0,.5); }
.logo h1 span { color: #ff5a3c; text-shadow: 0 6px 0 #7a1a0a, 0 12px 20px rgba(0,0,0,.5); margin-left: 12px; }
.logo-sub { font-size: 22px; letter-spacing: 10px; color: #fff; text-shadow: 0 3px 0 #000; }
.menu-btns { margin-top: auto; margin-bottom: 8vh; display: flex; flex-direction: column; gap: 12px; align-items: center; min-width: 300px; }
.menu-btns .btn { width: 100%; }

.dialog { background: linear-gradient(#20345a, #13203a); border: 2px solid #3fa9f5aa; border-radius: 20px; padding: 26px 30px;
  display: flex; flex-direction: column; gap: 12px; align-items: center; min-width: 300px; max-width: 92vw; max-height: 94vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.6); }
.dialog h2 { margin: 0 0 6px; }
.help { text-align: left; line-height: 1.9; padding-left: 20px; margin: 0; }
.help b { color: #ffd23f; }

/* ---------- map ---------- */
.map { position: relative; flex: 1; width: min(1100px, 96vw); margin-bottom: 20px; }
#map-path { position: absolute; inset: 0; width: 100%; height: 100%; }
.node { position: absolute; transform: translate(-50%, -50%); width: 64px; height: 64px; border-radius: 50%; border: 4px solid #8fd3ff;
  background: radial-gradient(circle at 35% 30%, #4f7fc0, #1c3a6e); color: #fff; font-weight: 800; font-size: 24px;
  box-shadow: 0 0 18px #3fa9f5aa, 0 5px 0 rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; }
.node:hover { filter: brightness(1.2); }
.node.locked { border-color: #555; background: #2a2f3a; box-shadow: none; color: #777; cursor: not-allowed; }
.node.boss { width: 78px; height: 78px; border-color: #ff5a3c; box-shadow: 0 0 22px #ff5a3caa, 0 5px 0 rgba(0,0,0,.4); }
.node.current { animation: pulse 1.2s infinite; }
.node .st { position: absolute; top: 100%; margin-top: 4px; font-size: 14px; letter-spacing: -1px; white-space: nowrap; }
.node .tag { position: absolute; bottom: 100%; margin-bottom: 4px; font-size: 12px; background: #ff5a3c; padding: 0 6px; border-radius: 6px; }
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.12); } }
.zone { position: absolute; font-weight: 700; color: #9fd8ffaa; font-size: 15px; transform: translateX(-50%); }

/* ---------- garage ---------- */
.garage { display: flex; gap: 18px; padding: 0 18px 18px; width: min(1400px, 100vw); flex: 1; min-height: 0; flex-wrap: wrap; overflow: auto; }
.card { flex: 1 1 340px; background: rgba(15,28,52,.85); border: 2px solid #2d4d80; border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card h3 { margin: 0; }
#preview { width: 100%; max-height: 250px; object-fit: contain; background: radial-gradient(ellipse at 50% 80%, #2d5a8a, #13203a 70%); border-radius: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; font-size: 14px; }
.stats div { background: #0d1830; border-radius: 10px; padding: 6px; }
.stats b { display: block; font-size: 18px; color: #ffd23f; }
.tank-list { display: flex; gap: 8px; }
.tank-card { flex: 1; background: #0d1830; border: 2px solid #2d4d80; border-radius: 12px; padding: 8px; text-align: center; font-size: 14px; color: #fff; }
.tank-card.sel { border-color: #4cd964; box-shadow: 0 0 12px #4cd96488; }
.tank-card b { display: block; font-size: 17px; }
.upg { display: flex; align-items: center; gap: 12px; background: #0d1830; border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.upg .ic { font-size: 28px; }
.upg .info { flex: 1; }
.upg .bar { display: flex; gap: 3px; margin-top: 4px; }
.upg .bar i { flex: 1; height: 7px; border-radius: 4px; background: #2a3a5a; }
.upg .bar i.on { background: #4cd964; }
.upg small { color: #9fb8d8; }

/* ---------- result ---------- */
.res-title { font-size: 56px; font-weight: 800; color: #ffd23f; text-shadow: 0 5px 0 #8a5000; line-height: 1; }
.res-title.lose { color: #ff5a5a; text-shadow: 0 5px 0 #6a1010; }
.stars { font-size: 46px; letter-spacing: 6px; }
.stars .off { filter: grayscale(1) brightness(.4); }
.rewards { width: 100%; background: #0d1830; border-radius: 12px; padding: 10px 16px; }
.rewards div { display: flex; justify-content: space-between; padding: 3px 0; }
.rewards .total { border-top: 1px solid #2d4d80; margin-top: 4px; padding-top: 6px; font-size: 20px; color: #ffd23f; }
.res-parts-box { width: 100%; background: #0d1830; border-radius: 12px; padding: 10px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.res-parts-title { align-self: flex-start; font-weight: 700; color: #9fd8ff; }
.res-parts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 460px; }
.part-item { width: 64px; padding: 6px 2px; border-radius: 10px; border: 2px solid var(--c); background: #13203a; text-align: center;
  font-size: 11px; color: var(--c); box-shadow: 0 0 10px color-mix(in srgb, var(--c) 40%, transparent); animation: pop .35s backwards; }
.part-item .pi { font-size: 26px; display: block; }
.res-parts .empty { color: #8a9ab8; font-size: 14px; }
@keyframes pop { from { transform: scale(0); opacity: 0; } }

/* workshop */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot { background: #0d1830; border: 2px dashed #2d4d80; border-radius: 12px; padding: 8px 4px; text-align: center; font-size: 12px; min-height: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.slot.on { border-style: solid; border-color: var(--c); box-shadow: 0 0 12px color-mix(in srgb, var(--c) 45%, transparent); }
.slot .pi { font-size: 30px; }
.slot .rn { color: var(--c); font-weight: 700; font-size: 13px; }
.slot small { color: #9fb8d8; }
.slot button { margin-top: auto; font-size: 12px; padding: 3px 10px; border-radius: 8px; border: none; background: #34496e; color: #fff; }
.hint { color: #9fb8d8; }
.inv-row { display: flex; align-items: center; gap: 6px; background: #0d1830; border-radius: 12px; padding: 8px; margin-bottom: 8px; }
.inv-row .lbl { width: 62px; font-size: 14px; }
.chip { flex: 1; position: relative; border: 2px solid var(--c); border-radius: 10px; background: #13203a; color: var(--c); font-weight: 700;
  padding: 4px 2px 18px; font-size: 13px; }
.chip:disabled { opacity: .35; cursor: default; }
.chip .merge { position: absolute; left: 3px; right: 3px; bottom: 2px; font-size: 10px; border: none; border-radius: 6px; background: #ffd23f; color: #3a2400; padding: 1px 0; font-weight: 800; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button { pointer-events: auto; }
.hud-btn { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: 48px; height: 48px; border-radius: 12px; border: none; font-size: 22px;
  background: rgba(10,20,40,.65); color: #fff; }
#skills { position: absolute; right: 18px; bottom: 18px; display: flex; gap: 12px; align-items: flex-end; }
.skill { position: relative; width: 66px; height: 66px; border-radius: 50%; border: 3px solid #8fd3ff; background: rgba(15,35,70,.8);
  color: #fff; font-size: 28px; overflow: hidden; --p: 0; }
.skill .key { position: absolute; bottom: 2px; right: 10px; font-size: 12px; font-weight: 800; color: #ffd23f; }
.skill .cd { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(0,0,0,.7) calc(var(--p) * 360deg), transparent 0); }
.skill.ready { box-shadow: 0 0 14px #3fa9f5; }
.fire { width: 96px; height: 96px; border-radius: 50%; border: 4px solid #ffb03f; background: radial-gradient(circle, #ff7a3c, #b03010); font-size: 40px; }
.fire:active, .pad:active, .pad.on { filter: brightness(1.4); }
#touch-move { position: absolute; left: 18px; bottom: 18px; display: flex; gap: 14px; }
.pad { width: 86px; height: 86px; border-radius: 22px; border: 3px solid #8fd3ffaa; background: rgba(15,35,70,.6); color: #8fd3ff; font-size: 36px; }
.touch-only { display: none !important; }
body.touch .touch-only { display: flex !important; align-items: center; justify-content: center; }
body.touch .skill .key { display: none; }

@media (max-height: 520px) {
  .logo h1 { font-size: 60px; }
  .menu-btns { margin-bottom: 3vh; gap: 8px; }
  .btn.big { font-size: 20px; padding: 10px 24px; }
  .skill { width: 54px; height: 54px; font-size: 22px; }
  .fire { width: 78px; height: 78px; }
  .pad { width: 70px; height: 70px; }
}

/* compact result dialog so all buttons fit on short screens */
.dialog.result { gap: 8px; padding: 16px 22px; }
.dialog.result .res-title { font-size: 46px; }
.dialog.result .stars { font-size: 34px; line-height: 1; }
.dialog.result .rewards div { padding: 1px 0; }
.dialog.result .rewards .total { font-size: 18px; }
.dialog.result .part-item { width: 56px; padding: 4px 2px; }
.dialog.result .part-item .pi { font-size: 22px; }

/* ---------- city map ---------- */
.btn-teal { background: linear-gradient(#3ad0c0, #1a8a80); }
.city-nav { display: flex; align-items: center; gap: 12px; }
.city-title { text-align: center; min-width: 240px; }
.city-title h2 { margin: 0; font-size: 26px; text-shadow: 0 3px 0 #000; }
.city-title small { color: #9fd8ff; }
.city-bar { display: flex; align-items: center; gap: 14px; width: min(1100px, 96vw); background: rgba(10,20,40,.7);
  border: 2px solid #3ad0c066; border-radius: 16px; padding: 8px 14px; }
.city-bar canvas { width: 100px; height: 58px; flex: none; }
.city-goal { flex: 1; display: flex; flex-direction: column; }
.city-goal b { color: #6ae0ff; }
.city-goal small { color: #b8c8e0; }
.city-prog { width: 220px; display: flex; flex-direction: column; gap: 3px; text-align: right; }
.city-prog i { background: linear-gradient(90deg, #ffd23f, #ffb030) !important; }
#scr-map .map { margin-top: 6px; border-radius: 20px; background: var(--map-bg, transparent); }
.node { width: 54px; height: 54px; font-size: 20px; }
.node.boss { width: 64px; height: 64px; }
.node.rescue { width: 76px; height: 76px; border-color: #3ad0c0; background: radial-gradient(circle at 35% 30%, #3ad0c0, #12605a);
  box-shadow: 0 0 22px #3ad0c0aa, 0 5px 0 rgba(0,0,0,.4); font-size: 28px; }
.node.rescue .tag { background: #1a8a80; }
.node.done { border-color: #ffd23f; }
.node .mi { position: absolute; top: -4px; right: -8px; font-size: 14px; }
.levelup.rescue { color: #6ae0ff; }

/* ---------- squad ---------- */
#squad-preview { width: 100%; max-height: 190px; object-fit: contain; background: radial-gradient(ellipse at 50% 80%, #2d5a8a, #13203a 70%); border-radius: 12px; }
.fcard { display: flex; gap: 12px; align-items: center; background: #0d1830; border: 2px solid #1f3558; border-radius: 14px; padding: 8px 10px; }
.fcard.in { border-color: #3ad0c0; box-shadow: 0 0 10px #3ad0c055; }
.fcard.locked { opacity: .5; }
.fcard canvas { width: 96px; height: 56px; flex: none; }
.fcard .finfo { flex: 1; min-width: 0; }
.fcard .finfo b { font-size: 17px; }
.fcard .finfo small { display: block; color: #9fb8d8; }
.fcard .role { font-size: 12px; background: #1a8a80; border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.fcard .btn { flex: none; width: 96px; }
/* keep the result buttons visible even when the dialog scrolls */
.dialog.result .row { position: sticky; bottom: -16px; background: linear-gradient(transparent, #13203a 30%); padding: 10px 0 4px; width: 100%; }

/* ---------- aim joystick (touch) ---------- */
.aim-stick { position: relative; width: 150px; height: 150px; border-radius: 50%; pointer-events: auto; touch-action: none;
  background: radial-gradient(circle, rgba(255,122,60,.18), rgba(15,35,70,.55) 70%); border: 3px solid #ffb03f99; }
.aim-ring { position: absolute; inset: 22px; border-radius: 50%; border: 2px dashed #ffb03f66; pointer-events: none; }
.aim-knob { position: absolute; left: 50%; top: 50%; width: 70px; height: 70px; margin: -35px 0 0 -35px; border-radius: 50%;
  border: 4px solid #ffb03f; background: radial-gradient(circle, #ff7a3c, #b03010); font-size: 30px;
  display: flex; align-items: center; justify-content: center; pointer-events: none; transition: transform .08s; }
.aim-stick.on { border-color: #ffd23f; }
.aim-stick.on .aim-knob { transition: none; filter: brightness(1.25); }
@media (max-height: 520px) { .aim-stick { width: 124px; height: 124px; } .aim-knob { width: 58px; height: 58px; margin: -29px 0 0 -29px; font-size: 24px; } }

/* city jump list + locked (preview-only) cities */
.city-select { margin-top: 4px; background: #0d1830; color: #dfe8f5; border: 1px solid #2d4d80; border-radius: 8px; padding: 2px 6px; font-family: inherit; font-size: 13px; max-width: 260px; }
#scr-map.city-locked .map { filter: saturate(.45) brightness(.8); }
#scr-map.city-locked .city-bar { border-color: #5a5a64; }

/* ---------- main menu: icon buttons + short screens (tablets with browser bars, phones) ---------- */
.top-right { display: flex; align-items: center; gap: 10px; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; border: 2px solid #3fa9f566; background: rgba(10,20,40,.7);
  color: #fff; font-size: 20px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { filter: brightness(1.2); }
.icon-btn.off { border-color: #ff5a5a88; }
#scr-main { overflow-y: auto; }
#scr-main .topbar { justify-content: space-between; }
@media (max-height: 600px) {
  .logo { margin-top: 0; }
  .logo h1 { font-size: clamp(40px, 9vh + 10px, 64px); }
  .logo-sub { font-size: 15px; letter-spacing: 6px; }
  .menu-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(640px, 94vw); margin-bottom: 3vh; }
  .menu-btns .btn.big { grid-column: 1 / -1; }
  .menu-btns .btn { font-size: 15px; padding: 10px 8px; }
  .topbar { padding: 8px 14px; }
}

/* iPad / iPhone: no text selection or long-press callout while tapping controls */
html, body, button, .screen, #hud { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* city map on short screens: keep the two rows apart and let the page scroll */
@media (max-height: 600px) {
  #scr-map { overflow-y: auto; }
  #scr-map .map { flex: none; height: 360px; }
  #scr-map .topbar h2 { font-size: 20px; }
  .city-bar { padding: 4px 10px; }
  .city-bar canvas { width: 70px; height: 40px; }
  .city-goal small { display: none; }
  .node { width: 46px; height: 46px; font-size: 17px; }
  .node.boss { width: 54px; height: 54px; }
  .node.rescue { width: 62px; height: 62px; font-size: 24px; }
}
