@font-face {
  font-family: 'Digital7Mono';
  src: url('/static/fonts/digital-7-mono.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #060708;
  --surface: #0e0f11;
  --card: #141518;
  --card-hi: #1c1d21;
  --border: #222428;
  --border-hi: #33363e;
  --amber: #ffb300;
  --amber-dim: #5c3d00;
  --amber-glow: rgba(255, 179, 0, 0.10);
  /* HD accent: hot magenta, the digital counterpoint to analog amber */
  --hd-dim: #5a1040;
  --hd-glow: rgba(255, 46, 143, 0.10);
  --hd-text: #ff2e8f;
  --red: #ff5252;
  --green: #2ee88a;
  --text: #f3f6fc;
  --text-dim: #9aa3b6;
  --text-mid: #bcc4d4;
  --text-muted: #565b6c;
  --font-lcd: 'Digital7Mono', monospace;
  --font-ui: 'Rajdhani', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --t-fast: 0.15s;
  --rule: 1px solid var(--border);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --topbar-h: 54px;
  --vol-h: 34px;
  --display-h: 148px;
  --hd-art-size: 88px;
  --hd-ch-h: 48px;
  --bg-outer: #020304;
  --overlay-strong: rgba(6, 7, 8, 0.97);
  --overlay-mid: rgba(6, 7, 8, 0.82);
  --overlay-soft: rgba(6, 7, 8, 0.7);
  --scale-h: 108px;
  --controls-h: 56px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 999;
  opacity: 0.45
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100svh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden
}

/* SHELVES — pure donor containers, never painted. Opening one puts the app in
   shelf-settings-docked mode and re-parents its header / controls / body into
   the topbar and panel slots; closing hands them back here, out of sight.
   Same treatment as #autogain-shelf. The undocked drop-down was unreachable. */
#sdr-shelf,
#clip-shelf {
  display: none
}

.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px 9px;
  border-bottom: var(--rule)
}

.shelf-title {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.16em;
  color: var(--amber);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px
}

.shelf-close {
  width: 26px;
  height: 26px;
  background: var(--border);
  border: none;
  border-radius: 0;
  color: var(--text-mid);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast)
}

.shelf-close:hover {
  background: var(--border-hi);
  color: var(--text)
}

.shelf-body {
  padding: 12px 16px 14px;
  max-height: calc(100dvh - 52px - 60px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column
}

#sdr-shelf-layout {
  display: flex;
  flex-direction: column;
  gap: 14px
}

#sdr-shelf-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px
}

.sdr-group {
  display: flex;
  flex-direction: column;
  gap: 5px
}

.sdr-group.full {
  grid-column: 1/-1
}

.sdr-group.control-disabled {
  opacity: 0.42;
}

.sdr-group.control-disabled .lo-sub,
.sdr-group.control-disabled .sdr-label,
.stereo-mode-switch.control-disabled {
  color: var(--text-muted);
}

.stereo-mode-switch.control-disabled,
.stereo-mode-switch.control-disabled .stereo-mode-btn {
  cursor: not-allowed;
}

.hidden-group {
  display: none
}

.hidden-group-bordered {
  border-top: var(--rule);
  padding-top: 12px;
  margin-top: 2px
}

.sdr-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.13em;
  color: var(--text-mid);
  text-transform: uppercase;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: space-between
}

.sdr-label-tight {
  margin-bottom: 5px
}

.sdr-label-section {
  margin-bottom: 8px
}

.sdr-label-compact {
  margin-bottom: 4px
}

.sdr-label span {
  color: var(--amber);
  font-weight: 400;
  letter-spacing: 0.02em
}

.sdr-label .lo-val {
  color: var(--amber)
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  background: transparent;
  border-radius: 0;
  margin: 0;
  padding: 0;
  outline: none
}

input[type=range]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--border);
  border-radius: 0
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  margin-top: -5.5px;
}

input[type=range]::-moz-range-track {
  height: 2px;
  background: var(--border);
  border-radius: 0
}

input[type=range]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--amber);
  border: none;
  cursor: pointer
}

input[type=range]::-moz-range-progress {
  height: 2px;
  background: var(--border);
  border-radius: 0
}

.sdr-select {
  background: var(--surface);
  border: var(--rule);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 0;
  outline: none;
  cursor: pointer;
  width: 100%
}

