/*
 * LanClicker — design tokens, shared components and the app shell.
 * Views add their own styles in tvs.css / remote.css / guide.css / setup.css and should build on
 * these tokens and classes. Theme: <html data-theme="dark|light" data-accent="…" data-size="normal|large">.
 */

/* ============================================================== tokens: dark */
:root {
  --accent-rgb: 61, 126, 255;
  --accent-2-rgb: 110, 160, 255;
  --danger-rgb: 255, 92, 108;
  --success-rgb: 48, 209, 140;
  --warning-rgb: 255, 190, 60;

  --bg: #070b16;
  --bg-elev: #0e1424;
  --bg-elev-2: #161d31;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.13);
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.17);
  --text: #eef2fb;
  --text-dim: rgba(226, 232, 246, 0.68);
  --text-faint: rgba(226, 232, 246, 0.42);

  --accent: rgb(var(--accent-rgb));
  --accent-2: rgb(var(--accent-2-rgb));
  --accent-contrast: #ffffff;
  --accent-soft: rgba(var(--accent-rgb), 0.18);
  --accent-text: rgb(var(--accent-2-rgb));
  --accent-glow: rgba(var(--accent-rgb), 0.55);
  --danger: rgb(var(--danger-rgb));
  --success: rgb(var(--success-rgb));
  --warning: rgb(var(--warning-rgb));

  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 24px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.045) inset, 0 10px 28px -8px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 28px 70px -12px rgba(0, 0, 0, 0.7), 0 2px 10px rgba(0, 0, 0, 0.35);

  --topbar-h: 56px;
  --tabbar-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --btn-h: 46px;
  --fs-btn: 15px;
  --remote-scale: 1;

  --ease: cubic-bezier(0.2, 0.9, 0.25, 1);
  --bar-bg: rgba(9, 13, 26, 0.74);
  --sheet-bg: linear-gradient(180deg, #141b30 0%, #0f1528 100%);
  --card-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.062) 0%, rgba(255, 255, 255, 0.03) 100%);
  --input-bg: rgba(0, 0, 0, 0.28);
  --toast-bg: rgba(26, 33, 54, 0.94);
  --switch-off: rgba(255, 255, 255, 0.16);
  --seg-on: rgba(255, 255, 255, 0.14);
  --backdrop: rgba(2, 5, 12, 0.6);
  --app-bg:
    radial-gradient(1100px 640px at 8% -14%, rgba(var(--accent-rgb), 0.2), transparent 62%),
    radial-gradient(900px 560px at 108% 4%, rgba(124, 92, 255, 0.12), transparent 60%),
    radial-gradient(900px 600px at 50% 125%, rgba(var(--accent-rgb), 0.08), transparent 60%),
    linear-gradient(180deg, #0a1020 0%, #070b16 55%, #060912 100%);
}

