/* ===========================================================
   Slither LAN — UI theme
   Dark neon, glassy panels, mobile-first, big touch targets.
   =========================================================== */

:root {
  --bg0: #070a14;
  --bg1: #0d1326;
  --accent: #22e1ff;
  --accent2: #6a5bff;
  --good: #39ff14;
  --danger: #ff3b5c;
  --text: #eaf2ff;
  --muted: #8ea3c8;
  --glass: rgba(18, 26, 48, 0.72);
  --glass-brd: rgba(120, 160, 255, 0.18);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 120% at 50% 0%, #11183a 0%, var(--bg0) 60%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans Thai", sans-serif;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 0;
}

/* ---------- Overlay screens ---------- */
.screen {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(80% 80% at 50% 40%, rgba(13, 19, 38, 0.35), rgba(5, 8, 18, 0.82));
  backdrop-filter: blur(3px);
  animation: fade 0.25s ease;
}
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: min(440px, 92vw);
  max-height: 92vh; overflow-y: auto;
  background: var(--glass);
  border: 1px solid var(--glass-brd);
  border-radius: 22px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

/* ---------- Logo / headings ---------- */
/* "Fat snake" title — chunky rounded font (uses Baloo Thai 2 / Mali / Itim if
   the device has them, otherwise a heavy system fallback) with a
   yellow -> green -> orange gradient. */