/* Button base — every mono instrument button starts from this recipe */
.src-btn,
.sdr-action-btn,
.scan-cancel,
.hd-ch-btn,
.sca-band-btn,
.si-hd-ch {
  font-family: var(--font-mono);
  background: var(--surface);
  border: var(--rule);
  border-radius: 0;
  color: var(--text-dim);
  cursor: pointer
}

.src-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  padding: 10px 12px;
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--t-fast);
  justify-content: center
}

.sdr-select:focus {
  border-color: var(--amber)
}

.sdr-inline-input {
  width: 100%;
  background: var(--surface);
  border: var(--rule);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 6px 8px;
  border-radius: 0;
  outline: none
}

.sdr-action-row {
  display: flex;
  gap: 6px
}

.sdr-action-row-tight {
  gap: 7px
}

.sdr-action-row-section {
  margin-bottom: 8px
}

.sdr-action-btn {
  flex: 1;
  padding: 9px 6px;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--t-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px
}

.sdr-action-btn-primary {
  background: var(--hd-glow);
  border-color: var(--hd-dim);
  color: var(--hd-text);
  gap: 6px
}

.clip-actions-row {
  gap: 8px;
  margin-top: 4px
}

.clip-action-cancel {
  padding: 10px 8px
}

.clip-action-save {
  flex: 2;
  padding: 10px 8px
}

.src-options-wrap {
  height: 80px;
  position: relative;
  overflow: hidden
}

.src-options-panel {
  position: absolute;
  inset: 0
}

.hidden-panel {
  display: none
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between
}

.toggle {
  position: relative;
  width: 34px;
  height: 18px
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.2s
}

.toggle input:checked+.toggle-track {
  background: var(--amber-dim)
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #555;
  border-radius: 0;
  transition: transform 0.2s, background 0.2s
}

.toggle input:checked+.toggle-track::after {
  transform: translateX(16px);
  background: var(--amber)
}

.toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
  font-family: var(--font-mono);
  letter-spacing: 0.04em
}

.stereo-mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  border: var(--rule);
  background: var(--border);
}

.stereo-mode-btn {
  appearance: none;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 9px 6px;
  text-transform: uppercase;
}

.stereo-mode-btn:disabled {
  color: var(--text-muted);
}

.stereo-mode-btn:disabled.active {
  background: var(--border);
  color: var(--text-dim);
  box-shadow: none;
}

.lo-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
  letter-spacing: 0.02em;
  line-height: 1.6
}

.lo-sub-tight {
  margin-top: 5px
}

/* SCAN OVERLAY */
#scan-overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-strong);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s
}

#scan-overlay.active {
  opacity: 1;
  pointer-events: all
}

#autogain-shelf {
  display: none
}

#autogain-shelf-body {
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 260px;
  text-align: center
}

.scan-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim)
}

.scan-freq-big {
  font-family: var(--font-lcd);
  font-size: 28px;
  color: var(--amber);
  letter-spacing: 0.03em
}

.scan-unit {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--amber-dim);
  letter-spacing: 0.1em;
  text-align: center;
  margin-top: 2px
}

.scan-bar-wrap {
  width: 240px
}

.scan-bar-track {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 0;
  overflow: hidden
}

.scan-bar-fill {
  height: 100%;
  background: var(--amber);
  border-radius: 0;
  width: 0%;
  transition: width 0.1s linear
}

.scan-found-row {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--green)
}

.scan-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  max-width: 280px
}

.scan-badge {
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 2px 7px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 0;
  color: var(--text-mid)
}

.scan-cancel {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 7px 18px;
  margin-top: 4px
}

.scan-cancel:hover {
  border-color: var(--border-hi);
  color: var(--text)
}

.scan-confirm {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--green);
  background: rgba(46, 232, 138, 0.12);
  border: 1px solid rgba(46, 232, 138, 0.45);
  padding: 9px 22px;
  border-radius: 0;
  cursor: pointer;
  margin-top: 4px;
  display: none
}

.scan-confirm:hover {
  border-color: var(--green);
  color: var(--text)
}

#autogain-shelf-body.confirming .scan-confirm {
  display: block
}

#autogain-shelf-body.confirming .scan-bar-wrap {
  display: none
}

/* MAIN FIXED REGIONS */
#main {
  display: flex;
  flex-direction: column;
  height: 100%
}

#topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: var(--rule);
  position: relative;
  perspective: 900px
}

