/* Serpentine — UI stylesheet (menu, overlays, HUD). Original design. */

:root {
  --bg: #0b0e17;
  --ink: #eef2ff;
  --ink-2: #c3cbe4;
  --muted: #7f89a8;
  --faint: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.1);
  --panel: rgba(13, 17, 30, 0.94);
  --hud-panel: rgba(10, 14, 26, 0.46);
  --green: #58f07a;
  --green-hi: #8dfaa6;
  --green-lo: #20b451;
  --green-edge: #148a3b;
  --red: #ff3b5c;
  --gold: #ffd23f;
  --silver: #d6deef;
  --bronze: #e39a5d;
  --font: "Segoe UI", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --font-round: "Arial Rounded MT Bold", "Varela Round", "Nunito", "Quicksand", "Comfortaa", "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --st: env(safe-area-inset-top, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --gap: 14px;
  --mm: 170px;
  --lb-w: 224px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

.hidden { display: none !important; }

/* touch / desktop specific bits ------------------------------------------- */
.touch-only { display: none !important; }
html.touch .touch-only { display: revert !important; }
html.touch .touch-only.hidden { display: none !important; }
html.touch .desk-only { display: none !important; }
html.touch #boost-btn.touch-only,
html.touch #hud-pause-btn.touch-only { display: flex !important; }

/* world canvas ------------------------------------------------------------- */
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
}

/* shared fade: shown elements fade in automatically; .is-leaving fades out */
@keyframes ui-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ui-rise-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }

#menu, #hud, .overlay { animation: ui-fade-in 0.28s ease-out; }
.is-leaving {
  opacity: 0 !important;
  transition: opacity 0.22s ease-in !important;
  pointer-events: none !important;
}

/* =========================================================================
   Buttons & inputs
   ========================================================================= */
button { font: inherit; color: inherit; }

.btn-primary {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 34px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--green-hi) 0%, var(--green) 38%, var(--green-lo) 100%);
  color: #04260f;
  font-family: var(--font-round);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--green-edge), 0 8px 26px rgba(88, 240, 122, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}
.btn-primary:hover { filter: brightness(1.07) saturate(1.05); transform: translateY(-1px); box-shadow: 0 6px 0 var(--green-edge), 0 10px 32px rgba(88, 240, 122, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.6); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--green-edge), 0 3px 12px rgba(88, 240, 122, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.btn-primary:focus-visible { outline: 3px solid rgba(141, 250, 166, 0.55); outline-offset: 4px; }

/* second primary button: online play (blue / cyan, so it never reads as another "Play") */
.btn-online {
  gap: 10px;
  background: linear-gradient(180deg, #b3f0ff 0%, #4cc9f5 40%, #1f86e0 100%);
  color: #032340;
  box-shadow: 0 5px 0 #145ea8, 0 8px 26px rgba(76, 201, 245, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.btn-online:hover { box-shadow: 0 6px 0 #145ea8, 0 10px 32px rgba(76, 201, 245, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.65); }
.btn-online:active { box-shadow: 0 1px 0 #145ea8, 0 3px 12px rgba(76, 201, 245, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.btn-online:focus-visible { outline-color: rgba(140, 220, 255, 0.65); }
.ob-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #eaffff;
  box-shadow: 0 0 0 3px rgba(3, 35, 64, 0.22), 0 0 10px rgba(255, 255, 255, 0.9);
  animation: ob-pulse 2.2s ease-in-out infinite;
}
@keyframes ob-pulse { 50% { box-shadow: 0 0 0 5px rgba(3, 35, 64, 0.08), 0 0 14px rgba(255, 255, 255, 1); } }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-2);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  -webkit-user-select: none;
  user-select: none;
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.12); color: #fff; border-color: rgba(255, 255, 255, 0.2); }
.btn-secondary:active { transform: translateY(1px) scale(0.98); }
.btn-secondary:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.6); outline-offset: 3px; }
.btn-secondary.btn-chip { min-height: 32px; padding: 0 14px; font-size: 13px; }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.4; cursor: default; filter: grayscale(0.4); transform: none; pointer-events: none; }

/* five-point star drawn with a clip-path (a "★" text glyph costs a slow first-use font fallback
   lookup — measurable when the gallery opens) */
.star-ico, .sk-star::before {
  content: "";
  display: block;
  flex: none;
  width: 1em;
  height: 1em;
  background: currentColor;
  clip-path: polygon(50% 2%, 61.8% 36.2%, 98% 36.5%, 69% 58.2%, 79.4% 93%, 50% 72.4%, 20.6% 93%, 31% 58.2%, 2% 36.5%, 38.2% 36.2%);
}

.swatch {
  display: inline-block;
  width: 26px;
  height: 12px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22), 0 0 10px rgba(255, 255, 255, 0.12);
  flex: none;
}

/* =========================================================================
   Main menu
   ========================================================================= */
#menu {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: calc(18px + var(--st)) calc(16px + var(--sr)) calc(10px + var(--sb)) calc(16px + var(--sl));
  /* No backdrop-filter: a full-viewport blur over the 60 Hz world canvas has to be recomputed
     every frame (it roughly halves the menu frame rate on software-composited machines).
     A stronger radial dim keeps the menu readable instead. */
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, rgba(9, 12, 22, 0.42) 0%, rgba(6, 8, 16, 0.72) 60%, rgba(3, 4, 10, 0.9) 100%);
  -webkit-user-select: none;
  user-select: none;
}
#menu, .overlay { scrollbar-width: none; }
#menu::-webkit-scrollbar, .overlay::-webkit-scrollbar { display: none; }

/* result screen arming (menu.js RESULT_ARM_MS): stray clicks from the round cannot hit Play */
#menu.arming #menu-inner,
#menu.arming .menu-corner { pointer-events: none; }
#menu.arming #play-btn, #menu.arming #online-btn { opacity: 0.7; }
#play-btn, #online-btn { transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease, opacity 0.2s ease; }

/* corner controls: graphics quality (all devices) and fullscreen (touch only) */
#menu .menu-corner {
  position: absolute;
  top: calc(10px + var(--st));
  z-index: 1;
  min-height: 34px;
  padding: 0 14px;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.045);
  transition: opacity 0.2s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
#menu .menu-corner:hover { color: #fff; }
#menu .menu-corner b { color: var(--ink-2); font-weight: 700; }
#quality-toggle { right: calc(12px + var(--sr)); }
#fullscreen-btn { left: calc(12px + var(--sl)); }
#menu.sub-open .menu-corner { opacity: 0.12; pointer-events: none; }

#menu.sub-open #menu-inner,
#menu.sub-open #menu-footer { opacity: 0.12; filter: blur(1px); pointer-events: none; }

/* The skin gallery covers the whole screen with a near-opaque backdrop: once it has faded in, the
   menu under it is not painted at all (two stacked full-screen translucent layers plus the
   animated logo cost ~10 ms per frame on software-composited machines). The menu's CONTENTS go at
   once, without the dim + blur transition above: re-filtering the logo and the buttons on every
   frame of it kept the GPU busy right when the gallery's own first frames have to be rasterised
   (measured: GPU-side work of the opening halves, the longest frame goes from 60-70 ms to ~40 ms).
   Only the menu's own dim backdrop stays until the gallery's has faded in, so the world behind
   never flashes up. Closing fades the contents back in (opacity only: composited). */
