/*
 * styles.css — replicates the desktop Flet UI (klipsch_remote) in the browser:
 * a narrow, portrait, screen-based remote on Google's dark-neutral Material 3
 * palette (blue #8AB4F8 accent on near-black surfaces), lifted from theme.py.
 */
:root {
  color-scheme: dark;          /* dark native UI everywhere: scrollbars, <select> popup, etc. */
  --primary: #8ab4f8;
  --on-primary: #202124;
  --bg: #161618;               /* window background (surface_container_lowest) */
  --card: #1f2023;             /* cards / groups, a step above the background */
  --card-2: #2a2b2e;           /* tiles, fields, buttons */
  --text: #e8eaed;             /* on_surface */
  --muted: #9aa0a6;            /* secondary text / descriptions */
  --outline: #5f6368;          /* field borders, switch track (off) */
  --outline-variant: #3c4043;  /* hairlines, inactive slider track */
  --active-tile: #36404e;      /* selected input tile fill */
  --error: #f28b82;
  --on-error: #601410;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; }
.muted { color: var(--muted); }

/* Material Symbols ---------------------------------------------------------- */
.mi {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  white-space: nowrap;
  direction: ltr;
  -webkit-font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  user-select: none;
}
.mi.fill { font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24; }

/* App shell — phone-width column, centred on wide screens ------------------- */
.app { max-width: 560px; margin: 0 auto; }
.screen { display: block; }
[hidden] { display: none !important; }

/* App bar (centered title) -------------------------------------------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  background: var(--bg);
}
.appbar-title { flex: 1; text-align: center; font-size: 20px; }
.iconbtn-spacer { width: 40px; flex: none; }

.scroll { padding: 4px 16px 0; }
.scroll-foot { height: 20px; }

/* Cards & groups ------------------------------------------------------------ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.no-pad { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.card-head .mi { font-size: 20px; }
.card-head h3 { font-size: 16px; }

.group {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 8px;
}
.hairline { height: 1px; border: 0; margin: 0; background: var(--outline-variant); }

.section-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; color: var(--muted);
  padding: 16px 0 4px 16px;
}
.sub-status { font-weight: 400; font-size: 13px; }

/* Icon buttons -------------------------------------------------------------- */
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%; background: transparent;
  color: var(--text); cursor: pointer;
  transition: background 0.15s;
}
.iconbtn:hover { background: rgba(255, 255, 255, 0.08); }
.iconbtn:active { background: rgba(255, 255, 255, 0.14); }
.iconbtn.xl { width: 56px; height: 56px; }
.iconbtn.xl .mi { font-size: 30px; }
.iconbtn.playpause { width: auto; padding: 0 10px; border-radius: 28px; gap: 2px; }

/* Pill buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  padding: 13px 24px;
  font: inherit; font-weight: 500;
  background: var(--card-2); color: var(--text);
  cursor: pointer; transition: filter 0.15s;
}
.btn .mi { font-size: 20px; }
.btn:hover { filter: brightness(1.12); }
.btn:active { filter: brightness(0.95); }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn-danger { background: var(--error); color: var(--on-error); border-color: transparent; }
.btn-block { width: 100%; }
/* Disconnect at the foot of Settings — a reversible action, so it's a quiet
   outlined button (not a filled error banner): a hairline outline and muted
   label at rest, with the error colour surfacing only on hover so the intent
   still reads. A little gap above separates it from the last group. */
.disconnect-btn {
  margin-top: 16px;
  background: transparent;
  border-color: var(--outline-variant);
  color: var(--muted);
}
.disconnect-btn:hover {
  filter: none;
  background: rgba(242, 139, 130, 0.08);   /* faint --error tint */
  border-color: var(--error);
  color: var(--error);
}
.disconnect-btn:active { filter: none; background: rgba(242, 139, 130, 0.14); }

/* Connect screen ------------------------------------------------------------ */
.connect { display: flex; flex-direction: column; min-height: 100dvh; padding: 16px; }
.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 30px; }
.brand-title { font-size: 24px; }
.subtitle { margin: 12px 0 0; }
.divider { height: 1px; border: 0; background: var(--outline-variant); margin: 16px 0; }
.note { line-height: 1.55; }
.repo-link {
  display: inline-block; white-space: nowrap;
  margin-top: 14px; font-size: 13px;
  color: var(--muted); text-decoration: none; transition: color 0.15s;
}
/* Leading icon: `vertical-align: middle` centres the glyph on the text's middle
   line — the standard Material way to align an icon with its label, no pixel
   nudging. The margin (not a flex gap) sets the icon↔label spacing. */
