:root {
  --ink: #15304f;
  --panel: rgba(8, 30, 60, 0.6);
  --blue: #1a7fd6;
  --deep: #0f4f86;
  --gold: #ffc61a;
  --p0: #ff7a1a;
  --p1: #2f8cff;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfeeff; color: #fff; overscroll-behavior: none; }
button { font: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
kbd {
  font: 700 0.85em/1 ui-monospace, monospace;
  padding: 0.15em 0.4em;
  border-radius: 0.3em;
  background: #eef5ff;
  border: 1px solid #c4d6ee;
  color: var(--ink);
}

/* ---------- Scene ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#split { position: absolute; left: 50%; top: 18%; bottom: 0; width: 0; border-left: 3px dashed rgba(255, 255, 255, 0.25); pointer-events: none; display: none; }
[data-players='2'][data-phase='play'] #split { display: block; }
.pop-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800; font-size: clamp(20px, 3.8vmin, 38px); line-height: 1;
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 4px #15304f;
  paint-order: stroke;
  animation: float-up 1.1s ease-out both;
}
.pop-label.gold { color: #ffe17a; }
.pop-label.bad { color: #ff7b54; }
.pop-label.big { font-size: clamp(30px, 7vmin, 70px); }
@keyframes float-up {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  15% { transform: translate(-50%, -80%) scale(1.15); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -220%) scale(1); opacity: 0; }
}

/* ---------- Top: toolbar and clock ---------- */
#hud-top {
  position: fixed; left: 0; right: 0; top: 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  z-index: 10;
  pointer-events: none;
}
#toolbar { display: flex; gap: 6px; pointer-events: auto; }
#toolbar button {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: none;
  background: var(--panel);
  font-size: 20px; font-weight: 800;
  cursor: pointer;
  color: #fff;
  display: grid; place-items: center;
}
#toolbar button:hover { background: rgba(8, 30, 60, 0.85); }
#clock {
  display: flex; flex-direction: column; align-items: center;
  background: var(--panel);
  border-radius: 22px;
  padding: 0 24px 4px;
  min-width: 130px;
}
#time { font-size: clamp(32px, 6vmin, 56px); line-height: 1.1; font-variant-numeric: tabular-nums; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); }
#frenzy-tag { display: none; font-size: clamp(14px, 2.4vmin, 20px); font-weight: 800; color: #ffe17a; line-height: 1; }
#clock.frenzy { background: linear-gradient(180deg, #ff9a3c, #d2361b); animation: throb 0.6s ease-in-out infinite; }
#clock.frenzy #frenzy-tag { display: block; }
#clock.endless #time { font-size: clamp(20px, 3.6vmin, 30px); }
@keyframes throb { 50% { transform: scale(1.06); } }
[data-phase='load'] #clock, [data-phase='menu'] #clock { visibility: hidden; }
[data-phase='load'] #toolbar [data-action=menu], [data-phase='menu'] #toolbar [data-action=menu] { display: none; }

/* ---------- Banner ---------- */
#banner {
  position: fixed; left: 50%; top: 24%;
  transform: translate(-50%, -50%) scale(0.6);
  max-width: 90vw;
  text-align: center;
  font-size: clamp(22px, 4.6vmin, 44px); font-weight: 800; line-height: 1.15;
  padding: 8px 28px 10px;
  border-radius: 24px;
  background: var(--panel);
  opacity: 0;
  pointer-events: none;
  z-index: 11;
  transition: opacity 0.3s, transform 0.3s;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); transition: opacity 0.2s, transform 0.35s cubic-bezier(.2, .9, .3, 1.5); }
#banner small { display: block; font-size: 0.5em; font-weight: 700; opacity: 0.9; letter-spacing: 0.08em; text-transform: uppercase; }
#banner.hot { background: linear-gradient(180deg, #ff9a3c, #d2361b); box-shadow: 0 8px 0 #7a1a08; font-size: clamp(30px, 7vmin, 64px); }
#banner.danger { background: linear-gradient(180deg, #5d6b7a, #1e2a38); box-shadow: 0 8px 0 #0a1018; }
#banner.prize { background: linear-gradient(180deg, #ffd84a, #e09a00); color: #4a2a00; box-shadow: 0 8px 0 #8a5a00; }

