:root {
  --sea-deep: #0b2a3c; --sea: #1c5b78; --sea-light: #2f7f9f;
  --parch: #efdfbc; --parch-2: #e3cf9f; --parch-3: #d4b97e; --ink: #2a1a0a; --ink-soft: #5a4631;
  --gold: #d9a441; --gold-dark: #a87a24; --danger: #b3362f; --good: #2e7d4f; --warn: #b06a1b;
  --panel: rgba(239, 223, 188, 0.96); --glass: rgba(14, 34, 48, 0.82);
  --radius: 12px;
  font-family: 'Source Sans 3', system-ui, sans-serif;
  color: var(--ink);
  font-size: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--sea-deep); line-height: 1.35; }
h1, h2, h3, .display { font-family: 'IM Fell English SC', 'IM Fell English', Georgia, serif; font-weight: 400; letter-spacing: .02em; margin: 0; }
h1 { font-size: 2.4rem; } h2 { font-size: 1.4rem; } h3 { font-size: 1.1rem; color: var(--ink-soft); border-bottom: 1px solid var(--parch-3); padding-bottom: 2px; margin-bottom: 6px; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--gold); color: var(--ink); border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; box-shadow: 0 2px 0 var(--gold-dark); }
button:hover { filter: brightness(1.06); } button:active { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-soft); color: var(--ink-soft); }
button.good { background: var(--good); color: #fff; box-shadow: 0 2px 0 #1d5635; }
button.small { padding: 3px 9px; font-size: .9rem; border-radius: 6px; }
button.tiny { padding: 1px 8px; font-size: .85rem; border-radius: 5px; box-shadow: none; line-height: 1.4; }
input[type=text], input[type=number], select { background: #fff8e8; border: 1px solid var(--parch-3); border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid #ffd166; outline-offset: 2px; }
#compass [data-dir]:focus-visible { outline: none; } #compass [data-dir]:focus-visible .blade { stroke: #fff; stroke-width: 2.5; }
label { display: block; font-size: .9rem; color: var(--ink-soft); font-weight: 600; }
.muted { color: var(--ink-soft); } .small { font-size: .88rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .grow { flex: 1 1 auto; }
.row > input[type=text], .row > select { width: auto; flex: 1 1 120px; }
.stack > * + * { margin-top: 10px; }
svg.ic { width: 1.25em; height: 1.25em; vertical-align: -.3em; }

/* Panels & screens */
.panel { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 12px 40px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.4); position: relative; }
.screen { height: 100%; overflow: auto; padding: 24px 16px 48px; background-image: radial-gradient(1200px 600px at 20% -10%, rgba(47,127,159,0.55), transparent 60%), radial-gradient(900px 500px at 90% 110%, rgba(47,127,159,0.4), transparent 60%); }
.screen > * { max-width: 1400px; margin-left: auto; margin-right: auto; }
.center { max-width: 560px; margin: 8vh auto 0; }
.brand { text-align: center; color: var(--parch); margin-bottom: 18px; }
.brand h1 { font-size: 3.4rem; text-shadow: 0 2px 0 var(--sea-deep), 0 6px 24px rgba(0,0,0,.5); }
.brand p { margin: 4px 0 0; opacity: .85; font-style: italic; font-family: 'IM Fell English', serif; font-size: 1.15rem; }
.code-input { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; font-size: 1.2rem; text-align: center; }
.lobby { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .lobby { grid-template-columns: 1fr; } }
.players { list-style: none; padding: 0; margin: 0; }
.players li { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px dashed var(--parch-3); }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(0,0,0,.25); display: inline-block; cursor: pointer; }
.swatch.on { outline: 3px solid var(--ink); outline-offset: 1px; } .swatch.taken { opacity: .3; cursor: not-allowed; }
button.swatch.big { width: 44px; height: 44px; padding: 0; box-shadow: none; border: 2px solid rgba(0,0,0,.25); }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.code-big { font-family: 'IM Fell English SC', serif; font-size: 2.2rem; letter-spacing: .25em; }
.rules h4 { margin: 10px 0 2px; font-family: 'IM Fell English SC', serif; font-weight: 400; font-size: 1.05rem; }
.rules p { margin: 0 0 4px; font-size: .92rem; }
.rules .doom { margin: 10px 0 6px; padding: 12px 16px; border-radius: 10px; background: var(--danger); color: #fff; font-family: 'IM Fell English', serif; font-size: 1.25rem; line-height: 1.35; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), 0 6px 20px rgba(179,54,47,.4); }
.rules .doom b { color: #ffd166; }

/* ===== Game: a grid. Chart in its own clipped frame; HUD panels around it ===== */
#game { position: fixed; inset: 0; display: grid; gap: 12px; padding: 12px; grid-template-columns: 220px minmax(0, 1fr) 470px; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "players top right" "players stage right" "resbar resbar right"; }
#players { grid-area: players; display: flex; flex-direction: column; gap: 8px; overflow: auto; scrollbar-width: thin; min-height: 0; }
#top { grid-area: top; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#right { grid-area: right; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
#stage { grid-area: stage; position: relative; overflow: hidden; border-radius: var(--radius); touch-action: none; cursor: grab; min-height: 0;
  background: radial-gradient(120% 90% at 35% 25%, #1f6d8e, #0a2a3c 85%); box-shadow: 0 12px 40px rgba(0,0,0,.5), inset 0 0 0 2px rgba(255,255,255,.14), inset 0 0 60px rgba(0,0,0,.35); }
#stage:active { cursor: grabbing; }
#chartwrap { position: absolute; inset: 0; }
#chartwrap svg { width: 100%; height: 100%; display: block; }
#resbar { grid-area: resbar; }
#dock { display: none; }
.hud { position: absolute; z-index: 5; }
.glass { background: var(--glass); color: var(--parch); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.08); backdrop-filter: blur(6px); }

/* top-centre: day & clock */
#daybox { padding: 8px 10px; display: flex; align-items: center; gap: 10px; }
.dayframe { padding: 4px 12px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); text-align: center; }
.daybtns { display: flex; gap: 4px; margin-left: 4px; }
#daybox .day { font-family: 'IM Fell English SC', serif; font-size: 1.7rem; line-height: 1.1; }
#daybox .sub { font-size: 1rem; opacity: .75; }
.clock { font-variant-numeric: tabular-nums; font-size: 2.7rem; font-family: 'IM Fell English', serif; min-width: 110px; text-align: center; }
.clock.hurry { color: #ff8c7a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.pips { display: flex; gap: 5px; }
.pip { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); opacity: .35; }
.pip.ready { opacity: 1; box-shadow: 0 0 0 2px #fff inset; }
#zoom { bottom: 12px; left: 12px; z-index: 6; display: flex; flex-direction: column; gap: 4px; padding: 4px; }
.ibtn { width: 50px; height: 50px; border-radius: 8px; background: rgba(255,255,255,.08); color: var(--parch); box-shadow: none; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.ibtn svg { width: 30px; height: 30px; } .ibtn:hover { background: rgba(255,255,255,.18); }
#notices { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.ntc { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; font-size: 1.1rem; font-weight: 600; cursor: default; }
.ntc svg { width: 26px; height: 26px; }
.ntc.pirates { box-shadow: inset 0 0 0 1.5px #ff6b5a; } .ntc.ritual { box-shadow: inset 0 0 0 1.5px var(--warn); } .ntc.discovery { box-shadow: inset 0 0 0 1.5px #7fd49a; } .ntc.treasure { box-shadow: inset 0 0 0 1.5px var(--gold); }

/* left: player cards */
.pcard { padding: 8px 10px; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.4), inset 0 0 0 1px rgba(255,255,255,.08); }
.pcard.me { box-shadow: 0 8px 24px rgba(0,0,0,.4), inset 0 0 0 2px rgba(255,214,102,.7); }
.pcard.lost { opacity: .55; }
.ptop { display: flex; align-items: center; gap: 8px; }
.ptop .swatch { width: 22px; height: 22px; flex: none; cursor: default; }
.pname { font-family: 'IM Fell English', serif; font-size: 1.3rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pready { width: 28px; height: 28px; opacity: .2; } .pready svg { width: 28px; height: 28px; } .pready.on { opacity: 1; filter: drop-shadow(0 0 3px #7fd49a); }
.ploc { font-size: 1rem; opacity: .7; margin: 2px 0 4px; }
.pbooty { display: flex; flex-wrap: wrap; gap: 6px; font-size: 1.15rem; font-weight: 700; }
.pbooty span { display: inline-flex; align-items: center; gap: 2px; background: rgba(255,255,255,.08); border-radius: 6px; padding: 1px 5px; }
.pbooty svg { width: 28px; height: 28px; } .pbooty .none { font-weight: 400; opacity: .5; background: none; padding: 0; }

/* top-right: log */
#logbox { flex: 1 1 auto; min-height: 120px; display: flex; flex-direction: column; }
#logbox.collapsed { width: auto; }
#logbox .tabs { display: flex; gap: 2px; padding: 6px 6px 0; }
#logbox .tabs .ibtn { width: 46px; height: 42px; } #logbox .tabs .ibtn.on { background: rgba(255,255,255,.22); }
#logbox .tabs .spacer { flex: 1; }
.loglist { overflow: auto; padding: 6px 12px 8px; font-size: 1.1rem; scrollbar-width: thin; }
.loglist div { padding: 3px 0; border-bottom: 1px dotted rgba(255,255,255,.12); display: flex; gap: 6px; align-items: flex-start; }
.loglist b { opacity: .6; font-weight: 600; min-width: 26px; }
.loglist .bad { color: #ff9c8c; } .loglist .good { color: #9fe0b4; } .loglist .warn { color: #ffd38a; } .loglist .event { color: #ffe9a8; font-style: italic; } .loglist .market { opacity: .8; }
.loglist .chatline b { opacity: 1; min-width: 0; }
.loglist .lhead { display: block; border: 0; font-family: 'IM Fell English SC', serif; opacity: .8; margin-top: 6px; }
.chatform { display: flex; gap: 6px; padding: 6px; }
.chatform input { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); color: var(--parch); }

/* bottom-center: resources */
#resbar { padding: 8px; display: flex; align-items: stretch; justify-content: center; gap: 6px; flex-wrap: wrap; }
.res { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px; min-width: 96px; padding: 8px 6px 6px; border-radius: 10px; position: relative; box-shadow: inset 0 0 0 1px rgba(255,255,255,.1); background: rgba(255,255,255,.04); }
.res svg { width: 56px; height: 56px; } .res .n { font-weight: 700; font-size: 1.6rem; line-height: 1; font-variant-numeric: tabular-nums; }
.res .n.small { font-size: .8rem; font-weight: 600; }
.res .lbl { font-size: .8rem; opacity: .75; text-transform: uppercase; letter-spacing: .05em; }
.res.zero svg, .res.zero .n { opacity: .4; }
.res.money .n { font-family: 'IM Fell English', serif; font-size: 1.8rem; }
.res.captain { justify-content: center; } .res.captain .swatch { width: 40px; height: 40px; cursor: pointer; }
.res .sub { display: flex; align-items: center; gap: 3px; margin-top: 2px; }
.res .pr { font-size: .95rem; font-weight: 700; color: #ffd166; } .res .pr small { font-weight: 400; opacity: .7; font-size: .75rem; }
.sb { width: 34px; height: 34px; padding: 0; border-radius: 8px; background: rgba(255,255,255,.14); color: var(--parch); box-shadow: none; font-size: 1.4rem; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.sb:hover { background: rgba(255,255,255,.28); } .sb:disabled { opacity: .25; }
.sb.sell { width: auto; padding: 0 8px; font-size: .9rem; font-weight: 700; background: rgba(46,125,79,.8); }
.res.hold { min-width: 150px; justify-content: center; gap: 5px; }
.res.hold .bar { width: 100%; }
.bar { height: 10px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; } .bar > div { height: 100%; background: #7fd49a; } .bar.full > div { background: #ff6b5a; }

/* bottom-right: compass & orders */
#orders { flex: none; padding: 10px; display: flex; gap: 10px; align-items: flex-end; }
#compass { width: 230px; height: 230px; display: block; }
#compass .needle { cursor: pointer; }
#compass .needle.off { cursor: not-allowed; }
#compass .needle.off .blade { fill: rgba(255,255,255,.1); stroke: rgba(255,255,255,.18); }
#compass .needle .blade { fill: #e7d7b1; stroke: #2a1a0a; stroke-width: 1.2; transition: fill .15s; }
#compass .needle.minor .blade { fill: #b8a67c; }
#compass .needle:not(.off):hover .blade { fill: #ffd166; }
#compass .needle.on .blade { fill: #ffd166; stroke: #fff; filter: drop-shadow(0 0 5px rgba(255,214,102,.9)); }
#compass .needle.calm .blade { stroke: #ff6b5a; stroke-dasharray: 3 2; }
#compass text { font-family: 'IM Fell English SC', serif; fill: #efdfbc; font-size: 18px; pointer-events: none; }
#compass .hub { cursor: pointer; } #compass .hub.on circle.c { fill: #ffd166; } #compass .hub.off { cursor: not-allowed; opacity: .4; }
.acts { display: grid; grid-template-columns: repeat(2, 76px); gap: 8px; }
.act { width: 76px; height: 76px; border-radius: 10px; background: rgba(255,255,255,.08); box-shadow: none; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--parch); position: relative; }
.act svg { width: 40px; height: 40px; } .act span { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; opacity: .8; line-height: 1; }
.act:hover { background: rgba(255,255,255,.18); } .act.on { background: rgba(255,214,102,.28); box-shadow: inset 0 0 0 2px #ffd166; }
.act.warn.on { background: rgba(255,120,90,.25); box-shadow: inset 0 0 0 2px #ff8c7a; }
.act .cnt { position: absolute; top: 4px; right: 6px; font-size: 1rem; font-weight: 700; background: rgba(0,0,0,.4); border-radius: 999px; padding: 0 5px; }
.act.readybtn { grid-column: 1 / -1; width: 100%; height: 76px; flex-direction: row; gap: 8px; background: var(--gold); color: var(--ink); font-family: 'IM Fell English SC', serif; font-size: 1.4rem; }
.act.readybtn span { font-size: 1.7rem; text-transform: none; letter-spacing: .02em; opacity: 1; }
.act.readybtn.on { background: var(--good); color: #fff; box-shadow: none; }
.plan { font-size: 1.15rem; max-width: 340px; line-height: 1.5; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.plan b { color: #ffd166; font-family: 'IM Fell English', serif; font-size: 1.35rem; }
.pn { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; } .pn svg { width: 30px; height: 30px; }
.plan .danger { color: #ff8c7a; } .plan .warn { color: #ffd38a; }

/* left: tile / trade panel */
#tilebox { top: 12px; left: 12px; width: 380px; max-height: calc(100% - 24px); overflow: auto; padding: 12px 14px; scrollbar-width: thin; }
#tilebox h2 { display: flex; align-items: center; gap: 8px; font-size: 1.6rem; }
#tilebox .close { margin-left: auto; }
.goods { width: 100%; border-collapse: collapse; font-size: 1.15rem; margin-top: 6px; }
.goods td { padding: 4px 3px; border-top: 1px dotted rgba(255,255,255,.15); vertical-align: middle; }
.goods td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.goods svg { width: 32px; height: 32px; vertical-align: -9px; margin-right: 6px; }
.goods .tiny { background: rgba(255,255,255,.14); color: var(--parch); }
.goods .tiny.sell { background: var(--good); color: #fff; }
.goods .tiny:disabled { opacity: .3; }
.wxline { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 1rem; }
.wxline svg { width: 30px; height: 30px; background: rgba(0,0,0,.35); border-radius: 6px; padding: 2px; }

/* tooltip */
#tooltip { position: fixed; z-index: 30; pointer-events: none; background: var(--glass); color: var(--parch); padding: 12px 15px; border-radius: 8px; font-size: 1.1rem; max-width: 320px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
#tooltip b { font-family: 'IM Fell English', serif; font-size: 1.35rem; }
#tooltip svg { width: 26px; height: 26px; vertical-align: -4px; }

/* Toasts */
#toasts { pointer-events: none; position: fixed; bottom: 200px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: 420px; align-items: center; }
.toast { background: var(--ink); color: var(--parch); padding: 14px 20px; font-size: 1.2rem; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5), inset 0 0 0 1.5px var(--gold); animation: rise-in .25s ease-out; }
.toast.error { box-shadow: 0 8px 30px rgba(0,0,0,.5), inset 0 0 0 1.5px var(--danger); } .toast.ready { box-shadow: 0 8px 30px rgba(0,0,0,.5), inset 0 0 0 1.5px var(--good); } .toast.day { box-shadow: 0 8px 30px rgba(0,0,0,.5), inset 0 0 0 1.5px var(--sea-light); }
@keyframes rise-in { from { transform: translateY(14px); opacity: 0; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal { max-width: 780px; max-height: 90vh; overflow: auto; width: 100%; }
.modal.dialog { max-width: 420px; }
.modal.dialog p { margin: 0; }
button.danger { background: var(--danger); color: #fff; box-shadow: 0 2px 0 #7a221c; }
.res.captain { cursor: pointer; } .res.captain .lbl { text-transform: none; font-size: .75rem; letter-spacing: 0; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings td, .standings th { padding: 6px 8px; } .standings .score { font-family: 'IM Fell English', serif; font-size: 1.3rem; }
table.grid { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.grid th { text-align: left; font-weight: 600; color: var(--ink-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; padding: 2px 4px; }
table.grid td { padding: 3px 4px; border-top: 1px dashed var(--parch-3); }
.notice { padding: 8px 12px; background: rgba(255,255,255,.4); border-radius: 8px; margin: 6px 0; font-size: .95rem; box-shadow: inset 0 0 0 1.5px rgba(90,70,49,.25); }
.notice.rejoin { font-size: 1.05rem; } .notice.rejoin b { font-family: 'IM Fell English', serif; font-size: 1.25rem; }
.notice.pirates { box-shadow: inset 0 0 0 1.5px var(--danger); } .notice.ritual { box-shadow: inset 0 0 0 1.5px var(--warn); } .notice.treasure { box-shadow: inset 0 0 0 1.5px var(--gold-dark); } .notice.discovery { box-shadow: inset 0 0 0 1.5px var(--good); }
.log { max-height: 240px; overflow: auto; font-size: .88rem; } .log div { padding: 2px 0; border-bottom: 1px dotted var(--parch-3); }
.log .bad { color: var(--danger); } .log .good { color: var(--good); } .log .warn { color: var(--warn); } .log b { font-weight: 600; color: var(--ink-soft); margin-right: 4px; }

/* ===== Chart animations ===== */
#chart .shipg { transition: transform 2.2s cubic-bezier(.45,.05,.3,1); will-change: transform; }
#chart .wxlayer { transition: opacity 2.4s ease-in-out; opacity: 1; }
#chart .wxlayer.enter { opacity: 0; }
#chart .wxlayer.leave { opacity: 0; pointer-events: none; }
#chart .shipg.ready .sloop path:last-child { filter: drop-shadow(0 0 3px #fff); }
#chart .bob { animation: bob 3.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-2.5px) rotate(2deg); } }
#chart .wave { animation: drift 7s linear infinite; }
#chart .wave.fast { animation-duration: 2.4s; }
@keyframes drift { from { transform: translateX(-14px); opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } to { transform: translateX(34px); opacity: 0; } }
#chart .glint { animation: glint 4s ease-in-out infinite; }
@keyframes glint { 0%, 100% { opacity: 0; } 50% { opacity: .9; } }
#chart .ripple { animation: ripple 3.2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes ripple { from { transform: scale(.5); opacity: .9; } to { transform: scale(1.8); opacity: 0; } }
#chart .rain { stroke-dasharray: 10 60; animation: rain 1.2s linear infinite; }
@keyframes rain { from { transform: translate(0, -20px); opacity: 0; } 20% { opacity: 1; } to { transform: translate(-8px, 40px); opacity: 0; } }
#chart .cloud { animation: cloud 5s ease-in-out infinite; }
@keyframes cloud { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(6px, 2px); } }
#chart .bolt { animation: bolt 6s linear infinite; opacity: 0; }
@keyframes bolt { 0%, 86%, 100% { opacity: 0; } 88%, 92% { opacity: 1; } 90% { opacity: .2; } }
#chart .streak { stroke-dasharray: 40 90; animation: streak 2.2s linear infinite; }
@keyframes streak { from { transform: translateX(-30px); opacity: 0; } 20% { opacity: 1; } to { transform: translateX(120px); opacity: 0; } }
#chart .caps { animation: caps 1.6s ease-in-out infinite; }
@keyframes caps { 50% { opacity: .3; } }
#chart .ring { animation: spin 9s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(-360deg); } }
#chart .beam { animation: beam 7s linear infinite; transform-box: fill-box; transform-origin: 3px 50%; }
@keyframes beam { to { transform: rotate(360deg); } }
#chart .smoke { animation: smoke 3.6s linear infinite; transform-box: fill-box; }
@keyframes smoke { from { transform: translateY(0); opacity: 0; } 20% { opacity: .9; } to { transform: translateY(-18px); opacity: 0; } }
#chart .twinkle { animation: twinkle 2.6s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .35; } }
#chart .pirate-ship .bob { animation-duration: 2.4s; }
#chart .dest { animation: pulse-dest 1.8s ease-in-out infinite; }
@keyframes pulse-dest { 50% { stroke-opacity: .5; } }
#chart .course { animation: march 1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -15; } }
#chart .swell { animation: swell 14s linear infinite; }
@keyframes swell { to { transform: translateX(60px); } }
@media (prefers-reduced-motion: reduce) {
  #chart .wave, #chart .glint, #chart .ripple, #chart .rain, #chart .cloud, #chart .bolt, #chart .streak, #chart .caps, #chart .ring, #chart .beam, #chart .smoke, #chart .twinkle, #chart .bob, #chart .dest, #chart .course, #chart .swell { animation: none !important; }
  #chart .shipg { transition-duration: .5s; } #chart .wxlayer { transition-duration: .6s; } .clock.hurry { animation: none; }
}

@media (max-width: 1300px) { #game { grid-template-columns: 200px minmax(0, 1fr) 460px; } #compass { width: 200px; height: 200px; } .acts { grid-template-columns: repeat(2, 70px); } .act { width: 70px; height: 70px; } }

/* ===== Phones and small tablets: chart in the middle, a tabbed dock below ===== */
@media (max-width: 900px) {
  :root { font-size: 16px; }
  #game { display: grid; gap: 6px; padding: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto auto; grid-template-areas: "top" "stage" "panel" "dock"; }
  #top { gap: 4px; }
  #daybox { padding: 4px 6px; gap: 6px; width: 100%; justify-content: center; }
  .dayframe { padding: 2px 8px; } #daybox .day { font-size: 1.15rem; } #daybox .sub { display: none; } .clock { font-size: 1.6rem; min-width: 70px; }
  .daybtns .ibtn, #daybox .ibtn { width: 44px; height: 44px; } .pip { width: 14px; height: 14px; }
  #notices { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; justify-content: flex-start; scrollbar-width: none; padding: 2px 0; }
  .ntc { flex: none; font-size: .95rem; padding: 5px 10px; }
  #stage { grid-area: stage; min-height: 0; }
  #zoom { bottom: 8px; left: 8px; } #zoom .ibtn { width: 44px; height: 44px; }
  #tilebox { top: auto; left: 6px; right: 6px; bottom: 6px; width: auto; max-height: 70%; }
  #right { display: contents; }
  #players, #resbar, #logbox, #orders { grid-area: panel; display: none; max-height: 38vh; min-height: 0; overflow: auto; }
  #game[data-tab="orders"] #orders { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px; overflow: hidden; }
  #game[data-tab="hold"] #resbar { display: flex; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; }
  #game[data-tab="captains"] #players { display: flex; flex-direction: column; }
  #game[data-tab="log"] #logbox { display: flex; min-height: 30vh; }
  #logbox.collapsed { width: auto; } #logbox .tabs .ibtn { width: 48px; height: 44px; }
  #compass { width: 170px; height: 170px; flex: none; }
  .acts { grid-template-columns: repeat(3, 56px); gap: 6px; }
  .act { width: 56px; height: 56px; } .act svg { width: 26px; height: 26px; } .act span { font-size: .75rem; } .act .cnt { font-size: .8rem; }
  .act.readybtn { display: none; }
  .plan { font-size: .95rem; max-width: 100%; gap: 2px 8px; margin-top: 4px; } .plan b { font-size: 1.05rem; } .pn svg { width: 22px; height: 22px; }
  #orders > div:first-child { display: flex; flex-direction: column; align-items: center; min-width: 0; }
  .res { min-width: 84px; padding: 6px 4px; } .res svg { width: 44px; height: 44px; } .res .n { font-size: 1.3rem; } .sb { width: 40px; height: 40px; }
  .pcard { min-width: 0; }
  #dock { grid-area: dock; display: flex; gap: 6px; padding: 6px; align-items: stretch; }
  .dtab { flex: 1 1 0; min-width: 0; height: 56px; padding: 0; border-radius: 10px; background: rgba(255,255,255,.07); color: var(--parch); box-shadow: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; }
  .dtab svg { width: 26px; height: 26px; } .dtab span { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; opacity: .85; }
  .dtab.on { background: rgba(255,214,102,.22); box-shadow: inset 0 0 0 2px #ffd166; }
  .dtab .cnt { position: absolute; top: 4px; right: 8px; font-size: .65rem; background: #ff6b5a; border-radius: 999px; padding: 0 5px; }
  .dready { flex: 1.4 1 0; height: 56px; border-radius: 10px; background: var(--gold); color: var(--ink); box-shadow: 0 2px 0 var(--gold-dark); display: flex; align-items: center; justify-content: center; gap: 6px; font-family: 'IM Fell English SC', serif; font-size: 1.25rem; padding: 0; }
  .dready svg { width: 28px; height: 28px; } .dready.on { background: var(--good); color: #fff; box-shadow: 0 2px 0 #1d5635; }
  #toasts { top: 64px; bottom: auto; max-width: calc(100vw - 24px); } .toast { font-size: 1rem; padding: 10px 14px; }
  #tooltip { display: none; }
  .modal { max-height: 86vh; }
  .screen button, .screen input[type=text], .screen input[type=number], .screen select, .modal button { min-height: 44px; }
  input[type=checkbox] { width: 26px; height: 26px; vertical-align: -6px; margin-right: 6px; }
  .screen button.small { padding: 8px 14px; font-size: 1rem; }
  .settings { grid-template-columns: 1fr; }
}
/* Landscape phone: chart left, dock column right */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  #game { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top top" "stage panel" "stage dock"; }
  #players, #resbar, #logbox, #orders { max-height: none; }
  #game[data-tab="orders"] #orders { flex-direction: column; overflow: auto; }
  #game[data-tab="hold"] #resbar { flex-wrap: wrap; overflow: auto; }
  #compass { width: 150px; height: 150px; }
  #daybox { width: auto; }
}

/* ===== Day transition: resources lift, get crossed out and fade; gains fly to the bank ===== */
.fly { position: fixed; z-index: 70; pointer-events: none; display: grid; place-items: center; }
.fly > svg:first-child { width: 100%; height: 100%; }
.fly .xmark { position: absolute; inset: -8px; width: auto; height: auto; opacity: 0; }
.fly .xmark path { stroke: #ff5a45; stroke-width: 3.4; stroke-linecap: round; fill: none; stroke-dasharray: 24; stroke-dashoffset: 24; filter: drop-shadow(0 0 4px rgba(0,0,0,.6)); }
.fly.crossed .xmark { opacity: 1; }
.fly.crossed .xmark path { animation: drawx .26s ease-out forwards; }
.fly.crossed .xmark path:nth-child(2) { animation-delay: .12s; }
@keyframes drawx { to { stroke-dashoffset: 0; } }
.fly.glow { filter: drop-shadow(0 0 10px #ffd166) drop-shadow(0 0 24px rgba(255,209,102,.75)); }
.res.shake, #resbar.shake { animation: shake .55s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake { 10%, 90% { transform: translate3d(-1px, 0, 0); } 20%, 80% { transform: translate3d(2px, 0, 0); } 30%, 50%, 70% { transform: translate3d(-4px, 0, 0); } 40%, 60% { transform: translate3d(4px, 0, 0); } }
.res .n.bump { display: inline-block; }
.res .n.bump.up { animation: bumpup .45s ease-out; color: #9fe0b4; }
.res .n.bump.down { animation: bumpdown .45s ease-out; color: #ff9c8c; }
@keyframes bumpup { 0% { transform: scale(1); } 40% { transform: scale(1.5); } 100% { transform: scale(1); } }
@keyframes bumpdown { 0% { transform: scale(1); } 40% { transform: scale(.7); } 100% { transform: scale(1); } }
.res.glow { box-shadow: inset 0 0 0 2px #ffd166, 0 0 22px rgba(255,209,102,.8); transition: box-shadow .3s; }
#resbar.replaying { box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 0 0 0 2px rgba(255,214,102,.45); }
@media (prefers-reduced-motion: reduce) { .fly { display: none; } .res.shake, #resbar.shake { animation: none; } }
