* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-light: #1f3056;
  --accent: #0f3460;
  --primary: #e94560;
  --text: #eee;
  --text-dim: #888;
  --green: #4caf50;
  --red: #e94560;
  --yellow: #ffc107;
  --radius-control: 8px;
  --radius-small: 6px;
  --touch-target: 44px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--accent);
}

header h1 {
  font-size: 16px;
  font-weight: 600;
}

.status-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  margin-left: 8px;
}

.dot.connected {
  background: var(--green);
}

.dot-label {
  font-size: 11px;
  color: var(--text-dim);
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 2px solid var(--accent);
}

.tab {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Main content */
main {
  position: relative;
  height: calc(100% - 90px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.disconnected-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.disconnected-message {
  color: #fff;
  font-size: 1.2rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 16px 28px;
  border-radius: var(--radius-control);
  border: 1px solid rgba(255,255,255,0.2);
}

.token-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 1rem;
}

.token-form .token-row {
  display: flex;
  gap: 8px;
}

.token-form input {
  flex: 1;
  min-width: 220px;
  padding: 8px 10px;
  border-radius: var(--radius-control);
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.5);
  color: #fff;
}

.token-form button {
  padding: 8px 16px;
  border-radius: var(--radius-control);
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.12);
  color: #fff;
  cursor: pointer;
}

.panel {
  display: none;
  padding: 16px;
}

.panel.active {
  display: block;
}

/* Buttons */
.btn {
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active {
  background: var(--surface-light);
}

.btn-large {
  padding: 20px 24px;
  font-size: 16px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--primary);
}

.btn-primary:active {
  background: var(--primary);
}

/* Control layout */
.control-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.control-row .btn {
  flex: 1;
}

/* Proclaim */
.slide-strip {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: center;
}

.slide-thumb {
  flex: 1;
  max-width: 33%;
  aspect-ratio: 16 / 9;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  overflow: hidden;
  opacity: 0.5;
}

.slide-thumb.active {
  opacity: 1;
  border-color: var(--primary);
}

.slide-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.slide-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  justify-content: flex-start;
}

.slide-thumb-btn {
  flex: 0 0 auto;
  width: calc(25% - 5px);
  aspect-ratio: 16 / 9;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 4px;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  opacity: 0.6;
}

.slide-thumb-btn.active {
  opacity: 1;
  border-color: var(--primary);
}

.slide-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

@media (max-width: 480px) {
  .slide-thumb-btn {
    width: calc(50% - 4px);
  }
}

.song-lyrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.song-slide {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 0 0 calc(33.333% - 4px);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 4px;
  padding: 8px;
  cursor: pointer;
  text-align: center;
  opacity: 0.6;
  color: var(--text);
}

.song-slide.active {
  opacity: 1;
  border-color: var(--primary);
}

.song-line {
  font-size: 13px;
  line-height: 1.35;
}

.proclaim-now-playing {
  text-align: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 20px;
}

.proclaim-now-playing .item-type {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.proclaim-now-playing strong {
  color: var(--text);
}

.proclaim-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.btn-on-air {
  flex: 1;
  background: var(--surface-light);
  border-color: var(--accent);
}

.btn-on-air.active {
  background: var(--red);
  border-color: var(--red);
  font-weight: 600;
}

.proclaim-av-controls .btn {
  flex: 1;
  padding: 12px 6px;
  font-size: 18px;
}

.proclaim-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-btn {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.item-btn:active {
  background: var(--surface-light);
}

.item-btn.active {
  background: var(--accent);
  border-color: var(--primary);
  font-weight: 600;
}

.item-section-header {
  padding: 10px 16px 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  border-top: 2px solid var(--accent);
  margin-top: 8px;
  font-weight: 600;
}

.item-section-header:first-child {
  border-top: none;
  margin-top: 0;
}

.item-group-header {
  padding: 6px 16px 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-top: 4px;
}

.item-grouped {
  margin-left: 12px;
}

.item-slide-count {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: normal;
}

/* Section header with edit button */
.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-header-row h2 {
  margin-bottom: 0;
}

.x32-header-row {
  padding: 0 4px 4px;
}

.btn-edit-toggle {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
}

.btn-edit-toggle.active {
  border-color: var(--primary);
  color: var(--primary);
}

.header-btn-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.fader-visibility-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  flex: 1 1 100%;
}


/* OBS */
.obs-section {
  margin-bottom: 24px;
}

.obs-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.scene-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.scene-btn {
  padding: 14px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.scene-btn:active {
  background: var(--surface-light);
}

.scene-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

/* Audio sources */
.audio-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audio-source {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-control);
  border: 1px solid var(--accent);
}

.audio-source .name {
  flex: 0 0 80px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-source input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--accent);
  border-radius: 3px;
  outline: none;
}

.audio-source input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

.audio-source input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.audio-source input[type="range"]:disabled::-webkit-slider-thumb {
  cursor: not-allowed;
}

.mute-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  background: var(--surface-light);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mute-btn.muted {
  background: var(--red);
}

.audio-source.live {
  border-color: var(--green);
}

.audio-source.live .name::after {
  content: ' \25CF';
  color: var(--green);
  font-size: 8px;
  vertical-align: middle;
}

.audio-source:not(.live) {
  opacity: 0.6;
}

.obs-meter {
  flex: 1 1 100%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  overflow: hidden;
}

.obs-meter-fill {
  width: 0%;
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.05s;
}

/* Stream/Record buttons */
#obs-stream-btn.active {
  background: var(--red);
  border-color: var(--red);
}

#obs-record-btn.active {
  background: var(--red);
  border-color: var(--red);
}

