:root {
  --bg: #070b1a;
  --panel: #0f1630;
  --panel2: #16204a;
  --ink: #dfe7ff;
  --dim: #7f8bb3;
  --dark: #121a3c;
  --dark2: #1a2452;
  --open: #0a1024;
  --line: #24305f;
  --cyan: #5ee0ff;
  --green: #6dff9e;
  --gold: #ffd166;
  --red: #ff4d6d;
  --violet: #b48cff;
  --cell: 36px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body {
  font: 15px/1.3 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1px 1px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 72% 8%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 33% 64%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 52%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 88%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 8% 80%, #fff6 50%, transparent 51%),
    radial-gradient(ellipse at 70% 20%, #1b1450 0%, transparent 55%),
    radial-gradient(ellipse at 20% 90%, #0d2a44 0%, transparent 50%),
    var(--bg);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
#app { height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-t); }

/* ---- HUD ---- */
#hud { display: flex; align-items: center; gap: 10px; padding: 8px 10px 4px; font-weight: 600; flex-wrap: wrap; }
#hud .sector { flex: 1 1 100%; display: flex; justify-content: space-between; font-size: 13px; color: var(--dim); font-weight: 500; }
#hud .sector b { color: var(--ink); }
.stat { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.stat svg { width: 16px; height: 16px; }
.hull { display: inline-flex; gap: 2px; }
.hull i { width: 9px; height: 14px; border-radius: 2px; background: var(--green); box-shadow: 0 0 6px #6dff9e66; }
.hull i.gone { background: #2a3360; box-shadow: none; }
.hull i.shield { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); border-radius: 7px; }
.fuel.low { color: var(--red); animation: blink 1s infinite; }
.worlds b { color: var(--gold); }
.spacer { flex: 1; }
@keyframes blink { 50% { opacity: .45; } }

/* ---- board ---- */
#boardwrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 4px; }
#board {
  display: grid; gap: 2px; padding: 6px; border-radius: 14px;
  background: #0b1230cc; box-shadow: 0 0 0 1px var(--line), 0 10px 40px #0008;
}
#board.shake { animation: shake .35s; }
@keyframes shake { 20% { transform: translate(-5px, 2px); } 40% { transform: translate(5px, -2px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(2px, 0); } }
.c {
  width: var(--cell); height: var(--cell); border-radius: 6px; border: 0; padding: 0; position: relative;
  background: linear-gradient(160deg, var(--dark2), var(--dark));
  box-shadow: inset 0 1px 0 #ffffff14, inset 0 -2px 0 #0004;
  display: grid; place-items: center; font-weight: 800; font-size: calc(var(--cell) * .5);
}
.c.o { background: var(--open); box-shadow: inset 0 0 0 1px #ffffff08; }
.c.o.pop { animation: pop .28s ease-out backwards; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.c svg { width: 70%; height: 70%; pointer-events: none; }
.n1 { color: var(--cyan); } .n2 { color: var(--green); } .n3 { color: var(--gold); }
.n4 { color: #ff9f43; } .n5, .n6, .n7, .n8 { color: var(--red); }
.n9, .n10, .n11, .n12, .n13, .n14, .n15, .n16 { color: #ff5ce1; }
.c.fog { color: var(--violet); background: radial-gradient(circle at 40% 40%, #3a2470, #1a1238); font-size: calc(var(--cell) * .42); }
.c.hostile { background: radial-gradient(circle, #5a1020, #2a0710); }
.c.hostile.tag { background: radial-gradient(circle, #4a3010, #20150a); }
.c.hit { animation: hit .5s; }
@keyframes hit { 0% { background: #fff; } 30% { background: var(--red); } }
.c.world { background: radial-gradient(circle, #13304a, #0a1024); }
.c .sub { position: absolute; right: 2px; bottom: 0; font-size: calc(var(--cell) * .3); line-height: 1; }
.c.mark::after {
  content: ''; position: absolute; inset: 3px; border-radius: 50%; border: 2px dashed var(--gold); animation: spin 6s linear infinite; opacity: .8;
}
@keyframes spin { to { transform: rotate(360deg); } }
.c.flag svg { width: 60%; height: 60%; }
.c.aim { outline: 2px solid var(--cyan); outline-offset: -2px; z-index: 1; }
.c.aim.risky { outline-color: var(--gold); }
.c.aim.bad { outline-color: var(--red); }
.c.aim.safe { outline-color: var(--green); }
.c.aim:not(.o) { background: linear-gradient(160deg, #2a3c84, #1c2a66); }
.c.aim.skip { outline-style: dashed; opacity: .7; }
.c.anchor::before { content: ''; position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #fff; top: 3px; left: 3px; }
.c.calm { box-shadow: 0 0 0 2px var(--green), 0 0 14px var(--green); z-index: 1; }
.c .scan {
  position: absolute; inset: -1px; border-radius: 6px; border: 2px solid var(--violet); color: var(--violet);
  font-size: calc(var(--cell) * .34); display: grid; place-items: start end; padding: 1px 3px; pointer-events: none;
}
.c .scan.ring { border-style: dotted; border-color: #b48cff55; }
.c .float { position: absolute; top: -6px; font-size: 12px; color: var(--gold); animation: float 1.1s ease-out forwards; pointer-events: none; z-index: 3; text-shadow: 0 1px 2px #000; white-space: nowrap; }
@keyframes float { to { transform: translateY(-26px); opacity: 0; } }

/* ---- hint + hand ---- */
#hint { min-height: 34px; padding: 2px 10px; font-size: 13px; line-height: 1.2; color: var(--dim); display: flex; align-items: center; gap: 8px; }
#hint b { color: var(--ink); }
#hint .x { margin-left: auto; flex: none; background: var(--panel2); border: 0; border-radius: 99px; padding: 6px 12px; }
#hand { display: flex; gap: 6px; padding: 2px 8px 4px; justify-content: center; }
.card {
  flex: 1 1 0; max-width: 108px; min-width: 0; height: 118px; border-radius: 12px; border: 1px solid #ffffff1a;
  background: linear-gradient(170deg, #1d2a62, #121a40); padding: 6px 6px 5px; text-align: left; position: relative;
  display: flex; flex-direction: column; gap: 3px; transition: transform .15s, box-shadow .15s;
}
.card.k-safe { background: linear-gradient(170deg, #154b3b, #0d2a26); }
.card.k-info { background: linear-gradient(170deg, #3a2470, #1d1440); }
.card.k-util { background: linear-gradient(170deg, #5a4316, #2a200c); }
.card.sel { transform: translateY(-10px); box-shadow: 0 0 0 2px var(--cyan), 0 8px 24px #000a; }
.card.poor { opacity: .75; }
.card .nm { font-weight: 700; font-size: 13px; padding-left: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .cost {
  position: absolute; left: 5px; top: 5px; width: 18px; height: 18px; border-radius: 50%; background: var(--gold); color: #2a1a00;
  font-size: 12px; font-weight: 800; display: grid; place-items: center;
}
.card .cost.free { background: #ffffff33; color: var(--ink); }
.card .shape { flex: 1; display: grid; place-items: center; min-height: 0; }
.card .shape svg { height: 34px; width: auto; max-width: 100%; }
.card .tx { font-size: 10px; line-height: 1.15; color: #cbd5ffcc; max-height: 3.45em; overflow: hidden; }
.card .rot { position: absolute; right: 5px; top: 5px; font-size: 12px; opacity: .7; }

/* ---- bottom bar ---- */
#bar { display: flex; gap: 6px; padding: 4px 8px calc(8px + var(--safe-b)); align-items: center; }
#bar button, .btn {
  border: 0; border-radius: 12px; padding: 10px 12px; background: var(--panel2); font-weight: 700; min-height: 44px;
}
#bar .pile { font-size: 12px; color: var(--dim); padding: 0 4px; line-height: 1.2; }
#bar .warp, .btn.go { background: linear-gradient(135deg, #2bd1ff, #6d5cff); color: #fff; box-shadow: 0 0 18px #4aa8ff66; }
#bar .warp.ghost { background: var(--panel2); box-shadow: none; color: var(--dim); }
#bar button:disabled { opacity: .35; }
.btn.gold { background: var(--gold); color: #2a1a00; }
.btn.red { background: #5a1726; }

/* ---- toasts ---- */
#toasts { position: fixed; left: 0; right: 0; top: calc(64px + var(--safe-t)); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 20; }
.toast { background: #0f1630ee; border: 1px solid var(--line); border-radius: 99px; padding: 7px 16px; font-weight: 600; font-size: 14px; animation: toast 2.4s forwards; box-shadow: 0 6px 20px #0008; }
.toast.good { border-color: var(--gold); color: var(--gold); }
.toast.bad { border-color: var(--red); color: #ffb3c1; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---- overlay screens ---- */
#overlay { position: fixed; inset: 0; background: #050817e8; backdrop-filter: blur(6px); z-index: 30; overflow-y: auto; display: flex; justify-content: center; }
#overlay[hidden] { display: none; }
.screen { width: 100%; max-width: 480px; padding: calc(20px + var(--safe-t)) 16px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.screen.center { justify-content: center; min-height: 100%; text-align: center; }
.screen h1 { margin: 0; font-size: 44px; letter-spacing: .06em; background: linear-gradient(90deg, var(--cyan), var(--violet)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.screen h2 { margin: 0; font-size: 22px; }
.screen h3 { margin: 6px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); }
.screen p { margin: 0; color: #c3ccef; }
.screen .tag { color: var(--dim); }
.col { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; }
.chips { display: flex; gap: 12px; justify-content: center; font-weight: 700; flex-wrap: wrap; }
.pick { display: flex; gap: 8px; }
.pick .card { height: 128px; max-width: none; }
.pick .card .tx { max-height: 3.6em; font-size: 11px; }
.mod { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.mod b { color: var(--cyan); }
.mod small { color: #c3ccef; }
.mod.owned { opacity: .6; }
.shopline { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 12px; padding: 8px 10px; }
.shopline .what { flex: 1; display: flex; flex-direction: column; }
.shopline .what small { color: var(--dim); }
.shopline .btn { min-width: 74px; }
.deck { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.deck .card { height: 104px; max-width: none; }
.big-icon { width: 96px; height: 96px; margin: 0 auto; }
.title-art { width: 180px; height: 120px; margin: 0 auto; }
.mods-line { font-size: 12px; color: var(--dim); }
