/* CellGame.io: lobby, death screen, touch controls and overlays. The game itself is drawn on #c.
   Loaded as an external sheet: the CSP forbids inline styles (style="" attributes and <style> blocks). */
* { box-sizing: border-box; }
/* safe area (notch, home indicator) with viewport-fit=cover; the canvas HUD reads these back (render/hud.ts) */
:root {
  --sa-t: env(safe-area-inset-top, 0px); --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px);
}
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: #0b0f17; color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-tap-highlight-color: transparent;
}
canvas { display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { font-family: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }
.hidden { display: none !important; }

/* ---------- overlays ---------- */
#lobby, #death {
  position: fixed; inset: 0; display: flex; overflow-y: auto;
  padding: max(16px, var(--sa-t)) max(16px, var(--sa-r)) max(16px, var(--sa-b)) max(16px, var(--sa-l));
  background: rgba(5, 8, 14, 0.6); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
/* margin:auto centres the panel but lets a tall lobby scroll from the top on short screens */
.panel {
  position: relative; margin: auto;
  background: #121826; border-radius: 16px; padding: 28px; width: min(440px, 100%);
  box-shadow: 0 10px 40px rgba(15, 23, 42, .12); border: 1px solid rgba(255, 255, 255, .07); color: #e2e8f0; text-align: center;
}
/* side padding keeps the title clear of the sound button in the corner (symmetric, so it stays centred) */
h1 { margin: 0 0 4px; padding: 0 24px; font-size: 40px; letter-spacing: -1px; color: #f8fafc; }
#deathTitle { margin: 0 0 4px; font-size: 28px; letter-spacing: -.5px; color: #f8fafc; line-height: 1.2; }
.sub { margin: 0 0 20px; color: #94a3b8; font-size: 14px; }
label, .lbl {
  display: block; text-align: left; font-size: 12px; font-weight: 700; color: #94a3b8; text-transform: uppercase;
  letter-spacing: .5px; margin: 14px 0 6px;
}
input[type=text] {
  width: 100%; padding: 12px 14px; font-size: 16px; border: 2px solid #253045; border-radius: 10px; outline: none;
  background: #0b0f17; color: #f1f5f9;
}
input[type=text]:focus { border-color: #3b82f6; }
.pts { float: right; color: #fbbf24; text-transform: none; }

/* ---------- sound toggle ---------- */
.sound {
  position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; padding: 0; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .1); background: #0b0f17; color: #e2e8f0; font-size: 18px; line-height: 1; cursor: pointer;
}
.sound:hover { background: #1e293b; }
.sound[aria-pressed=false] { opacity: .65; }

/* ---------- skin shop ---------- */
#skins { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.skin {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 50%; cursor: pointer; border: 3px solid transparent;
  display: flex; align-items: center; justify-content: center; font-size: 26px; line-height: 1; transition: transform .1s;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.skin:hover { transform: scale(1.08); }
.skin.sel { box-shadow: 0 0 0 3px #121826 inset; }
.skin.locked { filter: grayscale(.85) brightness(.9); }
.skin.busy { opacity: .6; cursor: progress; }
.skin .price {
  position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%); background: #0b0f17; color: #fbbf24;
  font: 800 10px system-ui, -apple-system, sans-serif; padding: 1px 5px; border-radius: 8px; filter: none;
}
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- modes + difficulty (segmented buttons) ---------- */
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1 1 0; min-width: 0; padding: 10px 6px; border: 2px solid #253045; background: #0b0f17; border-radius: 10px;
  font-size: 14px; font-weight: 600; line-height: 1.15; cursor: pointer; color: #cbd5e1;
}
.seg button:hover { border-color: #334155; }
.seg button[aria-pressed=true] { border-color: #3b82f6; background: #172554; color: #93c5fd; }
.modes button:last-child { flex-grow: 1.7; }

/* ---------- invite link ---------- */
#invite .codeRow { margin-top: 0; }
#inviteLink { font-size: 13px; padding: 10px 12px; color: #93c5fd; text-overflow: ellipsis; }
.hint { margin: 6px 0 0; font-size: 12px; color: #64748b; text-align: left; }

/* ---------- play / paywall ---------- */
.play {
  margin-top: 22px; width: 100%; padding: 14px; font-size: 18px; font-weight: 700; color: #fff; border: 0; border-radius: 12px;
  background: #2563eb; cursor: pointer; transition: background .15s, transform .1s;
}
.play:hover { background: #1d4ed8; }
.play:active { transform: scale(.98); }
.play:disabled { opacity: .55; cursor: default; transform: none; }
.secondary { background: #1e293b; color: #cbd5e1; margin-top: 10px; font-size: 16px; }
.secondary:hover { background: #273449; }
.buy { background: #635bff; }
.buy:hover { background: #5249e6; }
.codeRow { display: flex; gap: 8px; margin-top: 10px; }
.codeRow input[type=text] {
  flex: 1; min-width: 0; padding: 10px 12px; font-size: 14px; border: 2px solid #253045; border-radius: 10px;
  background: #0b0f17; color: #f1f5f9; outline: none;
}
#code { text-transform: uppercase; }
#code::placeholder { text-transform: none; }
.codeRow input:focus { border-color: #635bff; }
.codeRow button {
  flex: none; padding: 0 16px; border: 0; border-radius: 10px; background: #1e293b; color: #e2e8f0; font-weight: 600; cursor: pointer;
}
.codeRow button:hover { background: #273449; }
.codeRow button:disabled { opacity: .6; cursor: progress; }
.payMsg { min-height: 18px; margin-top: 8px; font-size: 13px; color: #f87171; }
.payMsg.ok { color: #4ade80; }
#lobbyMsg:empty { min-height: 0; margin: 0; }

/* ---------- small print ---------- */
.keys { margin-top: 16px; font-size: 13px; color: #94a3b8; line-height: 1.5; }
kbd { background: #1e293b; border: 1px solid #334155; border-radius: 4px; padding: 1px 6px; font-family: inherit; white-space: nowrap; }
.touchkeys { display: none; }
body.touch .touchkeys { display: inline; }
body.touch .deskkeys { display: none; }
.about { margin: 12px 0 0; font-size: 12px; line-height: 1.5; color: #64748b; }

/* ---------- death screen ---------- */
#stats { font-size: 18px; color: #e2e8f0; margin: 10px 0; line-height: 1.6; }
.deathPts { font-size: 18px; color: #fbbf24; line-height: 1.6; }
.deathPts:empty { display: none; }

/* ---------- in-page Stripe checkout ---------- */
#payModal {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(3, 6, 12, .72); backdrop-filter: blur(6px);
}
.payCard {
  position: relative; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: #fff; border-radius: 16px; padding: 44px 8px 8px; box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
#payClose {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border: 0; border-radius: 50%;
  background: #f1f5f9; color: #334155; font-size: 20px; line-height: 1; cursor: pointer;
}
#payClose:hover { background: #e2e8f0; }
#payMount { min-height: 420px; }

/* ---------- connecting ---------- */
#connecting {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; align-items: center; gap: 10px;
  width: max-content; max-width: calc(100vw - 32px); /* left: 50% alone would squeeze it to half the screen */
  padding: 14px 20px; border-radius: 12px; background: rgba(17, 24, 39, .92); border: 1px solid rgba(255, 255, 255, .08);
  color: #e2e8f0; font-size: 15px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); pointer-events: none;
}
/* the overlay lets touches through to the arena; only its button takes them */
#cancelJoin {
  pointer-events: auto; margin-left: 4px; padding: 6px 12px; border: 0; border-radius: 8px; background: #1e293b; color: #cbd5e1;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
#cancelJoin:hover { background: #273449; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(147, 197, 253, .25); border-top-color: #60a5fa;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch .tbtn {
  position: absolute; pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  display: flex; align-items: center; justify-content: center; padding: 0; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .16); background: rgba(17, 24, 39, .6); color: #e2e8f0;
  font: 700 12px system-ui, -apple-system, sans-serif; letter-spacing: .3px;
}
#touch .tbtn.on { background: rgba(37, 99, 235, .75); border-color: rgba(147, 197, 253, .6); }
/* offsets from the safe area; render/hud.ts keeps the leaderboard above this cluster (164px tall) */
#tBoost { width: 76px; height: 76px; right: calc(16px + var(--sa-r)); bottom: calc(16px + var(--sa-b)); }
#tSplit { width: 60px; height: 60px; right: calc(24px + var(--sa-r)); bottom: calc(104px + var(--sa-b)); }
#tEject { width: 60px; height: 60px; right: calc(104px + var(--sa-r)); bottom: calc(24px + var(--sa-b)); }
/* leave the game (touch has no Esc); 36px at the top centre, render/hud.ts keeps the HUD clear of it */
#tExit {
  position: absolute; top: calc(10px + var(--sa-t)); left: 50%; width: 36px; height: 36px; margin-left: -18px; padding: 0;
  pointer-events: auto; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .16); background: rgba(17, 24, 39, .6); color: #cbd5e1;
  font: 400 24px/1 system-ui, -apple-system, sans-serif;
}
#tExit:active { background: rgba(37, 99, 235, .75); }
/* a bigger invisible hit area than the 36px dot */
#tExit::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; }
#stick {
  position: absolute; display: none; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .04);
}
#stick.on { display: block; }
#knob { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(255, 255, 255, .3); }

.noscript { position: fixed; left: 0; right: 0; top: 40%; margin: 0; text-align: center; color: #e2e8f0; font-size: 16px; }

/* ---------- narrow phones ---------- */
@media (max-width: 400px) {
  .panel { padding: 22px 16px; }
  h1 { font-size: 34px; padding: 0 34px; }
  #skins { gap: 6px; }
  .skin { font-size: 22px; }
  .seg button { font-size: 13px; padding: 9px 4px; }
}
@media (max-width: 340px) {
  h1 { font-size: 32px; }
}
@media (max-height: 560px) {
  .panel { padding-top: 18px; padding-bottom: 18px; }
  .sub { margin-bottom: 10px; }
  .play { margin-top: 14px; padding: 11px; }
  .about { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .shake, .spinner { animation: none; }
  .skin, .play { transition: none; }
}

/* ---------- install card (/install link) and lobby install button ---------- */
#installCard {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(3, 6, 12, .78); backdrop-filter: blur(8px);
}
.installPanel { text-align: center; max-width: 420px; }
.installPanel h2 { margin: 6px 0 6px; font-size: 26px; color: #f8fafc; letter-spacing: -.5px; }
.installIcon { display: block; margin: 0 auto; border-radius: 22px; box-shadow: 0 10px 30px rgba(37, 99, 235, .35); }
.installIos { text-align: left; margin: 14px 0 4px; padding-left: 22px; color: #cbd5e1; line-height: 1.9; font-size: 15px; }
.iosShare { display: inline-block; padding: 0 6px; border-radius: 6px; background: #1e293b; color: #93c5fd; font-weight: 700; }
.installLobby {
  position: absolute; top: 14px; left: 14px; padding: 6px 10px; border: 1px solid rgba(255, 255, 255, .1); border-radius: 10px;
  background: #1e293b; color: #cbd5e1; font-size: 12px; font-weight: 700; cursor: pointer;
}
.installLobby:hover { background: #273449; }