#menu.gallery-open { visibility: hidden; transition: visibility 0s linear 0.3s; }
#menu.gallery-open #menu-inner,
#menu.gallery-open #menu-footer,
#menu.gallery-open .menu-corner { visibility: hidden; opacity: 0; filter: none; transition: opacity 0.2s ease; }

#menu-inner {
  margin: auto;
  width: min(100%, 470px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 0 18px;
  transition: opacity 0.2s ease, filter 0.2s ease;
  animation: ui-rise-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---- logo: each letter its own glowing colour, slithering wave ---------- */
#logo {
  margin: 0;
  display: flex;
  justify-content: center;
  font-family: var(--font-round);
  font-weight: 900;
  font-size: clamp(46px, 13.5vw, 108px);
  line-height: 1;
  letter-spacing: -0.01em;
  padding: 0.12em 0 0.06em;
  white-space: nowrap;
  cursor: default;
}
#logo span {
  --c: #fff;
  display: inline-block;
  color: var(--c);
  text-shadow:
    0 0 0.06em rgba(255, 255, 255, 0.55),
    0 0 0.16em var(--c),
    0 0 0.42em var(--c),
    0 0.05em 0.02em rgba(0, 0, 0, 0.55);
  animation: logo-slither 2.6s ease-in-out infinite;
  will-change: transform;
}
#logo span:nth-child(1)  { --c: #58f07a; animation-delay: 0s; }
#logo span:nth-child(2)  { --c: #7dffcf; animation-delay: -0.2s; }
#logo span:nth-child(3)  { --c: #4fd8e8; animation-delay: -0.4s; }
#logo span:nth-child(4)  { --c: #3a9cff; animation-delay: -0.6s; }
#logo span:nth-child(5)  { --c: #6f8cff; animation-delay: -0.8s; }
#logo span:nth-child(6)  { --c: #b77cff; animation-delay: -1.0s; }
#logo span:nth-child(7)  { --c: #f05fe0; animation-delay: -1.2s; }
#logo span:nth-child(8)  { --c: #ff6f6f; animation-delay: -1.4s; }
#logo span:nth-child(9)  { --c: #ffab4a; animation-delay: -1.6s; }
#logo span:nth-child(10) { --c: #ffd23f; animation-delay: -1.8s; }

@keyframes logo-slither {
  0%   { transform: translateY(0.07em) rotate(-3deg); }
  25%  { transform: translateY(0) rotate(0deg); }
  50%  { transform: translateY(-0.07em) rotate(3deg); }
  75%  { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(0.07em) rotate(-3deg); }
}

#tagline {
  margin-top: -6px;
  color: var(--muted);
  font-size: 15px;
  letter-spacing: 0.22em;
  text-transform: lowercase;
  text-align: center;
}

/* ---- last result -------------------------------------------------------- */
#last-result {
  width: 100%;
  padding: 14px 16px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(20, 26, 44, 0.82), rgba(12, 16, 28, 0.82));
  border: 1px solid var(--line);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  text-align: center;
  animation: ui-rise-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.lr-head { font-size: 16px; color: var(--ink-2); }
.lr-len {
  display: inline-block;
  margin-left: 4px;
  font-family: var(--font-round);
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 14px rgba(88, 240, 122, 0.55);
  font-variant-numeric: tabular-nums;
  vertical-align: -3px;
}
.lr-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe27a, #f4b31f);
  color: #3a2600;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 0 18px rgba(255, 210, 63, 0.45);
  animation: badge-pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) 0.5s both;
}
@keyframes badge-pop { from { transform: scale(0.3); opacity: 0; } to { transform: none; opacity: 1; } }

.lr-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}
.lr-item {
  flex: 1 1 88px;
  max-width: 180px;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.lr-k { display: block; font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.lr-v {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.lr-cause { margin-top: 3px; font-size: 14px; color: var(--muted); }
.lr-killer { color: #ff8a9c; font-weight: 700; }
.lr-killer.anon { font-style: italic; font-weight: 600; }

/* ---- nickname & play ---------------------------------------------------- */
#nickname {
  width: min(100%, 340px);
  height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.09);
  background: rgba(14, 19, 34, 0.9);
  color: #fff;
  font-family: var(--font);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  outline: none;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-user-select: text;
  user-select: text;
}
#nickname::placeholder { color: #5c6684; font-weight: 500; }
#nickname:hover { border-color: rgba(255, 255, 255, 0.16); }
#nickname:focus { border-color: rgba(88, 240, 122, 0.75); box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(88, 240, 122, 0.14), 0 0 24px rgba(88, 240, 122, 0.2); }

.play-row {
  width: min(100%, 340px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 13px;
  margin: 2px 0 6px;
}
#play-btn { min-height: 58px; font-size: 25px; }
#online-btn { min-height: 48px; font-size: 18px; }

/* connected to a server: where, and a way out */
#online-status {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  max-width: 100%;
  margin-top: -2px;
  padding: 6px 8px 6px 14px;
  border-radius: 18px; /* (wraps to two lines on phones) */
  background: rgba(76, 201, 245, 0.1);
  border: 1px solid rgba(76, 201, 245, 0.3);
  color: var(--ink-2);
  font-size: 13px;
}
.os-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #4cc9f5; box-shadow: 0 0 8px #4cc9f5; }
.os-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.os-text b { color: #fff; }
#os-meta { color: var(--muted); font-variant-numeric: tabular-nums; }
#leave-server-btn { min-height: 28px; }
#leave-server-btn:hover { background: rgba(255, 90, 110, 0.18); border-color: rgba(255, 90, 110, 0.45); color: #fff; }
#online-note { margin-top: -4px; color: #ffc47a; font-size: 13px; text-align: center; animation: ui-fade-in 0.2s ease-out; }

.menu-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#controls-help {
  max-width: 440px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.75;
  text-align: center;
}
#controls-help .grp { display: inline-block; white-space: nowrap; margin: 0 9px; }
#controls-help b {
  display: inline-block;
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--ink-2);
  font-weight: 600;
  line-height: 1.45;
}

#menu-tip {
  max-width: 420px;
  min-height: 1em;
  color: #9aa6c7;
  font-size: 12.5px;
  font-style: italic;
  text-align: center;
  opacity: 0.85;
}
#menu-tip:empty { display: none; }
#menu-tip::before { content: "tip — "; font-style: normal; color: var(--green); opacity: 0.8; letter-spacing: 0.06em; }

#menu-footer {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 6px;
  padding-top: 8px;
  color: #56607d;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  transition: opacity 0.2s ease;
}
#menu-footer .dot { opacity: 0.6; margin-right: 6px; }
#menu-footer b { color: #8d97b5; }
#footer-best { display: inline; }

/* =========================================================================
   Overlays: skin picker & settings
   ========================================================================= */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: calc(16px + var(--st)) calc(16px + var(--sr)) calc(16px + var(--sb)) calc(16px + var(--sl));
  background: rgba(4, 6, 12, 0.55);
  -webkit-user-select: none;
  user-select: none;
}
.overlay-title {
  font-family: var(--font-round);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}
