/* =========================================
   UCM Mandala Engine – UI Styling v1.0
========================================= */

/* ---------------------------
   Global
--------------------------- */

:root {
  --bg-deep: #040e18;
  --bg-mid:  #081624;
  --bg-light:#0b2440;
  --accent:  #6fa8ff;
  --accent-soft: #9cc6ff;
  --accent-glass: #7df0d4;
  --accent-heat: #ffcf70;
  --text-main: #e6edf7;
  --text-sub:  #9fb3d9;
  --panel-bg: rgba(8, 18, 35, 0.72);
  --panel-border: rgba(170, 200, 255, 0.45);
  --shadow-soft: 0 0 30px rgba(0, 100, 255, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Noto Sans JP", sans-serif;
  background: radial-gradient(circle at center,
    var(--bg-light) 0%,
    var(--bg-mid) 45%,
    var(--bg-deep) 100%);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

body[data-playing="true"] {
  --panel-border: rgba(125, 240, 212, 0.48);
  --shadow-soft: 0 0 36px rgba(70, 210, 210, 0.24);
}

body[data-playing="true"][data-auto="true"] {
  --accent: var(--accent-glass);
  --accent-soft: #b8fff1;
}

/* ---------------------------
   Lang Switch
--------------------------- */

#lang-switch {
  position: fixed;
  top: 14px;
  right: 18px;
  display: flex;
  gap: 8px;
  z-index: 50;
}

#lang-switch button {
  background: rgba(5, 15, 32, 0.7);
  border: 1px solid rgba(140, 180, 255, 0.5);
  color: var(--text-sub);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
  transition: 0.2s;
}

#lang-switch button.active,
#lang-switch button:hover {
  background: rgba(125, 170, 255, 0.4);
  color: #f7fbff;
}

/* ---------------------------
   Mandala Visual
--------------------------- */

#mandala-container {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

#mandala-bg {
  position: absolute;
  inset: 0;
  width: 160%;
  left: -30%;
  top: -25%;
  opacity: 0.22;
  filter: blur(4px);
}

#mandala-layers img {
  position: absolute;
  width: 140%;
  left: -20%;
  top: -20%;
  opacity: 0.25;
  mix-blend-mode: screen;
  animation: mandala-rotate 90s linear infinite;
}

@keyframes mandala-rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ---------------------------
   UI Shell
--------------------------- */

#ui-shell {
  position: absolute;
  inset: auto 0 18px 0;
  display: flex;
  justify-content: center;
  pointer-events: auto; /* allow header/select interaction */
}

#control-panel {
  width: min(1080px, 96vw);
  background: var(--panel-bg);
  border-radius: 20px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-soft);
  padding: 16px 18px 18px;
  backdrop-filter: blur(18px) saturate(160%);
  pointer-events: auto;
  transition: border-color 0.45s ease, box-shadow 0.45s ease, background 0.45s ease;
}

/* Header */

#ui-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}

#ui-header h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--text-sub);
}

#mode-indicator {
  text-align: right;
  font-size: 11px;
}

#mode-indicator .label {
  display: block;
  color: var(--text-sub);
  margin-bottom: 2px;
}

#mode-label {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(130, 175, 255, 0.7);
  background: radial-gradient(circle at top left,
    rgba(130, 170, 255, 0.2),
    rgba(5, 15, 32, 0.9));
  transition: border-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}

body[data-playing="true"] #mode-label {
  border-color: rgba(125, 240, 212, 0.72);
  color: #dffff8;
  box-shadow: 0 0 16px rgba(125, 240, 212, 0.16);
}

/* ---------------------------
   Layout Columns
--------------------------- */

#control-panel main,
#control-panel #control-panel {
  /* safety for old structure: we style by id */
}

#control-panel {
  display: grid;
  grid-template-columns: 1.1fr 2.1fr 1.0fr;
  column-gap: 18px;
}

/* 左カラム：ENERGY ＋ BPM */

#energy-column {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  padding-right: 8px;
  border-right: 1px solid rgba(200, 220, 255, 0.16);
}

.fader-column {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fader-title {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--accent-soft);
}

#bpm-indicator {
  margin-top: 10px;
  text-align: center;
}

#bpm-indicator .label {
  display: block;
  font-size: 10px;
  color: var(--text-sub);
}

#bpm-value {
  font-size: 14px;
}

/* 中央カラム：観フェーダーグリッド */

#obs-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: 12px;
  row-gap: 10px;
  padding: 0 8px;
}

.fader-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 148px;
  padding: 8px 7px;
  border: 1px solid rgba(150, 190, 255, 0.14);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(10, 24, 44, 0.48), rgba(3, 10, 22, 0.32));
  transition: border-color 0.3s ease, background 0.3s ease, transform 0.3s ease;
}

.fader-label {
  font-size: 11px;
  margin-bottom: 4px;
  color: var(--text-sub);
  letter-spacing: 0.04em;
}

body[data-playing="true"][data-auto="true"] .fader-group {
  border-color: rgba(125, 240, 212, 0.22);
  background: linear-gradient(180deg, rgba(15, 38, 54, 0.56), rgba(3, 12, 23, 0.34));
}

/* 右カラム：Auto & Transport */

#right-column {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-left: 8px;
  border-left: 1px solid rgba(200, 220, 255, 0.16);
}

/* ---------------------------
   Horizontal fallback faders
---------------------------- */

.fader-vertical {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 160px;
  gap: 4px;
  justify-content: center;
}

.fader-vertical.small {
  height: 120px;
}

.fader-min,
.fader-max {
  font-size: 10px;
  color: var(--text-sub);
  opacity: 0.72;
}

.fader-value {
  margin-top: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.fader-vertical input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: min(140px, 100%);
  height: 6px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  transition: filter 0.25s ease;
}

/* トラック */
.fader-vertical input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    rgba(80, 140, 255, 0.22),
    rgba(125, 240, 212, 0.62),
    rgba(255, 207, 112, 0.72));
}
.fader-vertical input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    rgba(80, 140, 255, 0.22),
    rgba(125, 240, 212, 0.62),
    rgba(255, 207, 112, 0.72));
}

/* サム（つまみ） */
.fader-vertical input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--accent-soft);
  background: #f5f8ff;
  box-shadow: 0 0 10px rgba(125, 240, 212, 0.46);
  margin-top: -5px;
}
.fader-vertical input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--accent-soft);
  background: #f5f8ff;
  box-shadow: 0 0 10px rgba(125, 240, 212, 0.46);
}

body[data-playing="true"][data-auto="true"] .fader-vertical input[type="range"] {
  filter: saturate(1.2) brightness(1.08);
}

/* ---------------------------
   Auto Block
--------------------------- */

#auto-block {
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(140, 180, 255, 0.4);
  background: radial-gradient(circle at top left,
    rgba(120, 180, 255, 0.1),
    rgba(3, 10, 24, 0.9));
  margin-bottom: 10px;
  transition: border-color 0.35s ease, box-shadow 0.35s ease, background 0.35s ease;
}

body[data-playing="true"][data-auto="true"] #auto-block {
  border-color: rgba(125, 240, 212, 0.62);
  box-shadow: 0 0 18px rgba(125, 240, 212, 0.16);
  background: linear-gradient(135deg, rgba(22, 58, 70, 0.56), rgba(3, 10, 24, 0.90));
}

.auto-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.auto-header .title {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auto-body {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.auto-body .label {
  color: var(--text-sub);
}

.auto-body input[type="range"] {
  flex: 1;
}

/* Auto の range を横向きに普通に表示 */
.auto-body input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  cursor: pointer;
}
.auto-body input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  background: #f6f8ff;
}
.auto-body input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
}
.auto-body input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  background: #f6f8ff;
}

.auto-body .hint {
  font-size: 10px;
  color: var(--text-sub);
}

