/* Self-hosted Nunito (latin-ext + latin, weights 400–900 via variable font) */
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("/assets/fonts/nunito-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("/assets/fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #151820;
  --surface-1: #20242c;
  --surface-2: #1a1e26;
  --surface-3: #12161d;
  --surface-glass: rgba(10, 14, 22, 0.82);
  --line: #3a3f4a;
  --line-soft: rgba(255, 255, 255, 0.15);
  --line-faint: rgba(255, 255, 255, 0.1);
  --fg: #f3f5f9;
  --fg-strong: #f6f8fc;
  --muted: #a9b2c3;
  --muted-soft: rgba(227, 233, 244, 0.9);
  --ok: #8de16f;
  --ok-strong: #4bd36b;
  --warn: #ff6a70;
  --overlay: rgba(4, 6, 10, 0.74);
  --menu-button-border: rgba(255, 255, 255, 0.28);
  --menu-button-bg: rgba(8, 11, 16, 0.6);
  --menu-button-fg: rgba(236, 241, 250, 0.9);
  --action-border: #5d8c4d;
  --action-bg: #243226;
  --accent-cool: #66ccff;

  /* Radier – används konsekvent överallt */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--fg);
  font-family: "Nunito", system-ui, sans-serif;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

body.overlay-active #game {
  visibility: hidden;
}

#screenRoot {
  position: fixed;
  inset: 0;
  height: 100dvh;
}

.view {
  position: absolute;
  inset: 0;
}

.hidden {
  display: none !important;
}

#connectView {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    radial-gradient(1200px 560px at 14% 16%, rgba(86, 126, 185, 0.16) 0%, rgba(86, 126, 185, 0) 62%),
    radial-gradient(980px 520px at 84% 84%, rgba(84, 148, 116, 0.14) 0%, rgba(84, 148, 116, 0) 66%),
    linear-gradient(165deg, #0f131a 0%, #121722 47%, #0d1118 100%);
}

#connectView::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.13;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 5px);
}

.connect-layout {
  width: min(980px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: minmax(320px, 500px) minmax(260px, 1fr);
  gap: 12px;
  align-items: stretch;
  margin-inline: auto;
  margin-block: auto;
}

.card {
  width: 100%;
  display: grid;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
  box-sizing: border-box;
}

.news-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 14px;
  box-sizing: border-box;
  min-height: 0;
  overflow: auto;
}

.news-meta {
  margin: 0 0 8px;
  color: var(--fg);
  font-size: 14px;
  font-weight: 600;
}

#newsPublishedAt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.news-notes {
  margin: 0;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

h1, h2, h3 {
  font-family: "Nunito", system-ui, sans-serif;
  letter-spacing: -0.01em;
}

.card h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.login-card {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(26, 31, 41, 0.92);
  border-color: rgba(104, 120, 147, 0.42);
  box-shadow: 0 18px 46px rgba(5, 8, 13, 0.52);
  border-radius: var(--r-lg);
}

.login-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.login-card-header h1 {
  margin: 0 0 6px;
}

/* ── Language flag buttons ─────────────────────────────────────────────── */

.lang-flags {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.lang-flag-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 2px 4px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s, border-color 0.15s;
  user-select: none;
}

.lang-flag-btn:hover {
  opacity: 0.8;
}

.lang-flag-btn.active {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.35);
}

.settingsLanguageRow .lang-flags {
  grid-column: 3;
  justify-self: end;
  margin-left: 0;
}

.settingsLanguageRow .lang-flag-btn {
  font-size: 18px;
  padding: 1px 3px;
}

.connect-tagline {
  margin: -2px 0 6px;
  color: rgba(216, 226, 244, 0.92);
  font-size: 13px;
  line-height: 1.45;
}

.connect-fullscreen-option {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  cursor: pointer;
  user-select: none;
}

.connect-fullscreen-option input[type="checkbox"] {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--ok-strong);
}

.connect-fullscreen-option:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.58;
}

.room-info {
  margin: auto 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line-faint);
  color: var(--muted);
  font-size: 12px;
}

label {
  color: var(--muted);
  font-size: 12px;
}

input,
button {
  font: inherit;
}

input {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--fg);
  padding: 9px 10px;
  font-weight: 600;
}