#topbar-left,
.topbar-right {
  transition: opacity 0.18s ease, transform 0.28s var(--ease-out)
}

#topbar-shelf-header-slot {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  pointer-events: none;
  opacity: 0;
  transform: rotateX(-82deg) translateY(-12px);
  transform-origin: top center;
  transition: opacity 0.18s ease, transform 0.42s cubic-bezier(0.18, 0.9, 0.2, 1.12)
}

#app.shelf-settings-docked #topbar-left,
#app.shelf-settings-docked .topbar-right {
  opacity: 0;
  transform: rotateX(32deg) translateY(8px);
  pointer-events: none
}

#app.shelf-settings-docked #topbar-shelf-header-slot {
  opacity: 1;
  transform: rotateX(0deg) translateY(0);
  pointer-events: auto
}

#topbar-shelf-header-slot>.shelf-header {
  flex: 1;
  padding: 0 20px;
  border-bottom: none;
  background: transparent
}

.app-logo {
  position: relative;
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 1;
  letter-spacing: 0.18em;
  white-space: nowrap;
  background: linear-gradient(45deg, #ff9800 0%, #ff4d2e 30%, #d0287a 58%, #7a2880 78%, #2a2040 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
  transition: opacity 0.42s ease, filter 0.42s ease
}

.app-logo::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  display: block;
  background: linear-gradient(135deg, #94a3b8 0%, #6f8097 34%, #536276 68%, #3d4958 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
  opacity: 0;
  filter: saturate(0.75) brightness(0.88);
  transition: opacity 0.42s ease, filter 0.42s ease;
  pointer-events: none
}

#app.server-off .app-logo,
#app.client-paused .app-logo {
  opacity: 0.16;
  filter: saturate(0.55) brightness(0.78)
}

#app.server-off .app-logo::after,
#app.client-paused .app-logo::after {
  opacity: 1;
  filter: saturate(0.9) brightness(1)
}

.topbar-right {
  display: flex;
  gap: 8px;
  align-items: center
}

/* Monochrome SVG icon driven by a file mask so it inherits currentColor
   (active/amber states tint it just like the old inline strokes did).
   Usage: <span class="app-icon" style="--icon:url(/static/icons/x.svg);width:15px;height:15px"></span> */
.app-icon {
  display: inline-block;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: var(--icon);
  mask-image: var(--icon);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain
}

.icon-btn,
#power-btn {
  width: 34px;
  height: 34px;
  border: var(--rule);
  background: var(--surface);
  border-radius: 0;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  flex: 0 0 auto;
  transition: all var(--t-fast)
}

.icon-btn:hover,
#power-btn:hover {
  border-color: var(--border-hi);
  color: var(--text)
}

/* ACTIVE STATES — one amber recipe for analog/selected, one magenta for HD */
.icon-btn.active-btn,
#power-btn.pwr-on,
.src-btn.active,
.stereo-mode-btn.active,
.hd-ch-btn.analog-btn.active,
.sca-band-btn.active {
  border-color: var(--amber-dim);
  color: var(--amber);
  background: var(--amber-glow)
}

.scan-badge.hd,
.hd-ch-btn.active,
.hd-ch-btn.analog-btn.hd1-active,
.si-hd-ch.active {
  border-color: var(--hd-dim);
  color: var(--hd-text);
  background: var(--hd-glow)
}

#power-btn.pwr-on:hover {
  background: rgba(255, 179, 0, 0.14)
}

#power-btn.pwr-pending {
  transform: scale(0.96);
  opacity: 0.84
}

#power-btn.pwr-pending::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 0;
  border: 1px solid currentColor;
  opacity: 0.35;
  animation: power-pulse 0.9s ease-out infinite
}

@keyframes power-pulse {
  from {
    transform: scale(0.92);
    opacity: 0.38
  }

  to {
    transform: scale(1.08);
    opacity: 0
  }
}

/* FIRST-TAP PROMPT — power button is the autoplay-unlock affordance until
   audio has started once this session */
#power-btn.pwr-prompt {
  border-color: var(--amber-dim);
  color: var(--amber)
}

#power-btn.pwr-prompt::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 0;
  border: 1px solid currentColor;
  animation: power-pulse 1.6s ease-out infinite
}

/* AUDIO ERROR BANNER — transient transport/playback failures */
#audio-error-banner {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--red);
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer
}