/* X32 Channels — horizontal layout */
.channel-list-vert {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.channel-row-h {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
}

.channel-row-h .ch-label {
  font-size: 12px;
  color: var(--text-dim);
  flex: 0 0 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fader-wrap-h {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.fader-wrap-h input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--accent);
  border-radius: 3px;
  outline: none;
}

.fader-wrap-h input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

.fader-wrap-h input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.fader-wrap-h input[type="range"]:disabled::-webkit-slider-thumb {
  cursor: not-allowed;
}

.ch-meter-h {
  width: 100%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  overflow: hidden;
}

.ch-meter-fill-h {
  width: 0%;
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.05s;
}

.channel-row-h .ch-mute {
  flex: 0 0 54px;
  min-height: var(--touch-target);
  padding: 8px 4px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  background: var(--surface-light);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.channel-row-h .ch-mute.muted {
  background: var(--red);
  border-color: var(--red);
}

/* Channel type distinctions — Sound panel */
.channel-row-h--main {
  border-color: #e0a020;
  background: #1a1a0e;
}

.channel-row-h--bus {
  border-color: #1a5f7a;
  background: #0e1a20;
}

/* ---- Overview panel ---- */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
}

/* Info cells (Row 1) */
.ov-cell {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
}

.ov-slide-desc {
  /* Clamp to 2 visual lines max */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  /* Override flex-direction: column set by .ov-cell */
  flex-direction: unset;
  line-height: 1.4;
}

.ov-slide-desc .item-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.ov-slide-desc strong {
  color: var(--text);
  font-size: 12px;
}

.ov-scene-info {
  align-items: flex-end;
  text-align: right;
  gap: 2px;
}

.ov-scene-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Slide thumbs fill their grid cell */
.overview-grid .slide-thumb {
  max-width: 100%;
  flex: none;
}

.ov-block {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px;
}

.ov-full-width {
  grid-column: 1 / -1;
}

.ov-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* OBS preview */
.ov-obs-preview-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-small);
  overflow: hidden;
  margin-bottom: 10px;
}

/* Remove bottom margin when preview is a direct grid cell */
.overview-grid .ov-obs-preview-wrap {
  margin-bottom: 0;
}

.ov-obs-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* X32 compact channel list */
.ov-channel-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 2-column grid for overview meter lists */
.ov-channel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
}

.ov-channel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ov-bars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Channel type distinctions — overview panel */
.ov-channel-row--main .ov-ch-label {
  color: #c89020;
}

.ov-channel-row--bus .ov-ch-label {
  color: #4a9aba;
}

.ov-ch-label {
  font-size: 12px;
  flex: 0 0 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

.ov-ch-label.muted {
  color: var(--red);
}

.ov-fader-bar {
  width: 100%;
  height: 8px;
  background: var(--accent);
  border-radius: 4px;
  overflow: hidden;
}

.ov-fader-fill {
  height: 100%;
  background: var(--text);
  border-radius: 4px;
  transition: width 0.1s;
}

.ov-fader-fill.muted {
  background: var(--red);
  opacity: 0.5;
}

.ov-level-bar {
  width: 100%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  overflow: hidden;
}

.ov-level-fill {
  width: 0%;
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.05s;
}



.ov-status-row {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
}

.ov-status-pill {
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--surface-light);
  font-weight: 600;
  font-size: 11px;
}

.ov-status-pill.active {
  background: var(--red);
  color: var(--text);
}

/* ---- Settings panel ---- */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}

.settings-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.settings-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 12px 0 8px;
}

.settings-section label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.settings-section input[type="text"],
.settings-section input[type="password"],
.settings-section input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.settings-section input:focus {
  border-color: var(--primary);
}

.discover-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.discover-status {
  font-size: 12px;
  color: var(--text-dim);
}

/* Server address list in Settings */
.server-address-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.server-address-link {
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  font-family: monospace;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-address-link:hover {
  text-decoration: underline;
}

/* QR code popup on hover */
.qr-anchor {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.qr-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target);
  height: var(--touch-target);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
}

.qr-popup {
  display: none;
  position: absolute;
  right: 0;
  top: 28px;
  width: 180px;
  height: 180px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: var(--radius-control);
  padding: 4px;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.qr-anchor:hover .qr-popup {
  display: block;
}


.settings-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
}

.log-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.log-output {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  padding: 10px;
  font-size: 11px;
  font-family: monospace;
  line-height: 1.5;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
}

.log-output .log-error {
  color: var(--red);
}

.log-output .log-warn {
  color: var(--yellow);
}

.log-output .log-info {
  color: var(--text-dim);
}


/* ===================== PTZ Camera Panel ===================== */
.ptz-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
}

.ptz-disconnected {
  color: var(--red, #e05c5c);
  font-size: 0.9em;
  padding: 6px 12px;
  border: 1px solid var(--red, #e05c5c);
  border-radius: var(--radius-small);
}

.ptz-obs-preview {
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-small);
  display: block;
}

.ptz-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.ptz-middle-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ptz-btn {
  min-width: 56px;
  min-height: 56px;
  font-size: 1.3em;
  background: var(--bg-raised, #2a2a2a);
  color: var(--text, #eee);
  border: 1px solid var(--accent, #444);
  border-radius: var(--radius-control);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.ptz-btn:active {
  background: var(--accent, #444);
}

.ptz-home {
  background: var(--bg, #1a1a1a);
  font-size: 1.1em;
}

.ptz-zoom-row,
.ptz-focus-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ptz-label {
  min-width: 48px;
  font-size: 0.85em;
  color: var(--text-dim, #888);
  text-align: right;
}

.ptz-zoom-out, .ptz-zoom-in {
  font-size: 1em;
  min-width: 64px;
}

.ptz-presets {
  width: 100%;
  max-width: 360px;
}

.ptz-preset-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ptz-preset-btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 1em;
}