.repo-link .mi { font-size: 16px; vertical-align: middle; margin-right: 6px; }
.repo-link:hover { color: var(--text); }
/* GitHub link + the (optional) PWA install link sit together, subtly, on one row. */
.connect-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin-top: 14px; }
.connect-links .repo-link { margin-top: 0; }
/* Make the install <button> read as a plain text link, not a pill button. Reset
   the button's family/weight but NOT its size — the .repo-link rule sets 13px, and
   the `font:` shorthand would clobber that back up to the inherited 15px. */
.link-btn { background: none; border: 0; padding: 0; font-family: inherit; font-weight: inherit; line-height: inherit; cursor: pointer; }
.connect-actions { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 16px; }
.status-line { text-align: left; }

/* About / FAQ popup — reuses .backdrop/.dialog, but with a fixed header and its
   own scrolling body so the long copy never overflows the viewport. The content
   is always in the DOM (just hidden), so it stays indexable. */
/* `.dialog.info-dialog` (specificity 0,2,0) so these beat the base `.dialog`
   rule, which is defined LATER in the file and would otherwise win max-width /
   padding / gap at equal specificity — that override was silently forcing 420px
   width + 22px padding + a 12px head/body gap (the "narrow + huge top" bug). */
.dialog.info-dialog { max-width: 640px; max-height: 82vh; padding: 0; gap: 0; overflow: hidden; }
/* Uniform 24px horizontal inset on the header and body so the title and copy
   share one left edge; 16px above and below the divider keeps it balanced. */
.info-dialog-head {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 16px 16px 24px;
  border-bottom: 1px solid var(--outline-variant);
}
.info-dialog-head h2 { flex: 1; font-size: 18px; line-height: 1.3; }
.info-dialog-head .iconbtn { margin: -8px -8px -8px 0; }   /* pull ✕ to the corner without shrinking its hit area */
.info-dialog-body {
  overflow-y: auto; padding: 20px 24px 24px;
  /* slim dark scrollbar to match the UI (not the light native one) */
  scrollbar-width: thin; scrollbar-color: var(--outline-variant) transparent;
}
.info-dialog-body::-webkit-scrollbar { width: 8px; }
.info-dialog-body::-webkit-scrollbar-track { background: transparent; }
.info-dialog-body::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 8px; }
.info-dialog-body::-webkit-scrollbar-thumb:hover { background: var(--outline); }
.info-dialog-body h3 { font-size: 14px; margin: 20px 0 8px; }
.info-dialog-body p { margin: 0 0 12px; color: var(--muted); line-height: 1.6; }
.info-dialog-body > *:first-child { margin-top: 0; }
.info-dialog-body b { color: var(--text); font-weight: 500; }
.info-list { margin: 0 0 12px; padding-left: 20px; color: var(--muted); line-height: 1.6; }
.info-list li { margin-bottom: 4px; }
.faq h4 { font-size: 14px; font-weight: 700; color: var(--text); margin: 16px 0 4px; }
.faq p { margin: 0 0 6px; }
.info-foot { font-size: 12px; line-height: 1.5; margin-top: 20px; }