#audio-error-banner[hidden] {
  display: none
}

/* Single-line truncation, one recipe for every metadata readout */
#audio-error-text,
#rds-rt-big,
#rds-rt-sub,
.hd-title,
.hd-artist,
.hd-album,
.hd-stat-label,
.hd-stat-val {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

/* VOLUME ROW */
#vol-row {
  height: var(--vol-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: var(--rule);
  background: var(--surface)
}

.vol-icon {
  color: var(--text-dim);
  flex-shrink: 0;
  width: 20px;
  text-align: center
}

#vol-w1,
#vol-w2 {
  transition: opacity 0.25s ease, stroke-dashoffset 0.25s ease
}

#vol-w1.hidden,
#vol-w2.hidden {
  opacity: 0
}

input[type=range].vol-slider {
  /* Tall element = large touch target; the visual track stays thin because the
     runnable-track and thumb are centered within this height by the browser. */
  height: 30px;
  flex: 1
}

input[type=range].vol-slider::-webkit-slider-thumb {
  width: 14px;
  height: 14px
}

/* UNIFIED DISPLAY — fixed height so layout never shifts on RDS/HD toggle.
   Height tracks viewport to keep HD content snug with no gap. */
#display-section {
  height: var(--display-h);
  min-height: var(--display-h);
  flex-shrink: 0;
  position: relative;
  border-bottom: var(--rule);
  overflow: hidden;
  background: var(--surface)
}

/* frequency chip — always visible, bottom-right */
#freq-chip {
  position: absolute;
  bottom: 8px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--overlay-soft);
  padding: 0 6px 3px 0;
  border-radius: 0;
  border: var(--rule)
}

#freq-mhz {
  font-family: var(--font-lcd);
  font-size: 36px;
  color: var(--amber);
  letter-spacing: 0;
  line-height: 1;
  position: relative;
  display: inline-block;
  width: 5ch;
  text-align: right;
  cursor: ew-resize
}

#freq-mhz::before {
  content: attr(data-ghost);
  position: absolute;
  inset: 0;
  font: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  text-align: inherit;
  color: rgba(255, 179, 0, 0.14);
  pointer-events: none
}

.freq-unit-sm {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--amber-dim);
  letter-spacing: 0.12em;
  line-height: 1;
  margin-top: 3px
}

/* RDS MODE — shown when no HD */
#rds-mode {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 8px 16px 10px;
  transition: opacity 0.35s
}

#rds-mode.hidden {
  opacity: 0;
  pointer-events: none
}

.rds-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap
}

.rds-ps-small {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--text-dim);
  text-transform: uppercase
}

.rds-ps-small:empty {
  display: none
}

.status-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 3px 7px;
  border-radius: 0;
  border: 1px solid;
  display: inline-flex;
  align-items: center;
  text-transform: uppercase;
  margin: 0
}

.status-pill[hidden] {
  display: none !important;
}

.pill-stereo {
  color: var(--green);
  border-color: rgba(46, 232, 138, 0.3);
  background: rgba(46, 232, 138, 0.05)
}

.pill-pty {
  color: var(--text-dim);
  border-color: var(--border);
  background: transparent
}

.pill-tp {
  color: #f5c542;
  border-color: rgba(245, 197, 66, 0.3);
  background: rgba(245, 197, 66, 0.05)
}

.pill-hd-ready {
  color: var(--green);
  border-color: rgba(46, 232, 138, 0.3);
  background: rgba(46, 232, 138, 0.05);
  cursor: pointer
}

#rds-rt-big {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.16
}

#rds-rt-big.scrolling,
#rds-rt-sub.scrolling,
.hd-title.scrolling,
.hd-artist.scrolling,
.hd-album.scrolling {
  overflow: hidden;
  text-overflow: clip
}

.scrolling .scroll-track {
  display: inline-block;
  white-space: nowrap;
  animation: marquee 14s linear infinite
}

.scroll-seg {
  display: inline-block;
  padding-right: 40px
}

#rds-rt-sub {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 300;
  font-style: italic;
  color: var(--text-dim);
  margin-top: 5px
}

@keyframes marquee {
  0% {
    transform: translateX(0)
  }

  100% {
    transform: translateX(-50%)
  }
}

/* HD MODE — shown when HD lock acquired */
#hd-mode {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
  padding: 8px 12px 8px;
  justify-content: flex-start
}

