/* Mobile-first Sand settings sheet. Slider mechanics and keyboard support: noUiSlider 15.8.1. */
html.sand-settings-open, html.sand-settings-open body { touch-action: auto !important; }
html.sand-settings-open #tools { opacity: 0; pointer-events: none; }
#settingsBtn {
  position: fixed; z-index: 5; top: max(6px, env(safe-area-inset-top));
  right: calc(max(6px, env(safe-area-inset-right)) + 51px);
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; color: #fff; background: rgb(24 22 20 / 35%);
  backdrop-filter: blur(10px);
}
#settingsBtn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; }

#settingsDialog {
  position: fixed; z-index: 12; bottom: 0; left: 0; box-sizing: border-box;
  display: grid; grid-template-rows: 49px 47px minmax(0, 1fr);
  width: 100%; max-width: none; height: min(54dvh, 480px);
  max-height: calc(100dvh - 12px); padding: 0;
  background: rgb(21 23 22 / 96%); color: #efeee8;
  border: 1px solid #ffffff26; border-bottom: 0;
  border-radius: 19px 19px 0 0; overflow: hidden;
  box-shadow: 0 -14px 48px #0008; backdrop-filter: blur(18px);
  font: 14px/1.35 system-ui, -apple-system, sans-serif;
  transition: height .18s ease-out;
}
#settingsDialog[hidden] { display: none !important; }
#settingsDialog.expanded { height: min(83dvh, 760px); }
.settings-head {
  box-sizing: border-box; display: flex; align-items: center; gap: 6px;
  min-width: 0; height: 49px; padding: 3px 9px 0 14px;
  border-bottom: 1px solid #ffffff14; touch-action: none;
}
.settings-head::before {
  content: ''; position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
  width: 37px; height: 4px; border-radius: 99px; background: #ffffff43;
  pointer-events: none;
}
.settings-head h2 { flex: 1 1 auto; margin: 0; min-width: 0; font-size: 15px; font-weight: 650; letter-spacing: .005em; }
.settings-head button {
  display: grid; place-items: center; flex: 0 0 auto; height: 40px; min-width: 40px;
  padding: 0 9px; border: 0; border-radius: 10px;
  font: 500 13px system-ui, sans-serif; color: #e3e1db; background: #ffffff0c;
}
.settings-head button:active, .settings-tab:active { background: #ffffff25; }
#settingsExpand svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; }
#settingsDialog.expanded #settingsExpand svg { transform: rotate(180deg); }
#settingsClose { font-size: 23px; font-weight: 300; }

#settingsTabs {
  display: flex; gap: 5px; align-items: stretch; min-width: 0; height: 47px;
  padding: 3px 9px 4px; box-sizing: border-box;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; touch-action: pan-x;
  border-bottom: 1px solid #ffffff18;
}
#settingsTabs::-webkit-scrollbar, #settingsPane::-webkit-scrollbar { display: none; }
.settings-tab {
  position: relative; flex: 0 0 auto; min-width: 67px; padding: 0 12px;
  border: 0; border-radius: 9px; font: 550 13px system-ui, sans-serif;
  color: #a9aaa5; background: none; white-space: nowrap;
}
.settings-tab.selected { color: #f3e5c6; background: #c9aa6325; }
.settings-tab.selected::after {
  content: ''; position: absolute; left: 13px; right: 13px; bottom: 1px;
  height: 2px; border-radius: 6px; background: #e8c783;
}
.settings-tab:focus-visible, .settings-head button:focus-visible,
.setting-value:focus-visible { outline: 2px solid #e8c783; outline-offset: -2px; }

#settingsPane {
  min-width: 0; min-height: 0; box-sizing: border-box; margin: 0;
  padding: 0 13px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  scrollbar-width: none; touch-action: pan-y;
  -webkit-overflow-scrolling: touch; scroll-padding-top: 2px;
}
.setting-row { box-sizing: border-box; min-height: 64px; padding: 4px 2px 5px; border-bottom: 1px solid #ffffff10; }
.setting-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 24px; }
.setting-name { color: #e5e4df; font-size: 13.5px; font-weight: 480; min-width: 0; }
.setting-value, .setting-value-input {
  box-sizing: border-box; flex: 0 0 auto; min-width: 50px; width: auto;
  height: 26px; padding: 0 2px; border: 0; border-radius: 0;
  background: transparent; color: #eacb8b;
  font: 600 12.5px/26px ui-monospace, SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums; text-align: right;
}
.setting-value-input { width: 84px; font-size: 16px; line-height: normal; border-bottom: 1px solid #eacb8b; outline: none; }
.setting-value:active { color: #fff; }
.setting-track { box-sizing: border-box; width: 100%; height: 12px; padding: 0; touch-action: none; }
.setting-track.noUi-target {
  height: 12px; margin: 9px 15px 10px; width: calc(100% - 30px);
  border: 0; border-radius: 999px; background: #535650;
  box-shadow: inset 0 1px 2px #0006;
}
.setting-track .noUi-connect { background: #d9b871; }
.setting-track .noUi-connects { border-radius: 99px; }
.setting-track.noUi-horizontal .noUi-handle {
  box-sizing: border-box; width: 40px; height: 40px; right: -20px; top: -14px;
  border: 0; border-radius: 50%; background: transparent; box-shadow: none; cursor: grab;
}
/* A 40px touch target surrounds the compact 30px visible knob. */
.setting-track .noUi-handle::before {
  content: ''; display: block; position: absolute; left: 5px; top: 5px;
  box-sizing: border-box; width: 30px; height: 30px;
  border: 2px solid #272824; border-radius: 50%;
  background: #f0d194; box-shadow: 0 2px 6px #0008, inset 0 1px 2px #fff8;
  transition: transform .1s ease;
}
.setting-track .noUi-handle::after { display: none; }
.setting-track .noUi-handle:active { cursor: grabbing; }
.setting-track .noUi-handle:active::before { transform: scale(1.08); }
.setting-track .noUi-handle:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.setting-switch-row {
  display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 42px; cursor: pointer;
}
.setting-row.setting-toggle { min-height: 53px; padding: 5px 2px; }
.setting-switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: 0 0 auto;
  width: 49px; height: 29px; margin: 0; border: 1px solid #ffffff23;
  border-radius: 99px; background: #545751; transition: background .14s ease;
}
.setting-switch::before {
  content: ''; position: absolute; width: 23px; height: 23px; left: 2px; top: 2px;
  border-radius: 50%; background: #f3f1e8; box-shadow: 0 1px 4px #0005;
  transition: transform .14s ease;
}
.setting-switch:checked { background: #d9b871; }
.setting-switch:checked::before { transform: translateX(20px); background: #2c2b24; }
.setting-switch:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

@media (min-width: 700px) and (max-height: 650px), (min-width: 900px) {
  #settingsDialog, #settingsDialog.expanded {
    inset: 7px 7px 7px auto; height: auto; width: min(380px, 43vw);
    border: 1px solid #ffffff26; border-radius: 18px;
    box-shadow: -12px 0 46px #0008;
  }
}
@media (max-height: 480px) and (max-width: 699px) {
  #settingsDialog { height: 72dvh; }
  #settingsDialog.expanded { height: 93dvh; }
}
@media (prefers-reduced-motion: reduce) {
  #settingsDialog, .setting-switch, .setting-switch::before { transition: none; }
}

/* Gestures beginning on the track can scroll vertically; only the knob drags a value. */
.setting-track, .setting-track.noUi-target, .setting-track .noUi-base, .setting-track .noUi-connects { touch-action: pan-y; }
/* Only the thumb captures touch movement; the rest of the row stays vertically scrollable.
   noUiSlider requires touch-action:none to receive a continuous touch drag on Android. */
.setting-track .noUi-handle,
.setting-track .noUi-touch-area { touch-action: pan-y !important; }

/* Touch gestures are direction-gated in settings-pane.js: vertical scrolling wins. */

/* Slider names can reset on double-tap without blocking vertical scrolling. */
.setting-meta .setting-name { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.setting-meta .setting-name:focus-visible { outline: 2px solid #e8c783; outline-offset: 2px; border-radius: 2px; }
