/* backdrop.css — the picture behind the sidebar and the about card
   (backdrop.js), and the dialog that fits it (backdrop_editor.js).

   Anatomy: a surface that shows the picture holds a .backdrop-layer as its
   first child, under everything else (z-index -1 inside the surface's own
   stacking context). The layer draws two things:
     ::before  the picture: cover, its point of interest (--backdrop-x/y) kept
               in view, brought nearer (--backdrop-zoom), softened
               (--backdrop-blur) and its colour taken down
               (--backdrop-saturation);
     ::after   a veil of the surface's own tone (--backdrop-tone: the
               sidebar's --sidebar-bg, the card's --bg2) at --backdrop-veil.
   The veil is set per theme (--backdrop-veil-light / -dark, worked out by
   the editor so the quieter text keeps its contrast), so one picture reads
   in both themes and a theme switch needs nothing but these rules.

   The fit's properties sit on <html> (backdrop.js) while a picture is kept
   (<html data-backdrop>); the editor sets a draft's on the surfaces it
   previews in (.is-draft, .is-backdrop-draft). */

.backdrop-layer {
  display: none;
  --backdrop-veil: var(--backdrop-veil-dark, .82);
}
:root[data-theme="light"] .backdrop-layer { --backdrop-veil: var(--backdrop-veil-light, .82) }

.has-backdrop {
  position: relative;
  isolation: isolate;
}

:root[data-backdrop] .has-backdrop > .backdrop-layer,
:root[data-backdrop] .sidebar > .backdrop-layer,
.sidebar.is-backdrop-draft > .backdrop-layer,
.backdrop-layer.is-draft {
  display: block;
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  border-radius: inherit;
  animation: backdrop-in .5s ease both;
}
.backdrop-layer::before,
.backdrop-layer::after {
  content: "";
  position: absolute;
}
.backdrop-layer::before {
  /* Softened, the picture's edge would fade into the tone: it reaches past
     the surface by twice the blur. */
  inset: calc(var(--backdrop-blur, 0px) * -2);
  background-image: var(--backdrop-image, none);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: var(--backdrop-x, 50%) var(--backdrop-y, 50%);
  transform: scale(var(--backdrop-zoom, 1));
  transform-origin: var(--backdrop-x, 50%) var(--backdrop-y, 50%);
  filter: blur(var(--backdrop-blur, 0px)) saturate(var(--backdrop-saturation, 1));
}
.backdrop-layer::after {
  inset: 0;
  background: var(--backdrop-tone, var(--sidebar-bg));
  opacity: var(--backdrop-veil);
}
@keyframes backdrop-in {
  from { opacity: 0 }
  to   { opacity: 1 }
}

/* ── The sidebar ──────────────────────────────────────────────────────
   Its own stacking context, so the layer stays under the rows. Positioned
   on a wide screen only: on a phone the drawer is fixed already (shell.css),
   and must stay so. */
:root[data-backdrop] .sidebar,
.sidebar.is-backdrop-draft { isolation: isolate }
@media (min-width: 821px) {
  :root[data-backdrop] .sidebar,
  .sidebar.is-backdrop-draft { position: relative }
}

/* ── The about card ───────────────────────────────────────────────────
   In its own window and in Settings (settings.css .settings-about) alike:
   the card's own tone over the picture; its links become frosted glass, so
   the picture shows through them a little and their words stay sharp. */
