*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  width: 100%;
  min-height: 100dvh;
  font-size: 20px;
  scrollbar-gutter: stable;
}

:root {
  /* Side panels: player cards, header brand, header docs CTA — keep in sync. */
  --sb-side-panel-width: clamp(228px, 19vw, 320px);
  /* Match js/config.js derivePlayerPalette + app applyPlayerThemeVars defaults (#ff6b2b / #00d4ff). */
  --player1-base: #ff6b2b;
  --player1-bright: #ff8651;
  --player1-dark: #c25121;
  --player2-base: #00d4ff;
  --player2-bright: #2edcff;
  --player2-dark: #00a1c2;
}

body {
  background-color: #080c14;
  color: #8899aa;
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.05rem;
  width: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
}

.sb-mono { font-family: 'Share Tech Mono', monospace !important; }
.sb-cond { font-family: 'Barlow Condensed', sans-serif !important; }

.sb-card {
  background: #0e1525;
  border: 1px solid #1a2a40;
  border-radius: 8px;
  box-shadow: none;
}

.sb-btn {
  background: #1a2638;
  border: 1px solid #334a6e;
  color: #a8b8cc;
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.08rem;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
  white-space: nowrap;
}

a.sb-btn:link,
a.sb-btn:visited {
  color: #a8b8cc;
}

.sb-btn:hover {
  background: #223048;
  border-color: #4a6490;
  color: #d8e4f0;
}

.sb-btn--danger {
  border-color: #8a3a3a;
  color: #f0b0b0;
  background: #2a1518;
}

.sb-btn--danger:hover:not(:disabled) {
  border-color: #c05050;
  color: #ffe0e0;
  background: #3a1a20;
}

.sb-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sb-btn--starter-download {
  border: 2px solid #41ff8f;
  box-shadow: 0 0 0 1px rgba(65, 255, 143, 0.45);
}

.sb-btn--starter-download:hover:not(:disabled) {
  border-color: #7dffc0;
  box-shadow: 0 0 0 1px rgba(125, 255, 192, 0.55);
}

.sb-btn--starter-download:focus-visible {
  outline: 2px solid #7dffc0;
  outline-offset: 2px;
}

.sb-label-xs {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: #8a9db4;
  text-transform: uppercase;
}

.sb-score {
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(3.1rem, 7vw, 5rem);
  line-height: 1;
  font-weight: 400;
}

.sb-divider {
  background-color: #1a2a40;
  height: 1px;
  width: 100%;
  border: none;
}

.hex-wrap {
  background: #070d1a;
  border-radius: 6px;
  overflow: auto;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  width: 100%;
}