.overlay-hint { margin-top: 2px; font-size: 12px; color: #5f6988; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 4px; }

/* ---- skin gallery -------------------------------------------------------
   .skin-wrap is a two-pane dialog: .sk-side (big preview, name, accessory, Cancel / Save) and
   .sk-main (search, category tabs, the scrolling thumbnail grid). While building a custom skin
   (#skin-picker.building) the #skin-builder pane replaces .sk-main. Phones: one column (portrait,
   .sk-side's children are re-ordered around the grid) or a slim two-pane layout (landscape). */
/* (the dialog is sized to fit; only on tiny screens, where even the minimum sizes do not fit, does the
   overlay itself scroll) */
#skin-picker { background: radial-gradient(ellipse 80% 70% at 50% 45%, rgba(8, 11, 22, 0.78), rgba(3, 4, 9, 0.95)); overflow-x: hidden; }
.skin-wrap {
  margin: auto;
  width: min(100%, 1360px);
  height: min(100%, 860px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(0, 1.6fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 22px;
  animation: ui-rise-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sk-side {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  overflow-y: auto;
  scrollbar-width: none;
}
.sk-side::-webkit-scrollbar { display: none; }
/* centred while it fits, top-aligned and scrollable when it does not (spacers shrink to nothing) */
.sk-side::before, .sk-side::after { content: ""; flex: 1 1 0; min-height: 0; margin: -5px 0; }
.skin-stage {
  position: relative;
  flex: none;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#skin-canvas {
  display: block;
  width: 100%;
  height: clamp(120px, 27vh, 250px);
  touch-action: pan-y;
  cursor: grab;
  transition: opacity 0.2s ease;
}
#skin-canvas:active { cursor: grabbing; }
#skin-canvas.ghost { opacity: 0.35; }
.skin-arrow {
  position: absolute;
  top: 50%;
  width: 42px;
  height: 42px;
  margin-top: -21px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 5px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(20, 26, 44, 0.78);
  color: #fff;
  font-size: 31px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.skin-arrow:hover { background: rgba(40, 52, 84, 0.92); border-color: rgba(141, 250, 166, 0.5); opacity: 1; }
.skin-arrow:active { transform: scale(0.92); }
.skin-arrow:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.7); outline-offset: 3px; opacity: 1; }
#skin-prev { left: 0; }
#skin-next { right: 0; }

.sk-namerow { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; max-width: 100%; }
#skin-name {
  min-width: 0;
  min-height: 1.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-round);
  font-size: clamp(21px, 2.6vw, 30px);
  font-weight: 900;
  color: #fff;
  text-align: center;
  text-shadow: 0 0 18px rgba(255, 255, 255, 0.25);
}
#skin-name.bump { animation: name-bump 0.28s ease-out; }
@keyframes name-bump { from { transform: translateY(6px); opacity: 0.2; } to { transform: none; opacity: 1; } }
/* favourite toggle of the focused skin (the stars on the tiles are mouse / touch shortcuts) */
.sk-favbtn {
  flex: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(20, 26, 44, 0.78);
  color: rgba(255, 255, 255, 0.4);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.sk-favbtn:hover { color: #fff; border-color: rgba(255, 210, 63, 0.5); }
.sk-favbtn:active { transform: scale(0.9); }
.sk-favbtn:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.7); outline-offset: 2px; }
.sk-favbtn.on { color: var(--gold); border-color: rgba(255, 210, 63, 0.55); background: rgba(255, 210, 63, 0.12); box-shadow: 0 0 14px rgba(255, 210, 63, 0.25); }
.sk-favbtn.bump { animation: fav-pop 0.3s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes fav-pop { from { transform: scale(0.6); } to { transform: none; } }

.skin-sub { flex: none; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#skin-meta { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.sk-badge { padding: 1px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.08); color: var(--ink-2); font-size: 12px; white-space: nowrap; }
#skin-swatches { display: inline-flex; gap: 5px; }
#skin-swatches i {
  display: block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25), 0 0 8px currentColor;
}
#skin-save, #sb-save { min-width: 140px; }
.skin-actions { flex: none; margin-top: 2px; }

/* ---- head accessory: name with ‹ › and a small grid --------------------------------- */
#acc-row { display: flex; align-items: center; justify-content: center; gap: 6px; }
.acc-label { margin-right: 4px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.acc-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0 0 3px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: rgba(20, 26, 44, 0.78);
  color: #fff;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.acc-arrow:hover { background: rgba(40, 52, 84, 0.92); border-color: rgba(141, 250, 166, 0.5); }
.acc-arrow:active { transform: scale(0.92); }
.acc-arrow:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.7); outline-offset: 2px; }
#acc-name { min-width: 104px; color: #fff; font-size: 15px; font-weight: 800; text-align: center; white-space: nowrap; }
#acc-name.none { color: var(--muted); font-weight: 600; }
#acc-name.bump { animation: name-bump 0.22s ease-out; }
/* a larger (invisible) hit area on touch screens */
html.touch .acc-arrow { position: relative; }
html.touch .acc-arrow::before { content: ""; position: absolute; inset: -6px; }
#acc-grid {
  position: relative;
  width: min(100%, 392px);
  display: grid;
  grid-template-columns: repeat(auto-fill, 58px);
  grid-auto-rows: 48px;
  justify-content: center;
  gap: 6px;
  padding: 3px;
  max-height: 195px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.acc-tile {
  position: relative;
  width: 58px;
  height: 48px;
  min-width: 0;
  padding: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink-2);
  cursor: pointer;
  overflow: hidden;
  touch-action: manipulation;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}
/* (the <img> shows ONE cell of a shared thumbnail sheet: menu.js widens and shifts it, the tile clips) */
.acc-tile img { position: absolute; left: 0; top: 0; display: block; width: 100%; max-width: none; height: 100%; visibility: hidden; pointer-events: none; }
.acc-tile.ready img { visibility: visible; }
.acc-tile.text { width: auto; min-width: 58px; padding: 0 8px; font-size: 11px; font-weight: 700; white-space: nowrap; }
#acc-grid:has(.acc-tile.text) { display: flex; flex-wrap: wrap; }
.acc-tile:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2); }
.acc-tile:active { transform: scale(0.94); }
.acc-tile:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.8); outline-offset: 1px; }
/* (the glow is inset: an outer one is cut off by the scrolling grid's edge) */
.acc-tile.sel { border-color: rgba(141, 250, 166, 0.85); background: rgba(88, 240, 122, 0.14); box-shadow: inset 0 0 12px rgba(88, 240, 122, 0.3); }
/* Scrolling strips (accessory grid, one-row tab bar / effect chips on phones): the content fades out
   towards an edge while there is more that way — menu.js sets .fade-t / -b / -l / -r — so a row or
   chip cut off by the edge reads as "scroll me", not as a layout accident. */