#output-body {
  margin-top: 7px;
}

#output_value {
  min-width: 22px;
  text-align: right;
}

.route-body {
  margin-top: 7px;
}

#audio_output_select,
#odd_logic_mode,
#culture_grammar_select,
#auto_arc_mode {
  min-width: 0;
  flex: 1;
  height: 22px;
  border: 1px solid rgba(140, 180, 255, 0.42);
  border-radius: 6px;
  background: rgba(5, 15, 32, 0.72);
  color: var(--text-main);
  font-size: 10px;
  letter-spacing: 0.04em;
}

#auto_arc_status {
  min-width: 44px;
  text-align: right;
}

#culture_grammar_status {
  min-width: 44px;
  text-align: right;
}

#odd_logic_status {
  min-width: 72px;
  text-align: right;
}

.mini-action {
  border: 1px solid rgba(93, 211, 220, 0.34);
  border-radius: 4px;
  background: rgba(1, 8, 10, 0.72);
  color: rgba(218, 250, 255, 0.86);
  cursor: pointer;
  font-size: 9px;
  letter-spacing: 0.12em;
  line-height: 1;
  padding: 5px 7px;
  text-transform: uppercase;
  touch-action: manipulation;
}

.mini-action.active,
.mini-action[aria-pressed="true"] {
  border-color: rgba(246, 91, 86, 0.78);
  box-shadow: 0 0 12px rgba(246, 91, 86, 0.16);
  color: rgba(255, 231, 224, 0.96);
}

/* スイッチ */

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
}

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

.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: rgba(120, 140, 180, 0.6);
  border-radius: 999px;
  transition: 0.2s;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: #f5f8ff;
  border-radius: 999px;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background-color: rgba(125, 240, 212, 0.82);
}

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

/* ---------------------------
   Transport
--------------------------- */

#transport {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

#transport button {
  min-width: 80px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(140, 180, 255, 0.7);
  background: rgba(5, 15, 32, 0.8);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  transition: 0.18s;
}

#transport button.primary {
  background: linear-gradient(
    135deg,
    rgba(120, 190, 255, 0.9),
    rgba(90, 150, 255, 0.9)
  );
  border-color: rgba(150, 210, 255, 0.9);
  color: #020712;
}

#transport button.ghost:hover {
  background: rgba(18, 30, 55, 0.95);
}

/* ステータス */
#status-line {
  margin-top: 6px;
  font-size: 11px;
  text-align: center;
  color: var(--text-sub);
}

#recorder-tools {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-left: 8px;
}

.recorder-button,
.recorder-link,
.packet-button {
  min-width: 0;
  border: 1px solid rgba(93, 211, 220, 0.34);
  border-radius: 4px;
  background: rgba(1, 8, 10, 0.72);
  color: rgba(218, 250, 255, 0.82);
  font-size: 9px;
  letter-spacing: 0.12em;
  line-height: 1;
  padding: 5px 7px;
  text-decoration: none;
  text-transform: uppercase;
}

.recorder-button,
.packet-button {
  cursor: pointer;
  touch-action: manipulation;
}

.packet-button {
  border-color: rgba(170, 220, 255, 0.34);
  color: rgba(225, 244, 255, 0.8);
}

.mic-button.is-active {
  border-color: rgba(164, 255, 204, 0.72);
  background: rgba(8, 38, 24, 0.88);
  color: rgba(206, 255, 226, 0.95);
}

.sync-next-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  text-align: left;
}

.packet-route-link {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(93, 211, 220, 0.34);
  border-radius: 4px;
  background: rgba(1, 8, 10, 0.72);
  color: rgba(218, 250, 255, 0.84);
  font-size: 9px;
  letter-spacing: 0.12em;
  line-height: 1;
  padding: 6px 8px;
  text-decoration: none;
  text-transform: uppercase;
}

.packet-route-link:hover {
  border-color: rgba(143, 255, 245, 0.54);
  color: rgba(233, 244, 239, 0.96);
}

body[data-recording="true"] .recorder-button {
  border-color: rgba(246, 91, 86, 0.8);
  box-shadow: 0 0 12px rgba(246, 91, 86, 0.16);
  color: rgba(255, 231, 224, 0.96);
}

/* ---------------------------
   Responsive
--------------------------- */

@media (max-width: 880px) {
  #control-panel {
    grid-template-columns: 1fr;
    row-gap: 16px;
  }

  #energy-column,
  #right-column {
    border: none;
    padding: 0;
  }

  #obs-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #ui-shell {
    inset: auto 0 8px 0;
  }
}

@media (max-width: 640px) {
  #control-panel {
    padding: 12px;
  }

  #obs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #ui-header {
    flex-direction: column;
    align-items: flex-start;
  }
}


/* Touch safety for mobile sliders/buttons */
input[type="range"], button, select { touch-action: manipulation; }

/* ---------------------------
   Preset Block
--------------------------- */

#preset-block{
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(140, 180, 255, 0.4);
  background: radial-gradient(circle at top left,
    rgba(120, 180, 255, 0.08),
    rgba(3, 10, 24, 0.92));
  margin-bottom: 10px;
}

#preset_select{
  width: 100%;
  background: rgba(5, 15, 32, 0.7);
  border: 1px solid rgba(140, 180, 255, 0.45);
  color: var(--text-main);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
}

#atmosphere_select,
#source_color_select {
  width: 100%;
  min-width: 0;
  background: rgba(5, 15, 32, 0.72);
  border: 1px solid rgba(93, 211, 220, 0.34);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 7px;
  font-size: 10px;
  letter-spacing: 0.05em;
}

.voice-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.voice-control {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.voice-label {
  color: var(--text-sub);
  font-size: 9px;
  letter-spacing: 0.16em;
}

.voice-readout {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(93, 211, 220, 0.18);
  background:
    linear-gradient(90deg, rgba(93, 211, 220, 0.08), rgba(246, 91, 86, 0.05)),
    rgba(1, 8, 10, 0.42);
  color: rgba(218, 250, 255, 0.82);
  font-size: 9px;
  letter-spacing: 0.13em;
  line-height: 1.2;
  padding: 5px 6px;
  text-align: center;
  text-transform: uppercase;
}

.voice-readout::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 3px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(93, 211, 220, 0.58), transparent);
  opacity: 0.5;
}

body[data-atmosphere="haze"] .voice-readout {
  border-color: rgba(158, 222, 203, 0.32);
  color: rgba(226, 255, 244, 0.86);
}

body[data-atmosphere="chrome"] .voice-readout,
body[data-source-color="opn"] .voice-readout {
  border-color: rgba(126, 218, 255, 0.42);
  color: rgba(220, 249, 255, 0.9);
}

body[data-atmosphere="ghost"] .voice-readout,
body[data-source-color="burial"] .voice-readout {
  border-color: rgba(128, 158, 205, 0.38);
  color: rgba(210, 226, 255, 0.86);
}

body[data-atmosphere="organic"] .voice-readout,
body[data-source-color="fsol"] .voice-readout {
  border-color: rgba(177, 222, 162, 0.36);
  color: rgba(232, 255, 220, 0.86);
}

body[data-atmosphere="void"] .voice-readout {
  border-color: rgba(203, 227, 255, 0.38);
  background:
    linear-gradient(90deg, rgba(203, 227, 255, 0.08), rgba(93, 211, 220, 0.04)),
    rgba(1, 8, 10, 0.56);
}

body[data-auto-voice-morph="true"] .voice-readout {
  background:
    linear-gradient(90deg, rgba(93, 211, 220, 0.1), rgba(246, 91, 86, 0.06), rgba(177, 222, 162, 0.07)),
    repeating-linear-gradient(90deg, rgba(93, 211, 220, 0.08) 0 1px, transparent 1px 18px),
    rgba(1, 8, 10, 0.48);
}

