:root {
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, sans-serif;
  --navy: #04233f;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--navy); color: #fff;
  font-family: var(--font); font-weight: 700;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
body { position: fixed; inset: 0; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#safe { position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; padding: var(--sat) var(--sar) var(--sab) var(--sal); }
.hidden { display: none !important; }
button, input { font-family: inherit; }

/* ---------- screens */
.screen {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 14px) calc(var(--sab) + 12px) calc(var(--sal) + 14px);
  background: radial-gradient(ellipse at center, rgba(3, 24, 52, 0.42), rgba(2, 14, 34, 0.8));
  animation: fade 0.25s ease;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel {
  background: linear-gradient(180deg, rgba(18, 74, 122, 0.82), rgba(6, 36, 72, 0.9));
  border: 1.5px solid rgba(150, 225, 255, 0.35);
  border-radius: 24px; padding: 18px;
  box-shadow: 0 18px 50px rgba(0, 8, 30, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center; margin: auto; animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } to { transform: none; opacity: 1; } }
h2 { margin: 0; font-size: 26px; font-weight: 900; letter-spacing: 0.3px; text-shadow: 0 2px 0 rgba(0, 20, 50, 0.5); }
.muted { color: #b9dcf2; font-weight: 600; margin: 0; line-height: 1.35; }
.small { font-size: 13px; }

/* ---------- logo */
.menu-wrap { display: flex; flex-direction: column; align-items: center; gap: 18px; width: min(430px, 100%); margin: auto; }
.logo { text-align: center; line-height: 0.9; filter: drop-shadow(0 8px 18px rgba(0, 10, 40, 0.55)); animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.logo-crown { width: 86px; height: 60px; display: block; margin: 0 auto -6px; transform: rotate(-6deg); }
.logo-king, .logo-ocean {
  font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(180deg, #fffbd1 0%, #ffd84a 45%, #ff9d1c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  -webkit-text-stroke: 2px #6b3a00; paint-order: stroke fill;
  text-shadow: none;
}
.logo-king { font-size: 78px; }
.logo-ocean {
  font-size: 66px;
  background: linear-gradient(180deg, #e9fdff 0%, #6fe3ff 45%, #1b9be6 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-stroke: 2px #063a6e;
}
.logo-of { font-size: 17px; letter-spacing: 4px; text-transform: uppercase; color: #dff6ff; margin: 6px 0 4px; font-weight: 800; }
.tagline { margin-top: 12px; font-size: 15px; color: #c8ecff; font-weight: 700; letter-spacing: 0.4px; line-height: 1.2; }
.menu-panel { width: 100%; display: flex; flex-direction: column; gap: 10px; }

/* ---------- controls */
.name-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #b9dcf2; }
.name-row span { white-space: nowrap; }
input {
  -webkit-user-select: text; user-select: text;
  flex: 1; min-width: 0; height: 42px; border-radius: 13px; border: 1.5px solid rgba(150, 225, 255, 0.4);
  background: rgba(2, 20, 46, 0.6); color: #fff; font-size: 18px; font-weight: 800; padding: 0 13px; outline: none;
}
input:focus { border-color: #7df2ff; box-shadow: 0 0 0 3px rgba(125, 242, 255, 0.22); }
.btn {
  --a: #49b8ff; --b: #1574e0; --s: #0a3f8a;
  position: relative; border: 0; border-radius: 17px; padding: 11px 14px; min-height: 56px; cursor: pointer;
  color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: linear-gradient(180deg, var(--a), var(--b));
  box-shadow: 0 5px 0 var(--s), 0 10px 20px rgba(0, 10, 40, 0.4), inset 0 1.5px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.08s, box-shadow 0.08s; width: 100%; touch-action: manipulation;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--s), 0 3px 8px rgba(0, 10, 40, 0.4), inset 0 1.5px 0 rgba(255, 255, 255, 0.45); }
.btn b { font-size: 21px; font-weight: 900; letter-spacing: 0.4px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22); }
.btn small { font-size: 12px; font-weight: 700; opacity: 0.92; }
.btn-gold { --a: #ffd95c; --b: #ff9a1f; --s: #a85a00; }
.btn-gold b, .btn-gold small { color: #4d2500; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4); }
.btn-teal { --a: #4ff0c0; --b: #0fae8c; --s: #076b58; }
.btn-blue { --a: #62c6ff; --b: #1c7fe8; --s: #0b468f; }
.btn[disabled] { filter: grayscale(0.7) brightness(0.8); pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.link-row { display: flex; justify-content: space-between; }
.link { background: none; border: 0; color: #a9dcff; font-weight: 800; font-size: 15px; padding: 8px 6px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; touch-action: manipulation; }

/* ---------- solo */
.rank-badge { display: flex; align-items: center; gap: 12px; justify-content: center; text-align: left; }
.rank-badge svg { width: 62px; height: 44px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4)); }
#rankNum { font-size: 13px; color: #b9dcf2; text-transform: uppercase; letter-spacing: 1.5px; }
#rankName { font-size: 25px; font-weight: 900; color: #ffe27a; text-shadow: 0 2px 0 rgba(80, 40, 0, 0.6); }
.pips { display: flex; gap: 5px; justify-content: center; }
.pips i { width: 22px; height: 9px; border-radius: 5px; background: rgba(2, 20, 46, 0.7); border: 1px solid rgba(150, 225, 255, 0.25); }
.pips i.on { background: linear-gradient(180deg, #ffe27a, #ff9d1c); border-color: #ffe9a0; }
.pips i.cur { box-shadow: 0 0 10px #ffd84a; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.18); } }
.stats-line { font-size: 13px; color: #9fd0ee; font-weight: 700; }

/* ---------- join */
.code-input { text-align: center; font-size: 40px; letter-spacing: 12px; height: 70px; text-transform: uppercase; flex: none; padding-left: 24px; }

/* ---------- lobby */
.lobby { width: min(460px, 100%); }
.lobby-left, .lobby-right { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.code-box { display: flex; align-items: center; justify-content: center; gap: 12px; }
.code-box span { font-size: 13px; color: #b9dcf2; text-transform: uppercase; letter-spacing: 1.5px; }
.code-box b { font-size: 42px; font-weight: 900; letter-spacing: 7px; color: #ffe27a; text-shadow: 0 3px 0 rgba(80, 40, 0, 0.6); }
.qr { align-self: center; background: #fff; border-radius: 14px; padding: 8px; line-height: 0; }
.qr img, .qr svg { width: 124px; height: 124px; display: block; image-rendering: pixelated; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 13px; background: rgba(2, 20, 46, 0.55); border: 1.5px solid rgba(150, 225, 255, 0.2); font-size: 15px; text-align: left; min-width: 0; }
.slot i { width: 16px; height: 16px; border-radius: 50%; background: var(--c); flex: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); }
.slot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.empty { opacity: 0.55; font-weight: 600; }
.slot.empty i { background: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25) inset; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; color: #cfeaff; justify-content: center; }
.check input { flex: none; width: 22px; height: 22px; accent-color: #ffb92e; padding: 0; }

/* ---------- how */
.how ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; text-align: left; }
.how li { display: flex; gap: 11px; align-items: center; font-size: 14px; font-weight: 600; color: #d6efff; line-height: 1.3; }
.how li b { color: #fff; font-weight: 900; }
.ic { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: rgba(2, 20, 46, 0.65); border: 1.5px solid var(--c, #ffd84a); color: var(--c, #ffd84a); font-style: normal; font-size: 20px; font-weight: 900; }
.ic svg { width: 28px; height: 20px; }

/* ---------- results */
.over-crown { width: 84px; height: 58px; align-self: center; margin: -52px 0 -6px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45)); animation: crownIn 0.7s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes crownIn { from { transform: translateY(-60px) rotate(-30deg) scale(0.3); opacity: 0; } }
.over { overflow: visible; margin-top: auto; margin-bottom: auto; }
#overTitle { color: #ffe27a; font-size: 27px; }
.table { display: flex; flex-direction: column; gap: 6px; }
.row { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 9px; align-items: center; padding: 8px 11px; border-radius: 12px; background: rgba(2, 20, 46, 0.55); font-size: 15px; text-align: left; border: 1.5px solid transparent; }
.row.win { border-color: #ffd84a; background: rgba(90, 60, 0, 0.45); }
.row i { width: 16px; height: 16px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); }
.row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .st { color: #9fd0ee; font-size: 12px; font-weight: 700; white-space: nowrap; }
.row .sc { font-weight: 900; color: #ffe27a; min-width: 38px; text-align: right; }

/* ---------- HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#chips { position: absolute; top: calc(var(--sat) + 8px); left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
.chip { position: relative; width: 86px; padding: 5px 8px 6px; border-radius: 13px; background: rgba(3, 22, 50, 0.66); border: 1.5px solid rgba(255, 255, 255, 0.14); transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s; }
.chip.me { border-color: rgba(255, 255, 255, 0.55); }
.chip.king { transform: scale(1.08); border-color: #ffd84a; box-shadow: 0 0 16px rgba(255, 210, 60, 0.55); z-index: 2; }
.chip.danger { animation: danger 0.5s infinite alternate; }
@keyframes danger { to { box-shadow: 0 0 22px rgba(255, 80, 80, 0.9); border-color: #ff6b6b; } }
.chip .top { display: flex; align-items: center; gap: 4px; font-size: 11.5px; line-height: 1.15; }
.chip .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--l); font-weight: 800; }
.chip .sec { font-weight: 900; font-variant-numeric: tabular-nums; }
.chip svg { width: 15px; height: 11px; display: none; flex: none; }
.chip.king svg { display: block; }
.chip .bar { height: 7px; border-radius: 4px; background: rgba(255, 255, 255, 0.14); margin-top: 4px; overflow: hidden; }
.chip .bar i { display: block; height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--c), var(--l)); }
#btnQuit { pointer-events: auto; position: absolute; top: calc(var(--sat) + 8px); right: calc(var(--sar) + 10px); width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, 0.3); background: rgba(3, 22, 50, 0.6); color: #fff; font-size: 16px; font-weight: 900; touch-action: manipulation; }
#btnQuit.arm { background: #e5484d; border-color: #fff; }

#banner {
  position: fixed; z-index: 12; left: 50%; top: calc(var(--sat) + 62px); transform: translate(-50%, -14px) scale(0.9); opacity: 0; pointer-events: none;
  padding: 8px 18px; border-radius: 999px; font-size: 17px; font-weight: 900; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
  background: rgba(3, 22, 50, 0.78); border: 2px solid var(--c, #ffd84a); color: var(--c, #ffd84a);
  box-shadow: 0 6px 20px rgba(0, 8, 30, 0.5); transition: opacity 0.25s, transform 0.25s cubic-bezier(0.2, 1.5, 0.4, 1);
}
#banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#count {
  position: fixed; z-index: 12; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 150px; font-weight: 900; color: #fff; -webkit-text-stroke: 5px #063a6e; paint-order: stroke fill; opacity: 0;
  text-shadow: 0 10px 30px rgba(0, 10, 40, 0.6);
}
#count.go { animation: count 0.85s ease-out; }
@keyframes count { 0% { opacity: 0; transform: scale(2.2); } 18% { opacity: 1; transform: scale(1); } 70% { opacity: 1; } 100% { opacity: 0; transform: scale(0.8); } }
#toast {
  position: fixed; z-index: 40; left: 50%; bottom: calc(var(--sab) + 22px); transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: rgba(2, 16, 40, 0.92); border: 1.5px solid rgba(150, 225, 255, 0.45); padding: 10px 16px; border-radius: 14px; font-size: 15px; max-width: 90vw; text-align: center;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- short landscape (phones on their side) */
@media (orientation: landscape) and (max-height: 520px) {
  .menu-wrap { flex-direction: row; width: min(760px, 100%); gap: 26px; align-items: center; }
  .logo { flex: 1; }
  .logo-crown { width: 62px; height: 44px; }
  .logo-king { font-size: 58px; } .logo-ocean { font-size: 50px; }
  .logo-of { font-size: 13px; margin: 3px 0 2px; } .tagline { font-size: 13px; margin-top: 8px; }
  .menu-panel { flex: 1.1; gap: 8px; padding: 14px; }
  .btn { min-height: 48px; padding: 7px 12px; } .btn b { font-size: 19px; }
  .card { gap: 8px; padding: 14px; }
  h2 { font-size: 22px; }
  .lobby { flex-direction: row; width: min(720px, 100%); gap: 18px; align-items: center; }
  .lobby-left, .lobby-right { flex: 1; min-width: 0; gap: 8px; }
  .qr img, .qr svg { width: 96px; height: 96px; }
  .code-box b { font-size: 34px; }
  .how { width: min(700px, 100%); }
  .how ul { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px; }
  .how li { font-size: 12.5px; } .ic { width: 32px; height: 32px; font-size: 17px; }
  .over { width: min(520px, 100%); }
  .over-crown { width: 60px; height: 42px; margin: -40px 0 -8px; }
  .row { padding: 5px 10px; font-size: 14px; }
  #count { font-size: 110px; }
  #banner { top: calc(var(--sat) + 56px); font-size: 15px; padding: 6px 15px; }
}
@media (max-width: 380px) {
  .chip { width: 78px; padding: 5px 6px 6px; }
  .logo-king { font-size: 68px; } .logo-ocean { font-size: 58px; }
}

@media (max-width: 560px) {
  #chips { left: calc(var(--sal) + 8px); right: calc(var(--sar) + 56px); transform: none; gap: 4px; }
  .chip { flex: 1; width: auto; min-width: 0; padding: 5px 6px 6px; }
}
@media (hover: hover) and (pointer: fine) {
  .tagline::after { content: "Keyboard: WASD / arrows to swim, Space to dash"; display: block; margin-top: 6px; font-size: 12px; opacity: 0.75; }
}