/* Connecting screen --------------------------------------------------------- */
.center-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; min-height: 100dvh; text-align: center;
}
.spinner {
  /* A faithful Material indeterminate CircularProgressIndicator — same as the
     desktop ft.ProgressRing (48px, 4px stroke, no track). Two un-synced
     animations: a constant rotation plus a stroke-dash sweep that grows the arc
     toward ~270° and shrinks it back. That interplay is the signature Material
     motion. A stroked path has no sharp radial edges, so nothing flickers. */
  width: 48px; height: 48px;
  animation: spinner-rotate 2s linear infinite;
}
.spinner-arc {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  animation: spinner-dash 1.5s ease-in-out infinite;
}
@keyframes spinner-rotate { 100% { transform: rotate(360deg); } }
@keyframes spinner-dash {
  0%   { stroke-dasharray: 1, 150;  stroke-dashoffset: 0; }
  50%  { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
  100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}
.connecting-text h2 { font-size: 20px; margin-bottom: 6px; }

/* Volume / sub rows --------------------------------------------------------- */
.vol-row { display: flex; align-items: center; gap: 8px; }
.vol-row .slider { flex: 1; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sub-level { padding: 8px 16px; }
.sub-level .row { margin-bottom: 4px; }

/* Input grid (3 × 2 tiles) -------------------------------------------------- */
.input-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.input-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px;
  border: 0; border-radius: 12px;
  background: transparent; color: var(--text);
  font: inherit; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.input-tile .mi { font-size: 28px; }
.input-tile span:last-child { font-size: 13px; }
.input-tile:hover { background: rgba(255, 255, 255, 0.05); }
.input-tile.active { background: var(--active-tile); color: var(--primary); }
.input-tile.active .mi { color: var(--primary); }

/* Transport ----------------------------------------------------------------- */
.transport { display: flex; align-items: center; justify-content: center; gap: 18px; }

/* Equalizer ----------------------------------------------------------------- */
.eq-top { display: flex; align-items: center; gap: 12px; }
.eq-top .select { flex: 1; }
.eq-bands { display: flex; justify-content: space-around; padding-top: 16px; }
.eq-band { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.eq-band span { font-size: 12px; color: var(--text); }

/* Collapsible list header (Audio Adjustments) + Settings entry -------------- */
.list-head {
  display: flex; align-items: center; gap: 16px; width: 100%;
  padding: 14px 16px; border: 0; background: transparent; color: var(--text);
  font: inherit; cursor: pointer; transition: background 0.15s;
}
.list-head:hover { background: rgba(255, 255, 255, 0.05); }
.list-head-title { flex: 1; text-align: left; font-size: 16px; font-weight: 700; }
.list-head .mi { font-size: 20px; }
.chevron { transition: transform 0.2s; }
.chevron.collapsed { transform: rotate(180deg); }
.as-card { background: var(--card); border-radius: var(--radius); margin-bottom: 12px; }

.reveal { overflow: hidden; max-height: 500px; transition: max-height 0.22s ease-in-out; }
.reveal.collapsed { max-height: 0; }

/* List items (settings rows, adjustment rows, about rows) ------------------- */
.list-item {
  display: flex; align-items: center; gap: 16px; width: 100%;
  padding: 12px 16px; border: 0; background: transparent; color: var(--text);
  font: inherit; text-align: left; text-decoration: none;
}
.list-item .mi { font-size: 20px; flex: none; }
.list-item.ink { cursor: pointer; transition: background 0.15s; }
.list-item.ink:hover { background: rgba(255, 255, 255, 0.05); }
.list-text { flex: 1; min-width: 0; }
.list-label { font-size: 15px; }
.list-desc { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.trailing { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.list-item.danger .mi,
.list-item.danger .list-label { color: var(--error); }

/* disabled subwoofer group (no sub detected): uniform 38% Material dim */
.group.disabled { opacity: 0.38; pointer-events: none; }

/* Switch (Material 3) ------------------------------------------------------- */
.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: 52px; height: 32px; border-radius: 999px;
  background: transparent; border: 2px solid var(--outline);
  cursor: pointer; transition: background 0.18s, border-color 0.18s;
}
.switch::after {
  content: ""; position: absolute; top: 50%; left: 8px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--outline); transform: translateY(-50%);
  box-shadow: 0 0 0 0 transparent;
  transition: left 0.18s, width 0.18s, height 0.18s, background 0.18s, box-shadow 0.18s;
}
.switch:checked { background: var(--primary); border-color: var(--primary); }
.switch:checked::after { left: 24px; width: 24px; height: 24px; background: #fff; }
/* M3 state layer: a translucent halo grows around the thumb on hover/press. */
.switch:hover::after { box-shadow: 0 0 0 8px color-mix(in srgb, var(--on-surface, #e8eaed) 8%, transparent); }
.switch:active::after { box-shadow: 0 0 0 10px color-mix(in srgb, var(--on-surface, #e8eaed) 12%, transparent); }
.switch:checked:hover::after { box-shadow: 0 0 0 8px color-mix(in srgb, var(--primary) 14%, transparent); }
.switch:checked:active::after { box-shadow: 0 0 0 10px color-mix(in srgb, var(--primary) 20%, transparent); }

/* Sliders (horizontal) — blue fill via the --p variable, set in JS ---------- */
.slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; background: transparent; cursor: pointer;
  --p: 0%;
}
.slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--primary) var(--p), var(--outline-variant) var(--p));
}
/* 20px thumb (Flutter's default Material slider) with a subtle elevation shadow;
   a translucent "overlay" halo grows around it on hover/press, like Flet. */
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; margin-top: -7px;
  width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: box-shadow 0.15s;
}
.slider:hover::-webkit-slider-thumb {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 0 0 8px color-mix(in srgb, var(--primary) 14%, transparent);
}
.slider:active::-webkit-slider-thumb {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 0 0 10px color-mix(in srgb, var(--primary) 22%, transparent);
}
.slider::-moz-range-track { height: 6px; border-radius: 999px; background: var(--outline-variant); }
.slider::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--primary); }
.slider::-moz-range-thumb {
  width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: box-shadow 0.15s;
}
.slider:hover::-moz-range-thumb {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 0 0 8px color-mix(in srgb, var(--primary) 14%, transparent);
}
.slider:active::-moz-range-thumb {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 0 0 10px color-mix(in srgb, var(--primary) 22%, transparent);
}

/* Sliders (vertical EQ bands) ---------------------------------------------- */
.vslider {
  -webkit-appearance: none; appearance: none;
  writing-mode: vertical-lr; direction: rtl;
  width: 18px; height: 170px; background: transparent; cursor: pointer;
  --p: 0%;
}
.vslider::-webkit-slider-runnable-track {
  width: 6px; border-radius: 999px;
  background: linear-gradient(to top, var(--primary) var(--p), var(--outline-variant) var(--p));
}
/* 22px thumb with a drop shadow, matching the desktop's custom VSlider (which
   has no overlay halo — so neither does this one). */
.vslider::-webkit-slider-thumb {
  -webkit-appearance: none; margin-left: -8px;
  width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--primary);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}
.vslider::-moz-range-track { width: 6px; border-radius: 999px; background: var(--outline-variant); }
.vslider::-moz-range-progress { width: 6px; border-radius: 999px; background: var(--primary); }
.vslider::-moz-range-thumb {
  width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--primary);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

/* Select / fields ----------------------------------------------------------- */
.select {
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--outline); border-radius: 8px;
  padding: 12px 36px 12px 14px; font: inherit; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='%23c4c7c5'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat; background-position: right 8px center;
}
.select:focus { outline: none; border-color: var(--primary); }

/* Speaker placement (Material 3 segmented button) --------------------------- */
.placement { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.segmented {
  display: flex; align-self: center; max-width: 100%;
  border: 1px solid var(--outline); border-radius: 999px; overflow: hidden;
}
.segment {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 0; border-right: 1px solid var(--outline);
  background: transparent; color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.segment:last-child { border-right: 0; }
.segment .mi { font-size: 18px; }
.segment:hover { background: rgba(255, 255, 255, 0.06); }
.segment.active { background: var(--active-tile); color: var(--primary); }
.segment.active .mi { color: var(--primary); }
.placement-hint { font-size: 11px; line-height: 1.4; }

/* Material ink ripple + slider value indicator ------------------------------ */
/* Flutter paints an InkWell ripple on every tappable surface; reproduce it with
   an expanding circle spawned at the press point (see attachRipples in app.js).
   The hosts must clip it and establish a positioning context. */
.input-tile, .btn, .iconbtn, .list-item.ink, .list-head, .segment {
  position: relative;
  overflow: hidden;
}
.ripple {
  position: absolute; border-radius: 50%;
  background: currentColor; opacity: 0.16;
  transform: scale(0); pointer-events: none;
  animation: ripple-expand 0.5s ease-out;
}
@keyframes ripple-expand { to { transform: scale(1); opacity: 0; } }

/* The value bubble that rides a horizontal slider's thumb while dragging — the
   web counterpart of the desktop Flet slider's `label=` indicator. */
.slider-bubble {
  position: fixed; z-index: 25; pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  background: var(--primary); color: var(--on-primary);
  /* weight 500 = Flutter's default value-indicator (labelMedium), not bold */
  font-size: 12px; font-weight: 500; line-height: 1;
  padding: 6px 10px; border-radius: 10px; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Banners / toast / dialog -------------------------------------------------- */
.banner { border-radius: 12px; padding: 14px 16px; margin: 12px; }
.banner.inline { margin: 0; }
.banner-error {
  background: color-mix(in srgb, var(--error) 16%, var(--card));
  border: 1px solid var(--error); color: var(--text);
}
.banner code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--card-2); color: var(--text); border: 1px solid var(--outline);
  padding: 10px 18px; border-radius: 999px; z-index: 20; max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.toast.toast-error { border-color: var(--error); }

.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 30; padding: 20px;
}
.dialog {
  background: var(--card); border-radius: var(--radius);
  padding: 22px; max-width: 420px; width: 100%;
  display: flex; flex-direction: column; gap: 12px;
}
.dialog h2 { font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* Responsive ---------------------------------------------------------------- */
@media (max-width: 420px) {
  .input-grid { gap: 6px; }
  /* Tighten the segments so Corner / Wall / Open still fit on narrow phones. */
  .segment { padding: 10px 12px; gap: 6px; }
}