body[data-auto-source-color="autechre"] .voice-readout {
  border-color: rgba(93, 211, 220, 0.48);
}

body[data-auto-source-color="boc"] .voice-readout {
  border-color: rgba(182, 214, 168, 0.38);
}

body[data-auto-source-color="burial"] .voice-readout {
  border-color: rgba(122, 151, 205, 0.42);
}

body[data-source-color="autechre"] #preset-block {
  box-shadow: inset 0 0 0 1px rgba(93, 211, 220, 0.09);
}

#btn_reload_presets{
  min-width: unset;
}

/* ---------------------------
   Momentary Performance Pads
--------------------------- */

#performance-pads {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 10px;
}

.performance-pad {
  min-height: 46px;
  padding: 8px 9px;
  border: 1px solid rgba(93, 211, 220, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(6, 22, 25, 0.88), rgba(1, 8, 10, 0.92)),
    repeating-linear-gradient(90deg, rgba(83, 238, 232, 0.05) 0 1px, transparent 1px 14px);
  color: rgba(218, 250, 255, 0.9);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: border-color 0.12s ease, background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.performance-pad .pad-main,
.performance-pad .pad-sub {
  display: block;
  line-height: 1.05;
}

.performance-pad .pad-main {
  font-size: 10px;
  letter-spacing: 0.18em;
}

.performance-pad .pad-sub {
  margin-top: 4px;
  font-size: 9px;
  color: rgba(104, 178, 188, 0.78);
  letter-spacing: 0.08em;
}

.performance-pad.active,
.performance-pad:active {
  transform: translateY(1px);
  border-color: rgba(246, 91, 86, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 120, 104, 0.26), 0 0 16px rgba(246, 91, 86, 0.18);
  background:
    linear-gradient(180deg, rgba(61, 18, 18, 0.92), rgba(8, 8, 10, 0.96)),
    repeating-linear-gradient(90deg, rgba(255, 89, 75, 0.09) 0 1px, transparent 1px 10px);
  color: rgba(255, 235, 226, 0.95);
}

.performance-pad.active .pad-sub,
.performance-pad:active .pad-sub {
  color: rgba(255, 164, 150, 0.86);
}

/* World spectrum visual system: original liminal ambient / IDM / hardcore states. */
body {
  --world-accent: rgba(83, 220, 255, 0.74);
  --world-accent-strong: rgba(255, 213, 122, 0.82);
  --world-shadow: rgba(40, 190, 255, 0.2);
  --world-panel: rgba(8, 20, 31, 0.82);
  transition: background 900ms ease, color 900ms ease;
}

body[data-world="ambient"] {
  --world-accent: rgba(155, 244, 217, 0.82);
  --world-accent-strong: rgba(215, 245, 255, 0.88);
  --world-shadow: rgba(124, 226, 211, 0.18);
  --world-panel: rgba(8, 28, 28, 0.8);
  background:
    linear-gradient(180deg, rgba(7, 20, 26, 0.96) 0%, rgba(12, 35, 37, 0.94) 52%, rgba(9, 17, 24, 0.98) 100%),
    repeating-linear-gradient(90deg, rgba(177, 255, 230, 0.05) 0 1px, transparent 1px 74px);
}

body[data-world="idm"] {
  --world-accent: rgba(92, 218, 255, 0.78);
  --world-accent-strong: rgba(255, 216, 122, 0.84);
  --world-shadow: rgba(255, 204, 92, 0.16);
  --world-panel: rgba(10, 22, 34, 0.84);
  background:
    linear-gradient(180deg, rgba(5, 14, 25, 0.97) 0%, rgba(18, 24, 36, 0.94) 45%, rgba(8, 12, 21, 0.99) 100%),
    repeating-linear-gradient(135deg, rgba(255, 219, 120, 0.045) 0 1px, transparent 1px 62px);
}

body[data-world="hardcore"] {
  --world-accent: rgba(255, 78, 74, 0.78);
  --world-accent-strong: rgba(255, 226, 119, 0.9);
  --world-shadow: rgba(255, 67, 54, 0.2);
  --world-panel: rgba(32, 12, 14, 0.84);
  background:
    linear-gradient(180deg, rgba(19, 7, 12, 0.98) 0%, rgba(37, 14, 18, 0.96) 48%, rgba(8, 8, 13, 0.99) 100%),
    repeating-linear-gradient(90deg, rgba(255, 75, 55, 0.055) 0 2px, transparent 2px 46px);
}

#mode-label {
  color: var(--world-accent-strong);
  letter-spacing: 0.16em;
  text-shadow: 0 0 18px var(--world-shadow);
  transition: color 700ms ease, text-shadow 700ms ease;
}

#control-panel,
.fader-card,
.preset-card,
.transport-card {
  background: var(--world-panel);
  border-color: var(--world-accent);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.28), 0 0 28px var(--world-shadow);
  transition: background 800ms ease, border-color 800ms ease, box-shadow 800ms ease;
}

#mandala-container {
  isolation: isolate;
}

#mandala-container::before,
#mandala-container::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  transition: opacity 900ms ease, background 900ms ease, filter 900ms ease;
}

#mandala-container::before {
  z-index: 1;
  opacity: 0.18;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 9px),
    linear-gradient(135deg, transparent, var(--world-shadow));
  mix-blend-mode: screen;
}

#mandala-container::after {
  z-index: 2;
  opacity: 0.16;
  background: radial-gradient(circle at center, transparent 0 44%, var(--world-shadow) 100%);
  mix-blend-mode: screen;
}

body[data-world="ambient"] #mandala-container::before {
  opacity: 0.1;
  filter: blur(0.4px);
}

body[data-world="hardcore"] #mandala-container::before {
  opacity: 0.28;
  background:
    repeating-linear-gradient(90deg, rgba(255, 226, 119, 0.12) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(0deg, rgba(255, 72, 61, 0.1) 0 1px, transparent 1px 13px);
}

body[data-world="hardcore"] #mandala-container::after {
  opacity: 0.28;
}

input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, var(--world-accent), var(--world-accent-strong));
}

input[type="range"]::-moz-range-track {
  background: linear-gradient(90deg, var(--world-accent), var(--world-accent-strong));
}

input[type="range"]::-webkit-slider-thumb {
  box-shadow: 0 0 14px var(--world-shadow), 0 0 0 1px rgba(255, 255, 255, 0.5);
}

input[type="range"]::-moz-range-thumb {
  box-shadow: 0 0 14px var(--world-shadow), 0 0 0 1px rgba(255, 255, 255, 0.5);
}
/* Identity polish: the app is a browser-native autonomous sound garden, not a generic synth toy. */
body[data-world="ambient"] #mode-label {
  text-shadow: 0 0 24px rgba(176, 255, 229, 0.32), 0 0 54px rgba(101, 214, 213, 0.18);
}

body[data-world="idm"] #mode-label {
  text-shadow: 0 0 22px rgba(91, 222, 255, 0.3), 0 0 44px rgba(255, 214, 116, 0.16);
}

body[data-world="hardcore"] #mode-label {
  text-shadow: 0 0 18px rgba(255, 74, 65, 0.38), 0 0 48px rgba(255, 201, 74, 0.18);
}

body[data-world="ambient"] .fader-card,
body[data-world="ambient"] .transport-card,
body[data-world="ambient"] .preset-card {
  backdrop-filter: blur(18px) saturate(1.18);
}

body[data-world="hardcore"] .fader-card,
body[data-world="hardcore"] .transport-card,
body[data-world="hardcore"] .preset-card {
  backdrop-filter: blur(10px) contrast(1.12) saturate(1.22);
}