.logo {
  margin: 6px 0 0;
  font-family: "Baloo Thai 2", "Mali", "Itim", "Segoe UI", "Noto Sans Thai", system-ui, sans-serif;
  font-size: 3.4rem; font-weight: 900; letter-spacing: 1px; line-height: 1.04;
  background: linear-gradient(100deg, #ffe14d 0%, #5cff5c 50%, #ff8a1e 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.28)) drop-shadow(0 0 22px rgba(120, 255, 90, 0.28));
}
.logo-sub {
  margin: 2px 0 0;
  font-family: "Baloo Thai 2", "Mali", "Segoe UI", system-ui, sans-serif;
  font-size: 1.5rem; font-weight: 800; letter-spacing: 4px;
  background: linear-gradient(100deg, #ffe14d, #5cff5c, #ff8a1e);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.tagline { color: var(--muted); margin: 10px 0 18px; font-size: 0.95rem; }

/* Clickable credit link */
.powered-by {
  display: inline-block; margin-top: 16px;
  font-size: 0.82rem; font-weight: 800; letter-spacing: 0.5px;
  text-decoration: none;
  background: linear-gradient(100deg, #ffe14d, #5cff5c, #ff8a1e);
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
  opacity: 0.95; transition: transform 0.1s ease, filter 0.15s ease;
  filter: drop-shadow(0 0 10px rgba(120, 255, 90, 0.2));
}
.powered-by:hover { transform: translateY(-1px); filter: drop-shadow(0 0 14px rgba(255, 180, 40, 0.45)); }
.powered-by:active { transform: translateY(0); }
h2 { margin: 0 0 14px; font-size: 1.5rem; }
h3 { margin: 0 0 10px; font-size: 0.92rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

/* ---------- Inputs ---------- */
.field { display: block; text-align: left; margin: 12px 0; }
.field > span { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 13px 14px;
  background: rgba(8, 12, 26, 0.85);
  border: 1px solid var(--glass-brd); border-radius: 12px;
  color: var(--text); font-size: 1rem; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 225, 255, 0.18); }

/* ---------- Buttons ---------- */
.btn {
  display: block; width: 100%;
  margin: 10px 0 0;
  padding: 15px 18px;
  border: none; border-radius: 14px;
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
  color: #07101c;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: #04111d;
  box-shadow: 0 10px 28px rgba(34, 225, 255, 0.28);
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost {
  background: rgba(120, 160, 255, 0.10);
  border: 1px solid var(--glass-brd);
  color: var(--text);
}
.mini-btn {
  background: rgba(120, 160, 255, 0.12);
  border: 1px solid var(--glass-brd);
  color: var(--text); border-radius: 8px;
  padding: 2px 8px; cursor: pointer; font-size: 0.9rem;
}

/* ---------- Menu skin preview ---------- */
.skin-row { display: flex; gap: 12px; align-items: center; margin: 16px 0; }
.menu-skin-preview {
  flex: 1; height: 64px; border-radius: 12px;
  background: rgba(8, 12, 26, 0.6);
  border: 1px solid var(--glass-brd);
}
.skin-row .btn { margin: 0; width: auto; white-space: nowrap; padding: 13px 16px; }

/* ---------- Advanced / connection ---------- */
.advanced { margin-top: 16px; text-align: left; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; padding: 6px 0; }
.hint { font-size: 0.78rem; color: var(--muted); line-height: 1.45; margin: 8px 0 0; }
.best-row { margin-top: 16px; font-size: 0.9rem; color: var(--muted); }
.best-row b { color: var(--good); }

.conn-state {
  position: fixed; bottom: 18px; left: 0; right: 0;
  text-align: center; color: var(--accent); font-size: 0.9rem;
  pointer-events: none; min-height: 1.2em;
}

/* ---------- Customization ---------- */
.skin-preview {
  width: 100%; max-width: 320px; height: 150px;
  border-radius: 16px; margin: 0 auto 16px; display: block;
  background: rgba(8, 12, 26, 0.55);
  border: 1px solid var(--glass-brd);
}
.cust-section { margin: 16px 0; text-align: left; }
.preset-list, .pattern-list { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-chip, .pattern-chip {
  padding: 9px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--glass-brd);
  background: rgba(120, 160, 255, 0.08);
  font-size: 0.85rem; color: var(--text);
  display: flex; align-items: center; gap: 7px;
}
.preset-chip .swatch { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.preset-chip.active, .pattern-chip.active {
  border-color: var(--accent);
  background: rgba(34, 225, 255, 0.16);
  box-shadow: 0 0 0 2px rgba(34, 225, 255, 0.25) inset;
}
.colors { display: flex; gap: 18px; align-items: flex-end; }
.color-field { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: var(--muted); }
.color-field input[type=color] {
  width: 64px; height: 42px; padding: 0; border: 1px solid var(--glass-brd);
  border-radius: 10px; background: none; cursor: pointer;
}

/* ===========================================================
   In-game HUD
   =========================================================== */
.hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
/* Info panels stay transparent to touch so the floating joystick can start
   anywhere on the canvas; only the interactive controls capture input. */
#muteBtn, #boostBtn { pointer-events: auto; }

.hud-top-left { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 14px; display: flex; gap: 10px; }
.stat {
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 12px; padding: 7px 13px; min-width: 78px;
  text-align: center; backdrop-filter: blur(6px);
}
.stat-label { display: block; font-size: 0.65rem; color: var(--muted); letter-spacing: 1px; }
.stat-value { display: block; font-size: 1.25rem; font-weight: 800; color: var(--accent); }

.hud-top-right { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px; }
.leaderboard {
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 12px; padding: 8px 12px; min-width: 150px;
  backdrop-filter: blur(6px);
}
.leaderboard h4 { margin: 0 0 6px; font-size: 0.78rem; color: var(--muted); text-align: center; }
.leaderboard ol { margin: 0; padding: 0; list-style: none; }
.leaderboard li {
  font-size: 0.82rem; padding: 2px 0;
  display: flex; align-items: center; gap: 8px;
}
.leaderboard li .lb-rank { width: 1.5em; text-align: right; color: var(--muted); flex: none; }
.leaderboard li .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li .lb-score { color: var(--accent); flex: none; }
.leaderboard li.you { color: var(--good); font-weight: 700; }
.leaderboard li.you .lb-rank, .leaderboard li.you .lb-score { color: var(--good); }
.leaderboard li.lb-sep { justify-content: center; color: var(--muted); padding: 0; line-height: 0.5; }

.hud-rank {
  position: absolute; bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 20px; padding: 6px 16px; font-size: 0.85rem; color: var(--muted);
  backdrop-filter: blur(6px);
}
.hud-rank b { color: var(--accent); }

.hud-net {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem; color: var(--muted);
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 16px; padding: 4px 11px; display: flex; gap: 6px; align-items: center;
}

.boost-btn {
  position: absolute; right: calc(22px + env(safe-area-inset-right));
  bottom: calc(80px + env(safe-area-inset-bottom));
  width: 96px; height: 96px; border-radius: 50%;
  border: 2px solid rgba(34, 225, 255, 0.5);
  background: radial-gradient(circle at 50% 35%, rgba(34, 225, 255, 0.35), rgba(34, 225, 255, 0.08));
  color: var(--accent); font-weight: 800; font-size: 0.9rem; letter-spacing: 1px;
  display: none; /* shown only on touch devices via body.touch */
  align-items: center; justify-content: center;
  box-shadow: 0 0 24px rgba(34, 225, 255, 0.25);
}
.boost-btn:active { background: radial-gradient(circle at 50% 35%, rgba(34, 225, 255, 0.6), rgba(34, 225, 255, 0.18)); transform: scale(0.96); }
body.touch .boost-btn { display: flex; }

/* ---------- Power-up bar ---------- */
.powerbar {
  position: absolute; left: 14px; top: calc(62px + env(safe-area-inset-top));
  display: flex; gap: 6px; pointer-events: none;
}
.power-chip {
  display: flex; align-items: center; gap: 4px;
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 9px; padding: 3px 8px; font-size: 1rem;
  backdrop-filter: blur(6px);
}
.power-chip b { font-size: 0.78rem; color: var(--text); font-weight: 800; }
.power-chip.pc-shield { border-color: rgba(255,210,74,0.65); box-shadow: 0 0 10px rgba(255,210,74,0.25); }
.power-chip.pc-speed  { border-color: rgba(34,225,255,0.65); box-shadow: 0 0 10px rgba(34,225,255,0.25); }
.power-chip.pc-magnet { border-color: rgba(255,90,208,0.65); box-shadow: 0 0 10px rgba(255,90,208,0.25); }
.power-chip.pc-ghost  { border-color: rgba(232,240,255,0.65); box-shadow: 0 0 10px rgba(232,240,255,0.2); }

/* ---------- Kill feed ---------- */
.killfeed {
  position: absolute;
  left: 14px; top: calc(108px + env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 5px;
  pointer-events: none; max-width: 48vw;
}
.kill-line {
  align-self: flex-start;
  background: var(--glass); border: 1px solid var(--glass-brd);
  border-radius: 9px; padding: 4px 10px;
  font-size: 0.8rem; color: var(--text); white-space: nowrap;
  backdrop-filter: blur(6px);
  opacity: 1; transition: opacity 0.4s ease, transform 0.4s ease;
  animation: kf-in 0.25s ease;
}
.kill-line.fade { opacity: 0; transform: translateX(-14px); }
.kill-line .kf-killer { color: var(--accent); font-weight: 700; }
.kill-line .kf-victim { color: #ff8aa0; font-weight: 700; }
.kill-line .kf-you { color: var(--good); font-weight: 800; }
.kill-line .kf-act { opacity: 0.85; }
@keyframes kf-in { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

/* ---------- Death ---------- */
.death-panel h2 { color: var(--danger); text-shadow: 0 0 24px rgba(255, 59, 92, 0.35); }
.death-stats { display: flex; justify-content: space-around; gap: 12px; margin: 18px 0 22px; }
.death-stat { display: flex; flex-direction: column; gap: 4px; }
.death-stat span { font-size: 0.75rem; color: var(--muted); }
.death-stat b { font-size: 1.7rem; color: var(--accent); }

/* ---------- Responsive tweaks ---------- */
@media (max-width: 480px) {
  .logo { font-size: 2.7rem; }
  .logo-sub { font-size: 1.25rem; letter-spacing: 3px; }
  .leaderboard { min-width: 120px; }
  .stat { min-width: 66px; padding: 6px 10px; }
  .stat-value { font-size: 1.05rem; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .panel { padding: 16px 20px; }
  .skin-preview { height: 100px; }
}