.modal-card--about,
.settings-about { --backdrop-tone: var(--bg2) }
:root[data-backdrop] .has-backdrop .about-links {
  background: color-mix(in srgb, var(--bg2) 64%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(1.1);
  backdrop-filter: blur(12px) saturate(1.1);
}
:root[data-backdrop] .has-backdrop .about-link { background: transparent }
:root[data-backdrop] .has-backdrop .about-link:hover { background: color-mix(in srgb, var(--text) 6%, transparent) }

/* ── While a picture is being fitted ──────────────────────────────────
   On a wide screen the dialog leaves the sidebar uncovered: the sidebar
   itself shows the draft, in the theme the panel is in, with the real rows
   on it. Only its theme button answers meanwhile. */
@media (min-width: 821px) {
  :root[data-backdrop-editing]:not([data-sidebar="collapsed"]) .modal-overlay { left: var(--sidebar-w) }
}
:root[data-backdrop-editing] .sidebar { pointer-events: none }
:root[data-backdrop-editing] .sidebar .sb-theme-toggle { pointer-events: auto }

/* ── The editor ─────────────────────────────────────────────────────── */
.modal-card--backdrop { max-width: 660px }
.bd-editor {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1.3rem;
  align-items: start;
  padding: .35rem 0 .2rem;
}
.bd-editor[data-busy] .bd-stage,
.bd-editor[data-busy] .bd-controls { opacity: .45; pointer-events: none }
.bd-busy {
  grid-column: 1 / -1;
  margin: 0;
  font-size: .82rem;
  color: var(--muted);
}
.bd-busy[hidden] { display: none }

.bd-stage { display: flex; flex-direction: column; gap: .6rem }
/* The two small sidebars: each the real width and height scaled down
   (--mock-k), so the picture lies in them as it does in the sidebar. */
.bd-previews {
  display: flex;
  gap: .7rem;
}
.bd-preview {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin: 0;
}
.bd-frame {
  position: relative;
  width: calc(var(--sidebar-w) * var(--mock-k, .45));
  height: calc(var(--mock-h, 760px) * var(--mock-k, .45));
  overflow: hidden;
  border-radius: 10px;
  box-shadow: 0 0 0 1px var(--border2), 0 6px 18px rgba(0, 0, 0, .14);
  cursor: grab;
  touch-action: none;
}
.bd-frame:active { cursor: grabbing }
.bd-frame:focus-visible { outline: 2px solid var(--focus-outline); outline-offset: 2px }
.bd-mock {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: var(--sidebar-w);
  height: var(--mock-h, 760px);
  padding: 0 .5rem;
  overflow: hidden;
  transform: scale(var(--mock-k, .45));
  transform-origin: 0 0;
  background: var(--mock-bg);
  color: var(--mock-text);
  font-size: .88rem;
  font-weight: 500;
  line-height: 1.25;
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}
/* Each small sidebar wears its theme's tones whatever the panel's theme:
   base.css --sidebar-bg, --text, --muted and --shell-active of that theme
   (test_panel_backdrop.py keeps them equal). */
.bd-mock[data-tone="light"] {
  --mock-bg: #f7f8fa;
  --mock-text: #111827;
  --mock-muted: #4b5563;
  --mock-active: rgba(17, 24, 39, .085);
  --backdrop-tone: #f7f8fa;
}
.bd-mock[data-tone="dark"] {
  --mock-bg: #101211;
  --mock-text: #ecedeb;
  --mock-muted: #9a9f9c;
  --mock-active: rgba(236, 237, 235, .09);
  --backdrop-tone: #101211;
}
.bd-mock[data-tone="light"] .backdrop-layer { --backdrop-veil: var(--backdrop-veil-light, .82) }
.bd-mock[data-tone="dark"] .backdrop-layer { --backdrop-veil: var(--backdrop-veil-dark, .82) }
.bd-mock-head {
  display: flex;
  align-items: center;
  height: var(--topbar-height);
  padding: 0 .5rem;
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bd-mock-row {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 2.05rem;
  padding: .48rem .6rem;
  border-radius: 9px;
  white-space: nowrap;
  overflow: hidden;
}
.bd-mock-row.is-current { background: var(--mock-active) }
.bd-mock-ico {
  flex: none;
  width: 16px;
  height: 16px;
  border: 1.6px solid currentColor;
  border-radius: 5px;
  opacity: .85;
}
.bd-mock-section {
  padding: .9rem .6rem .35rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--mock-muted);
}
.bd-mock-line {
  display: block;
  height: .62em;
  border-radius: 99px;
  background: currentColor;
  opacity: .78;
}
.bd-mock-line.is-quiet { background: var(--mock-muted) }
.bd-preview-cap {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  font-size: .76rem;
  color: var(--text);
}
.bd-preview-name { font-weight: 600 }
/* Whether the theme's text still reads over the picture: a lamp and a
   word, quiet while it does. */
.bd-read {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .72rem;
  color: var(--muted);
}
.bd-read::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--led-on);
}
.bd-read[data-read="fair"] { color: var(--warn) }
.bd-read[data-read="fair"]::before { background: var(--led-warn) }
.bd-read[data-read="poor"] { color: var(--err) }
.bd-read[data-read="poor"]::before { background: var(--led-err) }
.bd-hint {
  max-width: 19rem;
  margin: 0;
  font-size: .76rem;
  line-height: 1.45;
  color: var(--muted);
}

.bd-controls {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  min-width: 0;
}
.bd-control { display: flex; flex-direction: column; gap: .15rem }
.bd-control-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  font-size: .84rem;
  color: var(--text);
}
.bd-control-value {
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bd-control-ends {
  display: flex;
  justify-content: space-between;
  font-size: .7rem;
  color: var(--muted2);
}
/* A slider of the panel's own: a thin track filled with the accent up to
   the knob (--fill, set as it moves), a round knob on the card's ground.
   base.css draws every input as a text field; this one opts out of it. */
.bd-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}
.bd-range:focus { border: 0; box-shadow: none }
.bd-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), var(--control-track-off) var(--fill, 50%));
}
.bd-range::-moz-range-track { height: 4px; border-radius: 999px; background: var(--control-track-off) }
.bd-range::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--accent) }
.bd-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  background: var(--bg2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .12s ease;
}
.bd-range::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  background: var(--bg2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.bd-range:active::-webkit-slider-thumb { transform: scale(1.12) }
.bd-range:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring-focus) }
.bd-range:focus-visible::-moz-range-thumb { box-shadow: var(--ring-focus) }
.bd-tools {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding-top: .15rem;
}
.bd-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1.1rem;
}
.bd-actions-gap { flex: 1 }

@media (max-width: 640px) {
  .bd-editor { grid-template-columns: minmax(0, 1fr) }
  .bd-previews { justify-content: center }
  .bd-hint { max-width: none; text-align: center }
  .bd-actions { flex-wrap: wrap }
}
@media (prefers-reduced-motion: reduce) {
  .backdrop-layer { animation: none !important }
  .bd-range::-webkit-slider-thumb { transition: none }
}