.edge-fade {
  --ft: 0px; --fb: 0px; --fl: 0px; --fr: 0px;
  -webkit-mask-image:
    linear-gradient(to bottom, transparent, #000 var(--ft), #000 calc(100% - var(--fb)), transparent),
    linear-gradient(to right, transparent, #000 var(--fl), #000 calc(100% - var(--fr)), transparent);
  mask-image:
    linear-gradient(to bottom, transparent, #000 var(--ft), #000 calc(100% - var(--fb)), transparent),
    linear-gradient(to right, transparent, #000 var(--fl), #000 calc(100% - var(--fr)), transparent);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
.edge-fade.fade-t { --ft: 22px; }
.edge-fade.fade-b { --fb: 22px; }
.edge-fade.fade-l { --fl: 26px; }
.edge-fade.fade-r { --fr: 26px; }

/* ---- browser pane: search, tabs, grid ------------------------------------------------- */
.sk-main, #skin-builder {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  /* (no big drop shadow: the backdrop is nearly black already, and an 80 px blur around a pane this
     size is slow to rasterise on software-rendered machines — it would land on the opening frame) */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.sk-tools { flex: none; display: flex; align-items: center; gap: 8px; }
#skin-search {
  flex: 1 1 140px;
  min-width: 0;
  height: 36px;
  padding: 0 12px 0 36px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Ccircle cx='6.8' cy='6.8' r='4.6' fill='none' stroke='%237f89a8' stroke-width='1.8'/%3E%3Cpath d='M10.4 10.4l3.6 3.6' stroke='%237f89a8' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 13px center,
    rgba(14, 19, 34, 0.9);
  color: #fff;
  font: 600 14px var(--font);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  -webkit-user-select: text;
  user-select: text;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#skin-search::placeholder { color: #5c6684; font-weight: 500; }
#skin-search:focus { border-color: rgba(88, 240, 122, 0.7); box-shadow: 0 0 0 3px rgba(88, 240, 122, 0.14); }
#skin-search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin-left: 6px; cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M3 3l8 8M11 3l-8 8' stroke='%239aa6c7' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center; }
.sk-tools .btn-chip { flex: none; min-height: 36px; }
#skin-build { gap: 0.3em; } /* "Build" + "your own" (.lbl-long, dropped on narrow layouts) */
/* (position: relative on #skin-tabs / #acc-grid / #sb-fx: menu.js keeps the chosen item of a one-row
   strip in view by its offsetLeft) */
#skin-tabs { position: relative; flex: none; display: flex; flex-wrap: wrap; gap: 6px; }
.sk-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.sk-tab .n { margin-left: 6px; color: var(--muted); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sk-tab:hover { background: rgba(255, 255, 255, 0.11); color: #fff; }
.sk-tab:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.7); outline-offset: 2px; }
.sk-tab[aria-selected="true"] { background: rgba(88, 240, 122, 0.16); border-color: rgba(141, 250, 166, 0.6); color: #fff; }
.sk-tab[aria-selected="true"] .n { color: #b9f7c8; }
.sk-tab-fav { color: #f3dc8f; }
.sk-tab .star-ico { margin-right: 5px; font-size: 12px; }

#skin-grid {
  position: relative; /* offsetParent of the tiles (menu.js scrolls by offsetTop) */
  flex: 1 1 0;
  min-height: 96px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  padding: 4px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  outline: none;
}
.sk-tile {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 6px 5px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
  outline: none;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  /* off-screen tiles skip style / layout / paint of their contents (hundreds of skins); all tiles
     are the same size, which menu.js measures once (.probe) and hands over as --tile-h */
  content-visibility: auto;
  contain-intrinsic-size: 96px var(--tile-h, 70px); /* (content-box size) */
}
/* measuring: real contents, and not stretched to the height of skipped neighbours in its row */
.sk-tile.probe { content-visibility: visible; align-self: start; }
.sk-tile:hover { background: rgba(255, 255, 255, 0.085); border-color: rgba(255, 255, 255, 0.18); }
.sk-tile:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.85); outline-offset: 2px; }
.sk-tile.sel { border-color: rgba(141, 250, 166, 0.85); background: rgba(88, 240, 122, 0.12); box-shadow: 0 0 0 1px rgba(141, 250, 166, 0.45), 0 0 18px rgba(88, 240, 122, 0.2); }
.sk-thumb { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; }
/* until its thumbnail is drawn a tile shows a dim capsule in the skin's colours (--ph) */
.sk-thumb::before {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  top: 50%;
  height: 12px;
  margin-top: -6px;
  border-radius: 999px;
  background: var(--ph, #58f07a);
  opacity: 0.3;
}
/* (no per-tile fade: dozens of simultaneous opacity transitions = dozens of compositor layers) */
.sk-tile.ready .sk-thumb::before { display: none; }
/* (the <img> shows ONE cell of a shared thumbnail sheet: menu.js widens and shifts it, .sk-thumb clips) */
.sk-thumb img { position: absolute; left: 0; top: 0; display: block; width: 100%; max-width: none; height: 100%; visibility: hidden; pointer-events: none; -webkit-user-drag: none; }
.sk-tile.ready .sk-thumb img { visibility: visible; }
.sk-tile-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-size: 11.5px; font-weight: 600; text-align: center; }
.sk-tile.sel .sk-tile-name { color: #fff; }
.sk-star {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.34);
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease, transform 0.08s ease;
}
.sk-tile:hover .sk-star, .sk-tile.sel .sk-star, .sk-tile.fav .sk-star { opacity: 1; }
.sk-star:hover { color: #fff; transform: scale(1.15); }
.sk-tile.fav .sk-star { color: var(--gold); }
/* the skin currently in use / the player's own design */
.sk-tile.cur::after, .sk-tile.custom::after {
  content: "in use";
  position: absolute;
  top: 5px;
  left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(88, 240, 122, 0.92);
  color: #04260f;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.sk-tile.custom::after { content: "yours"; background: rgba(76, 201, 245, 0.92); color: #032340; }
.sk-tile.custom.cur::after { content: "yours · in use"; }
#skin-empty {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 96px;
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* ---- "Build your own" skin builder ---------------------------------------- */
#skin-picker.building .sk-main,
#skin-picker.building .skin-arrow,
#skin-picker.building .sk-namerow,
#skin-picker.building .skin-sub,
#skin-picker.building .skin-actions,
#skin-picker.building .skin-hint { display: none !important; }
#skin-picker.building #skin-canvas {
  cursor: default;
  /* the builder's longer snake runs close to the canvas edges: fade them so a boost halo is never cut */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 6%, #000 94%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 6%, #000 94%, transparent 100%);
}
#sb-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(10, 14, 26, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}
#skin-picker.building .skin-wrap {
  width: min(100%, 880px);
  height: auto;
  max-height: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, auto);
  gap: 14px;
}
#skin-picker.building .sk-side { overflow: visible; }
#skin-picker.building #skin-canvas { height: clamp(120px, 30vh, 270px); }
#skin-builder { align-items: center; justify-content: center; gap: 14px; padding: 18px 14px 16px; overflow-y: auto; scrollbar-width: none; }
#skin-builder::-webkit-scrollbar { display: none; }
.sb-top { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 14px; min-height: 22px; }
#sb-strip { display: flex; flex-wrap: wrap; align-items: center; padding-left: 3px; min-height: 18px; }
#sb-strip i {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
  margin-left: -3px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), 0 0 6px currentColor;
}
#sb-strip i.head { width: 18px; height: 18px; z-index: 1; }
/* two little eyes on the head chip */
#sb-strip i.head::before,
#sb-strip i.head::after {
  content: "";
  position: absolute;
  left: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 1px 0 0 1px #111;
}
#sb-strip i.head::before { top: 3px; }
#sb-strip i.head::after { bottom: 3px; }
#sb-strip i.new { animation: sb-pop 0.28s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes sb-pop { from { transform: scale(0.2); } to { transform: none; } }
#sb-count { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
#sb-count.full { animation: sb-shake 0.3s ease; color: #ff8a9c; }
@keyframes sb-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
/* effect preset chips (SG.FX_PRESETS) */
#sb-fx { position: relative; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; }
.sb-fx-chip {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.sb-fx-chip:hover { background: rgba(255, 255, 255, 0.11); color: #fff; }
.sb-fx-chip:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.7); outline-offset: 2px; }
.sb-fx-chip[aria-checked="true"] { background: rgba(76, 201, 245, 0.18); border-color: rgba(120, 215, 250, 0.7); color: #fff; }
#sb-palette {
  display: grid;
  width: 100%;
  justify-content: center;
  grid-template-columns: repeat(10, minmax(0, 38px));
  gap: 8px;
}
.sb-color {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 10px currentColor, inset 0 1px 0 rgba(255, 255, 255, 0.25);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.sb-color:hover { border-color: rgba(255, 255, 255, 0.6); transform: scale(1.06); }
.sb-color:active { transform: scale(0.9); }
.sb-color:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.8); outline-offset: 2px; }

