:root {
  --ink: #3a2615;
  --wood: #c8783c;
  --wood-d: #8e5428;
  --cream: #fff6e3;
  --green: #43b84b;
  --green-d: #2e8c35;
  --sea: #2aa7e3;
  --red: #e24a3b;
  --font: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #8fd3ef;
  font-family: var(--font); color: var(--ink);
  user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.top {
  position: absolute; top: calc(10px + var(--safe-t)); left: 12px; right: 12px;
  display: flex; gap: 8px; align-items: center; justify-content: space-between;
}
.pill {
  background: var(--cream); border: 3px solid var(--wood-d); border-radius: 999px;
  box-shadow: 0 4px 0 var(--wood-d); padding: 2px 14px; font-weight: 800; font-size: 20px;
  display: flex; align-items: center; gap: 6px; min-height: 40px;
}
.money { font-size: 24px; padding-left: 8px; transition: transform .12s; }
.money.bump { animation: bump .25s; }
@keyframes bump { 50% { transform: scale(1.15); } }
.coin { font-size: 22px; }
.lvl { flex-direction: column; gap: 0; align-items: stretch; padding: 3px 12px; font-size: 15px; line-height: 1.1; min-width: 74px; }
.lvl .bar { height: 7px; background: #e8d3b0; border-radius: 9px; overflow: hidden; margin-top: 2px; }
.lvl .bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width .4s; }
.net { font-size: 14px; min-width: 52px; justify-content: center; color: var(--green-d); }
.net.off { color: #999; }
.net.off::before { content: "⚠ "; }

#objective {
  position: absolute; top: calc(64px + var(--safe-t)); left: 50%; transform: translate(-50%, -8px);
  background: rgba(58, 38, 21, .82); color: #fff; padding: 4px 16px; border-radius: 999px;
  font-weight: 700; font-size: 16px; white-space: nowrap; opacity: 0; transition: .25s;
}
#objective.show { opacity: 1; transform: translate(-50%, 0); }

.side { position: absolute; right: 12px; top: calc(110px + var(--safe-t)); display: flex; flex-direction: column; gap: 10px; }
.round {
  pointer-events: auto; position: relative; width: 52px; height: 52px; border-radius: 16px;
  background: var(--cream); border: 3px solid var(--wood-d); box-shadow: 0 4px 0 var(--wood-d);
  font-size: 24px; display: grid; place-items: center; padding: 0;
}
.round:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-d); }
#upgDot { position: absolute; top: -5px; right: -5px; width: 16px; height: 16px; border-radius: 50%; background: var(--red); border: 2px solid #fff; display: none; }
#upgDot.on { display: block; animation: bump 1s infinite; }

/* ---------- joystick ---------- */
#joy {
  position: fixed; width: 116px; height: 116px; border-radius: 50%;
  background: rgba(255, 255, 255, .25); border: 3px solid rgba(255, 255, 255, .6);
  transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: opacity .1s;
}
#joy.on { opacity: 1; }
#knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255, 255, 255, .9); box-shadow: 0 3px 8px rgba(0, 0, 0, .25); transform: translate(-50%, -50%);
}

#toast {
  position: fixed; left: 50%; bottom: calc(40px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--cream); border: 3px solid var(--wood-d); border-radius: 16px; padding: 8px 18px;
  font-weight: 800; font-size: 18px; opacity: 0; transition: .25s; pointer-events: none; text-align: center; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- panels ---------- */
#overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 40, .45); display: none;
  align-items: center; justify-content: center; padding: 16px;
}
#overlay.show { display: flex; }
.panel {
  display: none; width: min(440px, 100%); max-height: 82vh; overflow: auto;
  background: var(--cream); border: 4px solid var(--wood-d); border-radius: 24px;
  box-shadow: 0 8px 0 var(--wood-d); padding: 14px 16px 18px; animation: pop .25s;
}
.panel.show { display: block; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.panel header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.panel h2 { margin: 0; font-size: 26px; }
.panel header button { background: var(--red); color: #fff; border: 0; width: 38px; height: 38px; border-radius: 12px; font-size: 20px; font-weight: 800; box-shadow: 0 3px 0 #a3271b; }
.muted { color: #8a6d52; margin: 4px 0 10px; }
.small { font-size: 13px; }

.upg { display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid #ecd3ad; border-radius: 16px; padding: 8px 10px; margin-bottom: 8px; }
.upg .ic { font-size: 30px; width: 44px; text-align: center; }
.upg .info { flex: 1; min-width: 0; }
.upg b { display: block; font-size: 17px; line-height: 1.1; }
.upg small { display: block; color: #8a6d52; font-size: 13px; line-height: 1.2; }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 12px; height: 6px; border-radius: 3px; background: #ecd3ad; }
.pips i.on { background: var(--green); }
.buy {
  background: var(--green); color: #fff; border: 0; border-radius: 12px; padding: 8px 12px;
  font-weight: 800; font-size: 16px; box-shadow: 0 4px 0 var(--green-d); white-space: nowrap;
}
.buy:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-d); }
.buy:disabled { background: #b9b0a4; box-shadow: 0 4px 0 #8f877c; }

#boardList .row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: #fff; margin-bottom: 6px; border: 2px solid #ecd3ad; }
#boardList .row.me { border-color: var(--green); background: #eefbe9; }
.rk { width: 32px; text-align: center; font-weight: 800; font-size: 18px; }
.nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv { color: #8a6d52; font-size: 14px; }
.sc { font-weight: 800; }

.lbl { font-weight: 700; display: block; margin: 6px 0 4px; }
.namebox { display: flex; gap: 8px; margin-bottom: 12px; }
.namebox input { flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 8px 12px; border-radius: 12px; border: 2px solid #ecd3ad; background: #fff; }
.wide { display: block; width: 100%; margin-bottom: 10px; padding: 10px; font-size: 17px; font-weight: 800; border-radius: 14px; border: 3px solid var(--wood-d); background: #fff; box-shadow: 0 4px 0 var(--wood-d); color: var(--ink); }
.wide.danger { border-color: #a3271b; color: #a3271b; box-shadow: 0 4px 0 #a3271b; }

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  background: radial-gradient(circle at 50% 35%, #7fd3f7, #2196d3 70%); color: #fff; transition: opacity .4s;
}
#loading.hide { opacity: 0; pointer-events: none; }
.logo { text-align: center; }
.logo .fish { font-size: 84px; animation: swim 2s ease-in-out infinite; }
@keyframes swim { 50% { transform: translateY(-10px) rotate(-8deg); } }
.logo h1 { margin: 0; font-size: 56px; line-height: .9; text-shadow: 0 5px 0 #0d5f8f; letter-spacing: 1px; }
.logo h1 span { color: #ffd23f; font-size: 72px; }
.logo p { margin: 10px 0 0; font-weight: 700; opacity: .9; }
#btnPlay {
  display: none; font-size: 30px; font-weight: 800; padding: 10px 56px; border-radius: 22px; border: 0;
  background: var(--green); color: #fff; box-shadow: 0 6px 0 var(--green-d); animation: bump 1.2s infinite;
}
#loading.ready #btnPlay { display: block; }
#loading.ready .spinner { display: none; }
.spinner { font-weight: 700; opacity: .85; }

@media (min-width: 800px) {
  .pill { font-size: 22px; }
  .money { font-size: 28px; }
}