/* ============================================================= tokens: light */
html[data-theme="light"] {
  --accent-rgb: 37, 99, 235;
  --accent-2-rgb: 59, 130, 246;
  --danger-rgb: 220, 38, 38;
  --success-rgb: 5, 150, 105;
  --warning-rgb: 217, 119, 6;

  --bg: #eef1f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #f6f8fc;
  --surface: #ffffff;
  --surface-2: rgba(15, 23, 42, 0.055);
  --surface-3: rgba(15, 23, 42, 0.09);
  --border: rgba(15, 23, 42, 0.09);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --text-dim: #4b5568;
  --text-faint: #8f9bb0;

  --accent-text: rgb(var(--accent-rgb));
  --accent-soft: rgba(var(--accent-rgb), 0.11);
  --accent-glow: rgba(var(--accent-rgb), 0.38);

  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px -10px rgba(15, 23, 42, 0.16);
  --shadow-lg: 0 30px 70px -16px rgba(15, 23, 42, 0.32), 0 2px 8px rgba(15, 23, 42, 0.08);

  --bar-bg: rgba(246, 248, 252, 0.8);
  --sheet-bg: linear-gradient(180deg, #ffffff 0%, #f8fafd 100%);
  --card-bg: #ffffff;
  --input-bg: #ffffff;
  --toast-bg: rgba(255, 255, 255, 0.96);
  --switch-off: rgba(15, 23, 42, 0.16);
  --seg-on: #ffffff;
  --backdrop: rgba(15, 23, 42, 0.38);
  --app-bg:
    radial-gradient(1100px 640px at 8% -14%, rgba(var(--accent-rgb), 0.11), transparent 62%),
    radial-gradient(900px 560px at 108% 4%, rgba(124, 92, 255, 0.07), transparent 60%),
    linear-gradient(180deg, #f8f9fd 0%, #eef1f7 100%);
}

/* ================================================================== accents */
html[data-accent="purple"] { --accent-rgb: 139, 92, 246; --accent-2-rgb: 178, 150, 255; }
html[data-accent="green"] { --accent-rgb: 16, 168, 112; --accent-2-rgb: 64, 214, 152; }
html[data-accent="orange"] { --accent-rgb: 238, 110, 28; --accent-2-rgb: 255, 156, 84; }
html[data-accent="red"] { --accent-rgb: 234, 62, 82; --accent-2-rgb: 255, 116, 128; }
html[data-accent="teal"] { --accent-rgb: 13, 158, 170; --accent-2-rgb: 56, 212, 214; }
html[data-theme="light"][data-accent="blue"] { --accent-rgb: 37, 99, 235; --accent-2-rgb: 59, 130, 246; }
html[data-theme="light"][data-accent="purple"] { --accent-rgb: 124, 58, 237; --accent-2-rgb: 139, 92, 246; }
html[data-theme="light"][data-accent="green"] { --accent-rgb: 5, 150, 105; --accent-2-rgb: 16, 185, 129; }
html[data-theme="light"][data-accent="orange"] { --accent-rgb: 234, 88, 12; --accent-2-rgb: 249, 115, 22; }
html[data-theme="light"][data-accent="red"] { --accent-rgb: 220, 38, 38; --accent-2-rgb: 239, 68, 68; }
html[data-theme="light"][data-accent="teal"] { --accent-rgb: 13, 148, 136; --accent-2-rgb: 20, 184, 166; }

/* Large buttons (prefs.buttonSize = large). Views scale remote controls with --remote-scale. */
html[data-size="large"] {
  --btn-h: 54px;
  --fs-btn: 17px;
  --remote-scale: 1.18;
}

/* ===================================================================== base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--bg);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html[data-theme="light"] {
  color-scheme: light;
}

body {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

#app {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: var(--app-bg);
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  line-height: 1.2;
  letter-spacing: -0.015em;
}

p {
  margin: 0 0 10px;
}

a {
  color: var(--accent-text);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

::selection {
  background: rgba(var(--accent-rgb), 0.35);
}

.icon {
  display: inline-block;
  flex: none;
  vertical-align: middle;
}

/* Controls: no text selection / callouts / double-tap zoom. */
button,
label,
.btn,
.chip,
.seg > button,
.tab,
.pressable,
.list-item.clickable,
.switch,
.ch-badge {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

input,
textarea,
.input,
.textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Hold-to-repeat controls must not turn into a scroll while held. */
.pressable-repeat {
  touch-action: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

[tabindex="-1"]:focus {
  outline: none;
}

/* ==================================================================== shell */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  padding: var(--safe-top) var(--safe-right) 0 var(--safe-left);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(170%) blur(22px);
  backdrop-filter: saturate(170%) blur(22px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-width: 0;
  height: 44px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex: none;
  box-shadow: 0 6px 16px -4px rgba(67, 56, 202, 0.6);
}

.env-btn,
.tv-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s, border-color 0.15s;
}

.env-btn {
  max-width: 240px;
}

.env-btn > .icon {
  color: var(--text-dim);
}

.env-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tv-chip {
  max-width: 380px;
  padding: 0 14px 0 12px;
  border-radius: 999px;
}

.tv-chip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.tv-chip-ch {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.tv-chip.empty-chip {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: rgba(var(--accent-rgb), 0.35);
}

.env-btn:active,
.tv-chip:active {
  transform: scale(0.97);
  background: var(--surface-3);
}

.tabbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(170%) blur(22px);
  backdrop-filter: saturate(170%) blur(22px);
  border-top: 1px solid var(--border);
}

.tabbar-inner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: var(--tabbar-h);
  max-width: 760px;
  margin: 0 auto;
  padding: 0 6px;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 5px 0 3px;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 0.15s;
}

.tab-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 30px;
  border-radius: 15px;
  transition: background 0.2s, transform 0.15s var(--ease);
}

.tab.on {
  color: var(--accent-text);
}

.tab.on .tab-ic {
  background: var(--accent-soft);
}

.tab:active .tab-ic {
  transform: scale(0.9);
}

.app-main {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Content scrolls underneath the translucent bars. */
.view-host {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: calc(var(--safe-top) + var(--topbar-h)) var(--safe-right) calc(var(--safe-bottom) + var(--tabbar-h)) var(--safe-left);
}

body.chrome-hidden .topbar,
body.chrome-hidden .tabbar {
  display: none;
}

body.chrome-hidden .view-host {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* A view fills the space between the bars; it is a flex column. */
.view {
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 16px 28px;
  animation: lc-view-in 0.22s ease-out both;
}

.view-loading {
  display: flex;
  justify-content: center;
  padding: 72px 0;
}

.view-error {
  width: 100%;
  max-width: 540px;
  margin: 32px auto;
}

.install-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: center;
  max-width: calc(100% - 32px);
  margin: 12px 16px 0;
  padding: 6px 6px 6px 14px;
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  border-radius: 14px;
  background: var(--accent-soft);
  font-size: 14px;
  line-height: 1.35;
}

.install-hint b {
  font-weight: 700;
}

.install-hint-ic {
  display: flex;
  color: var(--accent-text);
}

.install-hint-text {
  flex: 1 1 auto;
  min-width: 0;
}

.env-list .env-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text-dim);
}