/* ---- settings ----------------------------------------------------------- */
.dialog {
  margin: auto;
  width: min(100%, 420px);
  padding: 22px 22px 20px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: ui-rise-in 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dialog h2 {
  margin: 0 0 14px;
  font-family: var(--font-round);
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  letter-spacing: 0.02em;
}
.set-list { display: flex; flex-direction: column; gap: 4px; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 46px;
  padding: 6px 4px 6px 12px;
  border-radius: 12px;
  color: var(--ink-2);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.set-row:hover { background: rgba(255, 255, 255, 0.04); }
.set-label { display: flex; flex-direction: column; min-width: 0; }
.set-label small { color: var(--muted); font-size: 11px; line-height: 1.3; }
.set-label small:empty { display: none; }
.set-label small.warn { color: #ffc47a; }
.set-row select {
  -webkit-appearance: none;
  appearance: none;
  min-width: 150px;
  height: 36px;
  padding: 0 34px 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239aa6c7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center,
    rgba(255, 255, 255, 0.06);
  color: #fff;
  font: 600 14px var(--font);
  cursor: pointer;
  outline: none;
}
.set-row select:focus-visible { border-color: rgba(88, 240, 122, 0.7); box-shadow: 0 0 0 3px rgba(88, 240, 122, 0.15); }
.set-row select option { background: #141a2c; color: #fff; }

input.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 26px;
  margin: 0 6px 0 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  outline: none;
  transition: background 0.18s ease;
}
input.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #c9d1e8;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  transition: transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1), background 0.18s ease;
}
input.switch:checked { background: var(--green-lo); box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 0 12px rgba(88, 240, 122, 0.3); }
input.switch:checked::after { transform: translateX(20px); background: #fff; }
input.switch:focus-visible { box-shadow: 0 0 0 3px rgba(88, 240, 122, 0.35); }

.set-note { margin: 12px 4px 14px; color: #66708f; font-size: 12px; line-height: 1.5; text-align: center; }

/* =========================================================================
   HUD
   ========================================================================= */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: var(--font);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* ---- leaderboard -------------------------------------------------------- */
#leaderboard {
  position: absolute;
  top: calc(10px + var(--st));
  right: calc(10px + var(--sr));
  width: var(--lb-w);
  padding: 8px 8px 7px;
  border-radius: 14px;
  background: var(--hud-panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}
.lb-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 6px 5px;
  margin-bottom: 3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-family: var(--font-round);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #d8def0;
}
#lb-count { font-family: var(--font); font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; text-transform: none; color: var(--muted); white-space: nowrap; }
/* online: the count line is longer ("12 players · 38 bots") */
#hud.online .lb-title { letter-spacing: 0.05em; }
#hud.online #lb-count { font-size: 10px; letter-spacing: 0; }
/* online room badge: name · code / players · bots · ping; click copies the invite link */
#room-badge {
  pointer-events: auto;
  display: block;
  width: 100%;
  margin: 0 0 4px;
  padding: 4px 7px 5px;
  border: 1px solid rgba(76, 201, 245, 0.22);
  border-radius: 9px;
  background: rgba(76, 201, 245, 0.08);
  color: var(--ink-2);
  font-family: var(--font);
  font-size: 11.5px;
  line-height: 1.35;
  text-align: left;
  text-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, border-color 0.15s ease;
}
#room-badge:hover { background: rgba(76, 201, 245, 0.16); border-color: rgba(76, 201, 245, 0.45); }
#room-badge:focus-visible { outline: 2px solid rgba(140, 220, 255, 0.65); outline-offset: 2px; }
.rb-top, .rb-sub { display: flex; align-items: center; gap: 5px; min-width: 0; white-space: nowrap; }
#rb-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: #fff; font-weight: 700; }
#rb-code { flex: none; margin-left: auto; padding: 0 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); color: #d5f3ff; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.06em; }
.rb-chip { flex: none; padding: 0 5px; border-radius: 5px; background: linear-gradient(180deg, #ffe27a, #f4b31f); color: #3a2600; font-size: 9px; font-weight: 800; letter-spacing: 0.08em; line-height: 1.5; }
.rb-sub { color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.rb-sub span + span:not(.hidden)::before { content: "·"; margin-right: 5px; opacity: 0.7; }
#rb-ping.good { color: #8dfaa6; }
#rb-ping.ok { color: var(--gold); }
#rb-ping.bad { color: #ff8a9c; }
#room-badge.warn { border-color: rgba(255, 210, 63, 0.5); background: rgba(255, 210, 63, 0.08); }
#room-badge.lost { border-color: rgba(255, 90, 110, 0.5); background: rgba(255, 90, 110, 0.08); }
#room-badge.copied { border-color: rgba(141, 250, 166, 0.7); background: rgba(88, 240, 122, 0.14); }
#room-badge.copied #rb-code { background: rgba(88, 240, 122, 0.3); color: #fff; }
#lb-list { list-style: none; margin: 0; padding: 0; }
#lb-list li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 19px;
  padding: 0 6px 0 2px;
  border-radius: 6px;
  color: rgba(236, 241, 255, 0.78);
  white-space: nowrap;
}
.lb-rank { flex: none; width: 26px; text-align: right; color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.lb-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18); }
.lb-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.lb-name.anon { font-style: italic; color: rgba(200, 208, 230, 0.5); }
.lb-score { flex: none; font-variant-numeric: tabular-nums; color: rgba(236, 241, 255, 0.9); }
#lb-list li.r1 .lb-rank { color: var(--gold); font-weight: 800; }
#lb-list li.r2 .lb-rank { color: var(--silver); font-weight: 800; }
#lb-list li.r3 .lb-rank { color: var(--bronze); font-weight: 800; }
#lb-list li.me {
  background: linear-gradient(90deg, rgba(88, 240, 122, 0.26), rgba(88, 240, 122, 0.08));
  box-shadow: inset 0 0 0 1px rgba(88, 240, 122, 0.25);
  color: #fff;
  font-weight: 700;
}
#lb-list li.me .lb-name.anon { color: #e2ffe9; }
#lb-list li.lb-extra { margin-top: 7px; }
#lb-list li.lb-extra::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: -5px;
  border-top: 1px dashed rgba(255, 255, 255, 0.16);
}

/* ---- stats (bottom-left) ------------------------------------------------ */
#stats {
  position: absolute;
  left: calc(16px + var(--sl));
  bottom: calc(14px + var(--sb));
  color: rgba(225, 232, 250, 0.72);
  font-size: 14px;
  line-height: 1.5;
}
#stats b { color: #fff; font-variant-numeric: tabular-nums; }
#stat-length { font-family: var(--font-round); font-size: 22px; font-weight: 900; text-shadow: 0 0 12px rgba(88, 240, 122, 0.45), 0 1px 2px rgba(0, 0, 0, 0.8); }
.stat-rank { font-size: 13px; }
.stat-kills { font-size: 13px; }

/* ---- minimap (bottom-right) -------------------------------------------- */
#minimap-wrap {
  position: absolute;
  right: calc(14px + var(--sr));
  bottom: calc(14px + var(--sb));
  width: var(--mm);
  height: var(--mm);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(24, 32, 54, 0.55) 0%, rgba(9, 12, 22, 0.72) 72%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 6px 26px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
