:root {
  --primary: #ff3838;
  --primary-dark: #e02c39;
  --secondary: #0f172a;
  --text: #f1f5f9;
  --background: #020617;
  --panel-bg: #1e293b;
  --graph-bg: #000000;
  --success: #2ed573;
  --btn-bg: transparent;
  --btn-border: rgba(255, 255, 255, 0.75);
  --btn-text: #ffffff;
  --popup-bg: rgba(8, 14, 28, 0.35);
  --rec-bar-bg: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] {
  --primary: #ff3838;
  --primary-dark: #e02c39;
  --secondary: #e2e8f0;
  --text: #0f172a;
  --background: #ffffff;
  --panel-bg: #e9ecef;
  --graph-bg: #ffffff;
  --btn-bg: transparent;
  --btn-border: rgba(0, 0, 0, 0.7);
  --btn-text: #000000;
  --popup-bg: rgba(232, 236, 242, 0.35);
  --rec-bar-bg: rgba(0, 0, 0, 0.08);
}

/* Viewport-scaled base: 1 rem ≈ 16 px at 1080p, grows to 20 px on large/4K screens.
   All layout values use rem so the whole UI scales proportionally. */
html {
  font-size: clamp(14px, 0.9vw, 20px);
}

/* Base styles */
body,
html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--background);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  overflow: hidden;
  transition: all 0.3s ease;
  touch-action: manipulation;
}

/* Fullscreen canvas container */
.canvas-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--graph-bg);
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  /* No background here — WebGL clears to transparent, so the
     container's background-color + grid pattern show through. */
}

/* BPM display — top center */
.overlay-top {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.625rem;
  align-items: center;
  pointer-events: auto;
  white-space: nowrap;
}

/* UDL logo — top left, vertical center tracks BPM bar center (same formula as bottom-right-group) */
.udl-logo {
  position: absolute;
  top: 2.25rem;           /* = overlay-top(1rem) + overlay-bpm-height(2.5rem)/2 */
  transform: translateY(-50%);
  left: 1rem;
  display: block;
  pointer-events: auto;
  z-index: 20;
  line-height: 0;
}

.udl-logo img {
  height: 2.5rem;
  width: auto;
}

.udl-logo .logo-dark         { display: block; }
.udl-logo .logo-light        { display: none;  }
.udl-logo .logo-dark-mobile  { display: none;  }
.udl-logo .logo-light-mobile { display: none;  }
[data-theme="light"] .udl-logo .logo-dark  { display: none;  }
[data-theme="light"] .udl-logo .logo-light { display: block; }

/* Tool buttons grouped at top-right — vertical center tracks BPM bar center */
.bottom-right-group {
  position: absolute;
  top: 2.25rem;           /* = overlay-top(1rem) + overlay-bpm-height(2.5rem)/2 */
  transform: translateY(-50%);
  right: 1rem;
  display: flex;
  gap: 0.625rem;
  align-items: center;
  pointer-events: auto;
  z-index: 20;
}

.bottom-right-group .fullscreen-theme-toggle {
  position: static;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  box-sizing: border-box;
}
.bottom-right-group .fullscreen-theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Disconnect button lives in the top-right group — match tool-button size */
.bottom-right-group .btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  box-sizing: border-box;
}
.bottom-right-group .btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

.overlay-metric {
  color: var(--text);
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.overlay-bpm {
  padding: 0 1rem;
  height: 2.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--btn-text);
  display: flex;
  align-items: center;
  gap: 0.44rem;
  white-space: nowrap;
  border: 2px solid var(--btn-border);
  border-radius: 0.625rem;
  background: transparent;
  box-sizing: border-box;
}

.overlay-bpm span {
  display: inline-block;
  min-width: 4.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.heart-icon {
  width: 1.625rem;
  height: 1.625rem;
  flex-shrink: 0;
  overflow: visible;
}

.heart-icon path {
  fill: transparent;
  stroke: var(--btn-border);
  stroke-width: 2;
  stroke-linejoin: round;
  transition: fill 0.15s ease-out;
}

.heart-icon.beating path {
  fill: var(--primary);
}

/* Fullscreen toggle button */
.fullscreen-btn {
  background: transparent;
  border: 2px solid var(--btn-border);
  color: var(--btn-text);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  transition: all 0.12s;
  box-sizing: border-box;
}

.fullscreen-btn:focus,
.fullscreen-btn:focus-visible {
  outline: none;
}

@media (hover: hover) {
  .fullscreen-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }
}
.fullscreen-btn:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.fullscreen-btn svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0.5;
}

