/**
 * Settings UI.
 *
 * Sized in vmin-scaled units rather than fixed pixels: the same drawer has to
 * be usable held in a hand on a tablet and read from across a room on a TV,
 * and 14px is unreadable at three metres. Everything inside is `em` off the
 * drawer's own font-size, so one clamp() moves the whole panel.
 *
 * Type follows the frame itself — light weights, wide tracking on the small
 * uppercase labels — so the drawer reads as part of the same object rather
 * than a browser dialog that happened to open on top of it.
 */

#gear, #drawer, #drawer-scrim { --ease: cubic-bezier(.32,.72,0,1); }

/* ---------------------------------------------------- pairing card ---- */

/**
 * The setup state. Visible only until a phone is paired, then gone for good —
 * so it can afford to be clear rather than apologetic, but it still sits in a
 * corner rather than over the picture.
 *
 * Sized in vmin like the clock, not in pixels like the drawer: this is the one
 * piece of UI that has to be legible, and scannable, from across a room.
 */
#pairing {
  position: fixed;
  bottom: clamp(14px, 2.4vmin, 32px);
  right: clamp(14px, 2.4vmin, 32px);
  z-index: 25;

  display: flex;
  align-items: center;
  gap: 1.8vmin;

  padding: 1.5vmin;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 1.4vmin;
  background: rgba(14,14,17,.5);
  backdrop-filter: blur(30px) saturate(1.5);
  -webkit-backdrop-filter: blur(30px) saturate(1.5);
  color: rgba(255,255,255,.92);
  text-shadow: 0 1px 12px rgba(0,0,0,.5);

  animation: pair-in 700ms cubic-bezier(.32,.72,0,1) both;
}
#pairing[hidden] { display: none; }

@keyframes pair-in {
  from { opacity: 0; transform: translateY(1.5vmin); }
  to   { opacity: 1; transform: none; }
}

/**
 * The code keeps its own white plate rather than adapting to the photo.
 * A QR needs a hard black-on-white edge, and what's behind it changes every
 * twelve seconds — sampling the image would mean recomputing per slide and
 * would still fail over anything busy. Unconditional beats clever here.
 */
.pair-qr {
  flex: 0 0 auto;
  width: 13vmin;
  aspect-ratio: 1;
  padding: .5vmin;
  border-radius: .7vmin;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0,0,0,.35);
}
.pair-qr svg { display: block; width: 100%; height: 100%; }

.pair-text { min-width: 0; }

.pair-lead {
  font-size: 1.45vmin;
  font-weight: 500;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: rgba(255,255,255,.5);
}
.pair-where {
  margin-top: .6vmin;
  font-size: 1.75vmin;
  font-weight: 300;
  color: rgba(255,255,255,.78);
  white-space: nowrap;
}
.pair-code {
  margin-top: 1vmin;
  font-size: 3.6vmin;
  font-weight: 300;
  /* Read aloud, squinted at, and typed into a phone — space the glyphs out
     and lock their width so it never reflows as it refreshes. */
  letter-spacing: .22em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #pairing { background: rgba(10,10,12,.9); }
}

@media (prefers-reduced-motion: reduce) {
  #pairing { animation-duration: 1ms; }
}

/* ------------------------------------------------------------- gear ---- */

#gear {
  position: fixed;
  top: clamp(14px, 2.2vmin, 30px);
  right: clamp(14px, 2.2vmin, 30px);
  z-index: 30;

  display: grid;
  place-items: center;
  width: clamp(42px, 5.4vmin, 68px);
  aspect-ratio: 1;

  border: 1px solid rgba(255,255,255,.14);
  border-radius: 50%;
  background: rgba(22,22,26,.42);
  backdrop-filter: blur(18px) saturate(1.5);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  color: rgba(255,255,255,.88);
  cursor: pointer;

  opacity: 0;
  transform: scale(.86);
  pointer-events: none;
  transition: opacity 260ms ease, transform 320ms var(--ease),
              background 160ms ease, border-color 160ms ease;
}
body.ui-visible #gear,
body.drawer-open #gear {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
#gear:hover { background: rgba(38,38,44,.6); border-color: rgba(255,255,255,.26); }
#gear svg { width: 52%; height: 52%; display: block; }

/* The gear must stay reachable by d-pad even while the body says hide. */
#gear:focus-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  outline: 2px solid rgba(255,255,255,.8);
  outline-offset: 3px;
}

