/* ============================================================
   SETTINGS — the window behind the gear (index.html #settings-modal).

   Rebuilt 2026-10-19 (Jeff: "the graphics are shit. Make the settings work and
   look nicely"). Before: a 512px-wide column, thirteen screens tall, with
   checkboxes in three sizes, emoji in front of half the labels, two "Look"
   pickers, and a shot-clock picker that duplicated the timer settings.

   Now: a sidebar of sections beside one scrolling page on a wide screen, a
   swipeable row of sections on a phone. Every row has the same anatomy —
   label and one line of explanation on the left, the control on the right —
   and every on/off control is the same switch. Rows sit in quiet cards.

   Every rule here is scoped to #settings-modal, so nothing leaks into the app.
   Control ids and handlers are unchanged (js/ui/modals.js seeds them); only
   the clothes changed.
   ============================================================ */

#settings-modal {
  --st-bg: #ffffff;
  --st-side: #f6f7f9;
  --st-card: #f8f9fb;
  --st-line: rgba(15, 23, 42, 0.08);
  --st-line-strong: rgba(15, 23, 42, 0.14);
  --st-ink: #0f172a;
  --st-ink-2: #475569;
  --st-ink-3: #94a3b8;
  --st-accent: #2563eb;
  --st-accent-soft: rgba(37, 99, 235, 0.10);
  --st-field: #ffffff;
  --st-hover: rgba(15, 23, 42, 0.05);
  --st-off: #cbd5e1;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.dark #settings-modal {
  --st-bg: #15171d;
  --st-side: #111318;
  --st-card: rgba(255, 255, 255, 0.025);
  --st-line: rgba(255, 255, 255, 0.07);
  --st-line-strong: rgba(255, 255, 255, 0.13);
  --st-ink: #f1f5f9;
  --st-ink-2: #a3acb9;
  --st-ink-3: #6b7280;
  --st-accent: #3b82f6;
  --st-accent-soft: rgba(59, 130, 246, 0.16);
  --st-field: #0f1116;
  --st-hover: rgba(255, 255, 255, 0.05);
  --st-off: #3a3f4b;
}

/* ---- the shell --------------------------------------------------------------- */
#settings-modal .st-shell {
  width: min(60rem, 94vw);
  height: min(88vh, 48rem);
  display: flex; flex-direction: column;
  background: var(--st-bg); color: var(--st-ink);
  border: 1px solid var(--st-line-strong);
  border-radius: 18px;
  box-shadow: 0 30px 80px -20px rgba(2, 6, 23, 0.55);
  overflow: hidden;
}
#settings-modal .st-head {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.85rem 1rem 0.85rem 1.4rem;
  border-bottom: 1px solid var(--st-line);
  flex: none;
}
#settings-modal .st-head h2 { margin: 0; font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; flex: none; }
#settings-modal .st-search { position: relative; flex: 1; max-width: 22rem; margin-left: auto; }
#settings-modal .st-search svg { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); width: 1rem; height: 1rem; color: var(--st-ink-3); pointer-events: none; }
#settings-modal #settings-search {
  width: 100%; height: 2.25rem; padding: 0 0.8rem 0 2.1rem;
  border-radius: 10px; border: 1px solid var(--st-line-strong); background: var(--st-field);
  color: var(--st-ink); font-size: 0.875rem; outline: none;
}
#settings-modal #settings-search::placeholder { color: var(--st-ink-3); }
#settings-modal #settings-search:focus { border-color: var(--st-accent); box-shadow: 0 0 0 3px var(--st-accent-soft); }
#settings-modal .st-close {
  flex: none; width: 2.25rem; height: 2.25rem; display: grid; place-items: center;
  border-radius: 10px; color: var(--st-ink-2); background: transparent; border: 0; cursor: pointer;
}
#settings-modal .st-close:hover { background: var(--st-hover); color: var(--st-ink); }
#settings-modal .st-close svg { width: 1.15rem; height: 1.15rem; }

#settings-modal .st-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 13.5rem minmax(0, 1fr); }

/* ---- the section list ---------------------------------------------------------- */
#settings-modal .st-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 0.9rem 0.7rem; background: var(--st-side);
  border-right: 1px solid var(--st-line); overflow-y: auto;
}
#settings-modal .st-nav button {
  display: flex; align-items: center; gap: 0.65rem;
  min-height: 2.35rem; padding: 0 0.75rem; border: 0; border-radius: 9px;
  background: transparent; color: var(--st-ink-2); font-size: 0.875rem; font-weight: 500;
  text-align: left; cursor: pointer;
}
#settings-modal .st-nav button svg { width: 1.05rem; height: 1.05rem; flex: none; opacity: 0.85; }
#settings-modal .st-nav button:hover { background: var(--st-hover); color: var(--st-ink); }
#settings-modal .st-nav button.on { background: var(--st-accent-soft); color: var(--st-accent); font-weight: 600; }
.dark #settings-modal .st-nav button.on { color: #93c5fd; }