/* Fill the column: scale the map to use width *and* height (not only width → tiny letterboxed grid). */
.hex-wrap svg {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

/* ── Layout ────────────────────────────────────────────────────────────── */

.app-container {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  min-height: 100dvh;
  min-height: 100vh;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  box-sizing: border-box;
  /* Avoid overflow-x:hidden + overflow-y:visible — that pair forces overflow-y:auto and clips popovers. */
  overflow: visible;
  gap: 10px;
}

/* Main column grows with content; the page scrolls on `body` so the dock is not pinned to the viewport. */
.app-main {
  flex: 0 0 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* Turn row + event log share one column so width tracks together. */
.app-dock {
  flex: 0 0 auto;
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.app-footer {
  flex: 0 0 auto;
  width: 100%;
  padding: 6px 4px 2px;
  text-align: center;
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.68rem, 1.9vw, 0.82rem);
  color: #5a6a82;
  line-height: 1.45;
}

.app-footer a {
  color: #5ec8ff;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

.header-brand-title {
  font-size: clamp(1.85rem, 3.6vw, 2.85rem);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: #dde8f0;
  flex: 0 0 auto;
}
.header-row-status {
  min-width: 0;
  text-align: center;
  width: 100%;
  flex-shrink: 0;
}
/* Docs entry point: reads as a link (not a button). */
.header-docs-link {
  flex: 0 0 auto;
  align-self: flex-end;
  width: fit-content;
  max-width: 100%;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: clamp(1.08rem, 2.15vw, 1.38rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c8e4f5;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
  line-height: 1.3;
}

.header-docs-link:hover {
  color: #e8f4fc;
}

.header-docs-link:focus-visible {
  outline: 2px solid #6a8ec4;
  outline-offset: 3px;
  border-radius: 2px;
}

.header-docs-link__ext {
  font-size: 0.92em;
  letter-spacing: 0;
  text-decoration: none;
  display: inline-block;
}

.header-links-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px 16px;
  align-self: flex-end;
  width: 100%;
}

.header-welcome-btn {
  flex: 0 0 auto;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: clamp(1.08rem, 2.15vw, 1.38rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c8e4f5;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.2em;
  line-height: 1.3;
}

.header-welcome-btn:hover {
  color: #e8f4fc;
}

.header-welcome-btn:focus-visible {
  outline: 2px solid #6a8ec4;
  outline-offset: 3px;
  border-radius: 2px;
}

.game-layout .hex-column:not(.hex-column--controls-only) .status {
  color: #6d8299;
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.12rem;
  letter-spacing: 0.16em;
}

@media (min-width: 841px) {
  .game-layout .hex-column:not(.hex-column--controls-only) .header-row-status:not(:empty) {
    padding-top: 10px;
  }
}
.button-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hex-control-bar {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 14px;
  margin-bottom: 0;
  background: #0a101c;
  border: 2px solid #2a3f5c;
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 1px rgba(0, 212, 255, 0.08),
    0 2px 12px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

.hex-control-bar .button-group {
  justify-content: center;
  flex-wrap: nowrap;
}

.hex-control-bar > .sb-btn,
.hex-control-bar .button-group > .sb-btn,
.hex-control-bar .button-group .sb-step-wrap > .sb-btn {
  padding-top: 2px;
  padding-bottom: 0;
}

.sb-step-wrap {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.sb-step-wrap .sb-btn {
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sb-step-main {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
  padding-right: 14px;
}

.sb-step-chevron {
  min-width: 42px;
  padding: 0 8px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  font-size: 0.75rem;
  line-height: 1;
}

.sb-step-wrap .sb-step-chevron {
  letter-spacing: 0;
}

.sb-step-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 60;
  min-width: 11.5rem;
  padding: 8px;
  background: #0e1525;
  border: 1px solid #1a2a40;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Author `display: flex` wins over the `hidden` attribute unless we restate it. */
#step-tick-menu[hidden] {
  display: none !important;
}

.sb-step-menu .sb-step-menu-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  white-space: nowrap;
}

.sb-step-menu .sb-step-menu-btn[aria-selected='true'] {
  border-color: #3a5070;
  color: #dde8f0;
  background: #151f35;
}

.sb-step-custom-panel {
  padding-top: 2px;
}

.sb-step-custom-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.sb-step-custom-input {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
}

.sb-step-custom-apply {
  flex-shrink: 0;
  min-height: 44px;
}

/* Header row + map row share one grid so the center column lines up with the hex area. */
.game-layout {
  width: 100%;
  flex: 0 1 auto;
  min-height: clamp(300px, 48dvh, 960px);
  min-width: 0;
  display: grid;
  grid-template-columns: var(--sb-side-panel-width) minmax(0, 1fr) var(--sb-side-panel-width);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

/* Must follow the base `.game-layout` rule above — otherwise `flex: 0 1 auto` wins and the map row stays content-height (dead band above the dock). */
@media (min-width: 841px) {
  .app-main {
    flex: 1 1 0%;
    min-height: 0;
  }

  .game-layout {
    flex: 1 1 0%;
    min-height: 0;
  }
}

.main-row-gutter {
  flex-shrink: 0;
  min-width: 0;
  box-sizing: border-box;
}

.main-row-gutter--brand {
  width: var(--sb-side-panel-width);
  display: flex;
  align-items: center;
  min-height: 0;
}

.main-row-gutter--actions {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
  min-height: 0;
}

.hex-column--controls-only {
  container-type: inline-size;
  container-name: match-controls;
  min-width: 0;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  /* Top-align: when row 1 is taller than the bar (e.g. status/docs column), centering adds empty space above and below. */
  justify-content: flex-start;
}

/* Narrow center column (grid layout): wrap match controls instead of overflowing. */
@container match-controls (max-width: 720px) {
  .hex-control-bar .button-group {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 8px;
  }
}

@container match-controls (max-width: 420px) {
  .hex-control-bar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .hex-control-bar .button-group > .sb-btn,
  .hex-control-bar .button-group .sb-step-wrap > .sb-btn {
    font-size: 0.92rem;
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* Browsers without container queries: still wrap when the window is fairly narrow. */
@supports not (container-type: inline-size) {
  @media (max-width: 960px) {
    .hex-control-bar .button-group {
      flex-wrap: wrap;
      justify-content: center;
      row-gap: 8px;
    }
  }
}

/* Full width of center column so it matches .hex-wrap below. */
.game-layout .hex-column--controls-only > .hex-control-bar {
  width: 100%;
  max-width: 100%;
}
.player-card {
  width: var(--sb-side-panel-width);
  min-width: 0;
  flex-shrink: 0;
  min-height: 0;
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow: hidden;
}

.player-card-summary {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.player-card-summary-main {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  flex: 1 1 auto;
}

.player-card-summary-trailing {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.player-card-match-stats-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  margin: 0;
  padding: 0 6px;
  border: 1px solid #334a6e;
  border-radius: 5px;
  background: #1a2638;
  color: #a8b8cc;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.player-card-match-stats-btn:hover:not(:disabled) {
  background: #223048;
  border-color: #4a6490;
  color: #d8e4f0;
}

.player-card-match-stats-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.player-card-expand-btn {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 1px solid #334a6e;
  border-radius: 5px;
  background: #1a2638;
  color: #a8b8cc;
  font-family: 'Share Tech Mono', monospace;
  cursor: pointer;
  line-height: 1;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

#app.app--player-cards-compact .player-card-expand-btn {
  display: inline-flex !important;
}

.player-card-expand-btn:hover {
  background: #223048;
  border-color: #4a6490;
  color: #d8e4f0;
}

.player-card-expand-icon {
  display: block;
  font-size: 0.72rem;
  line-height: 1;
  transition: transform 0.18s ease;
  transform: rotate(-90deg);
}

.player-card.player-card--expanded .player-card-expand-icon {
  transform: rotate(0deg);
}

.player-card-details {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* !important beats [hidden] / grid / flex quirks so collapsed cards reliably hide details. */
#app.app--player-cards-compact .player-card:not(.player-card--expanded) .player-card-details {
  display: none !important;
}

/* Single padding in compact mode so expand/collapse does not shift the card shell (avoids background “tearing”). */
#app.app--player-cards-compact .player-card {
  padding: 10px 14px 10px;
}

#app.app--player-cards-compact .player-card.player-card--expanded .player-card-details {
  display: flex !important;
}

.player-card .sb-score {
  font-size: clamp(2.2rem, 5vw, 3.35rem);
  line-height: 1;
}

#player-card-1 .player-card-title {
  color: var(--player1-dark);
}

#player-card-2 .player-card-title {
  color: var(--player2-dark);
}

#score-1 {
  color: var(--player1-base);
}

#score-2 {
  color: var(--player2-base);
}

#pct-1 {
  color: var(--player1-bright);
}

#pct-2 {
  color: var(--player2-bright);
}

.player-card .sb-divider {
  margin: 0.15rem 0;
}

.player-card-log-block {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.2rem;
}

.player-card-feed-heading {
  letter-spacing: 0.12em;
  opacity: 0.72;
  flex-shrink: 0;
}

.player-card-feed {
  flex: 1 1 0;
  min-height: 0;
  padding: 4px 0 0;
  margin: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.72rem, 2.2vw, 0.88rem);
  line-height: 1.38;
  color: #8a9eb8;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  overflow-x: hidden;
}