#minimap { display: block; width: 100%; height: 100%; }
#minimap-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 5px 1px rgba(255, 255, 255, 0.9);
  will-change: transform;
  display: none;
}
#minimap-dot::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  animation: mm-ping 1.1s ease-out infinite;
}
@keyframes mm-ping { 0% { transform: scale(0.35); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }

/* ---- fps ------------------------------------------------------------------ */
#fps {
  position: absolute;
  top: calc(8px + var(--st));
  left: calc(10px + var(--sl));
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  color: #9fe8b2;
  font-family: var(--mono);
  font-size: 11px;
  text-shadow: none;
}
#fps.warn { color: #ffd23f; }
#fps.bad { color: #ff6f6f; }

/* ---- toasts ------------------------------------------------------------- */
#toasts {
  position: absolute;
  top: calc(16% + var(--st));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(92vw, 520px);
}
.toast {
  max-width: 100%;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(10, 14, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: #eef2ff;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.32s cubic-bezier(0.2, 1.4, 0.4, 1);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.toast b { color: var(--green); }
.toast-sub { color: var(--muted); font-size: 0.85em; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.9); } to { opacity: 1; transform: none; } }

/* ---- spectate bar ------------------------------------------------------- */
#spectate-bar {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--sb));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 2 * var(--mm) - 70px);
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  background: rgba(10, 14, 26, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: var(--ink-2);
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  animation: ui-fade-in 0.3s ease-out;
}
.sb-eye { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--red); box-shadow: 0 0 8px var(--red); animation: rec-blink 1.4s ease-in-out infinite; }
@keyframes rec-blink { 50% { opacity: 0.3; } }
.sb-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#spectate-name { color: #fff; }
.sb-hint { flex: 0 1 auto; min-width: 0; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.sb-text { flex: 0 0 auto; max-width: 60vw; }
#spectate-menu-btn {
  pointer-events: auto;
  flex: none;
  height: 30px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-shadow: none;
}
#spectate-menu-btn:hover { background: rgba(255, 255, 255, 0.16); }
html.touch #spectate-menu-btn { height: 38px; padding: 0 18px; }

/* ---- pause -------------------------------------------------------------- */
/* below the centre: the camera keeps the player's head in the middle of the screen */
#pause-banner {
  position: absolute;
  left: 50%;
  top: auto;
  bottom: calc(18% + var(--sb));
  transform: translateX(-50%);
  padding: 18px 40px 16px;
  border-radius: 22px;
  background: rgba(8, 11, 20, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.5);
  animation: ui-fade-in 0.2s ease-out;
}
.pb-title { font-family: var(--font-round); font-size: 34px; font-weight: 900; letter-spacing: 0.08em; color: #fff; }
.pb-sub { margin-top: 4px; font-size: 14px; color: var(--muted); }
#pause-leave-btn {
  margin-top: 12px;
  min-height: 36px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-shadow: none;
  touch-action: manipulation;
}
#pause-leave-btn:hover { background: rgba(255, 90, 110, 0.18); border-color: rgba(255, 90, 110, 0.45); color: #fff; }
#pause-leave-btn:focus-visible { outline: 2px solid rgba(141, 250, 166, 0.6); outline-offset: 3px; }

/* ---- online: host migration / connection lost -------------------------------------
   sits where the pause banner would be (pause is disabled online), clear of the head */
#net-banner {
  position: absolute;
  left: 50%;
  bottom: calc(18% + var(--sb));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 560px);
  padding: 11px 20px 11px 16px;
  border-radius: 16px;
  background: rgba(8, 11, 20, 0.8);
  border: 1px solid rgba(255, 210, 63, 0.4);
  color: var(--ink-2);
  font-size: 14.5px;
  line-height: 1.35;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.5);
  animation: ui-fade-in 0.2s ease-out;
}
#net-banner b { color: #fff; }
.nb-icon {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 210, 63, 0.25);
  border-top-color: var(--gold);
  animation: nb-spin 0.9s linear infinite;
}
@keyframes nb-spin { to { transform: rotate(360deg); } }
#net-banner.lost { border-color: rgba(255, 90, 110, 0.5); }
#net-banner.lost .nb-icon { border: 0; background: var(--red); box-shadow: 0 0 10px var(--red); width: 10px; height: 10px; margin: 0 4px; animation: rec-blink 1.4s ease-in-out infinite; }

/* ---- touch controls ------------------------------------------------------ */
#boost-btn {
  pointer-events: auto;
  position: absolute;
  left: calc(22px + var(--sl));
  bottom: calc(24px + var(--sb));
  width: 92px;
  height: 92px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: radial-gradient(circle at 50% 38%, rgba(88, 240, 122, 0.4), rgba(20, 90, 45, 0.45) 70%);
  color: #fff;
  font-family: var(--font-round);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.08em;
  touch-action: none;
  -webkit-touch-callout: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.12s ease, opacity 0.2s ease, filter 0.2s ease;
}
#boost-btn.pressed, #boost-btn:active { transform: scale(0.93); background: radial-gradient(circle at 50% 38%, rgba(141, 250, 166, 0.75), rgba(32, 180, 81, 0.6) 70%); }
#boost-btn.on { box-shadow: 0 0 0 4px rgba(88, 240, 122, 0.25), 0 0 34px rgba(88, 240, 122, 0.6); }
/* too short to boost yet (mass <= BOOST_MIN_MASS) */
#boost-btn.locked { opacity: 0.45; filter: grayscale(0.7); }

#hud-pause-btn {
  pointer-events: auto;
  position: absolute;
  top: calc(10px + var(--st));
  left: 50%;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(10, 14, 26, 0.55);
  touch-action: manipulation;
}
/* a slightly larger square hit area (also covers the corners the round shape lets through) */
#hud-pause-btn::before { content: ""; position: absolute; inset: -6px; }
#hud-pause-btn span { display: block; width: 4px; height: 14px; border-radius: 2px; background: #e8ecf8; }

/* touch joystick: SG.Input sets position / left / top / transform inline (never set them here) */
#joystick {
  z-index: 3;
  width: 112px;
  height: 112px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.02) 40%, rgba(255, 255, 255, 0.07));
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
}
#joystick > i {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25), 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* touch-only settings rows (e.g. Touch steering) */
html.touch .set-row.touch-only { display: flex !important; }

/* touch layout: boost bottom-left, so stats move to top-left */
html.touch #stats { top: calc(10px + var(--st)); bottom: auto; }
html.touch #fps { top: auto; bottom: calc(126px + var(--sb)); }

/* spectating: no personal stats / controls */
#hud.spectating #stats,
#hud.spectating #boost-btn,
#hud.spectating #hud-pause-btn { display: none !important; }

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 760px) {
  :root { --mm: 132px; --lb-w: 186px; }
  #leaderboard { font-size: 12px; padding: 6px 6px 5px; }
  #lb-list li { height: 17px; }
  .lb-rank { width: 22px; font-size: 10.5px; }
  .sb-hint.desk-only { display: none; }
}

