/* Snake Royale: dark board, neon snakes, chunky letters. */

:root {
  --bg: #08080f;
  --bg-panel: #12121f;
  --bg-raised: #1c1c30;
  --line: #2b2b45;
  --text: #eaeaf5;
  --muted: #8a8aa8;
  --neon: #4cc9f0;
  --hot: #f72585;
  --good: #a7c957;
  --danger: #e63946;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  background-image:
    radial-gradient(circle at 20% 0%, rgba(76, 201, 240, .10), transparent 55%),
    radial-gradient(circle at 90% 100%, rgba(247, 37, 133, .10), transparent 55%);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#app { height: 100%; }

.screen {
  display: none;
  height: 100%;
  padding: 16px;
}
.screen.is-active { display: flex; }

#screen-start.is-active,
#screen-lobby.is-active {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

/* ---------- panels ---------- */

.panel {
  width: 100%;
  max-width: 520px;
  padding: 28px;
  background: var(--bg-panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.panel--narrow { max-width: 420px; }

.logo {
  margin: 0 0 6px;
  font-size: clamp(34px, 8vw, 52px);
  font-weight: 900;
  letter-spacing: 2px;
  line-height: .95;
  color: var(--neon);
  text-shadow: 0 0 18px rgba(76, 201, 240, .55);
}
.logo span {
  display: block;
  color: var(--hot);
  text-shadow: 0 0 18px rgba(247, 37, 133, .55);
}

.tagline { margin: 0 0 24px; color: var(--muted); }

.label {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.field { display: block; margin-bottom: 18px; }
.field > span {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 17px;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--neon);
}

.code-input {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 8px;
  text-align: center;
  text-transform: uppercase;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.swatch {
  aspect-ratio: 1;
  border: 3px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: transform .1s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch.is-picked {
  border-color: #fff;
  box-shadow: 0 0 14px currentColor;
}

/* ---------- buttons ---------- */

.btn {
  padding: 13px 18px;
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--neon); }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn--primary {
  background: var(--neon);
  border-color: var(--neon);
  color: #04121a;
}
.btn--primary:hover:not(:disabled) { background: #6ed8fb; }
.btn--primary.is-on {
  background: var(--good);
  border-color: var(--good);
  color: #16240a;
}
/* Restated for the on state on purpose: the plain primary hover is more
   specific than .is-on, so without this a hovered ready button goes back to
   looking exactly like a button that was never pressed. */
.btn--primary.is-on:hover:not(:disabled) { background: #bade7c; }
.btn--ghost { background: transparent; }
.btn--small { padding: 8px 12px; font-size: 13px; }

.actions {
  display: flex;
  gap: 10px;
  margin: 20px 0 12px;
}
.actions .btn { flex: 1; }

/* The lobby stacks its actions: being ready is the one thing everybody does,
   the host only gets a small extra button to skip the auto start wait. */
.actions--lobby { flex-direction: column; gap: 8px; }
.actions--lobby .btn { flex: none; }

.btn--ready {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.btn__sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: none;
  opacity: .7;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 16px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--line);
}

.join-row { display: flex; gap: 10px; }
.join-row .code-input { flex: 1; }

.notice {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.notice--error { color: var(--danger); }

/* ---------- lobby ---------- */

.room-code {
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: clamp(48px, 13vw, 72px);
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--hot);
  text-shadow: 0 0 24px rgba(247, 37, 133, .5);
}

.players {
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 10px;
}
.player__dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex: none;
  box-shadow: 0 0 10px currentColor;
}
.player__name {
  flex: 1;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tag {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.tag--host { background: rgba(247, 37, 133, .18); color: var(--hot); }
.tag--ready { background: rgba(167, 201, 87, .18); color: var(--good); }
.tag--wait { background: rgba(138, 138, 168, .15); color: var(--muted); }
.tag--spec { background: rgba(76, 201, 240, .15); color: var(--neon); }
.tag--bot { background: rgba(114, 9, 183, .28); color: #c9a7ff; }

.bots {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 10px;
}
.bots__label {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--muted);
}
.bots__count {
  min-width: 20px;
  text-align: center;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}
.bots__hint {
  flex: 1;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
}
.btn--step {
  flex: none;
  width: 34px;
  padding: 0;
  height: 34px;
  font-size: 18px;
  line-height: 1;
}

/* ---------- game ---------- */

.screen--game {
  gap: 16px;
  padding: 12px;
}

.board {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
}

.sidebar {
  width: 280px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--bg-panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  overflow-y: auto;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.hud__item {
  padding: 8px;
  background: var(--bg-raised);
  border-radius: 8px;
  text-align: center;
}
.hud__label {
  display: block;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.hud__item b {
  font-family: var(--mono);
  font-size: 18px;
}
.hud__item.is-warning b { color: var(--danger); }

/* The room's deaths as they happen. Empty it takes no room at all, so the
   scoreboard keeps its place until somebody dies. */
.feed {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  font-size: 13px;
}
.feed:empty { display: none; }
.feed__line {
  padding: 5px 8px;
  background: var(--bg-raised);
  border-left: 3px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  animation: feed-in .25s ease;
}
.feed__who { font-weight: 700; }
.feed__who.is-me { text-decoration: underline; }

@keyframes feed-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: none; }
}

.scoreboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.scoreboard th {
  padding: 6px 4px;
  border-bottom: 2px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1px;
  text-align: right;
  text-transform: uppercase;
}
.scoreboard th:first-child { text-align: left; }
.scoreboard td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  text-align: right;
}
.scoreboard td:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  font-weight: 700;
  text-align: left;
}
.scoreboard tr.is-dead { opacity: .38; }
.scoreboard tr.is-me td { background: rgba(255, 255, 255, .06); }
.scoreboard .dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
}
.scoreboard .who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint {
  margin: auto 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* The way out sits under the hint, at the bottom of the sidebar. Armed it
   turns red, so the second click is clearly the one that ends your round. */
.btn--leave { margin-top: 10px; }
.btn--leave.is-armed {
  border-color: var(--danger);
  color: var(--danger);
}
.btn--leave.is-armed:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

/* ---------- overlays ---------- */

.big-countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(90px, 26vw, 220px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px var(--neon);
  pointer-events: none;
  animation: pop .35s ease-out;
}
@keyframes pop {
  from { transform: scale(.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  background: rgba(8, 8, 15, .82);
  border-radius: 12px;
  text-align: center;
}
.overlay__title {
  margin: 0;
  font-size: clamp(34px, 7vw, 58px);
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--danger);
  text-shadow: 0 0 24px rgba(230, 57, 70, .6);
}
.overlay--results .overlay__title { color: var(--neon); text-shadow: 0 0 24px rgba(76, 201, 240, .6); }

/* A dead player is a spectator, so the notice steps aside and lets them watch. */
.overlay--dead {
  transition: background .5s ease, padding .5s ease;
}
.overlay--dead.is-compact {
  justify-content: flex-start;
  padding-top: 10px;
  background: transparent;
  pointer-events: none;
}
.overlay--dead.is-compact .overlay__title {
  font-size: 22px;
  text-shadow: 0 0 10px rgba(0, 0, 0, .9);
}
.overlay--dead.is-compact .overlay__reason {
  font-size: 14px;
  color: var(--muted);
}
.overlay--dead.is-compact .overlay__sub { display: none; }
.overlay__reason { margin: 0; font-size: 20px; }
.overlay__sub { margin: 0; color: var(--muted); }

.ranking {
  margin: 14px 0;
  padding: 0;
  list-style: none;
  width: min(420px, 100%);
  display: grid;
  gap: 6px;
  max-height: 55vh;
  overflow-y: auto;
}
.ranking li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 10px;
  text-align: left;
}
.ranking li:first-child {
  border-color: #ffd166;
  box-shadow: 0 0 20px rgba(255, 209, 102, .3);
}
.ranking .place {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 900;
  color: var(--muted);
  min-width: 34px;
}
.ranking li:first-child .place { color: #ffd166; }
.ranking .who { flex: 1; font-weight: 700; }
.ranking .stats { font-family: var(--mono); color: var(--muted); font-size: 14px; }

/* The running score of the room, in the lobby and under the round ranking. */
.standings {
  margin: 22px 0 0;
  width: min(420px, 100%);
}
.standings--overlay { margin: 0 0 14px; }
.standings__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  max-height: 28vh;
  overflow-y: auto;
}
.standings__list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: var(--bg-raised);
  border: 2px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  text-align: left;
}
.standings__list li:first-child { border-color: #ffd166; }
.standings__list .place {
  font-family: var(--mono);
  font-weight: 900;
  color: var(--muted);
  min-width: 26px;
}
.standings__list li:first-child .place { color: #ffd166; }
.standings__list .dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
}
.standings__list .who {
  flex: 1;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.standings__list .stats {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.connection {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--danger);
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  z-index: 20;
}

[hidden] { display: none !important; }

/* ---------- small screens ---------- */

@media (max-width: 860px) {
  .screen--game {
    flex-direction: column;
    justify-content: flex-start;
  }
  /* The board keeps the grid's own shape, the scoreboard takes what is left. */
  .board {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: var(--board-aspect, 4 / 3);
    max-height: 62vh;
  }
  .sidebar {
    width: 100%;
    flex: 1;
    min-height: 0;
  }
  .hint { display: none; }
  /* The hint is gone here, so the leave button takes over pushing itself down. */
  .btn--leave { margin-top: auto; }
}