body[data-world="hardcore"] input[type="range"]::-webkit-slider-runnable-track {
  background: repeating-linear-gradient(90deg, var(--world-accent) 0 10px, var(--world-accent-strong) 10px 16px);
}

body[data-world="hardcore"] input[type="range"]::-moz-range-track {
  background: repeating-linear-gradient(90deg, var(--world-accent) 0 10px, var(--world-accent-strong) 10px 16px);
}

body[data-world="ambient"] input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, rgba(127, 238, 218, 0.72), rgba(222, 252, 255, 0.92));
}

body[data-world="ambient"] input[type="range"]::-moz-range-track {
  background: linear-gradient(90deg, rgba(127, 238, 218, 0.72), rgba(222, 252, 255, 0.92));
}

.identity-line {
  margin: 4px 0 0;
  color: rgba(223, 245, 255, 0.66);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

body[data-character="ambient"] .identity-line {
  color: rgba(198, 255, 233, 0.76);
}

body[data-character="techno"] .identity-line,
body[data-character="trance"] .identity-line {
  color: rgba(255, 221, 126, 0.76);
}

body[data-character="dub"] .identity-line,
body[data-character="lofi"] .identity-line {
  color: rgba(190, 217, 255, 0.72);
}

/* Mobile performance surface: dense cyber-brutalist control panel, no language toggle. */
#lang-switch {
  display: none;
}

.label-main,
.label-sub {
  display: block;
  line-height: 1.05;
}

.label-main {
  color: rgba(214, 246, 255, 0.92);
  font-size: 10px;
  letter-spacing: 0.16em;
}

.label-sub {
  margin-top: 2px;
  color: rgba(104, 178, 188, 0.72);
  font-size: 9px;
  letter-spacing: 0.08em;
}

@media (max-width: 640px), (max-height: 760px) {
  :root {
    --panel-bg: rgba(1, 7, 10, 0.9);
    --panel-border: rgba(61, 196, 210, 0.34);
    --text-main: #d8faff;
    --text-sub: #6f939a;
  }

  html,
  body {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    background:
      linear-gradient(180deg, rgba(1, 5, 7, 0.98), rgba(3, 12, 15, 0.98)),
      repeating-linear-gradient(0deg, rgba(77, 255, 244, 0.035) 0 1px, transparent 1px 14px);
  }

  #mandala-bg {
    width: 120%;
    left: -10%;
    top: -4%;
    opacity: 0.09;
    filter: blur(2px) contrast(1.2);
  }

  #mandala-layers img {
    width: 110%;
    left: -5%;
    top: 0;
    opacity: 0.08;
  }

  #ui-shell {
    position: fixed;
    inset:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 6px;
    width: auto;
    height: auto;
    justify-content: stretch;
  }

  #ui-header {
    min-width: 0;
    margin: 0;
    padding: 6px 8px;
    border: 1px solid rgba(68, 211, 221, 0.28);
    background: rgba(2, 8, 11, 0.78);
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
  }

  #ui-header h1 {
    font-size: 13px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
  }

  .subtitle {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 9px;
  }

  .identity-line {
    display: none;
  }

  #mode-indicator {
    text-align: left;
    font-size: 9px;
  }

  #mode-label {
    max-width: 100%;
    padding: 2px 6px;
    border-radius: 0;
    font-size: 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #control-panel {
    width: 100%;
    min-height: 0;
    max-height: 100%;
    padding: 7px;
    border-radius: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    row-gap: 6px;
    overflow: hidden;
    backdrop-filter: blur(10px) saturate(1.05);
    box-shadow: inset 0 0 0 1px rgba(95, 232, 236, 0.08), 0 0 18px rgba(0, 0, 0, 0.44);
  }

  #energy-column {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border: 1px solid rgba(76, 202, 209, 0.22);
    background: rgba(2, 8, 12, 0.68);
  }

  .fader-column {
    align-items: stretch;
  }

  .fader-title,
  .fader-label {
    margin: 0 0 3px;
    text-align: left;
  }

  #bpm-indicator {
    margin: 0;
    min-width: 64px;
    padding-left: 6px;
    border-left: 1px solid rgba(76, 202, 209, 0.22);
  }

  #bpm-value {
    font-size: 12px;
    color: rgba(246, 91, 86, 0.88);
  }

  #obs-grid {
    min-height: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(44px, 1fr);
    gap: 5px;
    overflow: hidden;
  }

  .fader-group {
    min-height: 0;
    height: auto;
    padding: 5px 6px;
    align-items: stretch;
    justify-content: center;
    border-radius: 0;
    border-color: rgba(70, 204, 214, 0.2);
    background:
      linear-gradient(90deg, rgba(6, 24, 27, 0.72), rgba(1, 8, 10, 0.76)),
      repeating-linear-gradient(90deg, rgba(83, 238, 232, 0.04) 0 1px, transparent 1px 18px);
  }

  .fader-vertical,
  .fader-vertical.small {
    height: auto;
    min-height: 26px;
    display: grid;
    grid-template-columns: 30px 1fr 34px;
    gap: 5px;
    align-items: center;
  }

  .fader-min,
  .fader-max {
    font-size: 8px;
    letter-spacing: 0.02em;
    opacity: 0.62;
    white-space: nowrap;
  }

  .fader-vertical input[type="range"] {
    width: 100%;
    height: 22px;
  }

  .fader-vertical input[type="range"]::-webkit-slider-runnable-track,
  .auto-body input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 0;
  }

  .fader-vertical input[type="range"]::-webkit-slider-thumb,
  .auto-body input[type="range"]::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
    border-radius: 2px;
    background: #dffcff;
    border-color: rgba(64, 238, 235, 0.9);
  }

  #right-column {
    min-height: 0;
    padding: 0;
    border: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "auto transport"
      "pads pads"
      "preset status";
    gap: 6px;
  }

  #auto-block,
  #preset-block,
  #performance-pads,
  #transport,
  #status-line {
    margin: 0;
    border-radius: 0;
  }

  #auto-block {
    grid-area: auto;
    padding: 6px;
  }

  #preset-block {
    grid-area: preset;
    padding: 6px;
  }

  #performance-pads {
    grid-area: pads;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }

  .performance-pad {
    min-height: 42px;
    padding: 6px 3px;
    border-radius: 0;
  }

  .performance-pad .pad-main {
    font-size: 8px;
    letter-spacing: 0.1em;
  }

  .performance-pad .pad-sub {
    margin-top: 2px;
    font-size: 7px;
  }

  #transport {
    grid-area: transport;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  #status-line {
    grid-area: status;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 31px;
    border: 1px solid rgba(76, 202, 209, 0.18);
    background: rgba(2, 8, 12, 0.56);
    font-size: 9px;
  }

  #recorder-tools {
    margin-left: 0;
    gap: 4px;
  }

  .recorder-button,
  .recorder-link {
    padding: 4px 5px;
    font-size: 8px;
    border-radius: 0;
  }

  .auto-header .title {
    font-size: 9px;
    letter-spacing: 0.12em;
  }

  .auto-body {
    gap: 4px;
    font-size: 8px;
  }

  .auto-body .hint,
  .auto-body .label,
  #preset-status,
  #btn_reload_presets,
  #preset-block .hint {
    display: none;
  }

  #output-body {
    margin-top: 5px;
  }

  #output-body .label,
  #output_value {
    display: inline;
    font-size: 8px;
    letter-spacing: 0.08em;
  }

  .route-body {
    margin-top: 4px;
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .route-body .label,
  .route-body .hint {
    display: none;
  }

  #audio_output_select {
    height: 24px;
    font-size: 8px;
    padding: 2px 4px;
  }

  .mini-action {
    min-height: 24px;
    padding: 4px 5px;
    font-size: 7px;
  }

  #preset_select {
    min-height: 30px;
    padding: 5px 6px;
    border-radius: 0;
    font-size: 10px;
    background: rgba(1, 8, 10, 0.88);
  }

  #atmosphere_select,
  #source_color_select {
    min-height: 24px;
    padding: 3px 4px;
    border-radius: 0;
    font-size: 8px;
    background: rgba(1, 8, 10, 0.88);
  }

  .voice-controls {
    gap: 4px;
  }

  .voice-label,
  .voice-readout {
    display: none;
  }

  #transport button {
    min-width: 0;
    min-height: 42px;
    padding: 8px 4px;
    border-radius: 0;
    font-size: 12px;
    letter-spacing: 0.12em;
  }

  body[data-playing="true"] #transport button.primary {
    background: rgba(246, 91, 86, 0.92);
    border-color: rgba(255, 116, 100, 0.9);
  }
}