button {
  border: 1px solid var(--action-border);
  border-radius: var(--r-sm);
  background: var(--action-bg);
  color: var(--fg);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* ── Glassknappar: delade av spectator, vinna, nerslagen, chatt ── */
.glass-btn,
#spectatorLobbyBtn,
#spectatorCycleButtons button,
#winLobbyBtn,
#downedLobbyBtn,
#gameChatSendBtn {
  pointer-events: auto;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--surface-glass);
  color: var(--fg-strong);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.7;
}

.error {
  min-height: 20px;
  color: var(--warn);
  font-size: 13px;
}

#lobbyView {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  min-width: 0;
}

#scoreboardBar {
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: auto;
  flex: 0 1 auto;
  max-height: 50%;
}

#scoreTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

#scoreTable th,
#scoreTable td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

#scoreTable th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 1;
}

#scoreTable .th-short {
  display: none;
}

.status-cell {
  white-space: nowrap;
}

.name-cell {
  white-space: nowrap;
}

.name-cell-inner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.ready-lamp {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--ok-strong);
  border-radius: 999px;
  margin-right: 7px;
  vertical-align: -1px;
  background: transparent;
  box-sizing: border-box;
}

.ready-lamp.on {
  background: var(--ok-strong);
  box-shadow: 0 0 7px rgba(75, 211, 107, 0.5);
}

.status-label {
  color: var(--fg);
  white-space: nowrap;
}

.name-ready-lamp {
  margin-right: 0;
  flex: 0 0 auto;
}

.name-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

#lobbyMain {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#lobbyStatusRow {
  min-height: 0;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--r-sm);
  background: rgba(14, 18, 25, 0.62);
  padding: 6px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
}

#lobbyStatusText {
  min-width: 0;
  color: var(--fg-strong);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#lobbyPlayersMeta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

/* ─── Game-start fade-in ───────────────────────────────────────────────────── */
#gameStartFade {
  position: fixed;
  inset: 0;
  background: #000;
  pointer-events: none;
  z-index: 11;
  opacity: 0;
}

#countdownOverlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  pointer-events: none;
  z-index: 12;
}

#countdownContent {
  width: min(860px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  justify-items: center;
}

#countdownHeading {
  margin: 0;
  text-align: center;
  font-size: clamp(13px, 2vw, 16px);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

#countdownTagline {
  margin: 4px 0 0;
  text-align: center;
  font-size: clamp(11px, 1.6vw, 13px);
  font-weight: 500;
  color: var(--muted-soft);
  letter-spacing: 0.03em;
}

#countdownTopRow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

#countdownText {
  font-size: clamp(100px, 22vw, 220px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--fg-strong);
  text-shadow: 0 8px 32px rgba(0, 0, 0, 0.72);
  font-variant-numeric: tabular-nums;
  text-align: center;
  width: 2ch;
  flex: 0 0 auto;
}

/* ── Karaktärskort – sömlöst, canvas fyller ytan ── */
#countdownCharacterCard {
  position: relative;
  flex: 0 0 auto;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 16px 40px rgba(0, 0, 0, 0.56);
  pointer-events: auto;
}

#countdownCharacterCanvas {
  display: block;
  width: 180px;
  height: 180px;
  background: var(--surface-3);
  border: none;
  border-radius: 0;
}

/* Label som overlay längst ner i kortet */
#countdownCharacterLabel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 8px 7px;
  background: linear-gradient(transparent, rgba(6, 8, 14, 0.82));
  color: rgba(220, 228, 244, 0.92);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
}

#countdownJoinBtn {
  pointer-events: auto;
  align-self: center;
  justify-self: center;
  padding: 14px 36px;
  font-size: 18px;
  font-weight: 800;
  border-radius: var(--r-md);
  border: none;
  background: var(--accent, #4f8ef7);
  color: #fff;
  cursor: pointer;
  letter-spacing: 0.03em;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s, transform 0.1s;
}

#countdownJoinBtn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

#countdownJoinBtn:active {
  opacity: 0.75;
  transform: translateY(0);
}

#countdownControlsCard {
  pointer-events: auto;
  background: var(--surface-glass);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 12px 14px;
  width: fit-content;
  margin: 0 auto;
}

#countdownControlsTitle {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.ctrl-tagline {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-soft);
  text-align: center;
  letter-spacing: 0.02em;
}

