/* UI accent colours — updated by apply_board_scheme() when the board scheme changes.
   Defaults match the Blue scheme so the page looks right before JS runs. */
:root {
  --cs-accent:      #2c6fad;
  --cs-accent-dk:   #1a4f80;
  --cs-tint:        #f0f4fb;
  --cs-tint2:       #dde6f5;
  --cs-tint3:       #e2eaf7;
  --cs-tint-border: #aac2e8;
  /* Neutral chrome ramp (Todo 85a) — cool, scheme-INDEPENDENT. These are the
     quiet surfaces/borders/text behind the board so the chrome works with every
     board scheme; the scheme's personality comes through the board squares and
     the scheme-aware --cs-accent/--cs-tint* tokens above. Not rewritten by
     apply_board_scheme(). Replaced the old warm floralwhite/#e0d8c8 chrome. */
  --cs-surface:     #ffffff;
  --cs-surface-2:   #f4f5f7;
  --cs-border:      #d9dce1;
  --cs-text:        #1f2329;
  --cs-text-muted:  #6b7280;
  --cs-text-faint:  #9aa0aa;
  /* Semantic section colours — traffic light: red danger, amber caution,
     green opportunity, grey neutral. Shared by UDAB (#sect-*) and Compare
     (.cs-diff-sect-*) so the two never drift. Not board-scheme dependent. */
  --sect-urgent:     #dc2626;
  --sect-defence:    #d97706;
  --sect-attack:     #16a34a;
  --sect-background: #6b7280;
  --sect-predicting: #7c3aed;
  color-scheme: light;
}

html {
  font-size: 13px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


::selection {
  background: var(--cs-accent);
  color: #fff;
}

/* Prevent accidental page scroll/pull-to-refresh when scrolling panels */
.left, .right, .left-tab-panel, #pgn_moves, .modal-body {
  overscroll-behavior: contain;
}

/* Remove 300ms tap delay on all interactive elements */
button, input, select, label, .left-tab, .right-tab, .ws-tab-item, .lib-tab-item, .move-san, .scheme-option, .piece-style-btn, .text-size-btn {
  touch-action: manipulation;
}

/* Thin custom scrollbars (webkit: Safari/Chrome) */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.18); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.32); }
/* Firefox */
* { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.18) transparent; }


/* Global button baseline */
button {
  font-family: inherit;
  font-size: 1rem;
  padding: 4px 14px;
  border: 1px solid var(--cs-border);
  border-radius: 6px;
  background: var(--cs-surface);
  color: var(--cs-text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) {
  background: var(--cs-tint2);
  border-color: var(--cs-text-faint);
}
button:active:not(:disabled) {
  background: var(--cs-tint3);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Primary / default action button */
#load_game_btn.is-default,
#load_position_btn.is-default {
  background: var(--cs-accent);
  color: #fff;
  border-color: var(--cs-accent-dk);
  font-weight: 600;
  outline: none;
}
#load_game_btn.is-default:hover,
#load_position_btn.is-default:hover {
  background: var(--cs-accent-dk);
  border-color: var(--cs-accent-dk);
}

/* Focus ring — replaces browser default; suppress on elements with their own active state */
:focus-visible {
  outline: 2px solid var(--cs-accent);
  outline-offset: 2px;
}
.left-tab:focus-visible, .right-tab:focus-visible, .move-san:focus-visible {
  outline: none;
}

/* App header / logo */
#app-header {
  position: relative;
  text-align: center;
  padding: 6px 0 10px;
  letter-spacing: 0.02em;
  user-select: none;
}

#debug-toggle-btn {
  position: absolute;
  left: 34px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  opacity: 0.3;
  transition: opacity 0.15s;
}

#debug-toggle-btn:hover {
  opacity: 0.6;
}

#debug-toggle-btn.active {
  opacity: 1;
}

#engine-toggle-btn { opacity: 0.4; }
#engine-toggle-btn:hover { opacity: 0.7; }
#engine-toggle-btn.active { opacity: 1; font-weight: bold; }

#help-btn {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 1.5px solid var(--cs-accent);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  color: var(--cs-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.15s;
}
#help-btn:hover { opacity: 1; }

.help-link {
  cursor: pointer;
  color: var(--cs-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

#debug-copy-btn {
  position: absolute;
  left: 62px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
  display: none;
}

#debug-copy-btn:hover { opacity: 1; }

body:not(.debug-off) #debug-copy-btn { display: block; }
body.debug-off #engine-log-btn { display: none !important; }

#version-badge {
  display: block;
  position: fixed;
  top: 6px;
  right: 12px;
  font-size: 0.85rem;
  color: var(--cs-accent);
  opacity: 0.4;
  pointer-events: none;
  z-index: 200;
}

#licences-badge-link {
  position: fixed;
  top: 21px;
  right: 12px;
  z-index: 200;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1;
  color: var(--cs-accent);
  opacity: 0.5;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
#licences-badge-link:hover { opacity: 1; }

.app-header-rook {
  font-size: 20px;
  vertical-align: middle;
  color: var(--cs-accent);
  margin: 0 8px;
}

.app-header-chess {
  font-size: 20px;
  font-weight: 700;
  color: var(--cs-accent-dk);
  vertical-align: middle;
}

.app-header-signals {
  font-size: 20px;
  font-weight: 400;
  color: var(--cs-accent);
  vertical-align: middle;
}

/* Split the screen in half */
.split {
  height: 100%;
  width: 50%;
  position: fixed;
  z-index: 1;
  top: 0;
  overflow-x: hidden;
  padding-top: 0;
}

/* Control the left side */
.left {
  left: 0;
  width: 100%;
  background-color: var(--cs-surface-2);
  overflow-y: auto;
}

/* Control the right side */
.right {
  right: 0;
  width: 260px;
  background-color: var(--cs-surface-2);
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  box-sizing: border-box;
  overflow-y: auto;
  transition: transform 0.22s ease;
  box-shadow: -2px 0 8px rgba(0,0,0,0.12);
}

/* Piece opacity slider widget */
#piece-opacity-widget {
  padding: 18px 4px 12px;
  border-bottom: 1px solid var(--cs-border);
}