@media (max-width: 380px), (max-height: 700px) {
  #ui-header {
    padding: 4px 6px;
  }

  #ui-header h1 {
    font-size: 11px;
  }

  .subtitle,
  #mode-indicator .label {
    display: none;
  }

  #control-panel {
    padding: 5px;
    row-gap: 4px;
  }

  #obs-grid {
    gap: 4px;
  }

  #performance-pads {
    gap: 4px;
  }

  .performance-pad {
    min-height: 34px;
    padding: 4px 2px;
  }

  #right-column {
    gap: 4px;
  }

  #auto-block,
  #preset-block {
    padding: 5px;
  }

  .voice-controls {
    gap: 3px;
  }

  #transport button {
    min-height: 36px;
  }

  .fader-group {
    padding: 4px 5px;
  }

  .label-main {
    font-size: 8px;
  }

  .label-sub,
  .fader-min,
  .fader-max {
    font-size: 7px;
  }
}

/* ---------------------------
   Core Industrial UI Pass
   Matte crypto-core control surface with austere factory markings.
--------------------------- */

:root {
  --core-black: #010304;
  --core-ink: #05090a;
  --core-panel: rgba(3, 7, 8, 0.92);
  --core-panel-2: rgba(6, 12, 13, 0.84);
  --core-line: rgba(174, 248, 245, 0.28);
  --core-line-hard: rgba(222, 255, 252, 0.64);
  --core-cyan: #8ffff5;
  --core-red: #ff4a3d;
  --core-amber: #d7b15a;
  --core-paper: #e9f4ef;
  --core-muted: rgba(194, 218, 213, 0.58);
  --core-shadow: rgba(0, 0, 0, 0.78);
  --panel-bg: var(--core-panel);
  --panel-border: var(--core-line);
  --text-main: var(--core-paper);
  --text-sub: var(--core-muted);
}

html,
body {
  background:
    radial-gradient(circle at 50% 18%, rgba(109, 255, 241, 0.1), transparent 23%),
    radial-gradient(circle at 50% 54%, rgba(255, 74, 61, 0.06), transparent 31%),
    linear-gradient(180deg, #030607 0%, #010304 58%, #000101 100%);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, "Noto Sans JP", monospace;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: 0;
  opacity: 0.44;
  background:
    linear-gradient(90deg, transparent 0 calc(50% - 1px), rgba(174, 248, 245, 0.16) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(0deg, transparent 0 calc(50% - 1px), rgba(174, 248, 245, 0.1) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-linear-gradient(90deg, rgba(174, 248, 245, 0.045) 0 1px, transparent 1px 64px),
    repeating-linear-gradient(0deg, rgba(174, 248, 245, 0.032) 0 1px, transparent 1px 38px);
}

body::after {
  z-index: 1;
  opacity: 0.22;
  background:
    repeating-linear-gradient(0deg, rgba(233, 244, 239, 0.08) 0 1px, transparent 1px 5px),
    linear-gradient(90deg, rgba(255, 74, 61, 0.08), transparent 18%, transparent 82%, rgba(143, 255, 245, 0.08));
  mix-blend-mode: screen;
}

#mandala-container {
  z-index: 0;
}

#mandala-bg {
  width: 122%;
  left: -11%;
  top: -9%;
  opacity: 0.12;
  filter: grayscale(1) contrast(1.55) brightness(0.66);
  mix-blend-mode: screen;
}

#mandala-layers img {
  opacity: 0.1;
  filter: grayscale(1) contrast(1.8);
  mix-blend-mode: screen;
}

#mandala-container::before {
  opacity: 0.24;
  background:
    conic-gradient(from 45deg, transparent 0 18deg, rgba(143, 255, 245, 0.08) 18deg 20deg, transparent 20deg 90deg),
    radial-gradient(circle at center, transparent 0 31%, rgba(233, 244, 239, 0.08) 31% 31.4%, transparent 31.4% 46%, rgba(255, 74, 61, 0.12) 46% 46.3%, transparent 46.3%);
}

#mandala-container::after {
  opacity: 0.2;
  background:
    radial-gradient(circle at center, transparent 0 29%, rgba(143, 255, 245, 0.08) 29.2% 29.6%, transparent 30%),
    linear-gradient(90deg, transparent 0 calc(50% - 120px), rgba(255, 74, 61, 0.12) calc(50% - 120px) calc(50% - 118px), transparent calc(50% - 118px) calc(50% + 118px), rgba(255, 74, 61, 0.12) calc(50% + 118px) calc(50% + 120px), transparent calc(50% + 120px));
}

#ui-shell {
  z-index: 4;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}

#ui-shell::before {
  content: "";
  display: none;
}

#ui-header {
  width: min(960px, 96vw);
  display: grid;
  grid-template-columns: minmax(220px, 0.95fr) minmax(230px, 1fr) minmax(188px, 0.78fr);
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 7px 9px;
  border: 1px solid rgba(233, 244, 239, 0.24);
  border-left: 3px solid var(--core-red);
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(255, 74, 61, 0.12), transparent 24%),
    repeating-linear-gradient(90deg, rgba(143, 255, 245, 0.045) 0 1px, transparent 1px 26px),
    rgba(2, 5, 6, 0.86);
  box-shadow: 0 14px 36px var(--core-shadow), inset 0 0 0 1px rgba(143, 255, 245, 0.06);
}

#ui-header h1 {
  color: var(--core-paper);
  font-size: 18px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.subtitle {
  color: rgba(233, 244, 239, 0.62);
  letter-spacing: 0.07em;
}

.identity-line {
  color: rgba(143, 255, 245, 0.62);
  letter-spacing: 0.14em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#mode-indicator .label,
#bpm-indicator .label,
.auto-body .label,
.auto-body .hint {
  color: rgba(194, 218, 213, 0.54);
}

#mode-indicator {
  min-width: 0;
  text-align: center;
}

#mode-label {
  max-width: 100%;
  border-radius: 0;
  border-color: rgba(143, 255, 245, 0.4);
  background:
    linear-gradient(90deg, rgba(143, 255, 245, 0.08), rgba(255, 74, 61, 0.08)),
    rgba(1, 4, 5, 0.86);
  color: var(--core-cyan);
  font-size: 10px;
  letter-spacing: 0.18em;
  box-shadow: inset 0 0 0 1px rgba(233, 244, 239, 0.05);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#header-runtime {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  min-width: 0;
}

#header-runtime span {
  min-width: 0;
  min-height: 38px;
  display: grid;
  place-items: center;
  padding: 4px 5px;
  border: 1px solid rgba(143, 255, 245, 0.26);
  background:
    linear-gradient(180deg, rgba(143, 255, 245, 0.055), rgba(1, 4, 5, 0.72)),
    rgba(2, 6, 7, 0.78);
  box-shadow: inset 0 0 0 1px rgba(233, 244, 239, 0.035);
}

#header-runtime strong {
  display: block;
  max-width: 100%;
  color: var(--core-red);
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0.1em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#header-runtime em {
  display: block;
  color: rgba(143, 255, 245, 0.66);
  font-size: 7px;
  font-style: normal;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