/* ---- the page ------------------------------------------------------------------- */
#settings-modal #settings-scroll {
  overflow-y: auto; padding: 1.4rem 1.9rem 3rem;
  display: flex; flex-direction: column; gap: 2.2rem;
  scroll-padding-top: 1rem;
}
#settings-modal [data-settings-section] { display: flex; flex-direction: column; gap: 0.9rem; scroll-margin-top: 1rem; }
#settings-modal .st-title { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: -0.015em; color: var(--st-ink); }
#settings-modal .st-sub { margin: -0.55rem 0 0; font-size: 0.82rem; color: var(--st-ink-3); line-height: 1.45; }
#settings-modal .st-group-label {
  margin: 0.3rem 0 -0.35rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--st-ink-3);
}

/* A card of rows. Rows are divided by hairlines; the card has no heavy border. */
#settings-modal .st-card {
  display: flex; flex-direction: column;
  background: var(--st-card); border: 1px solid var(--st-line);
  border-radius: 14px; padding: 0 1rem;
}
#settings-modal .st-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1.25rem;
  padding: 0.85rem 0; min-height: 3.25rem;
}
#settings-modal .st-card > .st-row + .st-row,
#settings-modal .st-card > .st-row + .st-block,
#settings-modal .st-card > .st-block + .st-row,
#settings-modal .st-card > .st-block + .st-block { border-top: 1px solid var(--st-line); }
#settings-modal .st-card > [style*="display: none"] + .st-row,
#settings-modal .st-card > [style*="display: none"] + .st-block { border-top-color: var(--st-line); }
#settings-modal .st-row.st-sub-row { padding-left: 1.1rem; min-height: 0; padding-top: 0.6rem; }
#settings-modal .st-label { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; flex: 1; cursor: default; }
#settings-modal label.st-row, #settings-modal label.st-row .st-label { cursor: pointer; }
#settings-modal .st-name { font-size: 0.9rem; font-weight: 550; color: var(--st-ink); line-height: 1.3; display: flex; align-items: center; gap: 0.4rem; }
#settings-modal .st-desc { font-size: 0.79rem; font-weight: 400; color: var(--st-ink-3); line-height: 1.45; }
#settings-modal .st-desc b { color: var(--st-ink-2); font-weight: 600; }
#settings-modal .st-control { flex: none; display: flex; align-items: center; gap: 0.5rem; }
/* A block: a row whose control is too wide to sit on the right (swatch grids,
   the ticker's three fields). Label on top, control under it. */
#settings-modal .st-block { display: flex; flex-direction: column; gap: 0.7rem; padding: 0.9rem 0; }
#settings-modal kbd, #settings-modal .st-kbd {
  display: inline-flex; align-items: center; height: 1.25rem; padding: 0 0.35rem;
  border-radius: 5px; border: 1px solid var(--st-line-strong); background: var(--st-field);
  font: 600 0.7rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--st-ink-2);
}
#settings-modal code { font: 500 0.78rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--st-ink-2); }

/* ---- the controls ----------------------------------------------------------------- */
/* Every on/off is one switch. appearance:none keeps the real checkbox (ids,
   handlers, :checked, keyboard) and only redraws it. */
#settings-modal input[type="checkbox"].st-switch {
  appearance: none; -webkit-appearance: none; flex: none;
  position: relative; width: 2.6rem; height: 1.5rem; margin: 0;
  border-radius: 999px; background: var(--st-off); border: 0; cursor: pointer;
  transition: background-color 0.18s ease;
}
#settings-modal input[type="checkbox"].st-switch::before {
  content: ''; position: absolute; top: 0.1875rem; left: 0.1875rem;
  width: 1.125rem; height: 1.125rem; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s ease;
}
#settings-modal input[type="checkbox"].st-switch:checked { background: var(--st-accent); }
#settings-modal input[type="checkbox"].st-switch:checked::before { transform: translateX(1.1rem); }
#settings-modal input[type="checkbox"].st-switch:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--st-accent-soft); }

#settings-modal select.st-select,
#settings-modal input.st-input {
  height: 2.25rem; border-radius: 9px; border: 1px solid var(--st-line-strong);
  background-color: var(--st-field); color: var(--st-ink);
  font-size: 0.85rem; font-weight: 500; padding: 0 0.75rem; outline: none;
}
#settings-modal select.st-select {
  appearance: none; -webkit-appearance: none; padding-right: 2rem; min-width: 11rem; max-width: 18rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.7rem center;
}
#settings-modal select.st-select:focus, #settings-modal input.st-input:focus { border-color: var(--st-accent); box-shadow: 0 0 0 3px var(--st-accent-soft); }
#settings-modal input.st-input::placeholder { color: var(--st-ink-3); }

/* Segmented choice (shot clock length, and anything with 2-4 short options). */
#settings-modal .st-seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px;
  background: var(--st-hover); border: 1px solid var(--st-line);
}
#settings-modal .st-seg button {
  min-width: 3.25rem; height: 1.85rem; padding: 0 0.7rem; border: 0; border-radius: 7px;
  background: transparent; color: var(--st-ink-2); font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