@media (max-width: 520px), (max-height: 520px) {
  :root { --mm: 104px; --lb-w: 150px; }
  #leaderboard { font-size: 11px; border-radius: 11px; }
  .lb-title { font-size: 10px; letter-spacing: 0.12em; padding-bottom: 3px; }
  #lb-count { display: none; }
  #lb-list li { height: 15px; gap: 4px; }
  .lb-rank { width: 18px; font-size: 10px; }
  .lb-dot { width: 6px; height: 6px; }
  #stats { font-size: 12px; left: calc(12px + var(--sl)); }
  #stat-length { font-size: 18px; }
  .stat-rank, .stat-kills { font-size: 11.5px; }
  #spectate-bar { max-width: calc(100vw - var(--mm) - 44px); left: calc(12px + var(--sl)); transform: none; font-size: 13px; gap: 8px; }
  #spectate-bar .sb-hint { display: none !important; }
  .sb-text { flex: 0 1 auto; max-width: none; }
  #sb-palette { gap: 6px; }
  .toast { font-size: 13px; padding: 6px 13px; }
  #toasts { top: max(16%, calc(215px + var(--st))); }
  #hud.online #toasts { top: max(16%, calc(252px + var(--st))); }
  #room-badge { padding: 3px 5px 4px; font-size: 10.5px; }
  .rb-sub { font-size: 9.5px; gap: 4px; }
  .rb-sub span + span:not(.hidden)::before { margin-right: 4px; }
  #net-banner { font-size: 13px; padding: 9px 14px 9px 12px; gap: 10px; bottom: calc(22% + var(--sb)); }
  #boost-btn { width: 78px; height: 78px; font-size: 13px; }
  html.touch #fps { bottom: calc(110px + var(--sb)); }
  .pb-title { font-size: 26px; }
  #pause-banner { padding: 14px 24px 12px; bottom: calc(22% + var(--sb)); }

  #menu-inner { gap: 11px; }
  #tagline { font-size: 12.5px; letter-spacing: 0.16em; }
  #nickname { height: 46px; font-size: 16px; }
  #play-btn { min-height: 52px; font-size: 22px; }
  #online-btn { min-height: 44px; font-size: 17px; }
  .play-row { gap: 12px; }
  #online-status { font-size: 12px; }
  .btn-secondary { min-height: 36px; padding: 0 13px; font-size: 13px; }
  .lr-len { font-size: 25px; }
  .lr-item { flex-basis: 74px; padding: 6px 4px; }
  .lr-k { letter-spacing: 0.06em; }
  .lr-v { font-size: 14px; }
  .dialog { padding: 18px 14px 16px; }
  .set-row { font-size: 14px; min-height: 42px; }
  .set-row select { min-width: 128px; }
}

@media (max-height: 520px) and (min-width: 521px) {
  /* phone landscape: compact menu / picker so they fit without scrolling where possible */
  #menu { padding-top: calc(8px + var(--st)); padding-bottom: calc(6px + var(--sb)); }
  #menu-inner { gap: 8px; padding: 0 0 6px; }
  #logo { font-size: clamp(38px, 15vh, 72px); padding-top: 0.06em; }
  #tagline { margin-top: -4px; }
  #nickname { height: 40px; }
  /* Play and Play Online side by side */
  .play-row { flex-direction: row; width: min(100%, 520px); gap: 10px; margin-bottom: 4px; }
  .play-row .btn-primary { flex: 1 1 0; min-width: 0; padding: 0 12px; }
  #play-btn { min-height: 46px; font-size: 21px; }
  #online-btn { min-height: 46px; font-size: 17px; }
  #menu-tip { display: none; }
  #controls-help { line-height: 1.6; font-size: 12px; }
  /* (id selector: must beat html.touch .touch-only's display:revert !important) */
  #skin-picker .overlay-title, #skin-picker .overlay-hint { display: none !important; }
  #menu .menu-corner { top: calc(6px + var(--st)); min-height: 30px; padding: 0 12px; font-size: 12px; }
  .dialog { padding: 14px 16px; }
  .dialog h2 { margin-bottom: 6px; }
  .set-row { min-height: 38px; padding-top: 3px; padding-bottom: 3px; }
  .set-note { margin: 6px 4px 8px; }
  /* settings in two columns so the whole panel (incl. Done) fits a landscape phone */
  #settings-panel .dialog { width: min(100%, 720px); }
  .set-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; row-gap: 2px; }
  /* toasts: top-centre under the pause button, between the stats and the leaderboard (the head
     sits at the screen centre, which is only ~160-215 px down on a landscape phone) */
  #toasts {
    top: calc(60px + var(--st));
    width: calc(100vw - 2 * (var(--lb-w) + 24px + max(var(--sl), var(--sr))));
  }
  #toasts .toast:nth-last-child(n+3) { display: none; }
  /* result screen fits without scrolling: drop tagline / help / footer, tighten the card */
  #menu.has-result #controls-help,
  #menu.has-result #tagline,
  #menu.has-result #menu-footer { display: none; }
  #menu.has-result #logo { font-size: clamp(32px, 11vh, 56px); }
  #last-result { padding: 7px 12px; }
  .lr-len { font-size: 24px; }
  .lr-badge { margin-top: 3px; }
  .lr-grid { margin-top: 5px; }
  .lr-item { padding: 4px 8px; }
  /* pause banner: compact two-column card near the bottom edge, clear of the head */
  #pause-banner {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 16px;
    align-items: center;
    padding: 9px 12px 9px 20px;
    bottom: calc(12px + var(--sb));
    border-radius: 18px;
  }
  #pause-banner .pb-title { grid-column: 1; grid-row: 1; font-size: 22px; }
  #pause-banner .pb-sub { grid-column: 1; grid-row: 2; margin-top: 0; font-size: 12.5px; }
  #pause-leave-btn { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; }
  #net-banner { bottom: calc(12px + var(--sb)); max-width: calc(100vw - 2 * (var(--mm) + 34px + max(var(--sl), var(--sr)))); }

  /* skin gallery: slim two-pane layout */
  #skin-picker { padding: calc(8px + var(--st)) calc(8px + var(--sr)) calc(8px + var(--sb)) calc(8px + var(--sl)); }
  .skin-wrap { grid-template-columns: minmax(216px, 0.6fr) minmax(0, 1.6fr); gap: 10px; height: 100%; }
  /* the preview takes whatever height the rest of the column leaves */
  .sk-side { gap: 5px; }
  .sk-side::before, .sk-side::after { display: none; }
  .skin-stage { flex: 1 1 0; min-height: 60px; max-height: 190px; }
  #skin-canvas { height: 100%; }
  .skin-arrow { width: 34px; height: 34px; margin-top: -17px; font-size: 25px; }
  #skin-name { font-size: 19px; }
  .sk-favbtn { width: 30px; height: 30px; font-size: 16px; }
  .skin-sub { gap: 4px; }
  #skin-meta { font-size: 12px; }
  #acc-row .acc-arrow { display: none; }
  #acc-name { min-width: 0; font-size: 13px; }
  #acc-grid { display: flex; max-height: none; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  #acc-grid::-webkit-scrollbar { display: none; }
  #acc-grid { justify-content: flex-start; } /* (centred overflow could not be scrolled to its start) */
  .acc-tile { flex: none; width: 54px; height: 45px; }
  .skin-actions { margin-top: 0; gap: 8px; }
  .skin-actions .btn-primary { min-height: 40px; font-size: 16px; }
  .skin-actions .btn-secondary { min-height: 40px; }
  #skin-save, #sb-save { min-width: 108px; }
  .sk-main, #skin-builder { padding: 8px; gap: 6px; border-radius: 14px; }
  .sk-tools .btn-chip, #skin-search { height: 32px; min-height: 32px; }
  #skin-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #skin-tabs::-webkit-scrollbar { display: none; }
  .sk-tab { min-height: 28px; }
  #skin-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; padding: 3px; }
  /* builder: preview left, two rows of colours right */
  #skin-picker.building .skin-wrap { width: 100%; height: 100%; grid-template-columns: minmax(200px, 0.5fr) minmax(0, 1.6fr); grid-template-rows: minmax(0, 1fr); gap: 10px; }
  #skin-picker.building .skin-stage { max-height: none; }
  .sb-fx-chip { min-height: 28px; padding: 0 10px; font-size: 12.5px; }
  #sb-palette { grid-template-columns: repeat(10, minmax(0, 30px)); gap: 5px; }
  #skin-builder { gap: 7px; }
  #skin-builder .dialog-actions .btn-primary, #skin-builder .dialog-actions .btn-secondary { min-height: 36px; font-size: 14px; }
  #skin-builder .overlay-hint { display: none !important; }
}

