:root {
  --ink: #eaf4ff; --dim: #9db4c8; --ice: #66d9ff; --red: #ff5a4a; --gold: #ffd34a; --green: #5ee08a;
  --panel: rgba(8, 20, 34, 0.62); --panel2: rgba(12, 30, 50, 0.92); --line: rgba(160, 210, 255, 0.18);
  --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px); --sa-r: env(safe-area-inset-right, 0px); --sa-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1724; color: var(--ink); font-family: Nunito, system-ui, sans-serif; font-weight: 700; touch-action: none; user-select: none; -webkit-user-select: none; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; font-weight: 800; color: inherit; cursor: pointer; }
#boot { position: fixed; inset: 0; display: grid; place-items: center; background: #0b1724; font-size: 20px; z-index: 50; }

/* ---------- effects ---------- */
#fxLayer { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
#vigCold { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 225, 255, 0.55) 100%); transition: opacity 0.6s; box-shadow: inset 0 0 120px rgba(220, 245, 255, 0.6); }
#vigHurt { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 40%, rgba(200, 20, 20, 0.6) 100%); }
#flashW { position: absolute; inset: 0; opacity: 0; background: #fff; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
#hud button, #hud .chips, #hud .touch .b { pointer-events: auto; }
.topbar { position: absolute; top: calc(8px + var(--sa-t)); left: calc(12px + var(--sa-l)); right: calc(12px + var(--sa-r)); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.prog { width: min(720px, calc(100% - 60px)); }
.prog-track { position: relative; height: 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); }
.prog-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 8px; background: linear-gradient(90deg, #2a7fb8, var(--ice)); width: 0; }
.prog-boat { position: absolute; top: -9px; font-size: 20px; transform: translateX(-50%); filter: drop-shadow(0 2px 2px #000); }
.lm { position: absolute; top: -3px; width: 4px; height: 18px; margin-left: -2px; border-radius: 2px; background: rgba(255, 255, 255, 0.45); }
.lm.done { background: var(--gold); }
.lm span { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font-size: 12px; white-space: nowrap; }
.prog-label { margin-top: 18px; text-align: center; font-size: 12px; color: var(--dim); text-shadow: 0 1px 2px #000; }
.compass { position: relative; width: min(340px, 70vw); height: 26px; overflow: hidden; border-radius: 8px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); -webkit-mask: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); mask: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); }
.compass-strip { position: absolute; top: 0; left: 50%; height: 100%; white-space: nowrap; font-size: 13px; line-height: 26px; }
.compass-strip span { position: absolute; transform: translateX(-50%); color: var(--dim); }
.compass-strip span.c { color: var(--ink); font-weight: 900; }
.compass-strip span.e { color: var(--gold); }
.compass-mark { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--red); }
.compass-wind { position: absolute; top: 2px; font-size: 14px; transform: translateX(-50%); }
.pausebtn { position: absolute; right: 0; top: 0; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; }

