/* Tom Pearl IO, light theme.
   Rules taken from agar.io: a pale ruled world so the saturated cells read first,
   a plain white menu sheet, white names with a black outline, and HUD text in
   translucent black boxes. Cell colour comes only from the characters. */
:root {
  --ink: #1d2a2e;
  --sub: #5f6f72;
  --line: #e3eaea;
  --go: #3cae4c;
  --go-edge: #2a8638;
  --hud: rgba(0, 0, 0, .4);
  --mine: #ffd23f;
}
body { background: #f4f8f5; color: var(--ink); font-family: 'Ubuntu', system-ui, sans-serif; }
canvas { cursor: default; }
/* The swallow zoom scales the canvas past the screen; the clip keeps phones from widening the page. */
.arena-clip { position: fixed; inset: 0; overflow: hidden; }
#game-canvas { transform-origin: 50% 50%; }
#game-canvas.swallowed { transform: scale(1.3); transition: transform .9s cubic-bezier(.5, 0, .75, 0); }

/* ── HUD: hidden while the menu is up ── */
#ui { transition: opacity .5s .4s; }
body.in-menu #ui { opacity: 0; transition: none; }
body.in-menu #mobile-controls, body.in-menu #joystick-zone { visibility: hidden; }

#hud { top: auto; right: auto; bottom: 14px; left: 14px; flex-direction: row; align-items: baseline; gap: 8px; padding: 6px 12px 7px; border: 0; border-radius: 6px; background: var(--hud); box-shadow: none; }
#mass-label { order: -1; color: #fff; opacity: .75; font: 500 15px 'Ubuntu', sans-serif; letter-spacing: 0; text-transform: none; }
#score-display { color: #fff; font: 700 24px/1 'Ubuntu', sans-serif; letter-spacing: 0; text-shadow: none; font-variant-numeric: tabular-nums; }
#rank-display { padding: 0; border: 0; border-radius: 0; background: none; color: #fff; opacity: .75; font: 500 14px 'Ubuntu', sans-serif; letter-spacing: 0; }
#rank-display:empty { display: none; }

#leaderboard { top: 12px; left: auto; right: 12px; width: 200px; min-width: 0; padding: 9px 14px 8px; border: 0; border-radius: 6px; background: var(--hud); backdrop-filter: none; box-shadow: none; }
#leaderboard h3 { margin: 0 0 5px; padding: 0; border: 0; color: #fff; font: 700 20px 'Ubuntu', sans-serif; letter-spacing: 0; text-transform: none; text-align: center; }
.lb-entry { gap: 4px; margin: 0; color: #fff; font: 500 15px/1.5 'Ubuntu', sans-serif; }
.lb-rank { width: auto; opacity: 1; font: inherit; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-entry.is-player { color: var(--mine); font-weight: 700; }

#minimap { top: auto; bottom: 14px; right: 14px; width: 150px; height: 150px; border: 0; border-radius: 0; background: none; box-shadow: none; overflow: visible; }
#controls-hint { display: none; }
#abilities { bottom: 14px; gap: 6px; }
.ability-key { flex-direction: row; gap: 6px; min-width: 0; padding: 5px 9px; border: 0; border-radius: 6px; background: var(--hud); font: 500 13px 'Ubuntu', sans-serif; }
.ability-key .key { color: #fff; font-size: 13px; font-weight: 700; }
.ability-key .label { color: #fff; opacity: .75; font-size: 12px; letter-spacing: 0; }

/* Big outlined words in the middle of the screen, agar-style */
.game-msg {
  top: 22%; padding: 0; border: 0; border-radius: 0; background: none !important; box-shadow: none;
  color: var(--msg, #fff); font: 700 clamp(22px, 3.4vw, 38px) 'Ubuntu', sans-serif; letter-spacing: 0;
  text-shadow: 3px 0 0 #000, -3px 0 0 #000, 0 3px 0 #000, 0 -3px 0 #000, 2px 2px 0 #000, -2px 2px 0 #000, 2px -2px 0 #000, -2px -2px 0 #000;
  opacity: 0; transform: translateX(-50%) scale(.9); transition: opacity .2s, transform .2s ease-in;
}
.game-msg.show { opacity: 1; transform: translateX(-50%) scale(1); animation: msg-pop .45s cubic-bezier(.2, 1.7, .4, 1) both; }
@keyframes msg-pop { from { transform: translateX(-50%) scale(.45); } }
#instr-banner {
  top: 54px; padding: 0; border: 0; border-radius: 0; background: none; color: #fff;
  font: 700 17px 'Ubuntu', sans-serif; letter-spacing: 0; white-space: nowrap;
  text-shadow: 2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000, 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
}

/* ── Menu: the live world behind, one white sheet in front ── */
.screen { padding: 16px; }
#start-screen { background: rgba(18, 32, 36, .14); transition: background-color .45s; }
#start-screen::before { content: none; }
#start-screen.leaving { background-color: transparent; pointer-events: none; }
.menu-shell {
  position: relative; width: min(400px, 100%); margin: auto; padding: 22px 24px 18px;
  border: 0; border-radius: 12px; background: #fff; box-shadow: 0 10px 34px rgba(0, 24, 30, .22); color: var(--ink);
  transition: transform .42s cubic-bezier(.6, 0, .4, 1), opacity .3s .1s;
  animation: sheet-in .55s cubic-bezier(.2, .9, .3, 1.15) backwards;
}
.menu-shell::after { content: none; }
#start-screen.leaving .menu-shell { transform: scale(.12); opacity: 0; }
@keyframes sheet-in { from { transform: translateY(18px) scale(.96); opacity: 0; } }

.game-title { margin: 0 0 14px; color: var(--ink); font: 700 40px/1 'Ubuntu', sans-serif; letter-spacing: -.01em; text-shadow: none; animation: none; }
.game-title span { color: #93a2a4; }

.skin-feature { display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 0; margin: 0 0 14px; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
.skin-feature::before, .skin-feature::after { content: none; }
.feature-ring {
  display: block; width: 112px; height: 112px; overflow: hidden;
  border: 7px solid var(--rim, #ad8a00); border-radius: 50%; background: var(--cell, #ffcc00); box-shadow: none;
  animation: membrane 5s ease-in-out infinite;
}
.feature-ring img { display: block; width: 100%; height: 100%; object-fit: cover; }
.feature-ring.gulp { animation: gulp .5s cubic-bezier(.3, 1.6, .5, 1), membrane 5s .5s ease-in-out infinite; }
/* a cell is never a perfect circle: the rim breathes a little */
@keyframes membrane {
  0%, 100% { border-radius: 50%; }
  25% { border-radius: 52% 48% 50% 50% / 49% 52% 48% 51%; }
  50% { border-radius: 48% 52% 51% 49% / 52% 48% 52% 48%; }
  75% { border-radius: 51% 49% 48% 52% / 48% 51% 49% 52%; }
}
@keyframes gulp { 0% { transform: scale(.8); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }
.feature-name { color: var(--ink); font: 700 18px 'Ubuntu', sans-serif; }
.cell-flyer { position: fixed; z-index: 300; margin: 0; pointer-events: none; transform-origin: 50% 50%; will-change: transform; }

.skin-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; max-width: 330px; margin: 0 auto 18px; }
.skin-card {
  position: relative; flex: 0 0 auto; width: 54px; height: 54px; min-width: 0; padding: 0; overflow: hidden;
  border: 4px solid var(--rim); border-radius: 50%; background: var(--cell); box-shadow: none; cursor: pointer;
  transition: transform .25s cubic-bezier(.3, 1.6, .5, 1), box-shadow .15s;
}
.skin-card-photo { display: block; width: 100%; height: 100%; border-radius: 0; background: none; overflow: hidden; }
.skin-card-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.skin-card-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skin-card:hover { transform: scale(1.1); border-color: var(--rim); background: var(--cell); }
.skin-card.active { transform: scale(1.2); border: 4px solid var(--rim); background: var(--cell); box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink); }
.skin-card:focus-visible, .play-btn:focus-visible { outline: 3px solid #2a74d6; outline-offset: 3px; }

.play-row { display: flex; gap: 8px; margin: 0; }
.name-input {
  flex: 1; min-width: 0; width: auto; margin: 0; padding: 10px 12px;
  border: 1px solid #c8d2d2; border-radius: 6px; background: #fff; box-shadow: none;
  color: var(--ink); text-align: left; font: 500 17px 'Ubuntu', sans-serif; letter-spacing: 0;
}
.name-input:focus { outline: none; border-color: #6c9ea0; box-shadow: 0 0 0 3px rgba(80, 150, 150, .2); }
.name-input:focus-visible { outline: none; }
.name-input::placeholder { color: #98a6a8; opacity: 1; }
.play-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0; flex: 0 0 auto; padding: 10px 26px;
  border: 0; border-radius: 6px; background: var(--go); box-shadow: 0 3px 0 var(--go-edge);
  color: #fff; font: 700 18px 'Ubuntu', sans-serif; letter-spacing: 0; text-shadow: none; cursor: pointer;
  transition: transform .08s, box-shadow .08s, background-color .15s;
}
.play-btn:hover { background: #45bd56; transform: none; box-shadow: 0 3px 0 var(--go-edge); }
.play-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--go-edge); }

.menu-help { margin: 14px 0 0; padding: 0; border: 0; color: var(--sub); font: 400 13px/1.55 'Ubuntu', sans-serif; letter-spacing: 0; text-align: center; }
.menu-help.touch { display: none; }
@media (pointer: coarse) { .menu-help.desk { display: none; } .menu-help.touch { display: block; } }

/* ── Death: the eater's colour floods out from where you were swallowed ── */
#death-screen { background: var(--flood, #41484a); backdrop-filter: none; }
#death-screen.flooding { animation: flood .7s cubic-bezier(.7, 0, .3, 1) both; }
#death-screen.closing { animation: iris .55s cubic-bezier(.7, 0, .3, 1) both; pointer-events: none; }
@keyframes flood { from { clip-path: circle(0% at var(--fx, 50%) var(--fy, 50%)); } to { clip-path: circle(150% at var(--fx, 50%) var(--fy, 50%)); } }
@keyframes iris { from { clip-path: circle(150% at var(--fx, 50%) var(--fy, 50%)); } to { clip-path: circle(0% at var(--fx, 50%) var(--fy, 50%)); } }
.death-card {
  width: min(340px, 100%); margin-top: 48px; padding: 0 24px 20px;
  border-radius: 12px; background: #fff; box-shadow: 0 14px 40px rgba(0, 0, 0, .25); color: var(--ink);
  animation: card-in .5s .45s cubic-bezier(.2, .9, .3, 1.15) backwards;
}
#death-screen.closing .death-card { opacity: 0; transform: scale(.95); transition: opacity .15s, transform .15s; }
@keyframes card-in { from { opacity: 0; transform: translateY(26px) scale(.95); } }
.death-eater {
  width: 92px; height: 92px; margin: -46px auto 10px; overflow: hidden;
  border: 6px solid var(--flood-rim, #222); border-radius: 50%; background: var(--flood, #41484a); box-shadow: 0 0 0 5px #fff;
}
.death-eater img { display: block; width: 100%; height: 100%; object-fit: cover; }
.death-title { margin: 0 0 14px; color: var(--ink); font: 700 26px/1.15 'Ubuntu', sans-serif; letter-spacing: 0; text-shadow: none; overflow-wrap: anywhere; }
.death-title small { display: block; margin-bottom: 3px; color: var(--sub); font: 500 14px 'Ubuntu', sans-serif; }
.death-stats { margin: 0 0 18px; opacity: 1; color: var(--ink); font: 400 15px/1 'Ubuntu', sans-serif; letter-spacing: 0; }
.death-stats div { display: flex; justify-content: space-between; padding: 10px 2px; border-top: 1px solid var(--line); }
.death-stats div:last-child { border-bottom: 1px solid var(--line); }
.death-stats b { font-weight: 700; font-variant-numeric: tabular-nums; }
#respawn-btn { width: 100%; }
.death-rank { min-height: 18px; margin: -6px 0 12px; color: var(--sub); font: 500 13px 'Ubuntu', sans-serif; text-align: center; }
.board-link {
  display: block; margin: 12px auto 0; padding: 4px 8px; border: 0; background: none;
  color: var(--ink); font: 500 14px 'Ubuntu', sans-serif; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.board-link:hover { color: var(--go-edge); }

/* ── Touch ── */
.touch-btn { border: 2px solid rgba(255, 255, 255, .85); background: rgba(0, 0, 0, .3); backdrop-filter: none; box-shadow: none; color: #fff; font: 700 16px 'Ubuntu', sans-serif; letter-spacing: 0; }
.touch-btn:active { background: rgba(0, 0, 0, .48); }
#joystick-base { border: 2px solid rgba(0, 0, 0, .22); background: rgba(0, 0, 0, .07); backdrop-filter: none; }
#joystick-knob { border: 2px solid rgba(255, 255, 255, .85); background: rgba(0, 0, 0, .3); }
@media (pointer: coarse) {
  /* below the FULL SCREEN button */
  #leaderboard { top: 52px; right: 8px; width: 132px; min-width: 0; max-width: none; padding: 6px 9px; }
  #leaderboard h3 { margin-bottom: 2px; font-size: 13px; }
  .lb-entry { font-size: 11px; line-height: 1.45; }
  #minimap { top: 8px; left: 8px; right: auto; bottom: auto; width: 92px; height: 92px; }
  #hud { top: 108px; bottom: auto; left: 8px; padding: 4px 9px 5px; }
  #score-display { font-size: 18px; }
  #mass-label, #rank-display { font-size: 12px; }
  #instr-banner { top: auto; bottom: 22px; font-size: 14px; }
}
@media (max-width: 400px) {
  .menu-shell { padding: 18px 16px 14px; }
  .game-title { font-size: 34px; }
  .skin-grid { gap: 10px; }
  .skin-card { width: 46px; height: 46px; border-width: 3px; }
  .skin-card.active { border-width: 3px; }
  .play-btn { padding: 10px 18px; }
}
@media (max-height: 560px) {
  .feature-ring { width: 84px; height: 84px; border-width: 5px; }
  .game-title { margin-bottom: 8px; font-size: 30px; }
  .skin-feature { margin-bottom: 8px; }
  .skin-grid { margin-bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .menu-shell, .death-card, .feature-ring, .feature-ring.gulp, .game-msg.show { animation: none; }
  #death-screen.flooding, #death-screen.closing { animation: none; }
  #game-canvas.swallowed { transform: none; transition: none; }
}

/* A sheet taller than the screen grows downward and scrolls instead of losing its top. */
#start-screen { justify-content: flex-start; }

/* Phone on its side: title, pick and Play on the left, the 20 faces on the right. */
@media (orientation: landscape) and (max-height: 560px) {
  .menu-shell {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    grid-template-areas: "title grid" "feature grid" "play grid" "help grid" "board grid";
    align-content: center; column-gap: 22px; width: min(740px, 100%); padding: 14px 18px 12px;
  }
  .game-title { grid-area: title; margin-bottom: 6px; font-size: 28px; }
  .skin-feature { grid-area: feature; margin-bottom: 10px; gap: 4px; }
  .feature-ring { width: 64px; height: 64px; border-width: 4px; }
  .feature-name { font-size: 15px; }
  .skin-grid { grid-area: grid; align-self: center; max-width: none; margin: 0; gap: 8px; }
  .skin-card { width: 44px; height: 44px; border-width: 3px; }
  .skin-card.active { border-width: 3px; transform: scale(1.12); }
  .play-row { grid-area: play; }
  .menu-help { grid-area: help; margin-top: 8px; font-size: 11.5px; line-height: 1.4; }
  .board-link { grid-area: board; justify-self: center; }
}