.env-list .selected .env-ic {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.env-hint {
  margin: 12px 4px 0;
}

/* ============================================================ view headers */
.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 2px 0 18px;
}

.view-header h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.028em;
}

.view-header .actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.section-title {
  margin: 24px 4px 10px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-title:first-child {
  margin-top: 4px;
}

/* ==================================================================== cards */
.card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

/* Cards stacked directly in a view get breathing room; cards inside grids/stacks use the gap instead. */
.view > .card + .card {
  margin-top: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-header h2,
.card-header h3 {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
}

.card-body {
  padding: 16px;
}

/* ==================================================================== lists */
.list {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
}

.card > .list,
.card-body > .list:only-child {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.card > .list:last-child {
  border-radius: 0 0 var(--radius) var(--radius);
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}

.list-item + .list-item {
  border-top: 1px solid var(--border);
}

.list-item.clickable {
  cursor: pointer;
  transition: background 0.12s;
}

.list-item.clickable:active,
.list-item.clickable.pressed {
  background: var(--surface-2);
}

.list-item.selected {
  background: var(--accent-soft);
}

.list-item:disabled {
  opacity: 0.45;
  cursor: default;
}

.li-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  gap: 1px;
}

.li-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 600;
}

.li-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 13.5px;
}

.li-end {
  display: flex;
  align-items: center;
  flex: none;
  gap: 8px;
  color: var(--text-dim);
}

/* ================================================================== buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: none;
  height: var(--btn-h);
  min-width: var(--btn-h);
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-btn);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.15s, box-shadow 0.2s, border-color 0.15s, opacity 0.15s;
}

.btn:active,
.btn.pressed {
  transform: scale(0.96);
  background: var(--surface-3);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.42;
  cursor: default;
  pointer-events: none;
}

.btn-primary {
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
  color: var(--accent-contrast);
  box-shadow: 0 10px 24px -8px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.btn-primary:active,
.btn-primary.pressed {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent) 100%);
  box-shadow: 0 4px 12px -6px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.btn-danger {
  border-color: transparent;
  background: linear-gradient(180deg, rgba(var(--danger-rgb), 0.92) 0%, rgb(var(--danger-rgb)) 100%);
  color: #ffffff;
  box-shadow: 0 10px 24px -10px rgba(var(--danger-rgb), 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-danger:active,
.btn-danger.pressed {
  background: rgb(var(--danger-rgb));
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-dim);
  box-shadow: none;
}

.btn-ghost:active,
.btn-ghost.pressed {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  height: 36px;
  min-width: 36px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13.5px;
}

.btn-lg {
  height: calc(var(--btn-h) + 10px);
  min-width: calc(var(--btn-h) + 10px);
  padding: 0 24px;
  border-radius: 15px;
  font-size: calc(var(--fs-btn) + 2px);
}

.btn-icon {
  width: var(--btn-h);
  padding: 0;
}

.btn-icon.btn-sm {
  width: 36px;
}

.btn-icon.btn-lg {
  width: calc(var(--btn-h) + 10px);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    background: var(--surface-3);
  }

  .btn-primary:hover {
    background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent-2) 100%);
  }

  .btn-danger:hover {
    background: rgb(var(--danger-rgb));
  }

  .btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
  }

  .list-item.clickable:hover,
  .env-btn:hover,
  .tv-chip:hover {
    background: var(--surface-2);
  }

  .tab:hover {
    color: var(--text-dim);
  }

  .tab.on:hover {
    color: var(--accent-text);
  }
}

/* ==================================================================== forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.label {
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
}

.hint {
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1.45;
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  height: var(--btn-h);
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  outline: none;
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px; /* 16px keeps iOS from zooming in on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: 0.55;
}

.input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

.select {
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.textarea {
  height: auto;
  min-height: 120px;
  padding: 12px 14px;
  line-height: 1.45;
  resize: vertical;
}

/* label.switch > input[type=checkbox] + span.slider */
.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 51px;
  height: 31px;
  vertical-align: middle;
}