#piece-opacity-widget label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 1rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 10px;
}

#opacity-info-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0;
  line-height: 1;
  margin-left: auto;
  opacity: 0.6;
  transition: opacity 0.15s;
}
#opacity-info-btn:hover { opacity: 1; }

.opacity-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opacity-slider-end {
  font-size: 0.85rem;
  color: var(--cs-text-muted);
  white-space: nowrap;
}

.opacity-slider-row input[type="range"] {
  flex: 1;
  cursor: pointer;
  accent-color: var(--cs-accent);
}

input[type="checkbox"] {
  accent-color: var(--cs-accent);
}

.slider-label-row {
  display: flex !important;
  justify-content: space-between;
  align-items: baseline;
}
.slider-label-row span {
  font-size: 0.92rem;
  font-weight: normal;
  color: var(--cs-text-muted);
}

#board-size-widget,
#strip-settings-widget {
  padding: 12px 4px 12px;
  border-bottom: 1px solid var(--cs-border);
}

#board-size-widget label,
#strip-settings-widget > label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 10px;
}

.signal-toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.92rem;
  color: #666;
}


#board-scheme-widget {
  padding: 12px 4px 14px;
  border-bottom: 1px solid var(--cs-border);
}

#board-scheme-widget > label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 10px;
}

.scheme-intensity-row {
  margin-top: 10px;
}

.scheme-intensity-row label {
  display: block;
  font-size: 0.92rem;
  color: #666;
  margin-bottom: 5px;
}

#board-scheme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.scheme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.scheme-swatch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 38px;
  height: 38px;
  border-radius: 3px;
  border: 2px solid transparent;
  overflow: hidden;
  box-sizing: border-box;
  transition: border-color 0.1s;
}

.scheme-option:hover .scheme-swatch {
  border-color: var(--cs-text-muted);
}

.scheme-option.selected .scheme-swatch {
  border-color: var(--cs-accent);
  box-shadow: 0 0 0 1px var(--cs-accent);
}

.scheme-label {
  font-size: 10px;
  color: #666;
  text-align: center;
  line-height: 1.2;
}

.scheme-option.selected .scheme-label {
  color: #222;
  font-weight: 600;
}

/* CSS filter on piece images creates a stacking context that would otherwise
   paint pieces above the board's rank/file notation spans. */
#board .notation-322f9 {
  z-index: 1;
}

/* Push notation labels just clear of the 3px inset highlight ring. */
#board .numeric-fc462 { top: 3px;  left: 3px;  }
#board .alpha-d2270   { bottom: 2px; right: 3px; }

#piece-style-widget {
  padding: 12px 4px 14px;
  border-bottom: 1px solid var(--cs-border);
}

#piece-style-widget label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 8px;
}

#piece-style-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.piece-style-btn {
  font-size: 0.92rem;
  padding: 3px 9px;
  border: 1px solid var(--cs-border);
  border-radius: 12px;
  background: var(--cs-surface);
  color: #555;
  cursor: pointer;
  white-space: nowrap;
}

.piece-style-btn.selected,
.piece-style-btn.selected:hover {
  background: var(--cs-accent);
  border-color: var(--cs-accent-dk);
  color: #fff;
}

#text-size-widget {
  padding: 12px 4px 14px;
  border-bottom: 1px solid var(--cs-border);
}

#text-size-widget label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 8px;
}

#text-size-btns {
  display: flex;
  gap: 5px;
}

.text-size-btn {
  font-size: 0.92rem;
  padding: 3px 12px;
  border: 1px solid var(--cs-border);
  border-radius: 12px;
  background: var(--cs-surface);
  color: #555;
  cursor: pointer;
}

.text-size-btn.selected,
.text-size-btn.selected:hover {
  background: var(--cs-accent);
  border-color: var(--cs-accent-dk);
  color: #fff;
}

#drawer-reset-row {
  padding: 14px 4px 4px;
  text-align: center;
}

#drawer-reset-btn {
  font-size: 0.92rem;
  color: #666;
  background: none;
}

/* Shashin summary strip — 3-column grid matching the geometric columns */
.shashin-strip {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 2px 0;
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(0,0,0,0.18);
  align-items: start;
}

.shashin-debug {
  padding-left: 8px;
}

.shashin-label {
  font-size: 0.85rem;
  font-weight: bold;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.shashin-item {
  font-size: 1rem;
  min-width: 0;
  padding-right: 6px;
}

/* Right Shashin cell stacks two sub-items */
.shashin-sub {
  font-size: 1rem;
}

/* Each geometric sub-pane takes half the remaining height */
.geo-pane {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0,0,0,0.15);
}

.geo-pane:last-child {
  border-bottom: none;
  padding-top: 6px;
}

.geo-header {
  flex: 0 0 auto;
  font-weight: bold;
  font-size: 1.08rem;
  padding-bottom: 3px;
  color: #222;
}

/* Three-column body: main list | + deltas | − deltas */
.geo-body {
  flex: 1 1 0;
  display: flex;
  gap: 0;
  overflow: hidden;
}

.geo-main {
  flex: 1 1 0;
  overflow-y: auto;
  font-size: 1.08rem;
  line-height: 1.5;
  padding-right: 6px;
}

.geo-delta-plus,
.geo-delta-minus {
  flex: 1 1 0;
  overflow-y: auto;
  font-size: 1rem;
  line-height: 1.5;
  border-left: 1px solid rgba(0,0,0,0.15);
  padding-left: 7px;
  color: #000;
}

/* Flex row inside the left panel: strip on left, board content on right */
#left-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: min-content;
  padding: 60px 28px 40px;
}