.ctrl-mobile-hint {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-soft);
  text-align: center;
  line-height: 1.4;
}

/* ── Kontroller-grid ── */
.ctrl-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: flex-start;
  justify-content: center;
}

/* Behåll .ctrl-row för bakåtkompatibilitet */
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.ctrl-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 52px;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted-soft);
  text-align: center;
  line-height: 1.25;
}

/* Tangent-cluster */
.ctrl-keys {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.ctrl-key-row {
  display: flex;
  gap: 3px;
}

/* Keyboard-tangenter */
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom: 3px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg-strong);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 12px;
  font-weight: 800;
  font-style: normal;
  letter-spacing: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
  white-space: nowrap;
}

.key-wide {
  min-width: 68px;
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* Mus-ikon */
.ctrl-mouse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 36px;
  color: var(--fg-strong);
  flex: 0 0 auto;
}

.ctrl-mouse svg {
  width: 20px;
  height: 28px;
}

/* Mobil-badges */
.ctrl-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 16px;
  flex: 0 0 auto;
}

#chatPanel {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  display: flex;
  flex-direction: column;
}

#chatMessages {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 7px;
  font-size: 12px;
  line-height: 1.3;
}

.chat-line {
  margin: 0 0 4px;
  word-break: break-word;
}

.chat-system {
  color: var(--fg-strong);
}

.chat-name {
  color: var(--ok);
}

#chatInputRow {
  display: flex;
  gap: 6px;
  border-top: 1px solid var(--line);
  padding: 7px;
}

#chatInput {
  flex: 1 1 auto;
}

#connectBtn {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  border-color: #7dcf96;
  border-radius: var(--r-sm);
  background: linear-gradient(180deg, #3f7f53 0%, #2c613f 100%);
  box-shadow:
    0 0 0 1px rgba(96, 191, 130, 0.3),
    0 8px 22px rgba(12, 26, 18, 0.42),
    0 0 20px rgba(102, 214, 141, 0.24);
}

#connectBtn:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow:
    0 0 0 1px rgba(120, 218, 156, 0.4),
    0 10px 25px rgba(12, 26, 18, 0.45),
    0 0 24px rgba(102, 214, 141, 0.3);
}

#connectBtn:active:not(:disabled) {
  transform: translateY(1px);
}

#playBtn {
  width: clamp(170px, 26vw, 280px);
  min-height: 40px;
  font-size: clamp(14px, 1.8vw, 17px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: var(--r-sm);
  padding: 8px 12px;
  background: linear-gradient(180deg, #2f4d64 0%, #1f3445 100%);
  border-color: #7cb0d1;
  box-shadow:
    0 6px 14px rgba(4, 6, 10, 0.34),
    0 0 0 1px rgba(136, 186, 220, 0.2);
  transition: transform 180ms ease, box-shadow 220ms ease, filter 180ms ease, background 220ms ease, border-color 220ms ease;
}

#playBtn[data-ready-state="not-ready"] {
  background: linear-gradient(180deg, #2f4d64 0%, #1f3445 100%);
  border-color: #7cb0d1;
  box-shadow:
    0 6px 14px rgba(4, 6, 10, 0.34),
    0 0 0 1px rgba(136, 186, 220, 0.2);
}

#playBtn[data-ready-state="ready"] {
  background: linear-gradient(180deg, #3f854e 0%, #295c36 100%);
  border-color: #91d49b;
  box-shadow:
    0 7px 16px rgba(8, 24, 12, 0.42),
    0 0 0 1px rgba(145, 212, 155, 0.34),
    0 0 24px rgba(99, 219, 129, 0.3);
  animation: ready-btn-pulse 1.6s ease-in-out infinite;
}

#playBtn[data-ready-state="inactive"] {
  background: linear-gradient(180deg, #434851 0%, #2f343d 100%);
  border-color: #788090;
  box-shadow: 0 4px 10px rgba(4, 6, 10, 0.26);
}

#playBtn:hover:not(:disabled) {
  filter: brightness(1.07);
}

#playBtn:active:not(:disabled) {
  transform: translateY(1px);
}