.switch input {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch .slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 31px;
  background: var(--switch-off);
  transition: background 0.2s;
}

.switch .slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 1px rgba(0, 0, 0, 0.2);
  transition: transform 0.24s var(--ease);
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.switch input:focus-visible + .slider {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.switch input:disabled + .slider {
  opacity: 0.45;
}

/* Segmented control: .seg > button(.on) */
.seg {
  display: inline-flex;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-2);
}

.seg > button {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--btn-h) - 8px);
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}

.seg > button.on {
  background: var(--seg-on);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}

.seg > button:disabled {
  opacity: 0.45;
}

/* =========================================================== chips, badges */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s var(--ease);
}

.chip:active,
.chip.pressed {
  transform: scale(0.96);
}

.chip.on {
  border-color: rgba(var(--accent-rgb), 0.5);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.badge-danger {
  background: rgba(var(--danger-rgb), 0.16);
  color: var(--danger);
}

.badge-success {
  background: rgba(var(--success-rgb), 0.16);
  color: var(--success);
}

.badge-warning {
  background: rgba(var(--warning-rgb), 0.18);
  color: var(--warning);
}

.kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.3;
}

/* Power dots: .dot.on / .standby / .unknown / .offline */
.dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-faint);
}

.dot.on {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(var(--success-rgb), 0.18), 0 0 10px rgba(var(--success-rgb), 0.6);
}

.dot.standby {
  background: var(--warning);
  box-shadow: 0 0 0 3px rgba(var(--warning-rgb), 0.16);
}

.dot.unknown {
  background: var(--text-faint);
}

.dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(var(--danger-rgb), 0.16);
}

/* Channel tiles: .ch-badge (md) / .ch-badge-sm / .ch-badge-lg; color comes from --ch-color. */
.ch-badge {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 64px;
  height: 44px;
  padding: 0 4px;
  overflow: hidden;
  border-radius: 11px;
  background-color: var(--ch-color, #44506a);
  background-image: linear-gradient(155deg, rgba(255, 255, 255, 0.26) 0%, rgba(255, 255, 255, 0) 52%, rgba(0, 0, 0, 0.2) 100%);
  color: #ffffff;
  line-height: 1.05;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 3px 10px -3px rgba(0, 0, 0, 0.45);
}

.ch-call {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.ch-num {
  font-size: 15px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.ch-badge.no-call .ch-num {
  font-size: 18px;
}

.ch-badge-sm {
  width: 50px;
  height: 34px;
  border-radius: 9px;
}

.ch-badge-sm .ch-call {
  font-size: 9px;
}

.ch-badge-sm .ch-num {
  font-size: 12.5px;
}

.ch-badge-sm.no-call .ch-num {
  font-size: 14px;
}

.ch-badge-lg {
  width: 100px;
  height: 66px;
  border-radius: 16px;
}

.ch-badge-lg .ch-call {
  font-size: 14px;
}

.ch-badge-lg .ch-num {
  font-size: 22px;
}

.ch-badge-lg.no-call .ch-num {
  font-size: 28px;
}

.progress {
  position: relative;
  height: 4px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--surface-3);
}

.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 0.6s var(--ease);
}

/* ============================================================ layout utils */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--grid-min, 280px), 1fr));
  gap: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.wrap {
  flex-wrap: wrap;
}

.spacer {
  flex: 1 1 auto;
  min-width: 0;
}