/* ------------------------------------------------------------ scrim ---- */

#drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,.4);
  opacity: 0;
  transition: opacity 340ms var(--ease);
}
body.drawer-open #drawer-scrim { opacity: 1; }

/* ----------------------------------------------------------- drawer ---- */

#drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 50;
  width: min(92vw, clamp(340px, 30vw, 480px));

  display: flex;
  flex-direction: column;
  font-size: clamp(14px, calc(9px + .62vmin), 19px);
  line-height: 1.45;
  color: rgba(255,255,255,.92);

  background: rgba(15,15,18,.82);
  backdrop-filter: blur(40px) saturate(1.7);
  -webkit-backdrop-filter: blur(40px) saturate(1.7);
  border-left: 1px solid rgba(255,255,255,.09);
  box-shadow: -30px 0 80px rgba(0,0,0,.5);

  transform: translateX(100%);
  transition: transform 380ms var(--ease);
  /* The frame sets `cursor:none` on the body; inside the drawer that would
     make every control unaimable. */
  cursor: default;
}
body.drawer-open #drawer { transform: none; }

/* Backdrop-filter is missing on some older Android WebViews, and a 82%
   transparent panel over a photo is illegible without it. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #drawer { background: rgba(12,12,14,.97); }
  #gear { background: rgba(22,22,26,.9); }
}

#drawer header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1em;
  padding: 1.5em 1.6em 1.1em;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
#drawer h1 {
  font-size: 1.45em;
  font-weight: 300;
  letter-spacing: -.01em;
}

#drawer .drawer-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .6em 1.6em 1.6em;
}

#drawer section { padding: 1.5em 0; }
#drawer section + section { border-top: 1px solid rgba(255,255,255,.07); }

/* Echoes #cap-album on the frame: small, spaced, quiet. */
#drawer h2 {
  font-size: .76em;
  font-weight: 500;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: rgba(255,255,255,.45);
  margin-bottom: 1.15em;
}

#drawer footer {
  padding: 1.2em 1.6em 1.6em;
  border-top: 1px solid rgba(255,255,255,.07);
}
#drawer footer .hint { margin-top: .9em; }

/* ----------------------------------------------------------- fields ---- */

.field + .field { margin-top: 1.5em; }
.field[hidden] { display: none; }

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  min-height: 1.9em;
}
.field-label {
  font-weight: 300;
  letter-spacing: .005em;
}
.readout {
  font-size: .92em;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,.55);
  text-align: right;
}
.hint {
  margin-top: .5em;
  font-size: .84em;
  font-weight: 300;
  line-height: 1.5;
  color: rgba(255,255,255,.42);
  max-width: 34em;
}

/* --------------------------------------------------------- controls ---- */

#drawer :is(button, input, select):focus-visible {
  outline: 2px solid rgba(255,255,255,.8);
  outline-offset: 2px;
}

/* switch */
.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 2.9em;
  height: 1.65em;
  border-radius: 1em;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.1);
  position: relative;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 50%;
  left: .17em;
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  background: rgba(255,255,255,.88);
  transform: translateY(-50%);
  transition: transform 200ms var(--ease), background 180ms ease;
}
.switch:checked {
  background: rgba(138,180,248,.85);   /* Google TV's blue accent */
  border-color: rgba(138,180,248,.5);
}
.switch:checked::after {
  transform: translate(1.22em, -50%);
  background: #10131a;
}

/* range */
#drawer input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  margin-top: .75em;
  background: transparent;
  cursor: pointer;
}
#drawer input[type="range"]::-webkit-slider-runnable-track {
  height: .32em;
  border-radius: 1em;
  background: rgba(255,255,255,.16);
}
#drawer input[type="range"]::-moz-range-track {
  height: .32em;
  border-radius: 1em;
  background: rgba(255,255,255,.16);
}
#drawer input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 1.1em;
  height: 1.1em;
  margin-top: -.39em;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.5);
}
#drawer input[type="range"]::-moz-range-thumb {
  width: 1.1em;
  height: 1.1em;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.5);
}

/* select, text inputs */
#drawer select,
#drawer input:is([type="url"], [type="search"], [type="text"]) {
  font: inherit;
  font-weight: 300;
  color: rgba(255,255,255,.92);
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: .55em;
  padding: .5em .7em;
  min-width: 0;
}
#drawer select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2em;
  cursor: pointer;
  /* chevron, inlined so the strict no-external-assets rule still holds */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23ffffff' stroke-opacity='.6' stroke-width='1.5' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .65em center;
  background-size: .7em;
}
#drawer select option { background: #16161a; color: #fff; }