.player-card-feed:empty {
  /* Still grows with .player-card-log-block so the column fills height; no log text yet. */
  color: transparent;
}

.player-card-feed-heading:has(+ .player-card-feed:empty) {
  display: none;
}

#player-card-1.player-card--feed-error .player-card-feed:not(:empty) {
  color: var(--player1-bright);
  border-left: 2px solid var(--player1-dark);
  padding-left: 8px;
  margin-left: -2px;
}

#player-card-2.player-card--feed-error .player-card-feed:not(:empty) {
  color: var(--player2-bright);
  border-left: 2px solid var(--player2-dark);
  padding-left: 8px;
  margin-left: -2px;
}

@keyframes player-card-log-highlight {
  from {
    box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.06);
    border-color: #3a5070;
  }
  to {
    box-shadow: none;
    border-color: #1a2a40;
  }
}

.player-card.player-card--feed-flash {
  animation: player-card-log-highlight 0.48s ease-out forwards;
}

.player-card .sb-select,
.player-card .sb-bot-picker {
  margin-top: 0;
}

.sb-bot-source-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
}

.sb-bot-source-actions .sb-btn {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: center;
}

.sb-bot-source-view-btn {
  justify-content: center;
}

/* BOT FILE block reads as its own section under view source. */
.player-card-details .sb-bot-source-actions + .sb-label-xs {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid #1a2a40;
}

/* When main Event Log panel is expanded, hide per-player mini log section. */
.app-container.event-log-expanded .player-card-log-block {
  display: none;
}

.hex-column {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.turn-row {
  width: 100%;
  flex: 0 0 auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
  background: #080c14;
  box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.35);
}

/* Desktop: TURN…slider participate directly in .turn-row (same visual as a flat list). */
.turn-row-mid {
  display: contents;
}

.turn-row-event-log-btn {
  margin-left: auto;
}

/* Narrow width: starter download + EVENT LOG each on their own full row. */
@media (max-width: 720px) {
  .turn-row #btn-download-starter-code {
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
  }

  .turn-row-mid {
    display: flex;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px 10px;
  }

  .turn-row-mid .sb-progress {
    flex: 1 1 0;
    min-width: 0;
  }

  .turn-row-mid .sb-slider {
    flex: 0 1 200px;
    width: auto;
    min-width: 72px;
    max-width: min(200px, 42vw);
  }

  .turn-row-event-log-btn {
    margin-left: 0;
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
    justify-content: center;
  }
}

.turn-row-event-log-btn::after {
  content: " \25BE";
  font-size: 0.78em;
  line-height: 1;
  margin-left: 0.35rem;
}

.turn-row-event-log-btn[aria-expanded="true"]::after {
  content: " \25B4";
}
.turn-num {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.18rem;
  color: #8899aa;
  flex-shrink: 0;
  min-width: 40px;
}
.max-turns {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.18rem;
  color: #8a9db4;
  flex-shrink: 0;
}

/* ── Event log ─────────────────────────────────────────────────────────── */

.event-log-card {
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

/* Author `display: flex` on .event-log-card wins over the `hidden` attribute unless we restate it. */
#event-log-panel[hidden] {
  display: none !important;
}

.event-log-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 2px;
  min-width: 0;
}
.event-log-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.event-log-filter-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.event-log-filter-toggle.event-log-filter-toggle--active {
  border-color: #4f6b90;
  background: #263b56;
  color: #d7e5f6;
}
.event-log-filter-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: #0c1524;
  border: 1px solid #324661;
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.event-log-filter-menu[hidden] {
  display: none !important;
}
.event-log-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.85rem;
  color: #a7b7cc;
  cursor: pointer;
  user-select: none;
}
.event-log-filter-option input[type='checkbox'] {
  accent-color: #4f6b90;
}
.event-log-filter-clear {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}