/* skin gallery, one column: narrow windows and portrait phones. .sk-side dissolves (display:
   contents) so its parts can sit around the grid: preview, name, accessory strip, [browser],
   Cancel / Save. */
@media (max-width: 760px) and (min-height: 521px), (max-width: 520px) {
  #skin-picker { padding: calc(10px + var(--st)) calc(10px + var(--sr)) calc(10px + var(--sb)) calc(10px + var(--sl)); }
  .skin-wrap { display: flex; flex-direction: column; align-items: center; gap: 7px; width: 100%; height: 100%; }
  .sk-side { display: contents; }
  .sk-side::before, .sk-side::after { display: none; }
  #skin-picker .overlay-title, #skin-picker .skin-hint { display: none !important; }
  #skin-picker.building .overlay-title { display: block !important; order: 0; }
  .skin-stage { order: 1; }
  #skin-canvas { height: clamp(78px, 14vh, 136px); }
  .skin-arrow { width: 38px; height: 38px; margin-top: -19px; font-size: 28px; }
  .sk-namerow { order: 2; }
  #skin-name { font-size: 22px; }
  .sk-favbtn { width: 34px; height: 34px; }
  .skin-sub { order: 3; gap: 5px; }
  #acc-row .acc-arrow { display: none; }
  #acc-name { min-width: 0; font-size: 14px; }
  #acc-grid { display: flex; width: 100%; max-height: none; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  #acc-grid::-webkit-scrollbar { display: none; }
  #acc-grid { justify-content: flex-start; }
  .acc-tile { flex: none; }
  .sk-main, #skin-builder { order: 4; flex: 1 1 0; width: 100%; padding: 10px; gap: 8px; border-radius: 16px; }
  #skin-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -2px; padding: 0 2px; }
  #skin-tabs::-webkit-scrollbar { display: none; }
  .sk-tab { min-height: 32px; }
  #skin-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; padding: 3px; }
  .skin-actions { order: 5; margin-top: 0; }
  #skin-picker.building .skin-wrap { height: 100%; justify-content: center; }
  #skin-picker.building #skin-canvas { height: clamp(96px, 22vh, 210px); }
  #skin-picker.building #skin-builder { flex: 0 1 auto; }
  .sk-tools { gap: 6px; }
  .sk-tools .btn-chip { padding: 0 11px; font-size: 12.5px; }
  #sb-palette { grid-template-columns: repeat(8, minmax(0, 38px)); gap: 7px; }
  #skin-builder { justify-content: flex-start; gap: 10px; }
  #skin-builder .overlay-hint { display: none !important; }
}

/* narrow browser panes: "Build your own" becomes "Build" so the search box keeps a usable width */
@media (max-width: 700px) {
  .lbl-long { display: none; }
}

/* short desktop windows: fewer accessory rows so the side column fits */
@media (max-height: 700px) and (min-width: 761px) {
  #acc-grid { max-height: 87px; }
}
/* tall windows: every accessory row at once (6 rows of 6) */
@media (min-height: 940px) and (min-width: 761px) {
  #acc-grid { max-height: 330px; }
}

/* short portrait phones: the settings list (incl. Touch steering) fits without scrolling */
@media (max-width: 520px) and (max-height: 640px) {
  .set-row { min-height: 38px; padding-top: 3px; padding-bottom: 3px; }
  .dialog h2 { margin-bottom: 8px; }
  .set-note { margin: 8px 4px 10px; }
}

/* very small landscape phones (e.g. 568 x 320) */
/* short landscape phones: the effect presets become one scrolling row instead of two wrapped ones */
@media (max-height: 370px) and (min-width: 521px) {
  #sb-fx { flex-wrap: nowrap; justify-content: flex-start; width: 100%; overflow-x: auto; scrollbar-width: none; }
  #sb-fx::-webkit-scrollbar { display: none; }
  #sb-fx > * { flex: none; }
}

@media (max-height: 340px) and (min-width: 521px) {
  #skin-canvas { height: 60px; }
  #skin-meta { display: none; }
  .set-row { min-height: 34px; padding-top: 2px; padding-bottom: 2px; }
  .set-note { margin: 4px 4px 6px; }
  .dialog { padding: 10px 16px; }
  .dialog h2 { margin-bottom: 4px; font-size: 20px; }
}

@media (max-height: 420px) {
  #lb-list li:nth-child(n+7):not(.lb-extra):not(.me) { display: none !important; }
}

/* very narrow phones: the centred pause button would overlap the leaderboard, so it moves
   under the stats on the left */
@media (max-width: 380px) {
  #hud-pause-btn { left: calc(12px + var(--sl)); margin-left: 0; top: calc(74px + var(--st)); }
}
/* small portrait phones (e.g. 320 x 568, 360 x 640): every fixed part of the gallery gives a little
   so the grid keeps 2-3 rows; the builder's effect presets become one scrolling row */
@media (max-width: 520px) and (max-height: 700px) {
  #skin-canvas { height: clamp(56px, 11vh, 80px); }
  #skin-name { font-size: 19px; }
  .sk-favbtn { width: 30px; height: 30px; font-size: 15px; }
  #skin-meta { display: none; }
  .acc-tile { width: 50px; height: 42px; }
  .skin-actions .btn-primary, .skin-actions .btn-secondary { min-height: 40px; }
  .skin-actions .btn-primary { font-size: 16px; }
  #skin-picker.building #skin-canvas { height: clamp(72px, 15vh, 110px); }
  #sb-fx { flex-wrap: nowrap; justify-content: flex-start; width: 100%; overflow-x: auto; scrollbar-width: none; }
  #sb-fx::-webkit-scrollbar { display: none; }
  #sb-fx > * { flex: none; }
  #skin-builder .dialog-actions { gap: 6px; }
  #skin-builder .dialog-actions .btn-secondary { min-height: 36px; padding: 0 11px; }
  #skin-builder .dialog-actions .btn-primary { min-height: 40px; min-width: 96px; padding: 0 18px; font-size: 16px; }
}
@media (max-width: 360px) {
  #skin-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .sk-tile-name { font-size: 10.5px; }
  #sb-palette { grid-template-columns: repeat(8, minmax(0, 32px)); gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  #logo span, #minimap-dot::after, .sb-eye, .ob-dot { animation: none !important; }
  .nb-icon { animation-duration: 2.4s !important; }
  #menu, #hud, .overlay, #menu-inner, .dialog, .skin-wrap, #last-result, .toast, #sb-strip i.new, #sb-count.full, #skin-name.bump, #acc-name.bump, .sk-favbtn.bump, #net-banner { animation-duration: 0.01s !important; }
}

.noscript {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: var(--bg);
  color: var(--ink-2);
  font-size: 18px;
}