#control-panel {
  position: relative;
  width: min(960px, 96vw);
  grid-template-columns: 0.82fr 1.58fr 0.94fr;
  column-gap: 12px;
  padding: 12px 13px 13px;
  border-radius: 0;
  border-color: rgba(233, 244, 239, 0.24);
  background:
    linear-gradient(135deg, rgba(143, 255, 245, 0.06), transparent 24%),
    linear-gradient(315deg, rgba(255, 74, 61, 0.08), transparent 28%),
    repeating-linear-gradient(90deg, rgba(233, 244, 239, 0.025) 0 1px, transparent 1px 38px),
    var(--core-panel);
  box-shadow:
    0 22px 72px rgba(0, 0, 0, 0.74),
    0 0 0 1px rgba(143, 255, 245, 0.08),
    inset 0 0 0 1px rgba(233, 244, 239, 0.04);
  backdrop-filter: blur(8px) contrast(1.16);
}

#control-panel::before {
  content: "";
  display: none;
}

#energy-column,
#right-column {
  border-color: rgba(233, 244, 239, 0.16);
}

#energy-column {
  padding-right: 6px;
}

#obs-grid {
  column-gap: 8px;
  row-gap: 8px;
  padding: 0 4px;
}

#right-column {
  justify-content: flex-start;
  gap: 8px;
  padding-left: 6px;
}

.fader-group,
#auto-block,
#preset-block,
#status-line {
  border-radius: 0;
  border-color: rgba(143, 255, 245, 0.2);
  background:
    linear-gradient(180deg, rgba(9, 16, 17, 0.84), rgba(1, 4, 5, 0.88)),
    repeating-linear-gradient(90deg, rgba(143, 255, 245, 0.04) 0 1px, transparent 1px 18px);
  box-shadow: inset 0 0 0 1px rgba(233, 244, 239, 0.035);
}

.fader-group::before {
  content: "";
  width: 100%;
  height: 2px;
  margin-bottom: 4px;
  background: linear-gradient(90deg, var(--core-red), transparent 34%, rgba(143, 255, 245, 0.48));
}

.label-main,
.auto-header .title {
  color: rgba(233, 244, 239, 0.92);
  letter-spacing: 0.2em;
}

.label-sub,
.fader-min,
.fader-max {
  color: rgba(143, 255, 245, 0.52);
}

.fader-value,
#bpm-value,
#output_value {
  color: var(--core-red);
}

.fader-vertical input[type="range"],
.auto-body input[type="range"] {
  filter: contrast(1.08);
}

.fader-vertical input[type="range"]::-webkit-slider-runnable-track,
.auto-body input[type="range"]::-webkit-slider-runnable-track {
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(143, 255, 245, 0.2), rgba(143, 255, 245, 0.72) 56%, rgba(255, 74, 61, 0.74)),
    repeating-linear-gradient(90deg, rgba(233, 244, 239, 0.5) 0 1px, transparent 1px 12px);
}

.fader-vertical input[type="range"]::-moz-range-track,
.auto-body input[type="range"]::-moz-range-track {
  border-radius: 0;
  background:
    linear-gradient(90deg, rgba(143, 255, 245, 0.2), rgba(143, 255, 245, 0.72) 56%, rgba(255, 74, 61, 0.74)),
    repeating-linear-gradient(90deg, rgba(233, 244, 239, 0.5) 0 1px, transparent 1px 12px);
}

.fader-vertical input[type="range"]::-webkit-slider-thumb,
.auto-body input[type="range"]::-webkit-slider-thumb {
  border-radius: 1px;
  border-color: rgba(233, 244, 239, 0.94);
  background: var(--core-red);
  box-shadow: 0 0 0 1px rgba(1, 3, 4, 0.9), 0 0 16px rgba(255, 74, 61, 0.28);
}

.fader-vertical input[type="range"]::-moz-range-thumb,
.auto-body input[type="range"]::-moz-range-thumb {
  border-radius: 1px;
  border-color: rgba(233, 244, 239, 0.94);
  background: var(--core-red);
  box-shadow: 0 0 0 1px rgba(1, 3, 4, 0.9), 0 0 16px rgba(255, 74, 61, 0.28);
}

.switch .slider {
  border-radius: 0;
  border: 1px solid rgba(143, 255, 245, 0.24);
  background: rgba(5, 9, 10, 0.94);
}

.switch .slider::before {
  border-radius: 1px;
  background: rgba(233, 244, 239, 0.92);
}

.switch input:checked + .slider {
  background: rgba(255, 74, 61, 0.8);
  box-shadow: 0 0 18px rgba(255, 74, 61, 0.2);
}

.performance-pad,
#transport button,
.recorder-button,
.recorder-link,
#preset_select,
#btn_reload_presets,
#audio_output_select,
.mini-action {
  border-radius: 0;
  font-family: inherit;
}

.performance-pad {
  border-color: rgba(143, 255, 245, 0.28);
  background:
    linear-gradient(135deg, transparent 0 11%, rgba(143, 255, 245, 0.08) 11% 12%, transparent 12%),
    linear-gradient(180deg, rgba(8, 16, 17, 0.94), rgba(1, 4, 5, 0.96));
  box-shadow: inset 0 0 0 1px rgba(233, 244, 239, 0.04);
}

.performance-pad .pad-main {
  color: rgba(233, 244, 239, 0.9);
}

.performance-pad .pad-sub {
  color: rgba(143, 255, 245, 0.54);
}

.performance-pad.active,
.performance-pad:active {
  border-color: rgba(255, 74, 61, 0.82);
  background:
    linear-gradient(135deg, rgba(255, 74, 61, 0.2), transparent 34%),
    linear-gradient(180deg, rgba(28, 8, 7, 0.96), rgba(2, 3, 4, 0.98));
  box-shadow:
    inset 0 0 0 1px rgba(255, 172, 154, 0.16),
    0 0 22px rgba(255, 74, 61, 0.22);
}

#transport button {
  border-color: rgba(233, 244, 239, 0.28);
  background:
    linear-gradient(180deg, rgba(9, 15, 16, 0.94), rgba(1, 3, 4, 0.96));
  color: rgba(233, 244, 239, 0.9);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

#transport button.primary {
  border-color: rgba(255, 74, 61, 0.86);
  background:
    linear-gradient(90deg, rgba(255, 74, 61, 0.9), rgba(215, 177, 90, 0.8));
  color: #050707;
}

#transport button.ghost:hover {
  background: rgba(20, 27, 28, 0.98);
  border-color: rgba(143, 255, 245, 0.52);
}

#preset_select {
  border-color: rgba(143, 255, 245, 0.24);
  background: rgba(1, 4, 5, 0.94);
}

#audio_output_select {
  border-color: rgba(143, 255, 245, 0.24);
  background: rgba(1, 4, 5, 0.94);
  color: rgba(233, 244, 239, 0.9);
}

.mini-action {
  border-color: rgba(143, 255, 245, 0.28);
  background:
    linear-gradient(180deg, rgba(8, 16, 17, 0.94), rgba(1, 4, 5, 0.96));
  color: rgba(233, 244, 239, 0.88);
}

.mini-action:hover,
.mini-action.active,
.mini-action[aria-pressed="true"] {
  border-color: rgba(255, 74, 61, 0.82);
  color: rgba(255, 235, 226, 0.95);
}

#status-line {
  color: rgba(194, 218, 213, 0.66);
}

body[data-playing="true"] {
  --panel-border: rgba(255, 74, 61, 0.52);
  --shadow-soft: 0 0 38px rgba(255, 74, 61, 0.15);
}

body[data-playing="true"][data-auto="true"] {
  --accent: var(--core-red);
  --accent-soft: var(--core-paper);
}

