:root {
  --sea: #0f2a44;
  --sea-dark: #08182a;
  --panel: #13385a;
  --frame: #ffc94a;
  --ink: #f4fbff;
  --muted: #a9c8e0;
  --accent: #ffb020;
  --accent-ink: #2a1600;
  --red: #e8473c;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink); font-family: var(--font); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; color: var(--ink); cursor: pointer;
  background: #1e5a86; border: 2px solid #3d86b8; border-bottom-width: 4px; border-radius: 12px;
  padding: 8px 14px; font-size: 1rem; line-height: 1.1;
  transition: transform 0.06s ease, background 0.15s;
}
.btn:hover { background: #276a9c; }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: #c47c00; }
.btn.primary:hover { background: #ffc24d; }
.btn.huge { font-size: 1.5rem; padding: 14px 28px; width: 100%; margin-top: 16px; }
.btn.round { width: 46px; height: 46px; padding: 0; font-size: 1.3rem; border-radius: 50%; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- panels & lobby ---------- */
.panel {
  background: var(--panel); border: 6px solid var(--frame); border-radius: 22px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 0 40px rgba(255, 201, 74, 0.2); padding: 22px;
}
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  padding: 16px; z-index: 20; overflow-y: auto;
  background:
    radial-gradient(circle at 78% 16%, rgba(255, 236, 170, 0.95) 0 40px, rgba(255, 200, 120, 0.25) 44px, transparent 120px),
    linear-gradient(180deg, #ff9a5c 0%, #ff7a6a 22%, #6b4f8a 48%, #1b4a72 70%, var(--sea-dark) 100%);
}
h1 { margin: 0 0 8px; font-size: 2.4rem; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4), 0 0 18px rgba(255, 201, 74, 0.6); }
.lobby-panel { width: min(540px, 100%); }
.lobby-panel label { display: block; font-weight: 700; margin: 14px 0 6px; }
.lobby-panel small { color: var(--muted); font-weight: 400; }
.tagline { color: var(--muted); margin: 0; }
input {
  font: inherit; font-size: 1.2rem; width: 100%; margin-top: 6px; padding: 10px 12px; color: var(--ink);
  background: var(--sea-dark); border: 2px solid #3d86b8; border-radius: 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--accent); }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 4px solid transparent; background: var(--c); cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
.swatch.on { border-color: #fff; transform: scale(1.1); }
.how { margin-top: 14px; font-size: 0.92rem; color: var(--muted); }
.how p { margin: 6px 0; }
#lobby-msg { min-height: 1.2em; margin: 10px 0 0; text-align: center; }

.loading-panel { text-align: center; font-size: 1.3rem; font-weight: 700; }
.spin { font-size: 4rem; animation: bob 1s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-6px) rotate(-6deg); } to { transform: translateY(6px) rotate(6deg); } }

/* ---------- in game ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: flex-start; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); pointer-events: none;
}
.top .col { display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.top .col.right { margin-left: auto; align-items: flex-end; }
.top .row { display: flex; gap: 6px; align-items: center; }
.top .row > *, .top .players > * { pointer-events: auto; }
.pill { background: rgba(8, 24, 42, 0.72); border-radius: 999px; padding: 7px 14px; font-weight: 700; white-space: nowrap; }
.clock { min-width: 150px; text-align: center; }
.clock.night { background: rgba(30, 20, 70, 0.85); box-shadow: 0 0 14px rgba(140, 120, 255, 0.5); }
.clock.dusk { background: rgba(120, 50, 20, 0.85); box-shadow: 0 0 14px rgba(255, 140, 60, 0.6); }
.lh-pill { display: flex; align-items: center; gap: 8px; padding: 5px 12px; }
.bar { width: 110px; height: 14px; border-radius: 8px; background: rgba(255, 255, 255, 0.15); overflow: hidden; border: 2px solid rgba(255, 255, 255, 0.4); }
.bar > div { height: 100%; width: 100%; background: linear-gradient(90deg, #6bdc5b, #b7f05a); transition: width 0.25s; }
.bar > div.low { background: linear-gradient(90deg, #e8473c, #ff8a4a); animation: blink 0.6s infinite alternate; }
@keyframes blink { to { opacity: 0.55; } }
.hearts { font-size: 1.1rem; letter-spacing: 1px; padding: 5px 12px; }
.hearts.hurt { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.players { display: flex; gap: 6px; flex-wrap: wrap; max-width: 46vw; }
.chip { background: rgba(8, 24, 42, 0.72); border: 2px solid var(--c); border-radius: 999px; padding: 3px 10px; font-weight: 700; color: var(--c); font-size: 0.85rem; }
.chip.me { background: var(--c); color: #0b1d30; }
.chip.away { opacity: 0.4; }

.res {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 6px; pointer-events: none;
}
.res .r { background: rgba(8, 24, 42, 0.78); border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: 1.2rem; min-width: 70px; text-align: center; }
.res .r.pop { animation: pop-r 0.35s; }
@keyframes pop-r { 40% { transform: scale(1.3); background: rgba(255, 201, 74, 0.6); } }

.minimap {
  width: 120px; height: 120px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.55);
  background: #0b3a5c; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); pointer-events: none;
}

.boss {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: 10px;
  background: rgba(40, 10, 50, 0.85); border: 3px solid #d16bff; border-radius: 999px; padding: 6px 16px; font-size: 1.5rem;
}
.boss .bar { width: min(40vw, 260px); height: 16px; }
.boss .bar > div { background: linear-gradient(90deg, #b23cff, #ff5ad1); }

.banner {
  position: fixed; top: 112px; left: 50%; z-index: 6; transform: translate(-50%, -20px) scale(0.9); opacity: 0;
  max-width: min(92vw, 640px); text-align: center; font-size: clamp(1.05rem, 3.2vw, 1.5rem); font-weight: 800;
  background: rgba(19, 56, 90, 0.94); border: 4px solid #5fb6ff; border-radius: 18px; padding: 12px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
body.at-sea .banner { top: 136px; }
.banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.banner.gold { border-color: #ffcc33; box-shadow: 0 0 30px rgba(255, 204, 51, 0.5); }
.banner.green { border-color: #7ed957; }
.banner.orange { border-color: #ff8a1a; }
.banner.purple { border-color: #d58cff; box-shadow: 0 0 30px rgba(213, 140, 255, 0.45); }
.banner.red { border-color: var(--red); box-shadow: 0 0 30px rgba(232, 71, 60, 0.5); }

/* fishing */
.fishing {
  position: fixed; left: 50%; bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); transform: translateX(-50%); z-index: 6;
  background: rgba(8, 24, 42, 0.85); border: 4px solid #5fb6ff; border-radius: 22px; padding: 10px 22px; text-align: center;
  font-weight: 800; font-size: 1.3rem; pointer-events: none; min-width: 200px;
}
.fishing .float { font-size: 2.6rem; animation: bob 0.9s ease-in-out infinite alternate; }
.fishing.bite { border-color: #ffcc33; background: rgba(120, 80, 0, 0.9); animation: shake 0.25s infinite; }
.fishing.bite .float { animation: none; transform: translateY(14px) scale(1.2); }

/* ready */
.btn.ready {
  position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5;
  font-size: 1.15rem; padding: 10px 20px; background: #3a2a7a; border-color: #7a64e0;
}
.btn.ready.on { background: #6bdc5b; color: #0b2a0b; border-color: #3f9c34; }

/* boarding the raft */
.btn.sail {
  position: fixed; left: 50%; bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px)); transform: translateX(-50%); z-index: 5;
  font-size: 1.05rem; padding: 10px 18px; max-width: 46vw; background: #1e5a86; white-space: normal;
}
.btn.sail:active { transform: translateX(-50%) translateY(2px); }
.btn.sail.go { background: #4cc04a; border-color: #2e8a2c; color: #082408; font-size: 1.3rem; animation: pulse-sail 0.7s infinite alternate; }
@keyframes pulse-sail { to { box-shadow: 0 0 26px #7dff6a; } }

/* at sea */
.voyage {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 5; pointer-events: none;
  background: rgba(8, 24, 42, 0.8); border: 3px solid #5fb6ff; border-radius: 18px; padding: 6px 14px; min-width: 260px;
  font-weight: 800; text-align: center;
}
.voy-row { display: flex; align-items: center; gap: 10px; justify-content: center; }
.voyage .bar { width: 150px; }
.voyage .bar > div { background: linear-gradient(90deg, #5fb6ff, #9fe8ff); }
.voy-arrow { display: inline-block; font-size: 1.6rem; transition: transform 0.2s; }
#voy-hint { font-size: 0.95rem; }
#voy-hint.warn { color: #ffd23a; animation: blink 0.5s infinite alternate; }
.act.main.steer { background: #8a5a2a; }

.chart { position: fixed; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgba(8, 18, 36, 0.55); }
.chart-panel { width: min(480px, 100%); text-align: center; padding: 14px; }
.chart-panel h2 { margin: 0 0 8px; }
.chart-map {
  position: relative; width: min(380px, 80vw, 62vh); aspect-ratio: 1; margin: 0 auto; border-radius: 50%;
  background: radial-gradient(circle, #2f8fd6 0%, #1c6aa8 55%, #0e3d66 100%); border: 4px solid #e8d6a8; overflow: hidden;
}
.chart-ring { position: absolute; left: 50%; top: 50%; border: 2px dashed rgba(255, 255, 255, 0.3); border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.isle {
  position: absolute; transform: translate(-50%, -50%); border: 3px solid #fff; border-radius: 14px; background: rgba(8, 24, 42, 0.8);
  color: #fff; font: inherit; font-weight: 800; font-size: 0.7rem; padding: 2px 6px; cursor: pointer; line-height: 1.1; min-width: 54px;
}
.isle .ic { font-size: 1.6rem; display: block; }
.isle.fog { background: rgba(80, 90, 110, 0.85); border-style: dashed; }
.isle.here { border-color: #ffd23a; box-shadow: 0 0 16px #ffd23a; cursor: default; }
.isle.home { background: #b52a22; }
.isle:disabled { opacity: 0.9; }
#chart-note { min-height: 1.2em; margin: 8px 0; }

/* build bar */
.buildbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7; display: flex; gap: 8px; overflow-x: auto; align-items: flex-end;
  padding: 10px max(150px, calc(env(safe-area-inset-right) + 150px)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: linear-gradient(0deg, rgba(8, 24, 42, 0.92), rgba(8, 24, 42, 0)); touch-action: pan-x;
}
.card {
  flex: none; width: 92px; border-radius: 16px; padding: 6px 4px; text-align: center; cursor: pointer; font: inherit; color: var(--ink);
  background: #1e5a86; border: 3px solid #3d86b8; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.card .ic { font-size: 2rem; line-height: 1.1; }
.card .nm { font-size: 0.72rem; font-weight: 700; line-height: 1.1; min-height: 1.6em; }
.card .cs { font-size: 0.72rem; font-weight: 800; color: #ffe08a; }
.card.on { background: var(--accent); color: var(--accent-ink); border-color: #fff; transform: translateY(-6px); }
.card.on .cs { color: #5a2c00; }
.card.poor { opacity: 0.55; }
.card.locked { opacity: 0.35; filter: grayscale(1); }
.card.close { background: #7a2a2a; border-color: #c35050; }

/* the floating joystick */
.stick { position: fixed; left: 0; top: 0; z-index: 4; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity 0.15s; }
.stick.on { opacity: 1; }
.stick::before {
  content: ''; position: absolute; left: -70px; top: -70px; width: 140px; height: 140px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08); border: 3px solid rgba(255, 255, 255, 0.35);
}
.knob {
  position: absolute; left: -32px; top: -32px; width: 64px; height: 64px; border-radius: 50%;
  background: rgba(255, 176, 32, 0.75); border: 3px solid #fff; box-shadow: 0 0 16px rgba(255, 176, 32, 0.7);
}

.buttons {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 8;
  display: flex; gap: 12px; align-items: flex-end;
}
.small-btns { display: grid; grid-template-columns: repeat(2, auto); gap: 10px; align-items: end; }
.act {
  position: relative; border: 4px solid #fff; border-radius: 50%; cursor: pointer; font-size: 2.2rem; line-height: 1; padding: 0;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 22px rgba(255, 255, 255, 0.2); touch-action: none; color: #fff;
}
.act.main { width: 116px; height: 116px; background: #e8743c; font-size: 3.2rem; }
.act.main.place { background: #4cc04a; }
.act.main.remove { background: var(--red); }
.act.main.strike { background: #ffcc33; animation: pulse 0.25s infinite alternate; }
.act.main.fish { background: #2f8fd6; }
.act.main.feed { background: #ff7ab6; }
.act.small { width: 70px; height: 70px; font-size: 1.9rem; }
.act.throw { background: #7d8a96; }
.act.build { background: #a2662a; }
.act.build.on { background: var(--accent); }
.act.eat { background: #e85a7a; }
.act.beam { background: #ffd23a; }
.act.beam.wait { background: #6b6b4a; filter: grayscale(0.6); }
.act.down { transform: translateY(4px) scale(0.94); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
.act .count {
  position: absolute; right: -6px; bottom: -6px; background: #0b1d30; color: #fff; font-size: 0.85rem; font-weight: 800;
  border-radius: 999px; padding: 2px 7px; border: 2px solid #fff;
}
@keyframes pulse { to { transform: scale(1.08); box-shadow: 0 0 30px #ffcc33; } }

.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(8, 18, 36, 0.45); pointer-events: none; }
.overlay-panel { width: min(440px, 100%); text-align: center; animation: pop 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
.overlay-panel h2 { font-size: 2rem; margin: 8px 0; }
.end-big { font-size: 3.4rem; animation: wobble 0.5s ease-in-out infinite alternate; }
.overlay.ko { background: rgba(60, 0, 20, 0.35); }
.overlay.party { background: transparent; }
.overlay.party .panel { background: rgba(19, 56, 90, 0.8); }
@keyframes pop { from { transform: scale(0.5); opacity: 0; } }
@keyframes wobble { from { transform: rotate(-8deg); } to { transform: rotate(8deg) scale(1.08); } }

body.hurt #view { animation: hurt 0.35s; }
@keyframes hurt { 30% { filter: saturate(2) hue-rotate(-30deg) brightness(1.3); } }

@media (max-height: 560px) {
  .act.main { width: 92px; height: 92px; font-size: 2.6rem; }
  .act.small { width: 58px; height: 58px; font-size: 1.6rem; }
  .minimap { width: 90px; height: 90px; }
  .banner { top: 96px; }
  .res .r { font-size: 1rem; min-width: 56px; padding: 4px 9px; }
}
@media (max-width: 720px) {
  .res { top: auto; bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); left: auto; right: max(10px, env(safe-area-inset-right)); transform: none; flex-direction: column; align-items: flex-end; }
  .players { max-width: 60vw; }
}