@keyframes ready-btn-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 7px 16px rgba(8, 24, 12, 0.42),
      0 0 0 1px rgba(145, 212, 155, 0.34),
      0 0 18px rgba(99, 219, 129, 0.2);
  }
  50% {
    transform: scale(1.02);
    box-shadow:
      0 9px 20px rgba(8, 24, 12, 0.46),
      0 0 0 1px rgba(161, 223, 170, 0.45),
      0 0 30px rgba(105, 233, 138, 0.38);
  }
}

@media (prefers-reduced-motion: reduce) {
  #playBtn[data-ready-state="ready"] {
    animation: none;
  }
}

#lobbyMatchStatus {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-height: 1.2em;
  padding: 2px 2px 0;
  color: var(--fg-strong);
  font-size: clamp(16px, 2.2vw, 24px);
  line-height: 1.15;
  letter-spacing: 0.01em;
}

#lobbyMatchStatusTitle {
  color: inherit;
  font-weight: 700;
  grid-column: 1;
  min-width: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

#playBtn {
  grid-column: 2;
}

#lobbySettingsBtn,
#gameMenuBtn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border: 1px solid var(--menu-button-border);
  border-radius: var(--r-sm);
  background: var(--menu-button-bg);
  color: var(--menu-button-fg);
  font-size: 20px;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
}

#lobbySettingsBtn {
  flex: 0 0 auto;
}

#lobbyDialogBackdrop {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--overlay);
  z-index: 6;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#lobbyDialogCard {
  width: min(540px, calc(100vw - 20px));
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--surface-glass);
  padding: 16px;
  box-sizing: border-box;
  max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#lobbyDialogTitle {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 800;
}

#lobbyDialogText {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-line;
}

#settingsPanel {
  margin: 0 0 14px;
  display: grid;
  gap: 10px;
}

#settingsAudioHelp {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

#settingsTrackpadHelp,
#settingsFullscreenHelp {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.settingsOptionRow,
.settingsAudioRow {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 86px;
  align-items: center;
  column-gap: 10px;
  row-gap: 8px;
}

.settingsOptionRow span,
.settingsAudioRow span {
  font-size: 14px;
}

.settingsInlineHint {
  grid-column: 2;
  justify-self: end;
  font-size: 11px !important;
  color: var(--muted);
  white-space: nowrap;
}

.settingsOptionRow button,
.settingsAudioRow button {
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settingsOptionRow button {
  grid-column: 3;
}

.settingsOptionRow input[type="checkbox"] {
  grid-column: 3;
  justify-self: center;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent-cool);
}

.settingsAudioRow input[type="range"] {
  width: calc(100% - 20px);
  min-width: 0;
  justify-self: center;
  display: block;
  margin: 0;
  accent-color: var(--accent-cool);
}

.settingsRangeValue {
  justify-self: center;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .settingsOptionRow,
  .settingsAudioRow {
    grid-template-columns: minmax(0, 1fr) 86px;
  }
  .settingsOptionRow span,
  .settingsAudioRow span:first-child {
    grid-column: 1 / -1;
  }
  .settingsOptionRow button {
    grid-column: 2;
  }
  .settingsInlineHint {
    grid-column: 1;
    justify-self: start;
    white-space: normal;
  }
  .settingsOptionRow input[type="checkbox"] {
    grid-column: 2;
    justify-self: start;
  }

  .settingsFullscreenRow {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    column-gap: 8px;
  }
  .settingsFullscreenRow span {
    grid-column: auto;
  }
  .settingsFullscreenRow span:first-child {
    grid-column: 1;
    min-width: 0;
  }
  .settingsFullscreenRow .settingsInlineHint {
    grid-column: 2;
    justify-self: end;
    white-space: nowrap;
  }
  .settingsFullscreenRow input[type="checkbox"] {
    grid-column: 3;
    justify-self: end;
  }

  .settingsLookSmoothingRow {
    grid-template-columns: minmax(0, 1fr) 86px;
    align-items: center;
  }
  .settingsLookSmoothingRow span,
  .settingsLookSmoothingRow span:first-child {
    grid-column: 1;
    min-width: 0;
  }
  .settingsLookSmoothingRow button,
  .settingsOptionRow.settingsLookSmoothingRow button {
    grid-column: 2;
  }

  .settingsMobileControlsRow {
    grid-template-columns: minmax(0, 1fr) 86px;
    align-items: center;
  }
  .settingsMobileControlsRow span,
  .settingsMobileControlsRow span:first-child {
    grid-column: 1;
    min-width: 0;
  }
  .settingsMobileControlsRow button,
  .settingsOptionRow.settingsMobileControlsRow button {
    grid-column: 2;
  }

  #playBtn {
    width: auto;
    min-width: 104px;
    min-height: 34px;
    font-size: 13px;
    padding: 6px 9px;
  }

  #lobbySettingsBtn {
    width: 30px;
    height: 30px;
    min-width: 30px;
    font-size: 18px;
  }
}