/* Strip column — owns the flex slot; contains the three analysis sections */
#strip-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#game-header {
  padding: 5px 8px 4px;
  border-bottom: 1px solid var(--cs-tint3);
  margin-bottom: 2px;
}
#game-header-title {
  display: flex;
  align-items: baseline;
  gap: 4px;
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: bold;
}
.gh-source-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font-size: 0.92rem;
  font-weight: bold;
  color: var(--cs-accent);
  cursor: pointer;
  flex-shrink: 0;
}
.gh-source-btn:hover { text-decoration: underline; text-underline-offset: 2px; }
.gh-sep {
  color: #bbb;
  font-weight: normal;
  flex-shrink: 0;
}
.gh-game-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  color: var(--cs-accent);
}
#game-header-row2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  min-height: 14px;
}
#game-header-meta {
  font-size: 0.85rem;
  color: var(--cs-text-muted);
}
#game-header-meta.ws-saving { color: var(--cs-text-muted); }
#game-header-meta.ws-saved  { color: #4a4; }
#game-header-meta.ws-failed { color: #c00; }

/* Last-move header above the Moves/Compare tabs — mirrors #game-header
   (the left-panel breadcrumb): same padding, divider, font and weight. */
#pgn-header {
  padding: 5px 8px 4px;
  border-bottom: 1px solid var(--cs-tint3);
  margin-bottom: 2px;
  font-size: 0.92rem;
  font-weight: bold;
  color: var(--cs-accent);
  min-height: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#left-tabs {
  display: flex;
  border-bottom: 2px solid var(--cs-tint3);
  margin-bottom: 2px;
}

.left-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cs-accent-dk);
  background: var(--cs-surface);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: border-bottom-color 0.15s, color 0.15s, background 0.12s;
}

.left-tab:hover { background: var(--cs-tint3); }

.left-tab.active {
  background: var(--cs-tint3);
  border-bottom-color: var(--cs-accent);
  color: var(--cs-accent);
}


@keyframes cs-tab-panel-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.left-tab-panel {
  display: none;
  flex-direction: column;
  align-items: stretch;
  overflow-y: auto;
  max-height: 60vh; /* fallback cap before JS sets the precise value */
}

.left-tab-panel.active {
  display: flex;
  animation: cs-tab-panel-in 0.12s ease-out both;
}

.lib-tab-item {
  display: flex;
  align-items: center;
  padding: 5px 4px 5px 8px;
  font-size: 1rem;
  cursor: pointer;
  gap: 2px;
}
.lib-tab-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.lib-kebab-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 6px;
  font-size: 16px;
  line-height: 1;
  color: inherit;
  opacity: 0.45;
}
.lib-kebab-btn:hover { opacity: 1; }
.lib-tab-item.selected .lib-kebab-btn { opacity: 0.7; }
.lib-tab-item:hover { background: var(--cs-tint2); }
.lib-tab-item.even { background: var(--cs-tint); }
.lib-tab-item.even:hover { background: var(--cs-tint2); }
/* .selected = currently loaded game; persists regardless of mouse position */
.lib-tab-item.selected { background: var(--cs-tint2); color: var(--cs-accent-dk); font-weight: 600; }
.lib-tab-item.selected:hover,
.lib-tab-item.even.selected,
.lib-tab-item.even.selected:hover { background: var(--cs-tint2); color: var(--cs-accent-dk); }
/* .cursor = keyboard navigation highlight (only visible when not the selected item) */
.lib-tab-item.cursor:not(.selected) { background: var(--cs-tint2); outline: 1px solid var(--cs-accent); outline-offset: -2px; }
#tab-library:focus { outline: none; }
mark.lib-search-match {
  background: none;
  font-weight: 700;
  color: inherit;
}
.lib-tab-item.selected mark.lib-search-match {
  opacity: 0.85;
}

.lib-tab-empty {
  padding: 12px 8px;
  font-size: 0.92rem;
  color: var(--cs-text-faint);
  font-style: italic;
}

/* ── New-user first-run: Library tab welcome panel ─────────────────── */

/* ── Library tab inline FEN/PGN paste area ──────────────────────────── */
#lib-tab-pgn-input { padding: 8px 10px; }
#lib-tab-pgn-input textarea {
  width: 100%;
  box-sizing: border-box;
  font-size: 0.85rem;
  font-family: monospace;
  border: 1px solid var(--cs-tint-border);
  border-radius: 3px;
  padding: 5px;
  resize: vertical;
  outline: none;
}
#lib-tab-pgn-input textarea:focus { border-color: var(--cs-accent); }
#lib-tab-pgn-input .lib-pgn-btns { display: flex; gap: 6px; margin-top: 6px; }
#lib-tab-pgn-input .lib-pgn-btns button {
  flex: 1;
  font-size: 0.92rem;
  padding: 5px 8px;
  border: 1px solid var(--cs-tint-border);
  border-radius: 3px;
  background: var(--cs-tint);
  cursor: pointer;
}
#lib-tab-pgn-input .lib-pgn-btns button:hover { background: var(--cs-tint2); }
#lib-tab-pgn-input .lib-pgn-load-btn { border-color: var(--cs-accent) !important; color: var(--cs-accent); font-weight: bold; }
#lib-tab-pgn-input .lib-pgn-error { font-size: 0.85rem; color: #c00; margin-top: 5px; }

/* ── New-user first-run: Signals tab empty state ────────────────────── */
#tab-signals-empty {
  display: none;
  padding: 20px 12px;
  text-align: center;
}
#tab-signals-empty p { font-size: 0.92rem; color: var(--cs-text-faint); margin: 0 0 6px; line-height: 1.5; }
#tab-signals-empty p:first-child { font-weight: bold; color: var(--cs-text-muted); }

/* ── Library tab header, search, dropdown ──────────────────────────── */
#lib-tab-sticky {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--cs-surface);
}
#lib-tab-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 7px;
  border-bottom: 1px solid var(--cs-tint3);
}
.lib-tab-name-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.92rem;
  font-weight: bold;
  color: var(--cs-accent);
  cursor: pointer;
  flex: 1 1 auto;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lib-tab-name-btn:hover { text-decoration: underline; text-underline-offset: 2px; }