.sb-btn--compact {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.98rem;
}

/* Pop-out window: cap height to the viewport and scroll inside (body uses overflow:hidden). */
.event-log.event-log--popout-fill {
  flex: 1 1 auto;
  align-self: stretch;
  min-height: 0 !important;
  height: auto !important;
  max-height: 100vh !important;
  overflow-y: auto !important;
  border-radius: 0;
}

/* Taller log; scroll inside when needed. */
.event-log {
  --event-log-viewport: clamp(6.5rem, 21dvh, 14rem);
  background: #070d1a;
  color: #9aacbf;
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.88rem, 2.8vw, 1.02rem);
  border-radius: 4px;
  flex: 0 0 auto;
  height: var(--event-log-viewport);
  min-height: var(--event-log-viewport);
  max-height: var(--event-log-viewport);
  width: 100%;
  overflow-y: auto;
  padding: 10px 14px;
  line-height: 1.5;
}

.event-log > div {
  white-space: pre-wrap;
  word-break: break-word;
}
.event-log-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.event-log-group-toggle {
  appearance: none;
  border: 1px solid #2d425e;
  background: #0f1a2b;
  color: #7f96af;
  border-radius: 4px;
  font: inherit;
  line-height: 1.3;
  text-align: left;
  padding: 4px 8px;
  cursor: pointer;
}
.event-log-group-toggle:hover {
  border-color: #436086;
  color: #b8cade;
}
.event-log-group-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: -2px 0 0 14px;
  padding: 8px 10px 8px 12px;
  border-left: 2px solid #2d425e;
  border-radius: 0 0 4px 4px;
  background: rgba(15, 26, 43, 0.45);
}
.event-log-group-item {
  padding-left: 2px;
}
.event-log-group-item + .event-log-group-item {
  border-top: 1px dashed rgba(87, 112, 141, 0.25);
  padding-top: 3px;
}
.event-log-group-preview {
  opacity: 0.95;
}

/* Error lines only: same accent idea as player-card feeds (see #player-card-* .player-card-feed). */
.event-log-line--error.event-log-line--p1:not(.event-log-line--p2) {
  color: var(--player1-bright);
  border-left: 2px solid var(--player1-dark);
  padding-left: 8px;
  margin-left: -2px;
}

.event-log-line--error.event-log-line--p2:not(.event-log-line--p1) {
  color: var(--player2-bright);
  border-left: 2px solid var(--player2-dark);
  padding-left: 8px;
  margin-left: -2px;
}

.event-log-line--error.event-log-line--p1.event-log-line--p2 {
  color: #c8d4e0;
  padding-left: 8px;
  margin-left: -2px;
  border-left: 3px solid #6a7a8a;
}

.event-log-line--error:not(.event-log-line--p1):not(.event-log-line--p2) {
  color: #c8b898;
  border-left: 2px solid #6a6048;
  padding-left: 8px;
  margin-left: -2px;
}

@supports not (height: 21dvh) {
  .event-log {
    --event-log-viewport: clamp(6.5rem, 21vh, 14rem);
  }
}

/* ── Progress bar ──────────────────────────────────────────────────────── */

.sb-progress {
  flex: 1;
  height: 6px;
  background: #111c2e;
  border-radius: 3px;
  overflow: hidden;
}
.sb-progress-fill {
  height: 100%;
  background: #dde8f0;
  transition: width 0.1s;
  width: 0%;
}

/* ── Input ─────────────────────────────────────────────────────────────── */

.sb-input {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.02rem;
  color: #9aacbf;
  background: #070d1a;
  border: none;
  border-radius: 4px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}

.sb-select {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1rem;
  color: #8899aa;
  background: #070d1a;
  border: 1px solid #1a2a40;
  border-radius: 4px;
  padding: 9px 12px;
  margin-top: 4px;
  width: 100%;
  max-width: 100%;
  cursor: pointer;
  outline: none;
}
.sb-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.sb-select option,
.sb-select optgroup {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.05rem;
  background: #0e1525;
  color: #8899aa;
}

/* ── Custom bot picker (replaces native select) ───────────────────────── */

.sb-bot-picker {
  position: relative;
  margin-top: 4px;
  width: 100%;
  max-width: 100%;
}

.sb-bot-picker-trigger {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1rem;
  color: #8899aa;
  background: #070d1a;
  border: 1px solid #1a2a40;
  border-radius: 4px;
  padding: 9px 12px;
  width: 100%;
  max-width: 100%;
  cursor: pointer;
  outline: none;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  box-sizing: border-box;
}

.sb-bot-picker-trigger::after {
  content: '\25BE';
  flex-shrink: 0;
  font-size: 0.75rem;
  color: #5a6a7a;
}

.sb-bot-picker--open .sb-bot-picker-trigger::after {
  content: '\25B4';
}

.sb-bot-picker-trigger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sb-bot-picker-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  max-height: min(320px, 50vh);
  overflow-y: auto;
  overflow-x: hidden;
  background: #0a101c;
  border: 1px solid #1a2a40;
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  padding: 6px 0;
  /* Match docs scrollbars (css/docs.css — .docs-sidebar-list et al.) */
  scrollbar-width: thin;
  scrollbar-color: #3f5875 #0e1525;
}