#lobbyDialogCloseBtn {
  min-width: 110px;
  position: sticky;
  bottom: 0;
  margin-top: 2px;
}

#gameHud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  color: var(--fg);
  z-index: 5;
}

#crosshairHud {
  --crosshair-color: rgba(255, 255, 255, 0.96);
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
}

#crosshairHud.targeting {
  --crosshair-color: rgba(255, 88, 88, 0.98);
}

#crosshairPlus {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

#crosshairHud.cooldown #crosshairPlus {
  opacity: 0;
}

.crosshair-line {
  position: absolute;
  display: block;
  background: var(--crosshair-color);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
  border-radius: 2px;
}

.crosshair-line-h {
  width: 18px;
  height: 2px;
}

.crosshair-line-v {
  width: 2px;
  height: 18px;
}

#crosshairCooldownRing {
  width: 44px;
  height: 44px;
  transform: rotate(-90deg);
  opacity: 0;
}

#crosshairHud.cooldown #crosshairCooldownRing {
  opacity: 1;
}

#crosshairCooldownArc {
  fill: none;
  stroke: var(--crosshair-color);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-dasharray: 81.6814;
  stroke-dashoffset: 0;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6));
}

#aliveOthersText {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  font-size: 11px;
  letter-spacing: 0.3px;
  color: rgba(255, 255, 255, 0.55);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

#debugOverlay {
  position: absolute;
  top: 28px;
  left: 12px;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: rgba(9, 11, 16, 0.72);
  color: var(--fg-strong);
  font-family: "JetBrains Mono", "Fira Code", Menlo, monospace;
  font-size: 11px;
  line-height: 1.32;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}

#spectatorHud {
  position: absolute;
  left: 0;
  right: 0;
  top: max(12px, env(safe-area-inset-top));
  display: grid;
  justify-items: center;
  gap: 6px;
  pointer-events: none;
}

#spectatorTargetText {
  margin: 0;
  font-size: 13px;
  color: var(--fg-strong);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
}

#spectatorCycleButtons {
  display: flex;
  gap: 8px;
}

#spectatorCycleButtons button {
  pointer-events: auto;
  min-width: 42px;
}

#spectatorActionRow {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

/* #spectatorLobbyBtn inherits from the unified glass-btn rule above */

#knockdownToast {
  position: absolute;
  left: 50%;
  top: 15%;
  transform: translateX(-50%);
  max-width: min(86vw, 560px);
  padding: 12px 18px;
  border-radius: var(--r-md);
  border: 1px solid rgba(141, 225, 111, 0.46);
  background: rgba(14, 24, 20, 0.9);
  color: var(--fg-strong);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  font-size: 24px;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.78);
}

#winOverlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  align-items: center;
  gap: 8px;
  padding: max(18px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  pointer-events: none;
  background: radial-gradient(circle at 50% 36%, rgba(75, 211, 107, 0.17), rgba(4, 6, 10, 0) 42%);
}

#winTitle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-width: min(90vw, 760px);
  padding: 14px 22px;
  border-radius: var(--r-md);
  border: 1px solid rgba(141, 225, 111, 0.42);
  background: rgba(8, 14, 13, 0.72);
  box-shadow: 0 18px 56px rgba(0, 0, 0, 0.38);
  font-size: 64px;
  line-height: 0.98;
  font-weight: 900;
  color: var(--fg-strong);
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.88);
}

#winCountdownText {
  margin: 0;
  align-self: end;
  font-size: 13px;
  font-weight: 700;
  color: rgba(220, 228, 242, 0.84);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.74);
}

#winLobbyBtn {
  align-self: end;
}

#downedOverlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  align-items: center;
  gap: 8px;
  padding: max(18px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  pointer-events: none;
  background: radial-gradient(circle at 50% 38%, rgba(255, 106, 112, 0.15), rgba(4, 6, 10, 0) 44%);
}