/* ---------- Player panels ---------- */
#panels {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 12px;
  padding: 0 max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  z-index: 10; pointer-events: none;
}
[data-players='2'] #panels { justify-content: space-between; }
[data-players='1'] .pl[data-i='1'] { display: none; }
[data-phase='load'] #panels, [data-phase='menu'] #panels, [data-phase='end'] #panels { display: none; }
.pl {
  --c: var(--p0);
  width: min(420px, 46vw);
  background: var(--panel);
  border-radius: 22px;
  border-bottom: 6px solid var(--c);
  padding: 6px 16px 10px;
}
.pl[data-i='1'] { --c: var(--p1); }
.pl-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pl-name { font-size: clamp(16px, 2.6vmin, 22px); font-weight: 800; color: var(--c); filter: brightness(1.25); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-score { font-size: clamp(30px, 5.6vmin, 50px); line-height: 1; font-variant-numeric: tabular-nums; }
.pl-score.bump { animation: bump 0.4s; }
@keyframes bump { 40% { transform: scale(1.35); color: #ffe17a; } }
.pl-say { font-size: clamp(16px, 2.8vmin, 24px); font-weight: 800; line-height: 1.15; min-height: 1.2em; }
.pl-say.strike { color: #ffe17a; font-size: clamp(26px, 5vmin, 44px); animation: shake 0.15s linear infinite; }
.pl-say.pull { color: #ff8a6a; }
@keyframes shake { 25% { transform: translateX(-3px) rotate(-1deg); } 75% { transform: translateX(3px) rotate(1deg); } }
.pl-bar {
  position: relative;
  height: 18px; margin-top: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
  visibility: hidden;
}
.pl-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 999px; background: #7ee07e; }
.pl-bar.power i { background: linear-gradient(90deg, #7ee07e, #ffd23f, #ff7a3a); }
.pl-bar.tension i { background: #7ee07e; }
.pl-bar.tension.mid i { background: #ffd23f; }
.pl-bar.tension.high i { background: #ff4a3a; }
.pl-bar.tension.pulling { box-shadow: 0 0 0 3px #ff4a3a; animation: shake 0.12s linear infinite; }
.pl-bar.show { visibility: visible; }
.pl-zone { position: absolute; right: 0; top: 0; bottom: 0; width: 15%; background: repeating-linear-gradient(45deg, rgba(255, 60, 40, 0.5) 0 6px, transparent 6px 12px); display: none; }
.pl-bar.tension .pl-zone { display: block; }
.pl-powers { display: flex; gap: 6px; margin-top: 4px; font-size: 15px; font-weight: 800; min-height: 0; }
.pl-powers span { background: rgba(255, 210, 60, 0.25); border-radius: 999px; padding: 0 10px; }
.pl-key { font-size: 13px; font-weight: 700; opacity: 0.75; margin-top: 2px; }

/* ---------- Catch cards ---------- */
#cards { position: fixed; inset: 0; pointer-events: none; z-index: 12; }
.card {
  position: absolute; top: 14%; left: 50%;
  transform: translateX(-50%);
  width: min(360px, 44vw);
  background: #fff;
  color: var(--ink);
  border-radius: 24px;
  padding: 10px 16px 12px;
  text-align: center;
  border: 6px solid var(--p0);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  animation: pop-in 0.45s cubic-bezier(.2, .9, .3, 1.4) both;
}
[data-players='2'] .card[data-i='0'] { left: 25%; }
[data-players='2'] .card[data-i='1'] { left: 75%; border-color: var(--p1); }
.card.legend { background: linear-gradient(180deg, #fff6d0, #ffe28a); border-color: #ffb800 !important; }
.card.junk { background: #eef1f4; }
.card.out { animation: pop-out 0.3s ease-in both; }
@keyframes pop-in { from { scale: 0.3; rotate: -8deg; opacity: 0; } }
@keyframes pop-out { to { scale: 0.6; opacity: 0; } }
.card img { width: 100%; max-width: 200px; height: auto; aspect-ratio: 200 / 140; display: block; margin: -4px auto -6px; }
.card .tier { display: inline-block; font-size: 13px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; padding: 0 10px; border-radius: 999px; background: #e3edf8; }
.tier.uncommon { background: #c9f0d2; color: #1d6b33; }
.tier.rare { background: #d4e4ff; color: #1a4fb4; }
.tier.legend { background: #ffb800; color: #fff; }
.tier.release { background: #d0f4f4; color: #15706f; }
.tier.junk { background: #dfe3e8; color: #5a6676; }
.card .name { font-size: clamp(22px, 3.6vmin, 32px); font-weight: 800; line-height: 1.05; margin-top: 2px; }
.card .kg { font-size: 17px; font-weight: 700; color: #4a6080; }
.card .pts { font-size: clamp(28px, 5vmin, 42px); font-weight: 800; color: #1a7f3a; line-height: 1; }
.card .new { position: absolute; top: -14px; right: -10px; background: #ff3d6e; color: #fff; font-weight: 800; padding: 2px 12px; border-radius: 999px; transform: rotate(8deg); font-size: 18px; }
.card .note { font-size: 15px; font-weight: 700; color: #4a6080; }

/* ---------- Menu, book and results ---------- */
#setup, #result, #book {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 20;
  overflow: auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
#setup { background: linear-gradient(90deg, rgba(5, 25, 55, 0.6), rgba(5, 25, 55, 0.1) 70%); place-items: center start; padding-left: max(4vw, env(safe-area-inset-left)); }
#result, #book { background: radial-gradient(ellipse at center, rgba(5, 25, 55, 0.25), rgba(5, 25, 55, 0.65)); animation: fade 0.4s both; }
#book { z-index: 25; }
@keyframes fade { from { opacity: 0; } }
.panel {
  width: min(640px, 94vw);
  background: rgba(255, 255, 255, 0.97);
  color: var(--ink);
  border-radius: 28px;
  padding: 20px 26px 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.panel.wide { width: min(980px, 96vw); max-height: 92vh; overflow: auto; }
.logo {
  margin: 0; font-size: clamp(44px, 9vmin, 72px); line-height: 1; font-weight: 800;
  background: linear-gradient(180deg, #4fc3ff, #1a7fd6 55%, #0f4f86);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.tagline { margin: 6px 0 8px; font-size: clamp(15px, 2.2vmin, 18px); line-height: 1.35; color: #3a5070; }
.row { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.row h2, .panel h2 { margin: 0; font-size: 18px; min-width: 64px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button, .places button, .animals button {
  border: 3px solid #dbe7f5;
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  padding: 2px 14px;
  font-size: 17px; font-weight: 700;
  cursor: pointer;
}
.seg button[aria-pressed='true'], .places button[aria-pressed='true'] { border-color: var(--blue); background: #e5f2ff; }
.places { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; flex: 1; }
.places button { padding: 4px 8px; text-align: left; line-height: 1.15; }
.places b { display: block; font-size: 17px; }
.places small { display: block; font-size: 13px; font-weight: 600; color: #5a7090; }
#who { display: grid; gap: 6px; margin-top: 8px; }
.who-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 8px; border-radius: 16px; background: #f3f7fc; border-left: 6px solid var(--p0); }
.who-row[data-i='1'] { border-left-color: var(--p1); }
.who-row input {
  font: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  width: 9em; padding: 2px 10px; border-radius: 12px; border: 2px solid #c8d8ea;
}
.animals { display: flex; gap: 4px; flex-wrap: wrap; }
.animals button { padding: 0 8px; font-size: 26px; line-height: 1.3; }
.animals button[aria-pressed='true'] { border-color: var(--p0); background: #fff1e5; }
.who-row[data-i='1'] .animals button[aria-pressed='true'] { border-color: var(--p1); background: #e5f0ff; }
.who-row .keys { font-size: 13px; font-weight: 700; color: #5a7090; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.buttons button {
  border: none;
  border-radius: 999px;
  font-size: 22px; font-weight: 800;
  padding: 8px 30px;
  cursor: pointer;
}
.buttons .primary { background: var(--blue); color: #fff; box-shadow: 0 6px 0 #0a3a6a; font-size: 26px; padding: 8px 40px; }
.buttons .primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #0a3a6a; }
.buttons .primary:disabled { opacity: 0.5; cursor: wait; }
.secondary { background: #e3edf8; color: var(--ink); box-shadow: 0 6px 0 #b4c7de; border: none; border-radius: 999px; font-weight: 800; cursor: pointer; }
.secondary.small { font-size: 17px; padding: 4px 18px; box-shadow: 0 4px 0 #b4c7de; }
#loading { font-size: 17px; font-weight: 700; color: #5a7090; }
#offline-status { margin: 10px 0 0; font-size: 14px; font-weight: 700; color: #2e7d4a; }
.help { margin-top: 10px; font-size: 15px; color: #3a5070; }
.help summary { cursor: pointer; font-weight: 700; }
.help ul { padding-left: 20px; line-height: 1.45; margin: 6px 0 0; }

.book-head { display: flex; align-items: center; gap: 14px; position: sticky; top: -20px; background: #fff; padding: 4px 0 8px; z-index: 1; }
.book-head h2 { font-size: 30px; }
#book-total { font-weight: 700; color: #5a7090; flex: 1; }
.book-place h3 { margin: 10px 0 6px; font-size: 20px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.fish-card { background: #f3f7fc; border-radius: 16px; padding: 4px 8px 8px; text-align: center; border: 3px solid transparent; }
.fish-card img { width: 100%; height: auto; aspect-ratio: 200 / 140; display: block; }
.fish-card.locked img { filter: brightness(0) opacity(0.25); }
.fish-card b { display: block; font-size: 16px; line-height: 1.1; }
.fish-card small { display: block; font-size: 13px; font-weight: 700; color: #5a7090; }
.fish-card.legend { border-color: #ffb800; background: #fff8e0; }
.fish-card.rare { border-color: #9cc0ff; }

#result .panel { text-align: center; width: min(640px, 94vw); }
#result p { margin: 0; }
.kicker { font-size: clamp(30px, 6vmin, 48px); font-weight: 800; color: var(--deep); line-height: 1.1; }
#result-players { display: flex; gap: 12px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.res { flex: 1; min-width: 220px; background: #f3f7fc; border-radius: 20px; padding: 8px 12px 10px; border-top: 8px solid var(--p0); }
.res[data-i='1'] { border-top-color: var(--p1); }
.res.win { background: #fff6d0; }
.res .who { font-size: 22px; font-weight: 800; }
.res .big { font-size: clamp(48px, 10vmin, 80px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.res .crown { font-size: 34px; line-height: 1; }
.res ul { list-style: none; padding: 0; margin: 4px 0 0; font-size: 15px; font-weight: 700; color: #3a5070; line-height: 1.4; }
#result-note { font-size: 17px; font-weight: 700; color: #b36b00; }
#result .buttons { justify-content: center; }

/* Phones on their side: keep the menu short */
@media (max-height: 560px) {
  .panel { padding: 10px 16px; border-radius: 20px; }
  .tagline, .help { display: none; }
  .logo { font-size: 36px; }
  #setup { place-items: center; }
  .pl-key { display: none; }
}
@media (max-width: 640px) {
  #setup { place-items: end center; padding-left: 12px; background: linear-gradient(0deg, rgba(5, 25, 55, 0.6), rgba(5, 25, 55, 0.1) 70%); }
  .panel { padding: 12px 14px; }
  .tagline { font-size: 14px; }
  .places { grid-template-columns: 1fr; }
  .places small { display: none; }
  .buttons button { flex: 1; padding: 8px 12px; white-space: nowrap; }
  .buttons .primary { font-size: 22px; padding: 8px 12px; }
  #toolbar button { width: 40px; height: 40px; }
  #toolbar [data-action=fullscreen] { display: none; }
  .pl { padding: 4px 10px 8px; }
  .pl-key { display: none; }
  .card { width: 46vw; padding: 6px 8px; }
  .card .kg, .card .note { font-size: 13px; }
}
[data-players='1'] #panels { justify-content: flex-start; }
[data-players='1'] .card { left: auto; right: max(16px, 4vw); transform: none; }