.lib-tab-open-inline {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--cs-accent);
  border-radius: 3px;
  padding: 2px 7px;
  font-size: 0.85rem;
  color: var(--cs-accent);
  cursor: pointer;
}
.lib-tab-open-inline:hover { background: var(--cs-tint); }
#lib-tab-search {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 8px;
  font-size: 0.92rem;
  border: none;
  border-bottom: 1px solid var(--cs-tint3);
  outline: none;
  background: var(--cs-tint);
}
#lib-tab-search:focus { background: var(--cs-surface); border-bottom-color: var(--cs-accent); }
#lib-tab-dropdown {
  position: fixed;
  display: none;
  background: var(--cs-surface);
  border: 1px solid var(--cs-tint-border);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
  z-index: 1000;
  min-width: 160px;
}
#lib-tab-dropdown.open { display: block; }
.lib-tab-dropdown-item {
  padding: 7px 12px;
  font-size: 0.92rem;
  cursor: pointer;
}
.lib-tab-dropdown-item:hover { background: var(--cs-tint2); }
.lib-tab-dropdown-sep {
  border-top: 1px solid var(--cs-tint3);
  margin: 2px 0;
}

/* ── Workspace tab ──────────────────────────────────────────────────── */
#tab-workspace:focus { outline: none; }
#ws-tab-toolbar, #lib-tab-toolbar {
  display: flex;
  gap: 4px;
  padding: 5px 7px;
  border-bottom: 1px solid var(--cs-tint3);
  background: var(--cs-surface);
  position: sticky;
  top: 0;
  z-index: 2;
}
.ws-toolbar-btn {
  font-size: 0.85rem;
  padding: 4px 10px;
  border: 1px solid var(--cs-tint-border);
  border-radius: 3px;
  background: var(--cs-tint);
  cursor: pointer;
  white-space: nowrap;
}
.ws-toolbar-btn:hover { background: var(--cs-tint2); }
.ws-menu-sep {
  height: 1px;
  background: var(--cs-tint3);
  margin: 3px 0;
  border: none;
}
.ws-menu-heading {
  padding: 2px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cs-text-muted);
}
.lib-open-note {
  padding: 4px 12px;
  max-width: 220px;
  font-size: 0.78rem;
  color: var(--cs-text-muted);
  line-height: 1.4;
}
.ws-tab-item {
  display: flex;
  align-items: center;
  padding: 5px 4px 5px 8px;
  font-size: 1rem;
  cursor: pointer;
  gap: 2px;
}
.ws-tab-item:hover { background: var(--cs-tint2); }
.ws-tab-item.even { background: var(--cs-tint); }
.ws-tab-item.even:hover { background: var(--cs-tint2); }
.ws-tab-item.selected { background: var(--cs-tint2); color: var(--cs-accent-dk); font-weight: 600; }
.ws-tab-item.selected:hover,
.ws-tab-item.even.selected,
.ws-tab-item.even.selected:hover { background: var(--cs-tint2); color: var(--cs-accent-dk); }
.ws-tab-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.ws-kebab-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 6px;
  font-size: 16px;
  line-height: 1;
  color: inherit;
  opacity: 0.45;
}
.ws-kebab-btn:hover { opacity: 1; }
.ws-tab-item.selected .ws-kebab-btn { opacity: 0.7; }
.ws-tab-empty {
  padding: 16px 10px;
  font-size: 1rem;
  color: var(--cs-text-muted);
  text-align: center;
  line-height: 1.6;
}

/* Kebab dropdown menu */
.ws-menu {
  position: fixed;
  background: var(--cs-surface);
  border: 1px solid var(--cs-tint3);
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  z-index: 1000;
  min-width: 150px;
  padding: 3px 0;
}
.ws-menu-item, .ws-new-item, .lib-menu-item {
  padding: 7px 14px;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
}
.ws-menu-item:hover, .ws-new-item:hover, .lib-menu-item:hover { background: var(--cs-tint2); }
.ws-menu-item.ws-menu-delete, .lib-menu-item.ws-menu-delete { color: #c00; }
.ws-menu-item.disabled, .lib-menu-item.disabled { color: #bbb; cursor: default; }
.ws-menu-item.disabled:hover, .lib-menu-item.disabled:hover { background: none; }

#export-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 0.92rem;
  padding: 7px 16px;
  border-radius: 20px;
  z-index: 2000;
  pointer-events: none;
  white-space: nowrap;
}

/* Each of the three collapsible sections in the analysis column */
.strip-section {
  border-bottom: 1px solid var(--cs-tint3);
}

/* Section header — label + arrow */
.strip-sect-hd {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px 5px 8px;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cs-accent);
  background: var(--cs-tint);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.strip-sect-hd:hover { background: var(--cs-tint3); }
.strip-sect-hd .collapsible-arrow { font-size: 9px; }
.strip-sect-count { font-weight: normal; opacity: 0.6; margin-left: 2px; }

#sect-predicting   .strip-sect-hd { border-left: 3px solid var(--sect-predicting); }
#sect-urgent     .strip-sect-hd { border-left: 3px solid var(--sect-urgent); }
#sect-defence    .strip-sect-hd { border-left: 3px solid var(--sect-defence); }
#sect-attack     .strip-sect-hd { border-left: 3px solid var(--sect-attack); }
#sect-background .strip-sect-hd { border-left: 3px solid var(--sect-background); }

#sect-predicting   .strip-item { border-left-color: var(--sect-predicting); }
#sect-urgent     .strip-item { border-left-color: var(--sect-urgent); }
#sect-defence    .strip-item { border-left-color: var(--sect-defence); }
#sect-attack     .strip-item { border-left-color: var(--sect-attack); }
#sect-background .strip-item { border-left-color: var(--sect-background); }

/* Bodies share the same padding/font as the old panels */
#predict-panel,
#strip-engine,
#strip-urgent,
#strip-defence,
#strip-attack,
#strip-panel,
#strip-background {
  padding: 6px 10px 8px 12px;
  font-size: 1rem;
  color: #222;
}

.predict-prompt,
.predict-reveal {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 3px 0 3px 6px;
  border-left: 2px solid var(--cs-accent);
  margin-bottom: 5px;
  font-weight: bold;
}

/* "Back to Study" — exit Predict mode / stop the engine, from where the player
   is looking. predict-exit-btn uses margin-left:auto to right-align on the
   prompt row; engine-exit-btn sits on its own line below the engine reasons. */