.muted {
  color: var(--text-dim);
}

.small {
  font-size: 13.5px;
}

.tiny {
  font-size: 11.5px;
}

.center {
  text-align: center;
  justify-content: center;
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accent-text {
  color: var(--accent-text);
}

.hidden {
  display: none !important;
}

/* =========================================================== empty states */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 44px 24px;
  text-align: center;
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  margin-bottom: 16px;
  border-radius: 22px;
  background: var(--accent-soft);
  color: var(--accent-text);
  box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), 0.25), 0 12px 30px -12px var(--accent-glow);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 700;
}

.empty-text {
  max-width: 440px;
  margin: 0;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
}

.empty-actions {
  justify-content: center;
  margin-top: 20px;
}

/* ===================================================== spinner / skeleton */
.spinner {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(127, 140, 170, 0.28);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: lc-spin 0.8s linear infinite;
  vertical-align: middle;
}

.skeleton-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton {
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 40%, var(--surface-2) 60%);
  background-size: 400% 100%;
  animation: lc-shimmer 1.4s ease infinite;
}

/* =========================================================== press state */
.pressable {
  transition: transform 0.1s var(--ease), background 0.12s, box-shadow 0.15s, filter 0.12s;
}

.pressed {
  transform: scale(0.95);
}

/* ================================================================== sheets */
html.sheet-open .app-main {
  overflow: hidden;
}

.sheet-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 0.24s ease;
}

.sheet-backdrop.open {
  opacity: 1;
}

.sheet-backdrop.closing {
  opacity: 0;
  pointer-events: none;
}

.sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100% - var(--safe-top) - 16px);
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: var(--sheet-bg);
  box-shadow: var(--shadow-lg);
  outline: none;
  transform: translateY(100%);
  transition: transform 0.34s var(--ease);
}

.sheet-backdrop.open .sheet {
  transform: none;
}

.sheet-backdrop.closing .sheet {
  transform: translateY(100%);
  transition-duration: 0.26s;
}

.sheet-top {
  flex: none;
  touch-action: none;
}

.sheet-grabber {
  width: 40px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 3px;
  background: var(--text-faint);
  opacity: 0.55;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 12px 6px 20px;
}

.sheet-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 19px;
  font-weight: 750;
}

.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sheet-actions {
  display: flex;
  flex: none;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

.sheet-actions > .btn {
  flex: 1 1 0;
  min-width: 0;
}

@media (min-width: 700px) {
  .sheet-backdrop {
    align-items: center;
    padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px);
  }

  .sheet {
    max-width: 560px;
    max-height: 100%;
    padding-bottom: 0;
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg);
    opacity: 0;
    transform: translateY(14px) scale(0.97);
    transition: transform 0.28s var(--ease), opacity 0.2s ease;
  }

  .sheet.sheet-wide {
    max-width: 860px;
  }

  .sheet-backdrop.open .sheet {
    opacity: 1;
    transform: none;
  }

  .sheet-backdrop.closing .sheet {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    transition-duration: 0.18s;
  }

  .sheet-grabber {
    display: none;
  }

  .sheet-header {
    padding-top: 14px;
  }

  .sheet-actions {
    justify-content: flex-end;
  }

  .sheet-actions > .btn {
    flex: 0 0 auto;
    min-width: 120px;
  }
}

.confirm-msg {
  margin: 0 0 4px;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-line;
}

.prompt-form .field {
  margin-bottom: 6px;
}

.menu-list .menu-ic {
  display: flex;
  color: var(--text-dim);
}

.menu-list .menu-item.danger,
.menu-list .menu-item.danger .menu-ic {
  color: var(--danger);
}

/* ================================================================== toasts */
.toast-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + var(--tabbar-h) + 14px);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}

body.chrome-hidden .toast-wrap {
  bottom: calc(var(--safe-bottom) + 20px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 540px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--toast-bg);
  -webkit-backdrop-filter: saturate(170%) blur(18px);
  backdrop-filter: saturate(170%) blur(18px);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: 15px;
  font-weight: 550;
  line-height: 1.35;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.26s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: none;
}

.toast.leaving {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
}

.toast.bump {
  animation: lc-bump 0.3s var(--ease);
}

.toast .icon {
  color: var(--accent-text);
}

.toast.success .icon {
  color: var(--success);
}

.toast.error {
  border-color: rgba(var(--danger-rgb), 0.38);
}