#settings-modal .st-seg button:hover { color: var(--st-ink); }
#settings-modal .st-seg button[aria-pressed="true"],
#settings-modal .st-seg button[aria-checked="true"] {
  background: var(--st-bg); color: var(--st-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--st-line);
}
.dark #settings-modal .st-seg button[aria-pressed="true"],
.dark #settings-modal .st-seg button[aria-checked="true"] { background: #2a2e38; }

/* Buttons: one primary, one quiet. No gradients, no emoji. */
#settings-modal .st-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  height: 2.25rem; padding: 0 0.95rem; border-radius: 9px;
  border: 1px solid var(--st-line-strong); background: var(--st-field); color: var(--st-ink);
  font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
#settings-modal .st-btn:hover { background: var(--st-hover); }
#settings-modal .st-btn svg { width: 1rem; height: 1rem; }
#settings-modal .st-btn.st-primary { background: var(--st-accent); border-color: var(--st-accent); color: #fff; }
#settings-modal .st-btn.st-primary:hover { filter: brightness(1.08); }
#settings-modal .st-btn.st-danger { color: #dc2626; }
.dark #settings-modal .st-btn.st-danger { color: #f87171; }
#settings-modal .st-link { background: none; border: 0; padding: 0; color: var(--st-accent); font-size: 0.82rem; font-weight: 600; cursor: pointer; }
#settings-modal .st-link:hover { text-decoration: underline; }

#settings-modal input[type="range"].st-range { width: min(16rem, 40vw); accent-color: var(--st-accent); }

/* ---- the footer --------------------------------------------------------------------- */
#settings-modal .st-foot {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 1rem 0.7rem 1.4rem; border-top: 1px solid var(--st-line); background: var(--st-side);
}

/* ---- the pieces filled in by other modules ------------------------------------------ */
/* The account line (renderAccountPanel). */
#settings-modal #settings-account {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.75rem 1rem; border-radius: 14px; background: var(--st-card); border: 1px solid var(--st-line);
}
/* Swatch grids (board theme, frame, background): smaller labels, even gaps. */
#settings-modal #board-theme-swatches,
#settings-modal #app-bg-swatches,
#settings-modal #board-frame-swatches { gap: 0.75rem 0.5rem; grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr)); }
#settings-modal .st-block summary { color: var(--st-ink-3); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; cursor: pointer; }
/* Graphics (js/features/graphics.js) draws its own cards; make them sit flat in ours. */
#settings-modal .gfx-block { background: transparent; border: 0; padding: 0; }
/* The ? help buttons (js/features/settings-help.js) line up with the label. */
#settings-modal .st-name .settings-help-btn, #settings-modal [data-help-slot] { margin-left: 0.15rem; }
/* The usage dashboard sits inside a card; keep its inner tiles quiet. */
#settings-modal #feature-usage-stats { background: transparent; border: 0; padding: 0.25rem 0 0; }

/* ---- phone / narrow --------------------------------------------------------------------- */
@media (max-width: 760px) {
  #settings-modal .st-shell { width: 100vw; height: 100dvh; max-height: none; border-radius: 0; border: 0; }
  #settings-modal .st-head { padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.6rem 0.6rem 1rem; gap: 0.6rem; flex-wrap: wrap; }
  #settings-modal .st-search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  #settings-modal .st-close { margin-left: auto; }
  #settings-modal .st-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #settings-modal .st-nav {
    flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 0.3rem;
    padding: 0.5rem 0.75rem; border-right: 0; border-bottom: 1px solid var(--st-line);
    scrollbar-width: none;
  }
  #settings-modal .st-nav::-webkit-scrollbar { display: none; }
  #settings-modal .st-nav button { flex: none; min-height: 2.25rem; padding: 0 0.8rem; border-radius: 999px; }
  #settings-modal #settings-scroll { padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom, 0px)); gap: 1.8rem; }
  #settings-modal .st-row { flex-wrap: wrap; gap: 0.6rem 1rem; }
  #settings-modal .st-row > .st-control { max-width: 100%; }
  /* A label never narrower than ~12rem: a wide control (the None-2-4-6-All
     buttons, a long select) drops under it instead of squeezing it to a word
     per line. */
  #settings-modal .st-row > .st-label { flex: 1 1 12rem; }
  #settings-modal select.st-select { min-width: 0; max-width: 100%; }
  #settings-modal .st-foot { padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  #settings-modal input[type="checkbox"].st-switch,
  #settings-modal input[type="checkbox"].st-switch::before { transition: none; }
}

/* Tailwind's .hidden is a single class; .st-row / .st-btn above outrank it.
   The JS still hides rows and buttons by toggling it (#timer-suboptions, the
   Lichess connect/disconnect pair), so it has to win inside the window. */
#settings-modal .hidden { display: none !important; }