#downedByText {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  max-width: min(90vw, 720px);
  padding: 13px 18px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 106, 112, 0.4);
  background: rgba(18, 12, 15, 0.74);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.38);
  font-size: 52px;
  line-height: 1;
  font-weight: 900;
  color: var(--fg-strong);
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.88);
}

#downedCountdownText {
  margin: 0;
  align-self: end;
  font-size: 13px;
  font-weight: 700;
  color: rgba(220, 228, 242, 0.84);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.74);
}

#downedActionRow {
  display: flex;
  gap: 8px;
  align-self: end;
  pointer-events: auto;
}

/* #downedLobbyBtn inherits from the unified glass-btn rule above */

#gameChatNotice {
  position: absolute;
  right: 14px;
  bottom: 188px;
  font-size: 11px;
  color: rgba(231, 235, 245, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

#gameMenuBtn {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  pointer-events: auto;
  z-index: 7;
}

#lobbyMenuBackdrop,
#gameMenuBackdrop {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--overlay);
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#lobbyMenuBackdrop {
  z-index: 6;
}

#lobbyMenuCard,
#gameMenuCard {
  width: min(320px, calc(100vw - 28px));
  background: var(--surface-glass);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 16px;
  display: grid;
  gap: 8px;
  max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#lobbyMenuTitle,
#gameMenuTitle {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#lobbyMenuCard button,
#gameMenuCard button {
  width: 100%;
}

#gameMenuBackdrop {
  pointer-events: auto;
}

#gameChatBox {
  position: absolute;
  right: 12px;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 72px));
  width: min(420px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  border: 1px solid var(--line-faint);
  border-radius: var(--r-sm);
  background: rgba(9, 11, 16, 0.58);
  backdrop-filter: blur(2px);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
}

#gameChatMessages {
  max-height: 120px;
  overflow: hidden;
  padding: 8px;
  font-size: 12px;
  line-height: 1.3;
}

#gameChatMessages .chat-line {
  margin: 0 0 3px;
  color: rgba(233, 236, 243, 0.86);
}

#gameChatMessages .chat-system {
  color: var(--fg-strong);
}

#gameChatInputRow {
  border-top: 1px solid var(--line-soft);
  padding: 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

#gameChatInput {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line-soft);
  background: rgba(10, 12, 18, 0.9);
  color: var(--fg);
  padding: 7px 8px;
}

/* #gameChatSendBtn inherits from the unified glass-btn rule above */

#gameChatBox.open #gameChatMessages {
  max-height: min(52vh, 380px);
  overflow-y: auto;
}

#mobileControls {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  gap: 12px;
  pointer-events: none;
}

#mobileLandscapePrompt {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(8, 12, 18, 0.82);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 11;
}

#mobileLandscapePromptCard {
  width: min(360px, calc(100vw - 40px));
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  background: rgba(12, 16, 24, 0.94);
  color: var(--fg-strong);
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  padding: 20px 18px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.36);
}

#mobileCombatPad button {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: rgba(12, 16, 24, 0.86);
  color: var(--fg);
  min-height: 36px;
  font-size: 14px;
  font-weight: 700;
  padding: 6px 8px;
}

#mobileJoystickWrap {
  width: min(34vw, 178px);
  display: grid;
  place-items: center;
}

#mobileJoystickBase {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  width: min(34vw, 178px);
  height: min(34vw, 178px);
  border-radius: 999px;
  border: 2px solid var(--line-soft);
  background:
    radial-gradient(circle at 35% 30%, rgba(140, 165, 192, 0.22), rgba(24, 30, 40, 0.88)),
    rgba(10, 13, 19, 0.85);
  position: relative;
  box-sizing: border-box;
}

#mobileJoystickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 42%;
  height: 42%;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(216, 229, 248, 0.2);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.32);
}

#mobileCombatPad {
  pointer-events: none;
  position: absolute;
  left: 50%;
  bottom: max(4px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(42vw, 220px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

#mobileActionPad {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(37vw, 188px);
  gap: 0;
}

#mobileLookPad {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: rgba(12, 16, 24, 0.8);
  color: rgba(233, 238, 248, 0.78);
  min-height: 92px;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 6px;
  box-sizing: border-box;
}