body[data-playing="true"][data-auto="true"] #auto-block,
body[data-playing="true"][data-auto="true"] .fader-group {
  border-color: rgba(255, 74, 61, 0.32);
  background:
    linear-gradient(90deg, rgba(255, 74, 61, 0.1), transparent 48%),
    rgba(3, 7, 8, 0.9);
}

#auto-block,
#preset-block {
  padding: 7px 8px;
  margin-bottom: 0;
}

.auto-header {
  margin-bottom: 5px;
}

.auto-body {
  gap: 6px;
}

.route-body {
  margin-top: 5px;
}

@media (max-width: 640px), (max-height: 760px) {
  .sync-next-row {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .packet-route-link {
    min-height: 44px;
    width: 100%;
  }

  body::before {
    opacity: 0.34;
  }

  body::after {
    opacity: 0.16;
  }

  #ui-shell {
    gap: 5px;
    padding: 0;
  }

  #ui-shell::before {
    display: none;
  }

  #ui-header {
    width: 100%;
    grid-template-columns: 1fr;
    align-items: stretch;
    border-left-width: 2px;
  }

  #ui-header h1 {
    font-size: 12px;
    letter-spacing: 0.12em;
  }

  #mode-indicator {
    grid-column: 1 / -1;
  }

  #header-runtime {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  #header-runtime span {
    min-height: 25px;
    padding: 3px 4px;
  }

  #header-runtime strong {
    font-size: 11px;
  }

  #control-panel::before {
    content: "";
  }
}

@media (max-width: 380px), (max-height: 700px) {
  #ui-header {
    grid-template-columns: 1fr;
  }
}

/* Final responsive operation pass.
   This sits last so the industrial skin cannot collapse the mobile controls. */
#transport-dock {
  display: grid;
  gap: 6px;
}

@media (max-width: 880px) {
  html,
  body {
    width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  body {
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }

  #ui-shell {
    position: relative;
    inset: auto;
    width: 100%;
    min-height: 100dvh;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    display: grid;
    grid-template-rows: auto 1fr;
    align-items: start;
    justify-content: stretch;
  }

  #ui-header,
  #control-panel {
    width: 100%;
    max-width: 720px;
    justify-self: center;
  }

  #ui-header {
    grid-template-columns: 1fr;
  }

  #control-panel {
    min-width: 0;
    max-height: none;
    overflow: visible;
    display: grid;
    grid-template-columns: 1fr;
    row-gap: 10px;
  }

  #energy-column,
  #right-column {
    min-width: 0;
    border-left: 0;
    border-right: 0;
    padding-left: 0;
    padding-right: 0;
  }

  #obs-grid {
    min-width: 0;
    overflow: visible;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #right-column {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #auto-block,
  #preset-block,
  #performance-pads,
  #transport-dock,
  #transport,
  #status-line {
    grid-area: auto;
  }
}

@media (max-width: 640px) {
  html,
  body {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-x: none;
  }

  #ui-shell {
    min-height: 100dvh;
    padding-bottom: calc(108px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  #ui-header {
    padding: 8px;
  }

  #ui-header h1 {
    font-size: 13px;
  }

  #header-runtime span {
    min-height: 34px;
  }

  #control-panel {
    padding: 8px;
    grid-template-rows: none;
    row-gap: 8px;
    backdrop-filter: none;
  }

  #energy-column {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #bpm-indicator {
    min-width: 0;
    padding: 7px 8px;
    border: 1px solid rgba(76, 202, 209, 0.2);
    text-align: left;
  }

  .fader-column,
  .fader-group {
    min-width: 0;
    align-items: stretch;
  }

  .fader-group {
    min-height: 68px;
    padding: 8px;
  }

  .fader-vertical,
  .fader-vertical.small {
    height: auto;
    min-height: 40px;
    display: grid;
    grid-template-columns: minmax(34px, auto) minmax(0, 1fr) minmax(40px, auto);
    gap: 8px;
    align-items: center;
  }

  .fader-vertical input[type="range"],
  .auto-body input[type="range"] {
    width: 100%;
    min-width: 0;
    height: 40px;
    touch-action: pan-y;
  }

  .fader-vertical input[type="range"]::-webkit-slider-runnable-track,
  .auto-body input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
  }

  .fader-vertical input[type="range"]::-moz-range-track,
  .auto-body input[type="range"]::-moz-range-track {
    height: 6px;
  }

  .fader-vertical input[type="range"]::-webkit-slider-thumb,
  .auto-body input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -9px;
  }

  .fader-vertical input[type="range"]::-moz-range-thumb,
  .auto-body input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  #right-column {
    grid-template-areas: none;
  }

  #auto-block,
  #preset-block {
    padding: 8px;
  }

  .auto-body,
  .route-body {
    min-height: 44px;
    display: grid;
    grid-template-columns: minmax(48px, auto) minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
  }

  .route-body .label,
  .auto-body .label,
  .auto-body .hint,
  .route-body .hint {
    display: inline;
  }

  #odd-logic-body {
    grid-template-columns: minmax(48px, auto) minmax(0, 1fr) auto auto;
  }

  #background-body {
    grid-template-columns: minmax(48px, auto) 1fr 1fr auto;
  }

  .switch {
    width: 48px;
    height: 28px;
  }

  .switch input {
    width: 48px;
    height: 28px;
  }

  .switch .slider::before {
    width: 22px;
    height: 22px;
    left: 2px;
    bottom: 2px;
  }

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

  button,
  select,
  .mini-action,
  .recorder-button,
  .recorder-link,
  #preset_select,
  #atmosphere_select,
  #source_color_select,
  #audio_output_select,
  #odd_logic_mode,
  #culture_grammar_select,
  #auto_arc_mode {
    min-height: 44px;
    font-size: 11px;
    touch-action: manipulation;
  }

  #performance-pads {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .performance-pad {
    min-height: 54px;
  }

  #transport-dock {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 20;
    max-width: 720px;
    margin: 0 auto;
    padding: 8px;
    border: 1px solid rgba(233, 244, 239, 0.24);
    background:
      linear-gradient(90deg, rgba(255, 74, 61, 0.12), transparent 34%),
      rgba(1, 4, 5, 0.94);
    box-shadow: 0 -14px 36px rgba(0, 0, 0, 0.58), inset 0 0 0 1px rgba(143, 255, 245, 0.08);
    backdrop-filter: blur(10px) contrast(1.08);
  }

  #transport {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
  }

  #transport button {
    min-width: 0;
    min-height: 50px;
    padding: 10px 8px;
    font-size: 13px;
  }

  #status-line {
    min-height: 44px;
    margin: 0;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    text-align: left;
  }

  #recorder-tools {
    margin-left: 0;
  }

  .recorder-button {
    min-width: 58px;
  }
}

@media (max-width: 430px) {
  #ui-shell {
    padding-left: max(6px, env(safe-area-inset-left));
    padding-right: max(6px, env(safe-area-inset-right));
  }

  #ui-header {
    gap: 6px;
  }

  .subtitle,
  .identity-line {
    display: none;
  }

  #control-panel {
    padding: 6px;
  }

  #obs-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  #energy-column,
  .fader-group {
    min-height: 52px;
  }

  .fader-title,
  .fader-label {
    margin-bottom: 2px;
  }

  .fader-vertical,
  .fader-vertical.small {
    min-height: 36px;
    grid-template-columns: 32px minmax(0, 1fr) 40px;
    gap: 6px;
  }

  .label-main {
    font-size: 9px;
  }

  .label-sub,
  .fader-min,
  .fader-max {
    font-size: 8px;
  }

  .auto-body,
  .route-body,
  #odd-logic-body,
  #background-body {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  #odd-logic-body,
  #background-body {
    grid-template-columns: 1fr 1fr;
  }

  #odd-logic-body .label,
  #odd-logic-body .hint,
  #background-body .label,
  #background-body .hint,
  #audio-route-body .hint {
    display: none;
  }

  .voice-controls {
    grid-template-columns: 1fr;
  }

  #transport-dock {
    padding: 7px;
  }

  #transport button {
    min-height: 48px;
  }
}