/* Controls overlay — bottom center */
.controls-overlay {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
  align-items: center;
  pointer-events: auto;
  z-index: 25;
  flex-wrap: nowrap;
  justify-content: center;
}

/* === Scrubber minimap (shown when paused) === */
.minimap-wrap {
  position: absolute;
  bottom: 5.5rem;
  left: 0.75rem;
  right: 0.75rem;
  height: 3.125rem;
  pointer-events: auto;
  z-index: 10;
  display: none;
}

.minimap-track {
  position: absolute;
  inset: 0;
  border-radius: 0.375rem;
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--btn-border);
  overflow: hidden;
}

[data-theme="light"] .minimap-track {
  background: rgba(255, 255, 255, 0.22);
}

.minimap-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.minimap-viewport {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.18);
  border-left: 1.5px solid rgba(255, 255, 255, 0.55);
  border-right: 1.5px solid rgba(255, 255, 255, 0.55);
  box-sizing: border-box;
  cursor: grab;
}

[data-theme="light"] .minimap-viewport {
  background: rgba(0, 0, 0, 0.12);
  border-color: rgba(0, 0, 0, 0.45);
}

.minimap-viewport:active { cursor: grabbing; }

.minimap-offset-label {
  position: absolute;
  top: -1.25rem;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text);
  opacity: 0.55;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.minimap-offset-label--left  { left: 0; }
.minimap-offset-label--right { right: 0; }

/* === Recording viewer header === */
.viewer-header {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0;
  height: 2.5rem;
  background: var(--popup-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: none;
  box-shadow: inset 0 0 0 2px var(--btn-border);
  border-radius: 0.625rem;
  padding: 0 0 0 0.875rem;
  z-index: 30;
  pointer-events: auto;
  white-space: nowrap;
  overflow: hidden;
  max-width: calc(100% - 2rem);
}

.viewer-filename {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--btn-text);
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  margin-right: 0.5rem;
}

.viewer-duration {
  font-size: 0.72rem;
  color: var(--btn-text);
  opacity: 0.6;
  margin-right: 0.25rem;
}

.viewer-close-btn {
  border: none !important;
  border-left: 2px solid var(--btn-border) !important;
  border-radius: 0 !important;
  align-self: stretch !important;
  height: auto !important;
  width: 2rem !important;
  flex-shrink: 0;
}

.recording-timer {
  position: absolute;
  bottom: 5.25rem;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--primary);
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  gap: 0.375rem;
  pointer-events: none;
  z-index: 20;
  /* Fixed width so changing digits don't resize the pill */
  width: max-content;
  min-width: 7.5rem;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.recording-dot {
  width: 0.5rem;
  height: 0.5rem;
  background-color: white;
  border-radius: 50%;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%,  50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

/* === Info button & panel === */
.info-btn-wrapper {
  position: relative;
  display: flex;
}

.info-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--btn-border);
  color: var(--btn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  transition: all 0.12s;
  touch-action: manipulation;
  flex-shrink: 0;
  box-sizing: border-box;
}

.info-btn:focus,
.info-btn:focus-visible { outline: none; }

@media (hover: hover) {
  .info-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }
}
.info-btn:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.info-panel {
  position: absolute;
  top: calc(100% + 0.625rem);
  right: 0;
  background: var(--popup-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--btn-border);
  border-radius: 0.625rem;
  padding: 0.75rem 0.875rem;
  min-width: 11.25rem;
  z-index: 500;
  pointer-events: none;
  opacity: 0;
  transform: translateY(0.375rem);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.info-panel.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.info-panel-title {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.info-panel table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.74rem;
  color: var(--text);
}

.info-panel td {
  padding: 0.125rem 0;
}

.info-panel td:first-child {
  opacity: 0.55;
  padding-right: 0.75rem;
  white-space: nowrap;
}

.info-panel td:last-child {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* === Recordings dropup === */
.recordings-dropup {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--popup-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--btn-border);
  border-radius: 0.75rem;
  padding: 0.625rem;
  min-width: 16rem;
  max-height: 9rem;
  overflow: hidden;
  display: none;
  z-index: 500;
  transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Slide just enough to reveal the recording timer pill below (pill ≈ 2rem + 0.5rem gap) */
.recordings-dropup.timer-active {
  bottom: calc(100% + 3rem);
}

.recordings-dropup.open {
  display: block;
}

.recordings-dropup-header {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text);
  opacity: 0.55;
  padding: 0.25rem 0.375rem 0.5rem;
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  max-height: 6rem;
  scrollbar-width: thin;
  scrollbar-color: var(--rec-bar-bg) transparent;
}
.file-list::-webkit-scrollbar { width: 4px; }
.file-list::-webkit-scrollbar-track { background: transparent; }
.file-list::-webkit-scrollbar-thumb { background: var(--rec-bar-bg); border-radius: 2px; }

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0 0 0.625rem;
  background: var(--rec-bar-bg);
  border: 1px solid var(--btn-border);
  margin-bottom: 0.375rem;
  border-radius: 0.5rem;
  overflow: hidden;
  transition: background 0.15s;
}