.sb-bot-picker-panel::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.sb-bot-picker-panel::-webkit-scrollbar-track {
  background: #0e1525;
  border-radius: 4px;
}

.sb-bot-picker-panel::-webkit-scrollbar-thumb {
  background: #334a6e;
  border-radius: 4px;
}

.sb-bot-picker-panel::-webkit-scrollbar-thumb:hover {
  background: #4a6490;
}

.sb-bot-picker-group-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5a6d82;
  padding: 8px 12px 4px;
  margin: 0;
}

.sb-bot-picker-placeholder {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.92rem;
  color: #5a6d82;
  padding: 8px 12px 10px;
  font-style: italic;
}

.sb-bot-picker-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-top: 1px solid #121b2c;
}

.sb-bot-picker-row:first-of-type {
  border-top: none;
}

.sb-bot-picker-option {
  flex: 1 1 auto;
  min-width: 0;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.95rem;
  color: #9aacbf;
  background: transparent;
  border: none;
  margin: 0;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  outline: none;
  border-radius: 0;
}

.sb-bot-picker-option:hover,
.sb-bot-picker-option:focus-visible {
  background: #121b2c;
  color: #dde8f0;
}

.sb-bot-picker-option--selected {
  background: #151f32;
  color: #dde8f0;
}

.sb-bot-picker-row--custom .sb-bot-picker-option {
  padding-right: 6px;
}

.sb-bot-picker-delete {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 40px;
  margin: 2px 6px 2px 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #5a6d82;
  cursor: pointer;
  outline: none;
  align-self: center;
}

.sb-bot-picker-delete:hover,
.sb-bot-picker-delete:focus-visible {
  color: #e07070;
  background: #1a1518;
}

.sb-bot-picker-delete-icon {
  display: block;
}

/* ── Bot file upload (player cards) ───────────────────────────────────── */

.sb-file-upload-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.sb-file-input-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sb-file-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.sb-file-choose-btn {
  margin: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  letter-spacing: 0.06em;
  background: #243248;
  border-color: #455e82;
  color: #c8d6e8;
  flex: 1 1 auto;
  min-width: 0;
}

.sb-file-status {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.78rem;
  color: #5c6d82;
  line-height: 1.35;
  min-height: 1.35em;
  word-break: break-word;
}

.sb-file-upload-wrap--loading .sb-file-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8a9db4;
}

.sb-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #334a6e;
  border-top-color: #c8d6e8;
  border-radius: 50%;
  flex-shrink: 0;
  animation: sb-spin 0.65s linear infinite;
}

@keyframes sb-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Slider (speed) ──────────────────────────────────────────────────── */

.sb-slider {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(120px, 18vw, 200px);
  height: 22px;
  background: transparent;
  outline: none;
  flex-shrink: 0;
  cursor: pointer;
}

.sb-slider:focus-visible {
  outline: 2px solid #4a6490;
  outline-offset: 2px;
  border-radius: 4px;
}

.sb-slider::-webkit-slider-runnable-track {
  height: 10px;
  background: #111c2e;
  border: 1px solid #334a6e;
  border-radius: 5px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

.sb-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -7px;
  background: linear-gradient(180deg, #eef4fa 0%, #c8d4e0 100%);
  border-radius: 50%;
  border: 2px solid #4a6490;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12) inset,
    0 2px 6px rgba(0, 0, 0, 0.45);
  cursor: grab;
}

.sb-slider:active::-webkit-slider-thumb {
  cursor: grabbing;
}

.sb-slider::-moz-range-track {
  height: 10px;
  background: #111c2e;
  border: 1px solid #334a6e;
  border-radius: 5px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

.sb-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: linear-gradient(180deg, #eef4fa 0%, #c8d4e0 100%);
  border-radius: 50%;
  border: 2px solid #4a6490;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12) inset,
    0 2px 6px rgba(0, 0, 0, 0.45);
  cursor: grab;
}

.sb-slider:active::-moz-range-thumb {
  cursor: grabbing;
}

/* ── Settings modal ────────────────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.settings-card {
  width: 880px;
  max-width: 94vw;
  padding: 24px 22px;
  font-size: 1.12rem;
}

.settings-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.settings-card-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #dde8f0;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
}

.settings-close-x {
  display: inline-flex;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid #334a6e;
  border-radius: 6px;
  background: #121b2c;
  color: #a8b8cc;
  font-family: system-ui, sans-serif;
  font-size: 1.45rem;
  font-weight: 400;
  line-height: 0;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.settings-close-x:hover {
  background: #1a2638;
  border-color: #4a6490;
  color: #e8f0f8;
}

.settings-close-x:focus-visible {
  outline: 2px solid #4a6490;
  outline-offset: 2px;
}

.bot-source-card {
  width: min(920px, 96vw);
  max-height: 88vh;
  padding: 16px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

.bot-source-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.bot-source-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #dde8f0;
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.bot-source-close-x {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid #334a6e;
  border-radius: 6px;
  background: #121b2c;
  color: #a8b8cc;
  font-family: system-ui, sans-serif;
  font-size: 1.45rem;
  font-weight: 400;
  line-height: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.bot-source-close-x:hover {
  background: #1a2638;
  border-color: #4a6490;
  color: #e8f0f8;
}

.bot-source-close-x:focus-visible {
  outline: 2px solid #6a8ec4;
  outline-offset: 2px;
}

/* Bot source body: same chrome as docs fenced blocks (css/docs.css). */
.bot-source-card .bot-source-docs-code-wrap {
  margin: 10px 0 0;
  border: 1px solid #1a2a40;
  border-radius: 8px;
  overflow: hidden;
  background: #070d1a;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(62vh, 520px);
  display: flex;
  flex-direction: column;
}

.bot-source-card .docs-code-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.4rem 0.55rem;
  background: #0e1525;
  border-bottom: 1px solid #1a2a40;
  flex-shrink: 0;
}

.bot-source-card .docs-code-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #9aacbf;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.bot-source-card .docs-copy-btn {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #9aacbf;
  background: #111c2e;
  border: 1px solid #1e2d47;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.bot-source-card .docs-code-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex: 0 0 auto;
}