.predict-exit-btn,
.engine-exit-btn {
  padding: 2px 9px;
  font-size: 0.8rem;
  font-weight: normal;
  white-space: nowrap;
  border: 1px solid var(--cs-tint-border);
  border-radius: 4px;
  background: var(--cs-tint2);
  color: var(--cs-accent);
  cursor: pointer;
}
.predict-exit-btn:hover,
.engine-exit-btn:hover { background: var(--cs-tint3); }
.predict-exit-btn,
.engine-exit-btn {
  flex: 0 0 auto;
  align-self: center;
  margin-left: auto;
}

/* Compare tab content */
#tab-diff {
  padding: 4px 0;
}
.cs-diff-block {
  margin-bottom: 10px;
}
.cs-diff-label {
  display: flex;
  align-items: center;
  padding: 5px 10px 5px 8px;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cs-accent);
  background: var(--cs-tint);
}
.cs-diff-block-resolved .cs-diff-label { border-left: 3px solid #6b7280; }
.cs-diff-block-new      .cs-diff-label { border-left: 3px solid var(--cs-accent); }
.cs-diff-block-changed  .cs-diff-label { border-left: 3px solid var(--cs-accent); }
.cs-diff-label:hover { background: var(--cs-tint3); }
/* "was: …" line under a Changed signal — the prior wording, muted. */
.cs-diff-was { display: block; margin-top: 2px; font-size: 0.78rem; font-weight: normal; color: var(--cs-text-muted); }
/* Predict "Differs" — two parallel alternatives, each prefixed by its move. */
.cs-diff-alt { display: block; }
.cs-diff-alt + .cs-diff-alt { margin-top: 3px; }
.cs-diff-alt-move { font-weight: 600; color: #999; }
/* Hairline divider between consecutive Differs entries. */
.cs-diff-changed + .cs-diff-changed { border-top: 1px solid rgba(0, 0, 0, 0.07); padding-top: 6px; }
.cs-diff-item {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  line-height: 1.5;
  padding: 3px 0 3px 6px;
  border-left: 2px solid var(--cs-accent);
  margin-bottom: 5px;
  font-size: 1rem;
}
.diff-copy-btn {
  flex: 0 0 auto;
  cursor: pointer;
  opacity: 0.35;
  color: var(--cs-accent);
  padding-top: 2px;
  line-height: 1;
}
.diff-copy-btn:hover { opacity: 1; }
body.debug-off .diff-copy-btn { display: none; }
/* Left-strip colour mirrors the UDAB section the signal belongs to (see
   #sect-* .strip-item rules), so a New signal reads by meaning, not alarm.
   Resolved vs New is conveyed by the block header, not the strip colour. */
.cs-diff-sect-urgent     { border-left-color: var(--sect-urgent); }
.cs-diff-sect-defence    { border-left-color: var(--sect-defence); }
.cs-diff-sect-attack     { border-left-color: var(--sect-attack); }
.cs-diff-sect-background { border-left-color: var(--sect-background); }
.cs-diff-empty {
  font-size: 1rem;                    /* read like a normal signal line */
  color: var(--cs-text);
  line-height: 1.5;
  padding: 3px 0 3px 6px;
  text-align: left;
}

/* Separator between "their threats" and "my opportunities" inside Urgent */

.strip-item {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  line-height: 1.5;
  padding: 3px 0 3px 6px;
  border-left: 2px solid var(--cs-accent);
  margin-bottom: 5px;
  text-align: left;
}
.strip-copy-btn {
  flex: 0 0 auto;
  cursor: pointer;
  opacity: 0.35;
  color: var(--cs-accent);
  padding-top: 2px;
  line-height: 1;
}
.strip-copy-btn:hover { opacity: 1; }
.strip-emoji { font-size: 0.9em; opacity: 0.85; margin-right: 2px; }
.strip-dot { display:inline-block; width:9px; height:9px; border-radius:50%; vertical-align:middle; margin-right:4px; }
.strip-text { flex: 1 1 0; min-width: 0; }

/* Clickable square references — rendered as plain inline text (no chip box) so
   short notation like "Ke1" reads as one word; still clickable to flash. */
.strip-blob {
  cursor: pointer;
  user-select: none;
  vertical-align: baseline;
}

.strip-blob:hover {
  text-decoration: underline;
}

/* Content column — fixed width, sits between the two side panels */
.centered {
  flex: 0 0 420px;
  text-align: center;
  padding-bottom: 30px;
  visibility: hidden; /* revealed by align_strip_panel once layout is settled */
}

/* Right sidebar — mirrors strip-col on the left */
#pgn-panel {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 0 20px 0;
  font-size: 1rem;
  color: #222;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#flip-glyph {
  cursor: pointer;
  color: var(--cs-accent);
  padding: 4px 2px;
  border-radius: 4px;
  display: block;
  user-select: none;
  margin-left: 8px;
}

#flip-glyph:hover {
  background: var(--cs-tint2);
}

#right-tabs {
  display: flex;
  border-bottom: 2px solid var(--cs-tint3);
  margin-bottom: 2px;
}

.right-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  font-size: 0.85rem;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cs-accent-dk);
  background: var(--cs-surface);
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-bottom-color 0.15s, color 0.15s, background 0.12s;
}

.right-tab:hover { background: var(--cs-tint3); }

.right-tab.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.right-tab.active {
  background: var(--cs-tint3);
  border-bottom-color: var(--cs-accent);
  color: var(--cs-accent);
}

.right-tab-panel {
  display: none;
  flex-direction: column;
  align-items: stretch;
  overflow-y: auto;
  max-height: 60vh;
}

.right-tab-panel.active {
  display: flex;
  animation: cs-tab-panel-in 0.12s ease-out both;
}
#game-title {
  display: none;
  padding: 4px 10px 2px;
  font-size: 0.92rem;
  font-weight: bold;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#pgn_moves {
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
  max-height: 60vh; /* fallback cap before JS sets the precise value */
}

.move-table {
  width: auto;
  border-collapse: collapse;
  font-size: 1rem;
  table-layout: fixed;
}