@media (hover: hover) {
  .file-item:hover { background: rgba(128, 128, 128, 0.16); }
}
.file-item:active { background: rgba(128, 128, 128, 0.16); }

.file-name {
  color: var(--text);
  font-size: 0.8rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: text;
  border-radius: 0.25rem;
  outline: none;
  padding: 0.5rem 0.25rem;
  margin: 0 -0.25rem;
}
.file-name:focus {
  background: rgba(128, 128, 128, 0.15);
  text-overflow: clip;
}

.file-actions {
  display: flex;
  gap: 0;
  align-self: stretch;
  align-items: stretch;
}

.file-action-btn {
  background: transparent;
  border: none;
  border-left: 1.5px solid var(--btn-border);
  color: var(--btn-text);
  width: 2rem;
  height: auto;
  border-radius: 0;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.file-action-btn svg { width: 1rem; height: 1rem; flex-shrink: 0; }

@media (hover: hover) {
  .file-action-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }
}
.file-action-btn:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.file-action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.no-files {
  text-align: center;
  color: var(--text);
  font-size: 0.82rem;
  padding: 1rem;
  opacity: 0.5;
}

/* === Toast notification — pops up above the recordings button === */
.rec-toast {
  position: absolute;
  bottom: calc(100% + 0.625rem);
  left: 50%;
  transform: translateX(-50%) translateY(0.375rem);
  min-width: 13.75rem;
  max-width: 18.75rem;
  background: var(--popup-bg);
  border: 1px solid var(--btn-border);
  border-radius: 0.625rem;
  padding: 0.625rem 0.875rem;
  color: var(--btn-text);
  font-size: 0.82rem;
  line-height: 1.6;
  z-index: 2000;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease,
    visibility 0s linear 0.3s;
  pointer-events: none;
  white-space: nowrap;
}

.rec-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition: opacity 0.3s ease, transform 0.3s ease,
    visibility 0s linear 0s;
}

.rec-toast strong {
  color: var(--btn-text);
  display: block;
  margin-bottom: 0.125rem;
  font-size: 0.88rem;
}

.btn.recording {
  border-color: var(--primary);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

.btn {
  background: transparent;
  border: 2px solid var(--btn-border);
  color: var(--btn-text);
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  position: relative;
  flex-shrink: 0;
}

.btn svg {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

.btn img {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
}

/* SVG files loaded via <img> resolve currentColor as black — dark mode is default so invert by default */
.btn img { filter: invert(1); }
[data-theme="light"] .btn img { filter: none; }

/* Peak marker icon: trimmed viewBox shifts aspect ratio taller; width% controls rendered size */
.btn .icon-peaks { width: 75%; height: auto; }

/* Diagonal slash when peaks are hidden */
.btn.peaks-off::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  height: 2px;
  background: var(--primary);
  transform: translate(-50%, -50%) rotate(45deg);
  pointer-events: none;
  border-radius: 1px;
  z-index: 1;
}

@media (hover: hover) {
  [data-theme="light"] .btn:hover:not(:disabled):not(.recording-locked) img { filter: invert(1); }
  .btn:hover:not(:disabled):not(.recording-locked) {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }
}
.btn:active:not(:disabled):not(.recording-locked) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
[data-theme="light"] .btn:active:not(:disabled):not(.recording-locked) img { filter: invert(1); }

.btn:disabled,
.btn.recording-locked {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Tooltip on the record button during the 12-s lock window.
   Shown only on click/tap via JS .show-tip — fades out after 2 s. */
.btn.recording-locked::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 0.375rem);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  border: 1px solid var(--btn-border);
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 500;
  font-style: normal;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  white-space: nowrap;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 600;
}

.btn.recording-locked.show-tip::after { opacity: 1; }

.btn:focus,
.btn:focus-visible {
  outline: none;
}