#hd-mode.visible {
  opacity: 1;
  pointer-events: all
}

.hd-art {
  width: var(--hd-art-size);
  min-width: var(--hd-art-size);
  max-width: var(--hd-art-size);
  height: var(--hd-art-size);
  object-fit: cover;
  display: block;
  border-radius: 0;
  border: none;
  background: transparent;
  flex-shrink: 0
}

.hd-art.hidden {
  display: none
}

.hd-meta {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 0;
  overflow: hidden;
  min-height: 0;
  flex: 1 1 auto;
  margin-top: 42px
}

.hd-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  flex: 1 1 auto;
  padding-top: 0;
  overflow: hidden
}

.hd-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text);
  line-height: 1.05;
  min-height: 0
}

.hd-artist {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-top: 0;
  line-height: 1.02;
  min-height: 0
}

.hd-album {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 0;
  line-height: 1.05;
  min-height: 0
}

.hd-stats {
  display: flex;
  gap: 12px;
  padding: 0;
  background: transparent;
  flex: 0 0 auto;
  position: absolute;
  top: 10px;
  left: 14px;
  right: 14px;
  min-height: 32px;
  align-items: flex-start;
  z-index: 2
}

.hd-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden
}

.hd-stat-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase
}

.hd-stat-val {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--hd-text);
  letter-spacing: 0.04em
}

/* HD CHANNEL ROW */
#hd-ch-row {
  height: var(--hd-ch-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: var(--rule);
  background: var(--card);
  overflow: hidden
}

.hd-ch-btns {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none
}

.hd-ch-btns::-webkit-scrollbar {
  display: none;
}

.hd-ch-btn {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 9px 8px;
  transition: all var(--t-fast);
  flex: 1;
  min-height: 36px;
  white-space: nowrap
}

.hd-ch-btn.analog-btn.escape-btn {
  margin-left: auto;
}

#sca-btns {
  display: none;
  gap: 5px;
  margin-left: auto;
  flex-shrink: 0
}

#sca-btns.sca-visible {
  display: flex
}

.sca-band-btn {
  font-size: 9px;
  letter-spacing: 0.1em;
  padding: 5px 9px;
  transition: all var(--t-fast);
  white-space: nowrap
}

#tuning-section {
  height: var(--scale-h);
  flex-shrink: 0;
  position: relative;
  border-bottom: var(--rule);
  background: var(--surface);
  overflow: hidden
}

#tuning-section canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  height: 100%;
  z-index: 1
}

#tuning-waterfall-canvas,
#tuning-static-canvas,
#tuning-overlay-canvas {
  pointer-events: none
}

#tuning-waterfall-canvas,
#tuning-static-canvas {
  transform: translate3d(0, 0, 0);
  transform-origin: 0 0;
  will-change: transform
}

#tuning-waterfall-canvas {
  z-index: 1
}

#tuning-overlay-canvas {
  transform: translate3d(0, 0, 0);
  transform-origin: 0 0;
  will-change: transform;
  width: 100%;
  z-index: 2
}

#tuning-static-canvas {
  z-index: 3
}

#tuning-canvas {
  touch-action: none;
  background: transparent;
  cursor: ew-resize;
  width: 100%;
  z-index: 4
}

#tuning-needle {
  position: absolute;
  bottom: 0;
  height: 30%;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  background: rgba(0, 0, 0, 0.96);
  clip-path: polygon(50% 0%, 82% 100%, 18% 100%);
  pointer-events: none;
  z-index: 5
}

#tuning-needle::before {
  content: '';
  position: absolute;
  inset: 3px 2px -2px 2px;
  background: linear-gradient(180deg,
    rgba(255, 207, 92, 1) 0%,
    rgba(255, 183, 28, 1) 28%,
    rgba(255, 164, 0, 1) 68%,
    rgba(217, 118, 0, 1) 100%);
  clip-path: polygon(50% 8%, 82% 100%, 18% 100%)
}

#tuning-needle::after {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 3px;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.92)
}

#controls-row {
  height: var(--controls-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0;
  border-bottom: var(--rule)
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0;
  background: var(--surface);
  border: var(--rule);
  border-radius: 0;
  cursor: pointer;
  transition: all var(--t-fast);
  flex: 1
}

.ctrl-btn:active {
  background: var(--card)
}

