@font-face {
  font-family: "OBS Noto Sans TC";
  src: url("./fonts/NotoSansTC-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "OBS Noto Serif TC";
  src: url("./fonts/NotoSerifTC-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "OBS WenKai TC";
  src: url("./fonts/LXGWWenKaiTC-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "OBS Iansui";
  src: url("./fonts/Iansui-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "OBS Huninn";
  src: url("./fonts/Huninn-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg-desk: #0d151e;
  --surface-rack: #14202d;
  --surface-card: #1a2a3b;
  --surface-well: #091018;
  --border-subtle: #263b50;
  --border-strong: #395773;
  --text-main: #f0f6fa;
  --text-muted: #95aec2;
  --brand-jade: #1ba6b8;
  --brand-jade-bright: #34c3d6;
  --signal-gold: #dfba69;
  --rec-crimson: #e03e3e;
  --ok-emerald: #26b879;
  --focus-ring: #f2c45a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg-desk);
  color: var(--text-main);
  accent-color: var(--brand-jade-bright);
  font-family: "OBS Noto Sans TC", "PingFang TC", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Simple Start vs Pro Mode visibility */
body[data-ui-mode="simple"] .pro-only {
  display: none !important;
}
body[data-ui-mode="pro"] .simple-only {
  display: none !important;
}

.studio-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface-rack);
  border-bottom: 1px solid var(--border-subtle);
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-emblem {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(140deg, #dfba69, #9a6f25);
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  font-family: "OBS Noto Serif TC", serif;
  font-weight: 800;
  font-size: 17px;
  color: #101922;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.brand-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

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

/* Workspace Layout */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 395px) minmax(0, 1fr);
  gap: 16px;
  padding: 14px 20px 18px;
  align-items: start;
}

@media (max-width: 880px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

.control-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 82px);
  overflow-y: auto;
  padding-right: 3px;
}

@media (max-width: 880px) {
  .control-column {
    max-height: none;
    overflow-y: visible;
  }
}

.rack-card {
  background: var(--surface-rack);
  border: 1px solid var(--border-subtle);
  border-radius: 15px;
  padding: 14px 15px;
}

.rack-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.rack-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--signal-gold);
  letter-spacing: 0.02em;
}

.section-divider {
  border: 0;
  border-top: 1px solid var(--border-subtle);
  margin: 13px 0;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 9px 0 4px;
}

.field-label:first-of-type {
  margin-top: 0;
}

.text-input,
.select-input {
  width: 100%;
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text-main);
  font-size: 13px;
}

.text-input:hover,
.select-input:hover {
  border-color: var(--border-strong);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Theme Gallery with Real Background Thumbnails */
.theme-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.theme-card {
  position: relative;
  border: 1.5px solid var(--border-subtle);
  border-radius: 9px;
  overflow: hidden;
  padding: 0;
  background: var(--surface-well);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, transform 0.12s ease;
}

.theme-card:hover {
  border-color: var(--border-strong);
}

.theme-card[aria-pressed="true"] {
  border-color: var(--signal-gold);
  box-shadow: 0 0 0 1px var(--signal-gold);
}

.theme-thumb {
  height: 36px;
  width: 100%;
  background-size: cover;
  background-position: center;
}

.theme-meta {
  padding: 4px 7px 5px;
}

.theme-meta strong {
  display: block;
  font-size: 12px;
  color: var(--text-main);
}

/* Font Selector Pills */
.font-pill-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.font-pill {
  border: 1px solid var(--border-subtle);
  background: var(--surface-well);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 4px;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}

.font-pill:hover {
  border-color: var(--border-strong);
  color: var(--text-main);
}

.font-pill[aria-pressed="true"] {
  border-color: var(--signal-gold);
  background: rgba(223, 186, 105, 0.16);
  color: #fff3d4;
  font-weight: 700;
}

/* Friendly Connect Source Cards */
.connect-stack {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.connect-card-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-card);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.connect-card-btn:hover {
  border-color: var(--brand-jade-bright);
  background: #203449;
}

.connect-card-btn.connected {
  border-color: var(--ok-emerald);
  background: rgba(38, 184, 121, 0.12);
}

.connect-icon {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.connect-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.connect-copy strong {
  font-size: 13px;
  color: var(--text-main);
}

.connect-copy span {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Layout Pills */
.layout-pill-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.layout-pill {
  border: 1px solid var(--border-subtle);
  background: var(--surface-well);
  border-radius: 9px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
}

.layout-pill[aria-pressed="true"] {
  border-color: var(--brand-jade-bright);
  background: rgba(27, 166, 184, 0.18);
  color: var(--text-main);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-card);
  color: var(--text-main);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--brand-jade-bright);
  background: #21364c;
}

.btn[aria-pressed="true"] {
  border-color: var(--signal-gold);
  background: rgba(223, 186, 105, 0.18);
  color: #fff2ce;
}

.btn-primary {
  background: var(--brand-jade);
  border-color: var(--brand-jade-bright);
  color: #04131a;
  font-weight: 700;
}

.btn-record {
  background: var(--rec-crimson);
  border-color: #f26464;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 24px;
  border-radius: 11px;
}

.btn-record:hover:not(:disabled) {
  background: #eb4c4c;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 7px;
}

.seg-row {
  display: flex;
  gap: 5px;
}

.seg-btn {
  flex: 1;
  border: 1px solid var(--border-subtle);
  background: var(--surface-well);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn[aria-pressed="true"] {
  border-color: var(--brand-jade-bright);
  background: rgba(27, 166, 184, 0.18);
  color: var(--text-main);
}

/* Switch Control (Native HTML switch + progressive fallback) */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  cursor: pointer;
}

input[type="checkbox"][switch] {
  accent-color: var(--brand-jade-bright);
  margin: 0;
  cursor: pointer;
}

input[type="checkbox"][switch]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

input[type="checkbox"].switch-fallback {
  appearance: none;
  -webkit-appearance: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #2b3f54;
  border: 1px solid var(--border-strong);
  position: relative;
  flex-shrink: 0;
  transition: background 0.16s ease;
}

input[type="checkbox"].switch-fallback::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s ease;
}

input[type="checkbox"].switch-fallback:checked {
  background: var(--brand-jade);
  border-color: var(--brand-jade-bright);
}

input[type="checkbox"].switch-fallback:checked::after {
  transform: translateX(16px);
}

@supports not (accent-color: #34c3d6) {
  input[type="checkbox"]:not(.switch-fallback) {
    width: 16px;
    height: 16px;
  }
}

/* Brand-Consistent Range Slider (separate WebKit / Moz rules) */
input[type="range"].studio-slider {
  --slider-track-size: 0.42rem;
  --slider-thumb-size: 1.08rem;
  --slider-track-radius: 999px;
  --slider-thumb-radius: 50%;
  --slider-track-color: #263a4f;
  --slider-fill-color: var(--brand-jade-bright);
  --slider-thumb-color: #eef8fb;
  --slider-direction: to right;
  --attr-min: attr(min type(<number>), 0);
  --attr-max: attr(max type(<number>), 100);
  --control-value: attr(value type(<number>), 50);
  --slider-progress: calc(
    progress(var(--control-value), var(--attr-min), var(--attr-max)) * 100%
  );

  appearance: none;
  -webkit-appearance: none;
  inline-size: 100%;
  block-size: 1.85rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

@supports not (opacity: progress(1, 0, 100)) {
  input[type="range"].studio-slider {
    --slider-progress: calc(
      (var(--control-value) - var(--attr-min)) /
      (var(--attr-max) - var(--attr-min)) * 100%
    );
  }
}

input[type="range"].studio-slider::-webkit-slider-runnable-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: linear-gradient(
    var(--slider-direction),
    var(--slider-fill-color) var(--slider-progress),
    var(--slider-track-color) var(--slider-progress)
  );
}

input[type="range"].studio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  margin-block-start: calc(
    (var(--slider-track-size) - var(--slider-thumb-size)) / 2
  );
  border: 2px solid var(--brand-jade);
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

input[type="range"].studio-slider::-moz-range-track {
  block-size: var(--slider-track-size);
  border: 0;
  border-radius: var(--slider-track-radius);
  background: var(--slider-track-color);
}

input[type="range"].studio-slider::-moz-range-progress {
  block-size: var(--slider-track-size);
  border-radius: var(--slider-track-radius);
  background: var(--slider-fill-color);
}

input[type="range"].studio-slider::-moz-range-thumb {
  inline-size: var(--slider-thumb-size);
  block-size: var(--slider-thumb-size);
  border: 2px solid var(--brand-jade);
  border-radius: var(--slider-thumb-radius);
  background: var(--slider-thumb-color);
}

input[type="range"].studio-slider:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

/* Audio Units & Meter */
.dsp-unit {
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 11px;
  margin-top: 8px;
}

.dsp-unit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dsp-readout {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 700;
  color: var(--signal-gold);
}

.meter-box {
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 11px;
  margin-top: 8px;
}

.meter-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: #14202d;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #24b47e 0%, #24b47e 70%, #e5b95c 86%, #e03e3e 100%);
  transition: width 0.05s linear;
}