/* Center connect/play-pause button — slightly larger than normal btns */
.btn-connect-center {
  width: 3rem;
  height: 3rem;
  border-radius: 0.75rem;
}
.btn-connect-center svg,
.btn-connect-center img {
  width: 1.5rem;
  height: 1.5rem;
}

/* Theme toggle & fullscreen-inside-fullscreen toggle */
.theme-toggle,
.fullscreen-theme-toggle {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--btn-border);
  color: var(--btn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99999;
  transition: all 0.12s;
  touch-action: manipulation;
  box-sizing: border-box;
}

.theme-toggle:focus,
.theme-toggle:focus-visible,
.fullscreen-theme-toggle:focus,
.fullscreen-theme-toggle:focus-visible {
  outline: none;
}

@media (hover: hover) {
  .theme-toggle:hover,
  .fullscreen-theme-toggle:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }
}
.theme-toggle:active,
.fullscreen-theme-toggle:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Neutralize all hover styles on actual touch devices (JS sets this class on first touchstart) */
.is-touch-device .btn:hover:not(:disabled),
.is-touch-device .fullscreen-btn:hover,
.is-touch-device .info-btn:hover,
.is-touch-device .theme-toggle:hover,
.is-touch-device .fullscreen-theme-toggle:hover,
.is-touch-device .file-action-btn:hover,
.is-touch-device .file-item:hover {
  background: transparent !important;
  border-color: var(--btn-border) !important;
  color: var(--btn-text) !important;
  transform: none !important;
}
.is-touch-device [data-theme="light"] .btn:hover:not(:disabled) img {
  filter: none !important;
}

.theme-toggle svg,
.fullscreen-theme-toggle svg {
  width: 1.375rem;
  height: 1.375rem;
}

.theme-icon-moon { display: none; }
[data-theme="light"] .theme-icon-sun { display: none; }
[data-theme="light"] .theme-icon-moon { display: block; }

/* canvas-overlay: covers canvas fully, children position against this */
.canvas-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* responsive layout */

/* portrait phones ≤ 600px */
@media (max-width: 600px) and (orientation: portrait) {

  .overlay-top { top: 0.875rem; }
  /* Logo: compact mobile variant, center = overlay-top(0.875rem) + bpm-height(2rem)/2 = 1.875rem */
  .udl-logo { top: 1.875rem; left: 0.875rem; }
  .udl-logo img { height: 2rem; }
  .udl-logo .logo-dark         { display: none; }
  .udl-logo .logo-dark-mobile  { display: block; }
  [data-theme="light"] .udl-logo .logo-dark-mobile  { display: none; }
  [data-theme="light"] .udl-logo .logo-light        { display: none; }
  [data-theme="light"] .udl-logo .logo-light-mobile { display: block; }

  /* BPM: compact for small screens */
  .overlay-bpm {
    padding: 0 0.625rem;
    height: 2rem;
    font-size: 0.9rem;
    gap: 0.25rem;
  }
  .overlay-bpm span { min-width: 4em; }
  .heart-icon { width: 1.125rem; height: 1.125rem; }

  /* Tool buttons: vertically centered with BPM bar (BPM top 0.875rem + height 2rem / 2 = 1.875rem) */
  .bottom-right-group { top: 1.875rem; right: 0.875rem; gap: 0.375rem; }
  .fullscreen-theme-toggle                     { width: 2rem; height: 2rem; }
  .fullscreen-theme-toggle svg                 { width: 1rem; height: 1rem; }
  .bottom-right-group .fullscreen-theme-toggle     { width: 2rem; height: 2rem; }
  .bottom-right-group .fullscreen-theme-toggle svg { width: 1rem; height: 1rem; }
  .fullscreen-btn              { width: 2rem; height: 2rem; }
  .fullscreen-btn svg          { width: 1rem; height: 1rem; }
  .info-btn                    { width: 2rem; height: 2rem; font-size: 0.82rem; }
  .bottom-right-group .btn     { width: 2rem; height: 2rem; }
  .bottom-right-group .btn svg { width: 1rem; height: 1rem; }

  /* Controls: full-width spread across screen */
  .controls-overlay {
    bottom: 0.875rem;
    left: 0.875rem;
    right: 0.875rem;
    transform: none;
    width: auto;
    justify-content: space-evenly;
    gap: 0;
  }

  /* Bottom control buttons */
  .btn     { width: 2.25rem; height: 2.25rem; }
  .btn svg { width: 1.125rem; height: 1.125rem; }
  .btn img { width: 1.125rem; height: 1.125rem; }

  /* Center connect button */
  .btn-connect-center              { width: 3.25rem; height: 3.25rem; border-radius: 0.625rem; }
  .btn-connect-center svg,
  .btn-connect-center img          { width: 1.625rem; height: 1.625rem; }

  /* Viewer header: sits below the logo/BPM row, matches mobile BPM height */
  .viewer-header   { top: 3.125rem; max-width: calc(100% - 1.75rem); height: 2rem; padding-left: 0.75rem; }
  .viewer-duration { display: none; }
  .viewer-close-btn { width: 2.25rem !important; }

  /* Recording timer + minimap: above tallest button (0.875 + 3.25 + 0.75 = 4.875rem) */
  .recording-timer { bottom: 4.875rem; font-size: 0.82rem; }
  .minimap-wrap    { bottom: 4.875rem; }

  /* Dropup: full-width fixed on narrow screens */
  .recordings-dropup {
    position: fixed;
    bottom: 4.875rem;
    left: 0.625rem;
    right: 0.625rem;
    transform: none;
    min-width: unset;
    max-height: 25vh;
  }
  .recordings-dropup.timer-active { bottom: 7.25rem; }
  .file-list { max-height: calc(25vh - 3.5rem); }

  /* Toast: full-width fixed pill */
  .rec-toast {
    position: fixed;
    bottom: 4.875rem;
    left: 0.75rem;
    right: 0.75rem;
    transform: translateY(0.375rem);
    max-width: none;
    white-space: normal;
  }
  .rec-toast.show { transform: translateY(0); }

  /* Info panel: keep inside viewport */
  .info-panel { right: 0; left: auto; min-width: 10rem; }
}