.hud-panel { position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; backdrop-filter: blur(4px); }
.stats { left: calc(10px + var(--sa-l)); top: calc(96px + var(--sa-t)); width: 172px; }
.stat { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.stat .ic { width: 22px; text-align: center; font-size: 15px; }
.bar { flex: 1; height: 9px; border-radius: 6px; background: rgba(0, 0, 0, 0.5); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; border-radius: 6px; transition: width 0.2s; }
#stHealth i { background: #ff5a6a; } #stWarm i { background: linear-gradient(90deg, #5ac8ff, #ffb04a); } #stFood i { background: #e8a24a; } #stHull i { background: #a8c4d8; }
.stat.low { animation: pulse 0.7s infinite alternate; }
@keyframes pulse { to { filter: brightness(1.8); } }
.pack, .crate { font-size: 12.5px; margin-top: 5px; color: var(--ink); }
.crate { color: var(--dim); }
.sail { right: calc(10px + var(--sa-r)); top: calc(96px + var(--sa-t)); width: 142px; text-align: center; }
.dial { width: 92px; height: 92px; display: block; margin: 0 auto; }
.dial-ring { fill: rgba(0, 0, 0, 0.35); stroke: rgba(160, 210, 255, 0.4); stroke-width: 2; }
.dial-boat { fill: #e8dcc0; }
.dial-wind { stroke: var(--ice); stroke-width: 5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dial-rogue { fill: var(--red); }
.speed b { font-size: 22px; } .speed small { color: var(--dim); margin-left: 4px; font-size: 11px; }
.trim { position: relative; height: 12px; margin: 6px 2px 2px; border-radius: 6px; background: rgba(0, 0, 0, 0.5); overflow: hidden; }
.trim-zone { position: absolute; top: 0; bottom: 0; background: rgba(94, 224, 138, 0.55); border-radius: 6px; }
.trim-needle { position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px; background: #fff; box-shadow: 0 0 4px #000; }
.trim-label { font-size: 12px; margin-top: 3px; }
.trim-label.good { color: var(--green); } .trim-label.bad { color: var(--red); } .trim-label.meh { color: var(--gold); }
.stove { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 13px; }
#stoveBar { background: linear-gradient(90deg, #ff6a1a, #ffd34a); }
.purse { font-size: 13px; margin-top: 5px; line-height: 1.45; color: var(--gold); }
.chips { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--sa-b)); display: flex; gap: 6px; }
.chips button { padding: 7px 11px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.chips button.at { border-color: var(--ice); background: rgba(40, 110, 160, 0.7); }
.crosshair { position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; transform: translate(-50%, -50%); }
.crosshair svg { width: 100%; height: 100%; } .crosshair circle { fill: none; stroke: rgba(255, 255, 255, 0.85); stroke-width: 2; }
.crosshair circle:first-child { fill: #fff; stroke: none; }
.crosshair .reload { stroke: var(--gold); stroke-width: 3; stroke-dasharray: 88; transform: rotate(-90deg); transform-origin: 20px 20px; opacity: 0.9; }
.prompt { position: absolute; left: 50%; bottom: calc(58px + var(--sa-b)); transform: translateX(-50%); font-size: 15px; padding: 6px 14px; border-radius: 10px; background: var(--panel); white-space: nowrap; }
.prompt:empty { display: none; }
.toast-wrap { position: absolute; left: 50%; top: calc(92px + var(--sa-t)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 5px; width: min(520px, 92vw); }
.toast { padding: 7px 14px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 14px; text-align: center; animation: tin 0.25s ease-out; max-width: 100%; }
.toast.warn { border-color: var(--gold); } .toast.bad { border-color: var(--red); background: rgba(70, 12, 12, 0.92); } .toast.good { border-color: var(--green); }
.toast.shark { border-color: #ff8a7a; } .toast.event { border-color: #c38bff; background: rgba(40, 20, 70, 0.92); } .toast.reward { border-color: var(--gold); color: #fff3c4; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: 0.4s; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px) scale(0.95); } }
.banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); font-family: 'Bowlby One', sans-serif; font-size: clamp(22px, 5vw, 44px); text-align: center; text-shadow: 0 3px 0 #000, 0 0 20px rgba(0, 0, 0, 0.6); opacity: 0; transition: opacity 0.3s; letter-spacing: 1px; white-space: nowrap; }
.banner.on { opacity: 1; }
.banner small { display: block; font-family: Nunito, sans-serif; font-size: 0.42em; letter-spacing: 0; }
.banner.danger { color: #ffcf9a; animation: shakeb 0.18s infinite; }
@keyframes shakeb { 50% { transform: translate(-50%, -52%); } }
.keys-hint { position: absolute; bottom: calc(100px + var(--sa-b)); left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--dim); text-shadow: 0 1px 2px #000; white-space: nowrap; transition: opacity 1s; }

/* touch */
.touch { display: none; }
body.is-touch .touch { display: block; }
body.is-touch .keys-hint { display: none; }
#joy { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); background: rgba(0, 0, 0, 0.2); opacity: 0; left: 90px; top: 70%; transition: opacity 0.15s; }
#joy.on { opacity: 1; }
#joyKnob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); }
.btns { position: absolute; right: calc(10px + var(--sa-r)); bottom: calc(14px + var(--sa-b)); width: 236px; height: 236px; }
.b { position: absolute; width: 62px; height: 62px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.35); background: rgba(10, 28, 46, 0.7); font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: none; }
.b small { font-size: 8.5px; margin-top: 3px; letter-spacing: 0.3px; }
.b.down { transform: scale(0.9); background: rgba(60, 140, 200, 0.8); }
.b-fire { width: 92px; height: 92px; right: 0; bottom: 0; font-size: 34px; background: rgba(120, 30, 30, 0.75); border-color: rgba(255, 140, 120, 0.7); }
.b-steer { right: 104px; bottom: 0; } .b-trim { right: 100px; bottom: 70px; } .b-eat { right: 0; bottom: 102px; }
.b-bait { right: 66px; bottom: 140px; } .b-use { right: 152px; bottom: 116px; } .b-fix { right: 0; bottom: 172px; }
.b.hot { border-color: var(--ice); box-shadow: 0 0 12px var(--ice); }
.b.off { opacity: 0.35; }
body.is-touch .chips { bottom: auto; top: calc(100px + var(--sa-t)); }
body.is-touch .stats, body.is-touch .sail { top: calc(146px + var(--sa-t)); }
body.is-touch .prompt { top: auto; bottom: calc(262px + var(--sa-b)); font-size: 13px; max-width: 92vw; white-space: normal; text-align: center; }
body.is-touch .toast-wrap { top: calc(345px + var(--sa-t)); }

@media (max-width: 760px) {
  .stats { top: calc(118px + var(--sa-t)); width: 128px; padding: 6px 8px; }
  .stat .ic { font-size: 12px; width: 16px; } .bar { height: 7px; }
  .pack, .crate { font-size: 11px; }
  .sail { top: calc(118px + var(--sa-t)); width: 104px; padding: 6px; }
  .dial { width: 64px; height: 64px; } .speed b { font-size: 17px; }
  .chips button { padding: 5px 8px; font-size: 11px; }
  .prog-label { font-size: 10.5px; } .lm span { font-size: 0; }
  .purse { font-size: 11px; }
  .btns { transform: scale(0.88); transform-origin: right bottom; }
}
@media (max-height: 500px) {
  .stats, .sail { top: calc(70px + var(--sa-t)); }
  .compass { display: none; }
  body.is-touch .chips { top: calc(42px + var(--sa-t)); right: 60px; left: auto; transform: none; }
  body.is-touch .stats, body.is-touch .sail { top: calc(70px + var(--sa-t)); }
  body.is-touch .prompt { top: auto; bottom: 8px; left: 40%; max-width: 40vw; }
  body.is-touch .toast-wrap { top: calc(70px + var(--sa-t)); }
  .btns { transform: scale(0.72); transform-origin: right bottom; }
  .prog-label { display: none; }
  .sail { width: 112px; padding: 5px 6px; } .dial { width: 50px; height: 50px; } .speed b { font-size: 16px; } .trim-label { font-size: 10.5px; }
  .stats { width: 150px; padding: 5px 8px; } .stat { margin: 1px 0; }
  .banner { top: 30%; }
}

/* ---------- screens ---------- */
#screen { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; touch-action: pan-y; }
#screen:empty { display: none; }
#screen.dim { background: rgba(4, 10, 18, 0.55); backdrop-filter: blur(3px); }
.card { width: min(560px, 100%); background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); margin: auto; }
.card.wide { width: min(860px, 100%); }
.logo { font-family: 'Bowlby One', sans-serif; text-align: center; line-height: 0.95; font-size: clamp(34px, 9vw, 64px); letter-spacing: 1px; text-shadow: 0 4px 0 #04101c, 0 0 30px rgba(102, 217, 255, 0.35); margin: 4px 0 6px; }
.logo span { color: var(--red); display: block; font-size: 1.15em; }
.tag { text-align: center; color: var(--dim); margin-bottom: 18px; font-size: 15px; }
h2 { font-family: 'Bowlby One', sans-serif; font-weight: 400; margin: 0 0 10px; font-size: 26px; letter-spacing: 0.5px; }
h3 { margin: 14px 0 6px; font-size: 15px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
p { line-height: 1.45; margin: 6px 0; }
.btn { display: block; width: 100%; padding: 14px; margin: 8px 0; border-radius: 14px; border: 1px solid var(--line); background: rgba(40, 90, 130, 0.55); font-size: 17px; letter-spacing: 0.5px; transition: transform 0.08s, background 0.15s; }
.btn:hover { background: rgba(60, 120, 170, 0.7); } .btn:active { transform: scale(0.98); }
.btn.big { background: linear-gradient(180deg, #e2483a, #a92a20); border-color: #ff8a7a; font-size: 20px; padding: 16px; font-family: 'Bowlby One', sans-serif; font-weight: 400; letter-spacing: 1px; }
.btn.small { padding: 9px; font-size: 14px; }
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
.muted { color: var(--dim); font-size: 13.5px; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); margin: 2px; font-size: 13px; }
.wallet { text-align: center; font-size: 18px; margin: 4px 0 10px; }
.opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opt { padding: 12px 8px; border-radius: 14px; border: 2px solid var(--line); background: rgba(255, 255, 255, 0.04); text-align: center; font-size: 13px; }
.opt b { display: block; font-size: 26px; } .opt.sel { border-color: var(--ice); background: rgba(102, 217, 255, 0.12); }
.opt small { display: block; color: var(--dim); font-weight: 600; margin-top: 4px; font-size: 11.5px; line-height: 1.3; }
select, input[type=text] { width: 100%; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); color: var(--ink); font: inherit; font-size: 16px; }
input.code { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-size: 26px; }
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 16px; padding: 12px; background: rgba(255, 255, 255, 0.04); }
.item .t { display: flex; align-items: center; gap: 8px; font-size: 16px; } .item .t b { font-size: 26px; }
.lv { display: flex; gap: 4px; margin: 6px 0; } .lv i { flex: 1; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); } .lv i.on { background: var(--ice); }
.item .cur { font-size: 13px; color: var(--dim); } .item .nx { font-size: 13px; margin-top: 4px; }
.item .btn { margin: 8px 0 0; padding: 10px; font-size: 14px; }
.btn[disabled] { opacity: 0.4; cursor: default; }
.lobby-list { margin: 8px 0; } .lobby-list div { padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); margin: 4px 0; display: flex; justify-content: space-between; }
.bigcode { font-family: 'Bowlby One', sans-serif; font-size: 44px; letter-spacing: 8px; text-align: center; color: var(--gold); user-select: text; -webkit-user-select: text; }
.stats-end { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stats-end div { background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 10px; text-align: center; } .stats-end b { display: block; font-size: 22px; }
.how li { margin: 6px 0; line-height: 1.4; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; }
.setrow select, .setrow input[type=range] { width: 55%; }
.cp { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 6px 0; }
.cp button { padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 13px; }
.cp button.sel { border-color: var(--gold); background: rgba(255, 211, 74, 0.15); }
.err { color: #ff9a8a; min-height: 1.2em; font-size: 14px; }