.meter-peak-pin {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  left: 0%;
}

.gr-track {
  height: 5px;
  border-radius: 999px;
  background: #14202d;
  overflow: hidden;
  margin-top: 4px;
}

.gr-fill {
  height: 100%;
  width: 0%;
  margin-left: auto;
  background: #f08c3a;
  transition: width 0.06s linear;
}

/* Stage & Transport */
.stage-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 14px;
}

.stage-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-rack);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 8px 12px;
}

.stage-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface-well);
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.48);
  -webkit-user-select: none;
  user-select: none;
}

#compositorCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.snap-guide-v,
.snap-guide-h {
  position: absolute;
  background: rgba(223, 186, 105, 0.88);
  pointer-events: none;
  z-index: 15;
}

.snap-guide-v { top: 0; bottom: 0; width: 1px; }
.snap-guide-h { left: 0; right: 0; height: 1px; }

.frame-gizmo {
  position: absolute;
  border: 1.5px dashed rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  pointer-events: auto;
  transition: border-color 0.12s ease;
}

.frame-gizmo:hover {
  border-color: rgba(52, 195, 214, 0.85);
}

.frame-gizmo.selected {
  border: 2px solid var(--signal-gold);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
  z-index: 12;
}

.frame-drag-grip {
  position: absolute;
  top: -26px;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 6px 6px 0 0;
  border: 1px solid rgba(223, 186, 105, 0.75);
  background: rgba(9, 16, 24, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.frame-gizmo[data-near-top="1"] .frame-drag-grip {
  top: 4px;
  left: 4px;
  border-radius: 6px;
}

.frame-gizmo.selected .frame-drag-grip,
.frame-gizmo:hover .frame-drag-grip,
.frame-gizmo:focus-within .frame-drag-grip {
  opacity: 1;
  pointer-events: auto;
}

.frame-drag-grip.dragging {
  cursor: grabbing;
  background: var(--signal-gold);
  color: #091018;
}

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--signal-gold);
  border: 1.5px solid #091018;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: none;
}