/* extra-small phones ≤ 360px */
@media (max-width: 360px) and (orientation: portrait) {
  /* Shrink top-group on very narrow screens so it doesn't crowd BPM */
  .bottom-right-group { gap: 0.125rem; }
  .fullscreen-theme-toggle                     { width: 2rem; height: 2rem; }
  .fullscreen-theme-toggle svg                 { width: 1rem; height: 1rem; }
  .bottom-right-group .fullscreen-theme-toggle     { width: 2rem; height: 2rem; }
  .bottom-right-group .fullscreen-theme-toggle svg { width: 1rem; height: 1rem; }
  .fullscreen-btn              { width: 2rem; height: 2rem; }
  .fullscreen-btn svg          { width: 1rem; height: 1rem; }
  .info-btn                    { width: 2rem; height: 2rem; font-size: 0.78rem; }
  .bottom-right-group .btn     { width: 2rem; height: 2rem; }
  .bottom-right-group .btn svg { width: 1rem; height: 1rem; }
  /* Bottom control buttons */
  .btn     { width: 2.125rem; height: 2.125rem; }
  .btn svg { width: 1.0625rem; height: 1.0625rem; }
  .btn img { width: 1.0625rem; height: 1.0625rem; }
  .btn-connect-center { width: 3.125rem; height: 3.125rem; }
  .btn-connect-center svg,
  .btn-connect-center img { width: 1.5rem; height: 1.5rem; }
  /* Recording timer + minimap: above tallest button (0.875 + 3.125 + 0.75 = 4.75rem) */
  .recording-timer { bottom: 4.75rem; }
  .minimap-wrap    { bottom: 4.75rem; }
  .recordings-dropup { bottom: 4.75rem; }
  .recordings-dropup.timer-active { bottom: 7rem; }
  .rec-toast { bottom: 4.75rem; }
  .overlay-bpm  { font-size: 0.82rem; padding: 0 0.375rem; height: 2rem; }
  .overlay-bpm span { min-width: 3.8em; }
  .udl-logo img { height: 2rem; }
  /* Viewer header: tighter on very narrow screens */
  .viewer-header   { padding-left: 0.5rem; }
  .viewer-filename { font-size: 0.7rem; }
  .viewer-close-btn { width: 1.875rem !important; }
}

/* landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
  /* Logo center = overlay-top(0.5rem) + bpm-height(2rem)/2 = 1.5rem */
  .udl-logo     { top: 1.5rem; left: 0.5rem; }
  .udl-logo img { height: 2rem; }

  .overlay-top  { top: 0.5rem; }
  .overlay-bpm  { height: 2rem; font-size: 0.82rem; padding: 0 0.5rem; gap: 0.25rem; }
  .overlay-bpm span { min-width: 3.8em; }
  .heart-icon   { width: 1.125rem; height: 1.125rem; }

  .controls-overlay { bottom: 0.5rem; gap: 0.375rem; }
  .btn          { width: 2rem; height: 2rem; }
  .btn svg      { width: 0.9375rem; height: 0.9375rem; }
  .btn img      { width: 0.9375rem; height: 0.9375rem; }

  /* Connect center: 1.5× of 2rem for landscape */
  .btn-connect-center              { width: 3rem; height: 3rem; border-radius: 0.625rem; }
  .btn-connect-center svg,
  .btn-connect-center img          { width: 1.5rem; height: 1.5rem; }

  /* Tool buttons: centered with BPM bar (BPM top 0.5rem + height 2rem / 2 = 1.5rem) */
  .bottom-right-group           { top: 1.5rem; right: 0.5rem; gap: 0.3125rem; }
  .fullscreen-theme-toggle,
  .fullscreen-btn               { width: 2rem; height: 2rem; }
  .fullscreen-theme-toggle svg,
  .fullscreen-btn svg           { width: 1rem; height: 1rem; }
  .bottom-right-group .fullscreen-theme-toggle     { width: 2rem; height: 2rem; }
  .bottom-right-group .fullscreen-theme-toggle svg { width: 1rem; height: 1rem; }
  .info-btn                     { width: 2rem; height: 2rem; font-size: 0.8rem; }
  .bottom-right-group .btn      { width: 2rem; height: 2rem; }
  .bottom-right-group .btn svg  { width: 1rem; height: 1rem; }

  /* controls_bottom(0.5rem) + connect_height(3rem) + clearance(0.75rem) */
  .recording-timer { bottom: 4.25rem; font-size: 0.75rem; padding: 0.25rem 0.625rem; }
  .recordings-dropup.timer-active { bottom: 6.5rem; }
  .minimap-wrap    { bottom: 4.25rem; height: 2.25rem; }

  .viewer-header   { top: 0.5rem; height: 2rem; padding-left: 0.625rem; }
  .viewer-filename { font-size: 0.72rem; }
  .viewer-duration { font-size: 0.66rem; }
  .viewer-close-btn { width: 2rem !important; }
}

/* fullscreen on phone landscape */
@media (max-height: 500px) and (orientation: landscape) {
  /* Button sizes: slightly larger than the base landscape values */
  .canvas-container.fullscreen .btn          { width: 2.25rem; height: 2.25rem; }
  .canvas-container.fullscreen .btn svg      { width: 1.125rem; height: 1.125rem; }
  .canvas-container.fullscreen .btn img      { width: 1.125rem; height: 1.125rem; }
  .canvas-container.fullscreen .btn-connect-center     { width: 3.25rem; height: 3.25rem; }
  .canvas-container.fullscreen .btn-connect-center svg,
  .canvas-container.fullscreen .btn-connect-center img { width: 1.625rem; height: 1.625rem; }

  /* More breathing room between bottom buttons */
  .canvas-container.fullscreen .controls-overlay { gap: 0.875rem; }

  /* Top-right circle buttons */
  .canvas-container.fullscreen .fullscreen-theme-toggle,
  .canvas-container.fullscreen .fullscreen-btn     { width: 2.25rem; height: 2.25rem; }
  .canvas-container.fullscreen .fullscreen-theme-toggle svg,
  .canvas-container.fullscreen .fullscreen-btn svg { width: 1.125rem; height: 1.125rem; }
  .canvas-container.fullscreen .info-btn                    { width: 2.25rem; height: 2.25rem; }
  .canvas-container.fullscreen .bottom-right-group .btn     { width: 2.25rem; height: 2.25rem; }
  .canvas-container.fullscreen .bottom-right-group .btn svg { width: 1.125rem; height: 1.125rem; }

  /* Recalculate: controls_bottom(0.5) + connect_height(3.25) + clearance(0.75) = 4.5rem */
  .canvas-container.fullscreen .recording-timer            { bottom: 4.5rem; }
  .canvas-container.fullscreen .minimap-wrap               { bottom: 4.5rem; }
  .canvas-container.fullscreen .recordings-dropup.timer-active { bottom: 7rem; }
}

/* tablets portrait 601–900px */
@media (min-width: 601px) and (max-width: 900px) and (orientation: portrait) {
  .udl-logo img     { height: 2.625rem; }
  .btn              { width: 2.125rem; height: 2.125rem; }
  .btn-connect-center { width: 2.875rem; height: 2.875rem; }
  .controls-overlay { gap: 0.625rem; }
}