.move-table .mn {
  width: 26px;
  text-align: right;
  padding: 4px 4px 4px 2px;
  color: var(--cs-text-faint);
  font-size: 0.85rem;
  user-select: none;
}

.move-table .mw {
  width: 78px;
  padding: 4px 8px 4px 4px;
}

.move-table .mb {
  width: 78px;
  padding: 4px 4px 4px 8px;
}

.move-row.even {
  background: var(--cs-tint);
}

.move-san {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}

.move-san:hover:not(.active) {
  background: var(--cs-tint2);
}

.move-san.active {
  background: var(--cs-accent);
  color: #fff;
  font-weight: bold;
  border-left: 2px solid rgba(255,255,255,0.55);
  padding-left: 2px;
}
.move-san.predict-placeholder {
  color: var(--cs-text-faint);
  font-style: italic;
  cursor: default;
  pointer-events: none;
}

#lib-mode-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px 2px;
}
#lib-mode-selector button {
  flex: 1;
  padding: 3px 0;
  font-size: 0.85rem;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: var(--cs-surface-2);
  color: #555;
  cursor: pointer;
}
#lib-mode-selector button.active {
  background: var(--cs-tint2);
  color: var(--cs-accent-dk);
  border-color: var(--cs-tint-border);
  font-weight: 600;
}
#lib-mode-selector button:disabled {
  opacity: 0.4;
  cursor: default;
}
#lib-mode-note {
  font-size: 10px;
  color: #999;
  flex: 2;
  padding-left: 4px;
}

.player-band {
  width: 400px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Three zones across the 400px band, all vertically centred on one line:
   captured pieces left, name centred, mobility right. Equal flex:1 on the two
   side zones keeps the name centred even when they differ in width (or the
   mobility zone is empty before move 10). DOM order is captures, name, mobility. */
.player-row {
  display: flex;
  align-items: center;
  font-size: 1rem;
  width: 100%;
}

.player-name {
  flex: 0 0 auto;
  color: #666;
}

/* Captured-piece tray beside each player name — rendered with the board's own
   piece images, so they read clearly (the Unicode glyphs were too thin). */
.player-captures {
  display: inline-flex;
  align-items: center;
  flex: 1 1 0;                 /* left zone */
  justify-content: flex-start;
  padding-left: 28px;          /* keep clear of the "? Chess terms" button at the band's left */
}
.player-captures .cap-piece {
  width: 22px;
  height: 22px;
  margin-right: -3px;   /* slight overlap keeps a row of pieces compact */
}
/* Mobility ratio, pushed to the far right of the player row (margin-left:auto),
   separated from the pictorial capture tray. Colour set inline by value. */
.player-mobility {
  flex: 1 1 0;                 /* right zone */
  text-align: right;
  padding-right: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: help;
}
.player-captures .cap-lead {
  margin-left: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--cs-text-muted);
}

.player-row.to-move .player-name {
  font-weight: 600;
  color: var(--cs-accent);
}


.player-name.player-name-editable {
  cursor: text;
  border-bottom: 1px dashed currentColor;
  opacity: 0.65;
  padding-bottom: 1px;
}
.player-name.player-name-editable:hover {
  opacity: 1;
}
.player-name-input {
  font-size: 1rem;
  font-family: inherit;
  color: inherit;
  border: none;
  border-bottom: 1px solid #444;
  background: transparent;
  outline: none;
  width: 100px;
  max-width: 140px;
  padding: 0;
  line-height: inherit;
}

.player-material {
  margin-left: auto;
  font-size: 0.92rem;
  color: #555;
  font-weight: normal;
}

/* Style the image inside the centered container, if needed */
.centered img {
  width: 150px;
  border-radius: 50%;
}

/* Add space below the element */
.bottom_margin {
  margin-bottom: 20px;
}

/* Add space above the element */
.top_margin {
  margin-top: 20px;
}

/* Add space to the left of the element */
.left_margin {
  margin-left: 20px;
}


#flip_board_btn .icon {
  font-size: 1.3em;
  line-height: 0;
  vertical-align: middle;
  position: relative;
  top: -0.13em;
}

#board {
  position: relative;
  margin: 0 auto;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.10);
  border-radius: 2px;
}
#to-move-indicator {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 5px;
  border-radius: 0 0 2px 2px;
  pointer-events: none;
  transition: background 0.25s;
  z-index: 10;
}
#to-move-indicator.w { background: rgba(255,255,255,0.80); }
#to-move-indicator.b { background: rgba(30,30,40,0.75); }

.copy-btn {
  cursor: pointer;
  font-size: 1.08rem;
  user-select: none;
  opacity: 0.7;
}

.copy-btn:hover {
  opacity: 1;
}

.copy-btn-disabled {
  opacity: 0.25;
  cursor: default;
}

.copy-btn-disabled:hover {
  opacity: 0.25;
}

#fen_left {
  word-break: break-all;
  font-size: 0.85em;
  color: #444;
}

.collapsible-hd {
  cursor: pointer;
  user-select: none;
}

.collapsible-arrow {
  font-size: 10px;
  display: inline-block;
  width: 1em;
}

#settings-body .collapsible-arrow {
  font-size: 18px;
}

#settings-body .collapsible-hd {
  font-size: 1.08rem;
  padding: 3px 4px;
  border-radius: 4px;
}
#settings-body .collapsible-hd:hover {
  background: rgba(0,0,0,0.05);
}

#settings-body .collapsible-body {
  font-size: 0.9em;
  color: #444;
}

.collapsible.collapsed .collapsible-body {
  display: none;
}

#pgn_left {
  width: auto;
  text-align: left;
  word-wrap: break-word;
}

/* Settings drawer */
#settings-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.18);
  z-index: 499;
}
#settings-backdrop.open { display: block; }

#settings-drawer {
  position: fixed;
  left: -260px;
  top: 0;
  width: 260px;
  height: 100vh;
  background: var(--cs-surface-2);
  border-right: 1px solid #bbb;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.18);
  z-index: 500;
  transition: left 0.22s ease;
  overflow-y: auto;
  padding: 12px 14px;
  box-sizing: border-box;
}
#settings-drawer.open { left: 0; }