.ctrl-btn.active-ctrl {
  border-color: var(--amber-dim);
  background: var(--amber-glow)
}

.ctrl-icon {
  line-height: 1
}

.ctrl-label {
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase
}

.ctrl-btn.active-ctrl .ctrl-label {
  color: var(--amber)
}

/* LAYOUT — portrait base */
#content-row {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0
}

#tuner-assembly {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  width: 100%
}

#info-col {
  display: flex;
  flex-direction: column;
  flex-shrink: 0
}

#tuner-col {
  display: flex;
  flex-direction: column;
  flex-shrink: 0
}

#station-panel {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0
}

#station-panel-settings-slot {
  display: none;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg)
}

#app.shelf-settings-docked #station-panel-settings-slot {
  display: block
}

#app.shelf-settings-docked .panel-tabs,
#app.shelf-settings-docked #panel-track-wrap {
  display: none
}

#station-panel-settings-slot>#sdr-shelf-controls {
  animation: docked-settings-open 0.28s var(--ease-out) both;
  padding: 16px 14px 20px;
  grid-template-columns: 1fr
}

#station-panel-settings-slot>.shelf-body {
  animation: docked-settings-open 0.28s var(--ease-out) both;
  max-height: none;
  overflow: visible;
  padding: 16px 14px 20px
}

#app.shelf-settings-closing #station-panel-settings-slot>#sdr-shelf-controls,
#app.shelf-settings-closing #station-panel-settings-slot>.shelf-body {
  animation: docked-settings-close 0.18s ease both
}

@keyframes docked-settings-open {
  from {
    opacity: 0;
    transform: translateY(-18px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

@keyframes docked-settings-close {
  from {
    opacity: 1;
    transform: translateY(0)
  }

  to {
    opacity: 0;
    transform: translateY(-18px)
  }
}

.panel-tabs {
  display: flex;
  padding: 0 8px;
  gap: 0;
  border-bottom: var(--rule);
  flex-shrink: 0;
  background: var(--surface);
  position: relative
}

.panel-tab {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 10px 12px;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--t-fast);
  display: flex;
  align-items: center;
  gap: 4px
}

.panel-tab.active {
  color: var(--amber);
  border-bottom-color: var(--amber)
}

.panel-list {
  overflow-y: auto;
  flex: 1
}

.panel-list::-webkit-scrollbar {
  width: 2px
}

.panel-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 0
}

.station-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.1s;
  min-height: 52px;
  border-bottom: var(--rule)
}

.station-item:active {
  background: var(--card-hi)
}

.station-item.active-station .si-freq {
  color: var(--amber)
}

.si-freq {
  font-family: var(--font-lcd);
  font-size: 20px;
  color: var(--text-mid);
  min-width: 58px;
  letter-spacing: 0.04em
}

.si-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden
}

.si-hd-chs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap
}

.si-hd-ch {
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 9px 16px;
  transition: all 0.12s;
  min-height: 40px
}

.si-fav-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 10px 8px;
  transition: color 0.15s;
  flex-shrink: 0;
  display: flex;
  align-items: center
}

.si-fav-btn.active {
  color: var(--amber)
}

/* TOOLTIPS */
.pill-tip {
  position: relative;
  cursor: pointer
}

.tip-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e2028;
  border: 1px solid var(--border-hi);
  border-radius: 0;
  padding: 5px 9px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 500;
  line-height: 1.5
}

.tip-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1e2028
}

.pill-tip.tip-open .tip-bubble {
  opacity: 1
}

/* SWIPEABLE PANEL TRACK */
#panel-track-wrap {
  flex: 1;
  overflow: hidden;
  position: relative
}

#panel-track {
  display: flex;
  width: 400%;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform
}

#panel-track.no-transition {
  transition: none
}

.panel-slide {
  flex: 0 0 25%;
  display: flex;
  flex-direction: column;
  overflow: hidden
}

.tab-indicator {
  position: absolute;
  bottom: 0;
  height: 2px;
  background: var(--amber);
  border-radius: 0;
  pointer-events: none;
  transition: left 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s
}

/* LOT DATA PANEL — CSS */
.lot-map-wrap {
  /* Largest square that fits the panel, regardless of whether the panel is
     wider or taller than it is tall. height:100%+max-width:100% alone breaks
     to a rectangle when the panel is taller than wide (e.g. desktop). */
  width: min(100cqw, 100cqh);
  height: auto;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  align-self: center;
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none
}