.bot-source-card .docs-code-toolbar .docs-copy-btn,
.bot-source-card .docs-code-toolbar .docs-try-btn {
  flex: 0 0 auto;
}

.bot-source-card .docs-copy-btn:hover,
.bot-source-card .docs-try-btn:hover {
  border-color: #3a5070;
  color: #c0d0e0;
}

.bot-source-card .docs-copy-btn--done {
  border-color: #2a6048;
  color: #7dccb0;
}

.bot-source-card .docs-try-btn {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #9aacbf;
  background: #111c2e;
  border: 1px solid #1e2d47;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.bot-source-download-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.bot-source-download-icon {
  flex-shrink: 0;
  opacity: 0.92;
}

.bot-source-card .docs-code-wrap pre {
  margin: 0;
  border: none;
  border-radius: 0;
}

.bot-source-card .bot-source-code-pre {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1rem 1.1rem;
  background: #070d1a;
}

.bot-source-card .bot-source-code-pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.95rem;
  font-family: 'Share Tech Mono', monospace;
  white-space: pre;
  tab-size: 4;
}

.bot-source-card .bot-source-code-pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 0;
  background: transparent;
}

.bot-source-card .bot-source-code-pre code:not(.hljs) {
  color: #8899aa;
}

.delete-custom-bot-card {
  width: min(480px, 92vw);
  padding: 22px 20px 18px;
  text-align: center;
}

.delete-custom-bot-title {
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #dde8f0;
}

.delete-custom-bot-message {
  margin: 14px 0 18px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.98rem;
  color: #a8b8cc;
  line-height: 1.45;
  text-align: left;
}

.duplicate-upload-card {
  width: min(480px, 92vw);
  padding: 22px 20px 18px;
  text-align: center;
}