#drawer input:is([type="url"], [type="search"], [type="text"]) { width: 100%; }
#drawer input::placeholder { color: rgba(255,255,255,.35); }

/* buttons */
#drawer button {
  font: inherit;
  font-weight: 400;
  color: rgba(255,255,255,.9);
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.13);
  border-radius: .55em;
  padding: .5em .95em;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
#drawer button:hover:not(:disabled) {
  background: rgba(255,255,255,.16);
  border-color: rgba(255,255,255,.24);
}
#drawer button:disabled { opacity: .5; cursor: default; }

#drawer .drawer-close { font-size: .9em; }
#drawer .drawer-reset { width: 100%; }

/* A quieter action than the one above it — available, not invited. */
#drawer .drawer-secondary {
  display: block;
  margin-top: .9em;
  padding: .4em .8em;
  font-size: .86em;
  background: transparent;
  border-color: rgba(255,255,255,.14);
  color: rgba(255,255,255,.6);
}
#drawer .drawer-secondary:hover:not(:disabled) {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.85);
}

/* ---------------------------------------------------------- albums ---- */

.albums { list-style: none; display: grid; gap: .5em; }
.albums li {
  display: flex;
  align-items: center;
  gap: .8em;
  padding: .65em .5em .65em .85em;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: .6em;
}
.album-name {
  flex: 1;
  font-weight: 300;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.album-count {
  flex: 0 0 auto;
  font-size: .84em;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,.45);
}
#drawer .album-remove {
  flex: 0 0 auto;
  padding: .25em .5em;
  font-size: .9em;
  line-height: 1;
  background: transparent;
  border-color: transparent;
  color: rgba(255,255,255,.5);
}
#drawer .album-remove:hover {
  background: rgba(255,80,80,.16);
  border-color: rgba(255,120,120,.3);
  color: rgba(255,190,190,.95);
}
.albums-empty {
  display: block;
  font-size: .86em;
  font-weight: 300;
  color: rgba(255,255,255,.42);
  background: none;
  border: 1px dashed rgba(255,255,255,.14);
}

.album-add {
  display: flex;
  gap: .5em;
  margin-top: .8em;
}
.album-add button { flex: 0 0 auto; }

.status {
  margin-top: .6em;
  font-size: .84em;
  font-weight: 300;
  line-height: 1.45;
}
.status:empty { display: none; }

/* The code shown in the drawer's own "pair a phone" section. */
.pair-qr-inline {
  width: 11em;
  aspect-ratio: 1;
  margin-top: 1em;
  padding: .5em;
  border-radius: .5em;
  background: #fff;
}
.pair-qr-inline[hidden] { display: none; }
.pair-qr-inline svg { display: block; width: 100%; height: 100%; }

/* The kiosk URL: long, and meant to be selected or copied whole. */
.kiosk-url {
  margin-top: .9em;
  padding: .7em .8em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78em;
  line-height: 1.5;
  color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: .5em;
  /* An id has no spaces, so it needs an explicit licence to wrap. */
  word-break: break-all;
  user-select: all;
}

.pair-code-inline {
  margin-top: .6em;
  font-size: 1.7em;
  font-weight: 300;
  letter-spacing: .2em;
  font-variant-numeric: tabular-nums;
}
.pair-code-inline:empty { display: none; }
.status--busy  { color: rgba(255,255,255,.5); }
.status--ok    { color: rgba(150,220,170,.9); }
.status--warn  { color: rgba(240,205,140,.9); }
.status--error { color: rgba(255,160,160,.92); }

/* ---------------------------------------------------------- places ---- */

.places { list-style: none; margin-top: .5em; display: grid; gap: .25em; }
.places:empty { margin-top: 0; }
#drawer .places button {
  width: 100%;
  text-align: left;
  font-weight: 300;
  background: rgba(255,255,255,.05);
}
.places-empty {
  font-size: .86em;
  font-weight: 300;
  color: rgba(255,255,255,.42);
  padding: .4em 0;
}

/* ------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  #gear, #drawer, #drawer-scrim, .switch, .switch::after {
    transition-duration: 1ms;
  }
}