/* Settings drawer (⚙️) HIDDEN, not deleted — its Library content was migrated to
   the Library tab (Todo 67–71). The drawer + this gear are kept so the drawer can
   be re-enabled later for behavioural (non-UI) config: delete this `display:none`
   override to bring the gear back. */
#settings-tab { display: none; }
#settings-tab.cs-enabled {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 38px;
  background: var(--cs-surface-2);
  border: 1px solid #bbb;
  border-left: none;
  border-radius: 0 4px 4px 0;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.12);
  z-index: 501;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  user-select: none;
  transition: left 0.22s ease;
}
#settings-drawer.open + #settings-tab { left: 260px; }


.strip-item.strip-sq-hover,
.cs-diff-item.strip-sq-hover {
  background: color-mix(in srgb, var(--cs-accent) 40%, transparent);
  border-radius: 3px;
}

/* Compare Background deltas: hidden while Background is collapsed, revealed for
   the squares a board hover points at (mirrors the Signals tab auto-expand). */
.cs-diff-item.cs-diff-bg-hidden { display: none; }
.cs-diff-item.cs-diff-bg-hidden.hover-reveal { display: flex; }

/* A diff block whose items are ALL hidden background deltas: kept in the DOM so
   a hover can reveal it, but not shown until then. */
.cs-diff-block-allhidden { display: none; }
.cs-diff-block-allhidden.block-reveal { display: block; }

@keyframes crucial-ring-pulse {
  0%   { box-shadow: inset 0 0 0 10px rgba(220, 0, 0, 0.75); }
  100% { box-shadow: inset 0 0 0 3px  rgba(220, 0, 0, 0.0);  }
}

.crucial-flash {
  position: absolute;
  pointer-events: none;
  animation: crucial-ring-pulse 0.45s ease-out 2 forwards;
}

@keyframes predict-sq-pulse {
  from { box-shadow: inset 0 0 0 5px rgba(255, 140, 0, 0.9); }
  to   { box-shadow: inset 0 0 0 5px rgba(255, 140, 0, 0);   }
}

.predict-flash-sq {
  animation: predict-sq-pulse 0.5s ease-in-out 3 alternate forwards;
}


/* Active state for toggle buttons (Predict, Dev) */
button.active {
  background: var(--cs-accent);
  color: #fff;
  border-color: var(--cs-accent-dk);
}


/* Right panel: hidden by default, slides in when panel-open */
.split.right {
  transform: translateX(100%);
}

body.panel-open .split.right {
  transform: translateX(0);
}

/* Analysis tab — sits at the seam between the two panels */
#analysis-tab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 38px;
  background: var(--cs-surface-2);
  border: 1px solid #bbb;
  border-right: none;
  border-radius: 4px 0 0 4px;
  box-shadow: -2px 0 5px rgba(0,0,0,0.15);
  z-index: 2;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  user-select: none;
  transition: right 0.22s ease;
}

body.panel-open #analysis-tab {
  right: 260px;
}

body.debug-off #null_move_btn,
body.debug-off .strip-copy-btn {
  display: none;
}

/* Replay bar — board-local media control */
#replay-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 30px;
  margin: 3px 0;
}
#replay-bar #replay-pause-btn,
#replay-bar #replay-speed-select,
#replay-bar #replay-stop-btn { display: none; }

#replay-bar.replay-active #replay-play-btn  { display: none; }
#replay-bar.replay-active #replay-pause-btn,
#replay-bar.replay-active #replay-speed-select,
#replay-bar.replay-active #replay-stop-btn  { display: inline-flex; align-items: center; }

#replay-bar.replay-paused #replay-pause-btn { display: none; }
#replay-bar.replay-paused #replay-play-btn,
#replay-bar.replay-paused #replay-speed-select,
#replay-bar.replay-paused #replay-stop-btn  { display: inline-flex; align-items: center; }

#replay-play-btn, #replay-pause-btn, #replay-stop-btn {
  background: none;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  color: #555;
  border-radius: 4px;
}
#replay-play-btn, #replay-pause-btn, #replay-stop-btn { color: var(--cs-accent); }
#replay-play-btn:hover:not(:disabled),
#replay-pause-btn:hover,
#replay-stop-btn:hover { background: var(--cs-tint2); color: #222; }
#replay-play-btn:disabled { opacity: 0.3; cursor: default; }
#replay-speed-select {
  font-size: 0.92rem;
  border: 1px solid var(--cs-tint3);
  border-radius: 3px;
  padding: 2px 4px;
  background: var(--cs-surface);
  cursor: pointer;
}

/* Selected spare piece highlight in build mode */
.spare-selected {
  outline: 3px solid var(--cs-accent);
  border-radius: 2px;
}

.build-square-selected {
  box-shadow: inset 0 0 0 3px var(--cs-accent);
}

/* Game Finder modal */
#game-finder-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  z-index: 600;
  align-items: center;
  justify-content: center;
}

#game-finder-modal.open {
  display: flex;
}

.game-finder-box {
  background: var(--cs-surface-2);
  border: 1px solid #bbb;
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.22);
  padding: 16px 20px 20px;
  min-width: 260px;
}

.game-finder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--cs-border);
  font-weight: bold;
  font-size: 1.08rem;
}

.game-finder-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
  line-height: 1;
  color: #666;
}

.game-finder-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.game-finder-item {
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.08rem;
  user-select: none;
  color: #222;
}

.game-finder-item:hover {
  background: var(--cs-tint2);
}

.game-finder-item.disabled {
  color: #bbb;
  cursor: default;
}

.game-finder-item.disabled:hover {
  background: transparent;
}
.game-finder-item.finder-active {
  background: var(--cs-tint2);
}

.game-finder-sep {
  height: 1px;
  background: var(--cs-border);
  margin: 5px 0;
  list-style: none;
}

/* Help modal and Opacity info modal */
#opacity-info-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 700;
  align-items: center;
  justify-content: center;
}
#opacity-info-modal.open { display: flex; }