/* Final desktop interaction recovery pass.
   Keep the transport inside the control surface except on phone layouts. */
html,
body {
  width: 100%;
  min-width: 0;
  min-height: 100dvh;
  overflow-x: hidden;
}

body {
  height: auto;
  overflow-y: auto;
}

#ui-shell {
  position: relative;
  inset: auto;
  width: 100%;
  min-height: 100dvh;
  padding: clamp(10px, 2vh, 18px) clamp(10px, 2vw, 18px);
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  justify-items: center;
  gap: 10px;
}

#ui-header,
#control-panel {
  width: min(980px, calc(100vw - 24px));
  max-width: 980px;
  justify-self: center;
}

#control-panel {
  min-width: 0;
  max-height: none;
  overflow: visible;
  display: grid;
  grid-template-columns: minmax(140px, 0.78fr) minmax(360px, 1.65fr) minmax(260px, 1fr);
  gap: 12px;
}

#energy-column,
#obs-grid,
#right-column {
  min-width: 0;
}

#right-column {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "auto"
    "pads"
    "preset"
    "transport";
  align-content: start;
  gap: 8px;
}

#auto-block {
  grid-area: auto;
}

#performance-pads {
  grid-area: pads;
}

#preset-block {
  grid-area: preset;
}

#transport-dock {
  grid-area: transport;
  position: static;
  inset: auto;
  z-index: auto;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  display: grid;
  gap: 7px;
}

#transport {
  grid-area: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  position: relative;
  z-index: 2;
}

#transport button {
  min-width: 0;
  min-height: 56px;
  padding: 12px 10px;
  cursor: pointer;
  touch-action: manipulation;
  pointer-events: auto;
}

#status-line {
  grid-area: status;
  min-width: 0;
  min-height: 48px;
  margin: 0;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}

#recorder-tools {
  flex: 0 0 auto;
}

@media (max-width: 1100px) {
  #ui-shell {
    align-content: start;
  }

  #control-panel {
    grid-template-columns: minmax(130px, 0.72fr) minmax(320px, 1.48fr) minmax(250px, 0.98fr);
  }
}

@media (max-width: 880px) {
  #ui-shell {
    min-height: 100dvh;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  #ui-header,
  #control-panel {
    width: 100%;
    max-width: 720px;
  }

  #control-panel {
    grid-template-columns: 1fr;
    row-gap: 10px;
  }

  #right-column {
  grid-template-areas:
    "auto"
    "pads"
    "preset"
    "transport";
  }

  #auto-block,
  #preset-block,
  #performance-pads,
  #transport-dock,
  #transport,
  #status-line {
    grid-area: unset;
  }

  #auto-block {
    grid-area: auto;
  }

  #performance-pads {
    grid-area: pads;
  }

  #preset-block {
    grid-area: preset;
  }

  #transport-dock {
    grid-area: transport;
    position: static;
  }

}

@media (max-width: 640px) {
  #ui-shell {
    padding-bottom: calc(108px + env(safe-area-inset-bottom));
  }

  #transport-dock {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 20;
    max-width: 720px;
    margin: 0 auto;
    padding: 8px;
    border: 1px solid rgba(233, 244, 239, 0.24);
    background:
      linear-gradient(90deg, rgba(255, 74, 61, 0.12), transparent 34%),
      rgba(1, 4, 5, 0.94);
    box-shadow: 0 -14px 36px rgba(0, 0, 0, 0.58), inset 0 0 0 1px rgba(143, 255, 245, 0.08);
    backdrop-filter: blur(10px) contrast(1.08);
  }

  #transport button {
    min-height: 50px;
    padding: 10px 8px;
    font-size: 13px;
  }
}

/* MIC FOLLOW visibility + compact transport fit pass */
#right-column,
#transport-dock,
#transport,
#status-line,
.mic-follow-panel,
.sync-next-row {
  min-width: 0;
  box-sizing: border-box;
}

#transport-dock {
  width: 100%;
  gap: 6px;
  padding: 8px;
  overflow: hidden;
  border: 1px solid rgba(76, 202, 209, 0.14);
  background:
    linear-gradient(90deg, rgba(228, 77, 58, 0.07), transparent 30%),
    rgba(0, 7, 10, 0.62);
  display: flex;
  flex-direction: column;
}

#transport {
  width: 100%;
  margin-top: 0;
}

#transport button {
  min-height: 38px;
  padding: 8px 10px;
}

#status-line {
  min-height: 0;
  margin: 0;
  padding: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 6px;
  border: 1px solid rgba(76, 202, 209, 0.16);
  background: rgba(2, 8, 12, 0.52);
  text-align: center;
}

#status-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#recorder-tools {
  width: 100%;
  margin-left: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 5px;
}

#rec_download[hidden] {
  display: none !important;
}

.recorder-button,
.recorder-link,
.packet-button {
  min-width: 0;
  min-height: 30px;
  width: 100%;
  padding: 6px 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mic-follow-panel {
  min-height: 40px;
  padding: 6px 7px;
  display: grid;
  grid-template-columns: minmax(58px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 5px 7px;
  border: 1px solid rgba(118, 178, 184, 0.16);
  border-radius: 4px;
  background: rgba(0, 8, 10, 0.42);
  color: rgba(210, 238, 242, 0.66);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mic-follow-panel.is-active {
  border-color: rgba(164, 255, 204, 0.56);
  color: rgba(219, 255, 233, 0.92);
  box-shadow: inset 0 0 0 1px rgba(133, 255, 196, 0.08);
  background:
    linear-gradient(90deg, rgba(43, 255, 141, 0.1), transparent 48%),
    rgba(0, 12, 9, 0.58);
}

.mic-follow-panel.is-reacting {
  border-color: rgba(255, 223, 126, 0.64);
  color: rgba(255, 242, 196, 0.96);
}

.mic-follow-panel.is-error {
  border-color: rgba(255, 145, 118, 0.52);
  color: rgba(255, 214, 201, 0.9);
}

.mic-follow-meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid rgba(121, 183, 190, 0.2);
  background: rgba(0, 0, 0, 0.38);
}

#mic_follow_bar {
  width: 0%;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(134, 255, 200, 0.78), rgba(255, 226, 133, 0.9));
  transition: width 0.1s linear;
}

#mic_follow_detail {
  grid-column: 1 / -1;
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-next-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(48px, auto);
  align-items: center;
  gap: 6px;
  text-align: left;
}

.sync-next-row .hint {
  min-width: 0;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.packet-route-link {
  width: 100%;
  min-height: 28px;
  justify-content: center;
}

@media (max-width: 640px) {
  #ui-shell {
    padding-bottom: calc(178px + env(safe-area-inset-bottom));
  }

  #transport-dock {
    gap: 6px;
    padding: 7px;
  }

  #transport button {
    min-height: 48px;
    padding: 10px 8px;
  }

  #status-line {
    padding: 6px;
    gap: 6px;
  }

  #recorder-tools {
    gap: 6px;
  }

  .recorder-button,
  .recorder-link,
  .packet-button {
    min-height: 38px;
  }

  .mic-follow-panel {
    min-height: 42px;
    grid-template-columns: minmax(62px, auto) minmax(0, 1fr);
  }

  #mic_follow_detail {
    font-size: 8px;
  }

  .sync-next-row {
    grid-template-columns: minmax(0, 1fr);
    text-align: center;
  }
}