.toast.error .icon {
  color: var(--danger);
}

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

/* ============================================================ TV chooser */
.tvpick-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 12px;
}

.tvpick-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  flex: none;
}

.tvpick .list + .section-title {
  margin-top: 20px;
}

.check-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: none;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s var(--ease);
}

.tvpick-item.selected .check-circle {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.tvpick.single .check-circle {
  border-color: transparent;
}

.tvpick.single .tvpick-item.selected .check-circle {
  border-color: transparent;
  background: transparent;
  color: var(--accent-text);
}

/* ======================================================= channel chooser */
.cc {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr);
}

.cc-seg {
  display: flex;
  width: 100%;
}

.cc-favs-wrap:empty {
  display: none;
}

.cc-strip-title {
  margin: 0 2px 8px;
}

.cc-favs {
  display: flex;
  gap: 6px;
  margin: 0 -4px;
  padding: 2px 4px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.cc-favs::-webkit-scrollbar {
  display: none;
}

.cc-fav {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: none;
  gap: 5px;
  width: 76px;
  padding: 6px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s, transform 0.12s var(--ease);
}

.cc-fav:active {
  background: var(--surface-2);
  transform: scale(0.96);
}

.cc-fav-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
}

.cc-display {
  margin-bottom: 12px;
  padding: 10px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  text-align: center;
}

.cc-num {
  min-height: 52px;
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  line-height: 52px;
}

.cc-num.placeholder {
  color: var(--text-faint);
  letter-spacing: 0.12em;
}

.cc-hint {
  min-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 14px;
}

.cc-keys {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.cc-key {
  width: 100%;
  height: 58px;
  padding: 0;
  border-radius: 16px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 600;
}

.cc-key-fn {
  color: var(--text-dim);
}

.cc-go {
  margin-top: 12px;
}

.cc-search {
  position: relative;
  margin-bottom: 10px;
}

.cc-search > .icon {
  position: absolute;
  top: 50%;
  left: 13px;
  color: var(--text-faint);
  pointer-events: none;
  transform: translateY(-50%);
}

.cc-search .input {
  padding-left: 40px;
}

.cc-item {
  min-height: 56px;
  padding: 8px 8px 8px 12px;
}

.cc-star {
  color: var(--text-faint);
}

.cc-star.on {
  color: var(--warning);
}

.cc-none {
  padding: 24px 12px;
  color: var(--text-dim);
  text-align: center;
}

.cc-none p {
  margin: 0 0 4px;
}

@media (max-width: 699px) {
  .cc[data-mode="keypad"] .cc-lineup {
    display: none;
  }

  .cc[data-mode="lineup"] .cc-pad {
    display: none;
  }
}

@media (min-width: 700px) {
  .cc {
    grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
    align-items: start;
    gap: 18px 22px;
  }

  .cc-seg {
    display: none;
  }

  .cc-favs-wrap {
    grid-column: 1 / -1;
  }

  .cc-list {
    max-height: 400px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

/* ========================================================== responsive */
@media (min-width: 700px) {
  .view {
    padding: 26px 28px 36px;
  }

  .tab {
    font-size: 11.5px;
  }
}

@media (min-width: 1024px) {
  .view {
    padding: 28px 36px 40px;
  }

  .topbar-inner {
    padding: 0 22px;
  }
}

@media (max-width: 560px) {
  .brand-name {
    display: none;
  }

  .env-btn {
    max-width: 128px;
    padding: 0 10px;
    gap: 6px;
  }

  .env-caret {
    display: none;
  }

  .tv-chip {
    max-width: 190px;
    padding: 0 12px 0 10px;
  }

  .view-header h1 {
    font-size: 26px;
  }
}

@media (max-width: 400px) {
  .topbar-inner {
    gap: 8px;
    padding: 0 12px;
  }

  .tv-chip-ch {
    display: none;
  }

  .env-btn > .icon:first-child {
    display: none;
  }
}

/* ============================================================== animation */
@keyframes lc-view-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes lc-spin {
  to { transform: rotate(360deg); }
}

@keyframes lc-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@keyframes lc-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .spinner {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }

  .skeleton {
    animation: none !important;
  }
}

/* Scrollbars on desktop browsers: thin and quiet. */
@media (hover: hover) and (pointer: fine) {
  .app-main,
  .sheet-body,
  .cc-list {
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
  }
}