[id^="lot-canvas-"] {
  display: block;
  width: 100%;
  height: 100%
}

.lot-map-wrap-radar {
  min-height: 0;
}

#lot-radar-map {
  position: absolute;
  inset: 0;
  z-index: 0;
  touch-action: none;
  background: var(--bg)
}

#lot-radar-map .leaflet-container {
  background: var(--bg) !important;
  touch-action: none !important
}

/* Esri's dark canvas sits around #333; pull it down toward the app
   background so the radar overlay keeps its contrast. */
#lot-radar-map .radar-base-tile {
  filter: brightness(0.68) saturate(0.9);
}

#lot-radar-map .leaflet-control-container {
  display: none;
}

#lot-radar-map .leaflet-pane,
#lot-radar-map .leaflet-top,
#lot-radar-map .leaflet-bottom,
#lot-radar-map .leaflet-control,
#lot-radar-map .leaflet-interactive {
  touch-action: none !important;
}

.lot-legend {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: var(--overlay-mid);
  border: var(--rule);
  border-radius: 0;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px
}

.lot-leg-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 7px;
  color: var(--text-dim);
  letter-spacing: 0.06em
}

.lot-leg-swatch {
  width: 10px;
  height: 6px;
  border-radius: 0;
  flex-shrink: 0
}

.lot-timestamp,
.lot-credit {
  position: absolute;
  left: 8px;
  z-index: 2;
  font-family: var(--font-mono);
  color: var(--text-dim);
  background: var(--overlay-soft)
}

.lot-timestamp {
  bottom: 8px;
  font-size: 8px;
  letter-spacing: 0.06em;
  padding: 2px 6px
}

.lot-credit {
  bottom: 24px;
  pointer-events: none;
  font-size: 7px;
  opacity: 0.7;
  letter-spacing: 0.04em;
  padding: 1px 5px;
}

.lot-map-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--overlay-mid);
  border-bottom: var(--rule);
}

.lot-map-controls input[type=range] {
  flex: 1;
}

#traffic-panel,
#radar-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 0;
  overflow: hidden;
  /* container for the 100cqw/100cqh square sizing of .lot-map-wrap */
  container-type: size;
}

.lot-time-btn {
  border: 1px solid var(--hd-dim);
  background: var(--hd-glow);
  color: var(--hd-text);
  border-radius: 0;
  min-width: 54px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.lot-time-readout {
  min-width: 56px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.lot-no-hd {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 8px;
  padding: 24px
}

.lot-no-hd-icon {
  display: flex;
  justify-content: center;
  opacity: 0.35
}

.lot-no-hd-text {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.06em;
  line-height: 1.8
}

/* LANDSCAPE — two-column: tuner assembly left, panel right */
@media (orientation: landscape) {

  /* App fills the full screen width in landscape */
  #app {
    max-width: 100%
  }

  #content-row {
    flex-direction: row
  }

  /* Left column: fixed width, holds display + vol + ruler + buttons */
  #tuner-assembly {
    width: 50%;
    flex-shrink: 0;
    border-right: var(--rule);
    display: flex;
    flex-direction: column;
    overflow: hidden
  }

  #info-col {
    flex-shrink: 0
  }

  /* Landscape geometry is a token swap, not a ruleset fight */
  :root {
    --display-h: 140px;
    --hd-art-size: 80px;
    --hd-ch-h: 48px
  }

  .hd-meta {
    margin-top: 40px;
  }

  #hd-ch-row {
    flex-shrink: 0
  }

  #tuner-col {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column
  }

  /* Ruler: fixed height in landscape, does NOT stretch */
  #tuning-section {
    flex: 0 0 auto
  }

  #vol-row {
    flex-shrink: 0
  }

  #controls-row {
    flex-shrink: 0
  }

  /* Right column: station panel fills remaining width */
  #station-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden
  }

}

@media(min-width:600px) and (orientation:portrait) {
  #app {
    border-left: var(--rule);
    border-right: var(--rule)
  }

  body {
    background: var(--bg-outer)
  }
}

@media(min-width:900px) and (orientation:landscape) {
  body {
    background: var(--bg-outer)
  }

  #app {
    max-width: 1200px;
    margin: 0 auto;
    border-left: var(--rule);
    border-right: var(--rule)
  }
}