.duplicate-upload-title {
  font-size: clamp(1.35rem, 3.5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #dde8f0;
}

.duplicate-upload-message {
  margin: 12px 0 8px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.98rem;
  color: #a8b8cc;
  line-height: 1.45;
  text-align: left;
}

.duplicate-upload-add-label {
  display: block;
  margin: 10px 0 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #7a8a9a;
  text-align: left;
}

.duplicate-upload-add-name-input {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 8px;
}

.duplicate-upload-add-name-input.duplicate-upload-name-input--invalid {
  border-color: #c44a4a;
}

.duplicate-upload-add-name-input.duplicate-upload-name-input--invalid:focus-visible {
  outline-color: #e07070;
  border-color: #d85a5a;
}

.duplicate-upload-name-error {
  margin: 0 0 14px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.88rem;
  line-height: 1.35;
  color: #e88888;
  text-align: left;
}

.duplicate-upload-name-error[hidden] {
  display: none !important;
}

.duplicate-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.duplicate-upload-actions .sb-btn {
  flex: 1 1 auto;
  min-width: 120px;
}

.match-end-card {
  width: min(520px, 92vw);
  padding: 24px 20px 18px;
  text-align: center;
}

.match-end-header {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.match-end-header-corner {
  width: 40px;
  height: 40px;
  pointer-events: none;
}

.match-end-header .match-end-title {
  margin: 0;
  text-align: center;
}

.match-end-title {
  font-size: clamp(1.8rem, 4vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #dde8f0;
}

/* Optical center of × in top-right close control. */
.match-end-header .match-end-dismiss-x {
  line-height: 1;
  align-self: center;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2px;
}

.match-end-message {
  margin-top: 10px;
  margin-bottom: 12px;
  font-size: clamp(1.05rem, 2.8vw, 1.3rem);
  color: #c6d6e6;
  letter-spacing: 0.04em;
}

.match-end-stats-wrap {
  margin: 2px 0 16px;
  border: 1px solid #21324a;
  border-radius: 6px;
  overflow: hidden;
}

.match-end-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

.match-end-stats-table th,
.match-end-stats-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #1a2a40;
  border-right: 1px solid #21324a;
  text-align: left;
}

.match-end-stats-table tbody tr:last-child td {
  border-bottom: none;
}

.match-end-stats-table th:last-child,
.match-end-stats-table td:last-child {
  border-right: none;
}

.match-end-stats-table thead th {
  font-family: 'Barlow Condensed', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9fb1c6;
  font-weight: 600;
  border-bottom: 1px solid #2a3f5d;
}

.match-end-stats-table th:first-child,
.match-end-stats-table td:first-child {
  color: #b4c5d8;
}

/* ── First-visit welcome onboarding ───────────────────────────────────── */

.welcome-modal-overlay {
  z-index: 1100;
}

.welcome-card {
  width: min(520px, 92vw);
  padding: 26px 22px 22px;
  text-align: center;
}

.welcome-header {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.welcome-header-corner {
  width: 40px;
  height: 40px;
  pointer-events: none;
}

.welcome-header .welcome-title {
  margin: 0;
  text-align: center;
}

/* × reads high with shared .bot-source-close-x line-height: 0; center it in the hit target. */
.welcome-header .bot-source-close-x {
  line-height: 1;
  align-self: center;
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 1px;
}

.welcome-title {
  font-size: clamp(1.85rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #dde8f0;
}

.welcome-body {
  margin: 14px 0 16px;
  font-family: 'Share Tech Mono', monospace;
  font-size: clamp(0.92rem, 2.2vw, 1.02rem);
  line-height: 1.55;
  color: #9fb1c6;
  text-align: left;
}

.welcome-open-startup {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 0 0 16px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.95rem;
  color: #9fb1c6;
  text-align: left;
}

.welcome-open-startup input[type='checkbox'] {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  accent-color: #6a8ec4;
  cursor: pointer;
}

.welcome-open-startup label {
  cursor: pointer;
  line-height: 1.4;
}

.welcome-inline-code {
  font-size: 0.95em;
  color: #c6d8ea;
  background: #0e1525;
  padding: 0.08em 0.35em;
  border-radius: 4px;
  border: 1px solid #1a2a40;
}

.welcome-kbd {
  font-weight: 600;
  color: #dde8f0;
  letter-spacing: 0.04em;
}

.welcome-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.welcome-actions .sb-btn {
  width: 100%;
  box-sizing: border-box;
}

.settings-fields {
  width: 100%;
  max-height: 55vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.settings-tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #1a2a40;
  flex-shrink: 0;
}
.settings-tab {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #5a6a82;
  padding: 8px 12px 6px;
  margin-bottom: -10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.settings-tab:hover {
  color: #9aacbf;
}
.settings-tab--active {
  color: #dde8f0;
  border-bottom-color: #3a5070;
}
.settings-panels-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}
.settings-tab-panel {
  width: 100%;
}
.settings-tab-description {
  margin: 0 0 10px;
  color: #8ea0b4;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.92rem;
  line-height: 1.35;
}
.settings-rules-matrix {
  width: 100%;
  margin-bottom: 4px;
  /* One grid so column widths match every row; ability is max-content so stun/cooldown sit beside it. */
  display: grid;
  grid-template-columns: 48px max-content 5.5rem 5.5rem;
  justify-content: start;
  align-items: center;
  gap: 12px;
}
.settings-rules-matrix-row {
  display: contents;
}
.settings-rules-matrix-row--header .settings-rules-matrix-cell {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6a7a92;
  text-align: left;
  padding-bottom: 8px;
  border-bottom: 1px solid #1a2a40;
}
.settings-rules-matrix-cell--name {
  color: #c8d4e0;
  font-size: 1.02rem;
  min-width: 0;
}
.settings-rules-matrix-cell:not(.settings-rules-matrix-cell--name) {
  min-width: 0;
}
.settings-rules-matrix .settings-input--number {
  width: 100%;
  text-align: left;
}
.settings-input--checkbox {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: #4a7ab0;
  cursor: pointer;
}
.settings-input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.settings-field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 10px;
}
.settings-field-label {
  width: min(280px, 38%);
  flex-shrink: 0;
}
.settings-field-row--bool .settings-input--checkbox {
  margin-left: auto;
  flex: 0 0 auto;
}
.settings-input {
  flex: 1;
  min-width: 0;
  background: #070d1a;
  color: #9aacbf;
  border: 1px solid #1a2a40;
  border-radius: 4px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.02rem;
}
.settings-input--enum {
  padding: 9px 12px;
}
.settings-input--number {
  padding: 9px 12px;
}
.settings-input--color {
  height: 44px;
  cursor: pointer;
}
.settings-reset-btn {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 12px;
}
.settings-profile-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  gap: 8px;
  margin-top: 10px;
}

/* ── Narrow / small viewports ──────────────────────────────────────────── */

@media (max-width: 840px) {
  .game-layout {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .game-layout > .main-row-gutter--brand {
    width: 100%;
    order: 1;
  }

  /* Lift status + docs link so we can reorder flex children of .game-layout. */
  .game-layout > .main-row-gutter--actions {
    display: contents;
  }

  /* Welcome + docs in one row directly under the title. */
  .game-layout .main-row-gutter--actions .header-links-actions {
    order: 2;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    align-self: center;
    gap: 10px 20px;
  }

  .game-layout .main-row-gutter--actions .header-welcome-btn {
    text-align: center;
  }

  .game-layout .main-row-gutter--actions .header-docs-link {
    width: fit-content;
    max-width: 100%;
    text-align: center;
    align-self: center;
  }

  .game-layout > .hex-column:not(.hex-column--controls-only) .header-row-status:empty {
    display: none;
  }

  .game-layout > #player-card-1 {
    order: 5;
  }

  .game-layout > .hex-column:not(.hex-column--controls-only) {
    order: 4;
  }

  .game-layout > #player-card-2 {
    order: 6;
  }

  /* Map column only: .hex-column--controls-only also has .hex-column — do not give it flex-grow or map min-height. */
  .hex-column:not(.hex-column--controls-only) {
    flex: 1 1 0;
    min-height: min(42dvh, 380px);
  }

  .hex-column--controls-only {
    order: 3;
    width: 100%;
    flex: 0 0 auto;
    min-height: 0;
  }

  .game-layout > .hex-column--controls-only > .hex-control-bar {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .player-card {
    width: 100%;
    /* Default overflow:hidden clips the bot-picker panel (position:absolute) and expanded details. */
    overflow: visible;
  }

  /* Column layout: .player-card height is content-based. Nested flex: 1 1 0 + min-height: 0
     otherwise resolves to ~0px, so compact expand only rotates the chevron. */
  .player-card-details {
    flex: 0 1 auto;
    overflow-x: hidden;
    overflow-y: visible;
    overscroll-behavior: auto;
  }

  .player-card-log-block,
  .player-card-feed {
    flex: 0 1 auto;
  }

  /* Open bot list stacks above the next card; picker already has position:relative. */
  .player-card .sb-bot-picker.sb-bot-picker--open {
    z-index: 80;
  }

  .header-brand-title {
    font-size: clamp(1.55rem, 5.8vw, 2.85rem);
  }

  .hex-control-bar .button-group {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Event log panel: FILTER + CLEAR LOG + POP OUT on one row (label duplicates dock control). */
  .event-log-toolbar {
    flex-wrap: nowrap;
    gap: 6px;
    align-items: stretch;
  }

  .event-log-toolbar > .sb-label-xs {
    display: none;
  }

  .event-log-filter-wrap {
    flex: 1 1 0;
    min-width: 0;
  }

  .event-log-filter-toggle {
    width: 100%;
    box-sizing: border-box;
  }

  .event-log-toolbar-actions {
    flex: 2 1 0;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .event-log-toolbar-actions > .sb-btn {
    flex: 1 1 0;
    min-width: 0;
  }

  /* Filter menu: FILTER sits in a ~⅓-width column; right:0 + min-width:190px draws mostly off-screen left.
     Dock is at bottom — open upward so the panel stays in the visual viewport. */
  .event-log-filter-menu {
    top: auto;
    bottom: calc(100% + 6px);
    left: 0;
    right: auto;
    min-width: 0;
    width: min(190px, calc(100vw - max(20px, env(safe-area-inset-left) + env(safe-area-inset-right) + 12px)));
    box-sizing: border-box;
  }

  /* Settings modal: full-width stacked actions so labels do not clip the card border. */
  .modal-overlay {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    box-sizing: border-box;
  }

  /* Settings: one scrollable column — tall forms + stacked buttons must fit small viewports. */
  #settings-modal.modal-overlay {
    align-items: flex-start;
    justify-content: center;
  }

  .settings-card {
    width: 100%;
    max-width: min(880px, calc(100vw - 20px));
    max-height: calc(100vh - max(28px, env(safe-area-inset-top) + env(safe-area-inset-bottom) + 24px));
    padding: 18px max(14px, env(safe-area-inset-left)) max(22px, env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-right));
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  @supports (height: 1dvh) {
    .settings-card {
      max-height: calc(100dvh - max(28px, env(safe-area-inset-top) + env(safe-area-inset-bottom) + 24px));
    }
  }

  /* Let the whole card scroll as one pane (avoid nested 55vh scroll + clipped footer buttons). */
  #settings-fields.settings-fields {
    max-height: none;
    overflow: visible;
  }

  #settings-fields .settings-panels-wrap {
    flex: 0 1 auto;
    overflow: visible;
    min-height: 0;
  }

  .settings-profile-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-top: 12px;
  }

  .settings-profile-actions > .sb-btn {
    width: 100%;
    box-sizing: border-box;
    justify-content: center;
    white-space: normal;
    text-align: center;
    line-height: 1.25;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .settings-actions {
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    gap: 10px;
    margin-top: 14px;
  }

  .settings-actions > .sb-btn {
    width: 100%;
    box-sizing: border-box;
    justify-content: center;
    white-space: normal;
    text-align: center;
    line-height: 1.25;
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

@media (max-width: 480px) {
  .app-container {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .sb-btn {
    font-size: 1.02rem;
    padding: 0 14px;
    min-height: 44px;
  }

  /* Keep expanded event log toolbar on one row (global .sb-btn sizing above would wrap it). */
  .event-log-toolbar .sb-btn.sb-btn--compact {
    min-height: 40px;
    padding: 0 6px;
    font-size: clamp(0.62rem, 2.6vw, 0.82rem);
  }
}

/* ── Loading overlay ───────────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: #080c14;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: #8899aa;
  font-family: 'Share Tech Mono', monospace;
  font-size: 1.15rem;
}
.loading-overlay.hidden { display: none; }