#glossary-modal, #help-modal, #licences-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 700;
  align-items: center;
  justify-content: center;
}

#glossary-modal.open, #help-modal.open, #licences-modal.open {
  display: flex;
}

#chesscom-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 700;
  align-items: center;
  justify-content: center;
}
#chesscom-modal.open { display: flex; }
.cc-import-box { width: min(380px, 94vw); }
.cc-import-note { margin: 0 0 16px; color: var(--cs-text-muted); font-size: 0.9rem; line-height: 1.4; }
.cc-field { display: block; margin-bottom: 12px; font-size: 0.82rem; color: var(--cs-text-muted); }
.cc-field input, .cc-field select {
  display: block; width: 100%; box-sizing: border-box; margin-top: 4px;
  padding: 7px 9px; font-size: 0.95rem;
  border: 1px solid var(--cs-border); border-radius: 5px;
  background: var(--cs-surface); color: var(--cs-text);
}
.cc-field input:focus, .cc-field select:focus { outline: none; border-color: var(--cs-accent); }
.cc-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.cc-btn {
  padding: 7px 16px; font-size: 0.9rem; cursor: pointer;
  border: 1px solid var(--cs-border); border-radius: 5px;
  background: var(--cs-surface-2); color: var(--cs-text);
}
.cc-btn:hover { background: var(--cs-tint); }
.cc-btn-primary { background: var(--cs-accent); border-color: var(--cs-accent); color: #fff; }
.cc-btn-primary:hover { background: var(--cs-accent-dk); }

#glossary-btn {
  background: none;
  border: none;
  color: var(--cs-accent);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  opacity: 0.6;
  white-space: nowrap;
}
#glossary-btn:hover { opacity: 1; }

.glossary-list { margin: 0; padding: 0; list-style: none; }
.glossary-list dt { font-weight: bold; margin-top: 14px; color: var(--cs-accent-dk); }
.glossary-list dt:first-child { margin-top: 0; }
.glossary-list dd { margin: 3px 0 0 0; line-height: 1.5; }

.help-box {
  background: var(--cs-surface-2);
  border: 1px solid #bbb;
  border-radius: 6px;
  box-shadow: 0 6px 32px rgba(0,0,0,0.26);
  width: min(560px, 94vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--cs-border);
  font-weight: bold;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.help-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
  line-height: 1;
  color: #666;
}

.help-close-btn:hover { color: #222; }

.help-body {
  overflow-y: auto;
  padding: 12px 18px 20px;
  overscroll-behavior: contain;
}

.help-section {
  margin-bottom: 18px;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--cs-accent-dk);
  margin: 0 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--cs-tint2);
}

.help-section h4 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--cs-accent-dk);
  margin: 14px 0 3px;
  padding: 2px 0 2px 7px;
  border-left: 3px solid var(--cs-tint-border);
}

.help-section blockquote {
  margin: 6px 0 8px 0;
  padding: 6px 10px;
  background: var(--cs-tint);
  border-left: 3px solid var(--cs-accent);
  border-radius: 3px;
  font-size: 0.88rem;
  color: #444;
  font-style: italic;
}

.help-section p {
  margin: 0 0 6px;
  font-size: 0.92rem;
  line-height: 1.55;
}

.help-section ul,
.help-section ol {
  margin: 0 0 6px;
  padding-left: 22px;
  font-size: 0.92rem;
  line-height: 1.55;
}

/* Verbatim licence text — monospace, wrapped, lightly tinted. */
.licence-text {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--cs-tint);
  border: 1px solid var(--cs-tint-border);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.help-section li {
  margin-bottom: 3px;
}

/* Toast notifications */
#toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

@keyframes cs-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes cs-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

.cs-toast {
  pointer-events: auto;
  max-width: 320px;
  padding: 10px 14px;
  background: var(--cs-surface);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.10);
  border-left: 4px solid #888;
  font-size: 0.92rem;
  line-height: 1.45;
  color: #222;
  cursor: pointer;
  animation: cs-toast-in 0.18s ease-out both;
}
.cs-toast.cs-toast-error { border-left-color: #dc2626; }
.cs-toast.cs-toast-info  { border-left-color: var(--cs-accent); }
.cs-toast.cs-toast-ok    { border-left-color: #16a34a; }
.cs-toast.cs-toast-dismissing {
  animation: cs-toast-out 0.18s ease-in both;
}

/* Test using a canvas - work in progress
#container {
  position: relative;
}

#myCanvas {
  position: absolute;
  z-index: 100;
}

#board {
  position: absolute;
  z-index: 1;
}

canvas {
  border: 1px solid black;
}
*/

/* Signals perspective banner (click to lock / follow the side to move) */
#signals-persp-banner {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  margin-bottom: 6px;
  border: 1px solid var(--cs-tint-border);
  border-left: 3px solid var(--cs-accent);
  border-radius: 4px;
  background: var(--cs-tint2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
#signals-persp-banner:hover { background: var(--cs-tint3); }
.persp-chip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid #888;
  flex-shrink: 0;
}
.persp-chip-w { background: #fff; }
.persp-chip-b { background: #333; }
.persp-side { color: var(--cs-accent); }
.persp-mode {
  margin-left: auto;
  font-weight: normal;
  font-size: 0.78rem;
  color: #777;
}

/* ── iPad-portrait baseline (Todo 92) ──────────────────────────────────────
   Keep the strip | board | PGN row side-by-side at tablet widths: the 420px
   board area stays fixed and the flex sidebars (flex: 1 1 0; min-width: 0)
   shrink to fit (420 + 174 + 174 = 768), so there is no horizontal scroll and
   no scaling — align_strip_panel reads real element positions, so the JS rank
   alignment keeps working. Laptops are >= 1024px and never match this query
   (and desktop browsers ignore the width=device-width viewport meta), so the
   laptop layout is provably unchanged. Tune the cosmetic values on-device. */
@media (max-width: 820px) {
  /* reclaim a little horizontal room in the narrowed sidebars */
  #strip-col { padding-right: 4px; }
  #pgn-panel { padding-left: 4px; }
}