.frame-gizmo.selected .resize-handle {
  display: block;
}

.resize-handle[data-dir="nw"] { top: -6px; left: -6px; cursor: nwse-resize; }
.resize-handle[data-dir="n"]  { top: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.resize-handle[data-dir="ne"] { top: -6px; right: -6px; cursor: nesw-resize; }
.resize-handle[data-dir="e"]  { top: calc(50% - 6px); right: -6px; cursor: ew-resize; }
.resize-handle[data-dir="se"] { bottom: -6px; right: -6px; cursor: nwse-resize; }
.resize-handle[data-dir="s"]  { bottom: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.resize-handle[data-dir="sw"] { bottom: -6px; left: -6px; cursor: nesw-resize; }
.resize-handle[data-dir="w"]  { top: calc(50% - 6px); left: -6px; cursor: ew-resize; }

.transport-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-rack);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px 18px;
}

.rec-tally {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-variant-numeric: tabular-nums;
  font-size: 19px;
  font-weight: 800;
}

.tally-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #52687a;
}

.tally-dot.live {
  background: var(--rec-crimson);
  box-shadow: 0 0 12px var(--rec-crimson);
  animation: tally-pulse 1.1s ease-in-out infinite alternate;
}

.tally-dot.paused {
  background: var(--signal-gold);
}

@keyframes tally-pulse {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tally-dot.live { animation: none; }
}

.takes-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 8px;
}

.take-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-well);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-size: 13px;
}

dialog {
  background: var(--surface-rack);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 20px;
  max-width: 440px;
  width: calc(100% - 32px);
}

dialog.preview-dialog {
  max-width: min(880px, calc(100% - 32px));
}

dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(4, 10, 16, 0.72);
  overflow: hidden;
  overscroll-behavior: contain;
}