body.mobile-controls-enabled #gameChatBox {
  display: none;
}

body.mobile-controls-enabled #gameChatNotice {
  display: none;
}

@media (max-width: 900px) {
  .connect-layout {
    width: min(520px, calc(100vw - 20px));
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) and (orientation: portrait),
       (max-height: 740px) {

  .card {
    width: 100%;
    padding: 14px;
    gap: 8px;
  }

  #scoreTable {
    min-width: 560px;
  }

  #scoreTable th,
  #scoreTable td {
    padding: 6px 7px;
    font-size: 12px;
  }

  #scoreTable th {
    font-size: 11px;
  }

  #lobbyMain {
    gap: 6px;
  }

  #countdownTopRow {
    gap: 14px;
  }

  #countdownCharacterCanvas {
    width: 148px;
    height: 148px;
  }

  .ctrl-label {
    font-size: 10px;
  }

  #chatMessages {
    padding: 6px;
  }

  #chatInputRow {
    padding: 6px;
  }

  #playBtn {
    width: auto;
    min-width: 110px;
    min-height: 36px;
    font-size: 13px;
    padding: 6px 9px;
  }

  #gameChatNotice {
    display: none;
  }

  #debugOverlay {
    top: 30px;
    font-size: 10px;
    padding: 6px 8px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  #scoreTable th,
  #scoreTable td {
    padding: 5px 6px;
    font-size: 11px;
  }

  #chatMessages {
    line-height: 1.24;
  }

  #playBtn {
    width: clamp(144px, 30vw, 200px);
    min-height: 34px;
    font-size: 13px;
    padding: 6px 9px;
  }

  #lobbyMatchStatus {
    font-size: clamp(14px, 1.9vw, 18px);
  }

  #gameChatMessages {
    max-height: 84px;
  }

  #gameChatNotice {
    bottom: 164px;
  }
}

@media (max-width: 560px) and (orientation: portrait) {
  #scoreTable {
    min-width: 0;
    table-layout: fixed;
  }

  #scoreTable th,
  #scoreTable td {
    padding: 4px 4px;
    font-size: 10.5px;
  }

  #scoreTable th:nth-child(2),
  #scoreTable th:nth-child(3),
  #scoreTable th:nth-child(4),
  #scoreTable th:nth-child(5),
  #scoreTable th:nth-child(6),
  #scoreTable td:nth-child(2),
  #scoreTable td:nth-child(3),
  #scoreTable td:nth-child(4),
  #scoreTable td:nth-child(5),
  #scoreTable td:nth-child(6) {
    width: 26px;
    text-align: center;
  }

  #scoreTable th:nth-child(7),
  #scoreTable td:nth-child(7) {
    width: 48px;
  }

  .status-cell {
    text-align: left;
  }

  .status-label {
    display: inline-block;
    max-width: 46px;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
  }

  .ready-lamp {
    width: 8px;
    height: 8px;
    border-width: 1px;
    margin-right: 5px;
  }

  .name-cell-inner {
    gap: 5px;
  }

  .name-label {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #scoreTable .th-full {
    display: none;
  }

  #scoreTable .th-short {
    display: inline;
  }

  #countdownTopRow {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
  }

  #countdownText {
    font-size: clamp(74px, 26vw, 150px);
  }

  #countdownCharacterCanvas {
    width: 130px;
    height: 130px;
  }

  #playBtn {
    width: clamp(80px, 24vw, 102px);
    min-width: 80px;
    min-height: 34px;
    font-size: 12px;
    padding: 6px 6px;
  }

  #lobbyMatchStatus {
    gap: 6px;
    font-size: clamp(13px, 4.2vw, 18px);
  }

  #lobbyPlayersMeta {
    font-size: 10px;
  }

}

@media (max-width: 720px), (max-height: 560px) {
  #winTitle {
    font-size: 38px;
    padding: 11px 14px;
  }

  #downedByText {
    top: 34%;
    font-size: 32px;
    padding: 11px 14px;
  }

  #knockdownToast {
    font-size: 20px;
    padding: 10px 14px;
  }

  #gameChatBox {
    width: min(360px, calc(100vw - 24px));
    bottom: max(82px, calc(env(safe-area-inset-bottom) + 82px));
  }

  #gameChatBox.open #gameChatMessages {
    max-height: 28vh;
  }
}
