:root {
  --bg-void: #070310;
  --bg-studio: #0d061a;
  --bg-card: #150b28;
  --bg-card-elev: #1d1035;
  --border-subtle: rgba(139, 30, 255, 0.28);
  --border-gold: rgba(255, 200, 87, 0.45);
  --purple: #8b1eff;
  --purple-bright: #b54cff;
  --magenta: #e028ff;
  --coral: #ff6e7f;
  --gold: #ffc857;
  --text-main: #f5f2ff;
  --text-muted: #b5aad0;
  --twitch-dark-bg: #0e0e10;
  --twitch-dark-card: #18181b;
  --twitch-dark-border: #2a2438;
  --twitch-light-bg: #f7f7f8;
  --twitch-light-card: #ffffff;
  --twitch-light-border: #e2dfea;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-void);
  color: var(--text-main);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Top App Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: linear-gradient(90deg, #090315 0%, #14072b 50%, #090315 100%);
  border-bottom: 1px solid rgba(139, 30, 255, 0.42);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), var(--magenta), var(--purple), var(--gold));
  opacity: 0.75;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 36px;
  border-radius: 8px;
  background: radial-gradient(circle at center, rgba(139, 30, 255, 0.35), rgba(14, 6, 27, 0.95));
  border: 1px solid rgba(255, 200, 87, 0.45);
  overflow: hidden;
  padding: 2px;
}

.topbar-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: #ffffff;
}

.brand-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--gold);
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.segmented-group {
  display: inline-flex;
  background: #0b0516;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover {
  color: #ffffff;
}

.seg-btn.is-active {
  background: linear-gradient(135deg, var(--purple) 0%, #6a11cb 100%);
  color: #ffffff;
  box-shadow: 0 0 12px rgba(139, 30, 255, 0.45);
}

.export-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ctrl-select {
  background: #120824;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-select:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.btn-volt {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 15px;
  background: linear-gradient(135deg, #ffd466 0%, #ffc857 55%, #ff9f43 100%);
  color: #120520;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(255, 200, 87, 0.35);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.btn-volt:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 24px rgba(255, 200, 87, 0.55);
}

.btn-outline-volt {
  appearance: none;
  background: rgba(255, 200, 87, 0.08);
  color: var(--gold);
  border: 1px solid rgba(255, 200, 87, 0.55);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-outline-volt:hover {
  background: var(--gold);
  color: #120520;
}

/* Workspace Layout */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 365px;
  min-height: calc(100vh - 60px);
}

body.mode-preview .workspace {
  grid-template-columns: minmax(0, 1fr);
}

body.mode-preview .sidebar {
  display: none;
}

/* Stage Surface Modes (Twitch Dark & Light) */
.stage {
  padding: 22px 24px 56px;
  overflow-x: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body.surface-dark .stage {
  background:
    radial-gradient(circle at 18% 0%, rgba(139, 30, 255, 0.14) 0%, transparent 45%),
    radial-gradient(circle at 86% 6%, rgba(255, 200, 87, 0.08) 0%, transparent 35%),
    var(--twitch-dark-bg);
  color: #efeff1;
}

body.surface-light .stage {
  background: var(--twitch-light-bg);
  color: #0e0e10;
}

.stage-inner {
  max-width: 1360px;
  margin: 0 auto;
}

/* Channel Banner & About Hero */
.channel-about-hero {
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--twitch-dark-border);
  background: #120922;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

body.surface-light .channel-about-hero {
  background: var(--twitch-light-card);
  border-color: var(--twitch-light-border);
  box-shadow: 0 6px 24px rgba(24, 12, 48, 0.08);
}

.hero-banner-art {
  position: relative;
  height: 175px;
  background: #03000b;
  overflow: hidden;
}

.hero-banner-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 45%;
  display: block;
}

.hero-banner-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(7, 3, 16, 0.05) 35%, rgba(14, 6, 27, 0.9) 100%);
}

body.surface-light .hero-banner-scrim {
  background: linear-gradient(180deg, rgba(7, 3, 16, 0.05) 45%, rgba(14, 6, 27, 0.72) 100%);
}

.hero-profile-card {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px 18px;
  margin-top: -28px;
  z-index: 2;
}

.hero-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 460px;
}

.hero-avatar-ring {
  flex: 0 0 auto;
  width: 78px;
  height: 78px;
  border-radius: 16px;
  padding: 4px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--coral) 45%, var(--purple) 100%);
  box-shadow: 0 0 22px rgba(139, 30, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 12px;
  background: #0a0415;
  padding: 4px;
}

.hero-meta {
  min-width: 0;
}

.hero-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.hero-name {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.gold-dj {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 200, 87, 0.55);
}

body.surface-light .gold-dj {
  color: #d98200;
  text-shadow: none;
}

.hero-verified {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--purple);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
}

.hero-live-pill {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 200, 87, 0.14);
  color: var(--gold);
  border: 1px solid rgba(255, 200, 87, 0.45);
}

body.surface-light .hero-live-pill {
  background: rgba(139, 30, 255, 0.1);
  color: #6a11cb;
  border-color: rgba(139, 30, 255, 0.35);
}

.hero-followers {
  margin: 3px 0 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

body.surface-light .hero-followers {
  color: #53535f;
}

.hero-bio {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.48;
  max-width: 720px;
}

.hero-social-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-pill {
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 7px;
  background: rgba(139, 30, 255, 0.16);
  border: 1px solid rgba(139, 30, 255, 0.35);
  color: #e9dcff;
}

body.surface-light .hero-pill {
  background: #efeaff;
  color: #4b158d;
  border-color: #d6c4ff;
}

.hero-pill.is-accent {
  background: linear-gradient(135deg, var(--purple) 0%, #a927ff 100%);
  border-color: rgba(255, 200, 87, 0.6);
  color: #ffffff;
}

/* Subbar */
.stage-subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.stage-subbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.count-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(139, 30, 255, 0.18);
  border: 1px solid rgba(139, 30, 255, 0.4);
  color: #e4d2ff;
}

body.surface-light .count-badge {
  background: #ece6ff;
  color: #511599;
}

.stage-hint {
  font-size: 12px;
  color: var(--text-muted);
}

body.surface-light .stage-hint {
  color: #53535f;
}

body.mode-preview .stage-hint,
body.mode-preview #btnAddPanelStage {
  display: none;
}

/* Authentic 320px Twitch Masonry Grid */
.panels-grid {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

.masonry-col {
  width: 320px;
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.twitch-panel-card {
  position: relative;
  width: 320px;
  border-radius: 10px;
  transition: transform 0.14s ease, box-shadow 0.16s ease;
}

body.mode-studio .twitch-panel-card {
  cursor: pointer;
}

body.mode-studio .twitch-panel-card:hover {
  transform: translateY(-2px);
}

body.mode-studio .twitch-panel-card.is-selected {
  box-shadow: 0 0 0 2px var(--gold), 0 0 24px rgba(139, 30, 255, 0.55);
}

.panel-actions-bar {
  position: absolute;
  top: -12px;
  right: 8px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 999px;
  background: rgba(11, 5, 22, 0.94);
  border: 1px solid rgba(255, 200, 87, 0.5);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
}

body.mode-studio .twitch-panel-card:hover .panel-actions-bar,
body.mode-studio .twitch-panel-card.is-selected .panel-actions-bar {
  opacity: 1;
  pointer-events: auto;
}

body.mode-preview .panel-actions-bar {
  display: none;
}

.panel-act-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: #f3ecff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 999px;
  cursor: pointer;
}

.panel-act-btn:hover {
  background: var(--purple);
  color: #ffffff;
}

.panel-act-btn.is-gold:hover {
  background: var(--gold);
  color: #120520;
}

.panel-banner-link {
  display: block;
  text-decoration: none;
  line-height: 0;
}

.panel-banner-canvas {
  display: block;
  width: 320px;
  height: auto;
}

/* Twitch Markdown Body */
.panel-markdown-body {
  padding: 10px 4px 4px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}

.panel-markdown-body:empty {
  display: none;
}

.panel-markdown-body h1,
.panel-markdown-body h2,
.panel-markdown-body h3 {
  margin: 10px 0 6px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold);
}

.panel-markdown-body h1:first-child,
.panel-markdown-body h2:first-child,
.panel-markdown-body h3:first-child {
  margin-top: 2px;
}

body.surface-light .panel-markdown-body h1,
body.surface-light .panel-markdown-body h2,
body.surface-light .panel-markdown-body h3 {
  color: #6a11cb;
}

.panel-markdown-body p {
  margin: 0 0 8px;
}

.panel-markdown-body p:last-child {
  margin-bottom: 0;
}

.panel-markdown-body ul,
.panel-markdown-body ol {
  margin: 4px 0 10px;
  padding-left: 20px;
}

.panel-markdown-body li {
  margin-bottom: 4px;
}

.panel-markdown-body strong {
  font-weight: 700;
  color: #ffffff;
}

body.surface-light .panel-markdown-body strong {
  color: #0e0e10;
}

.panel-markdown-body a {
  color: #bf94ff;
  font-weight: 600;
  text-decoration: none;
}

.panel-markdown-body a:hover {
  color: var(--gold);
  text-decoration: underline;
}

body.surface-light .panel-markdown-body a {
  color: #772ce8;
}

.panel-markdown-body code {
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(139, 30, 255, 0.2);
  color: var(--gold);
}

body.surface-light .panel-markdown-body code {
  background: #ece5ff;
  color: #511599;
}

.panel-markdown-body blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--gold);
  background: rgba(255, 200, 87, 0.08);
  border-radius: 0 6px 6px 0;
  color: #ded6f3;
  font-size: 13px;
}

body.surface-light .panel-markdown-body blockquote {
  background: #efeaff;
  border-left-color: #772ce8;
  color: #2f2b3a;
}

.panel-markdown-body hr {
  border: 0;
  border-top: 1px solid rgba(139, 30, 255, 0.3);
  margin: 10px 0;
}

/* Studio Inspector Sidebar */
.sidebar {
  background: var(--bg-studio);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 58px);
  position: sticky;
  top: 58px;
  overflow-y: auto;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border-subtle);
  background: #090315;
  position: sticky;
  top: 0;
  z-index: 10;
}

.tab-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 700;
  padding: 12px 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.is-active {
  color: #ffffff;
  border-bottom-color: var(--gold);
  background: rgba(139, 30, 255, 0.12);
}

.tab-content {
  display: none;
}

.tab-content.is-active {
  display: block;
}

.inspector-section {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(139, 30, 255, 0.16);
}

.field-group {
  margin-bottom: 12px;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.field-label-row .field-label {
  margin-bottom: 0;
}

.field-hint {
  font-size: 10px;
  color: #8f82ae;
}

.value-pill {
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
}

.ctrl-input,
.ctrl-textarea {
  width: 100%;
  background: #140a27;
  color: #ffffff;
  border: 1px solid rgba(139, 30, 255, 0.35);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

.ctrl-textarea {
  resize: vertical;
  line-height: 1.45;
}

.ctrl-input:focus,
.ctrl-textarea:focus {
  outline: 0;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 200, 87, 0.22);
}

.btn-row-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.btn-sm {
  appearance: none;
  background: #1c0f34;
  color: #efe9ff;
  border: 1px solid rgba(139, 30, 255, 0.35);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.btn-sm:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.btn-sm.btn-danger:hover {
  border-color: #ff6b8b;
  color: #ff9cb2;
}

.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.icon-choice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: 8px;
  background: #140a27;
  border: 1px solid rgba(139, 30, 255, 0.28);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
}

.icon-choice-btn:hover {
  border-color: var(--purple-bright);
  color: #ffffff;
}

.icon-choice-btn.is-active {
  background: rgba(139, 30, 255, 0.28);
  border-color: var(--gold);
  color: var(--gold);
}

.icon-choice-canvas {
  display: block;
  width: 28px;
  height: 28px;
}

.single-export-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-primary-purple {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 9px 12px;
  background: linear-gradient(135deg, #a828ff 0%, #7d17eb 100%);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary-purple:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  appearance: none;
  border: 1px solid rgba(139, 30, 255, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  background: #170c2b;
  color: #f3ecff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.style-preset-grid,
.palette-swatch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-btn {
  appearance: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  background: #140a27;
  border: 1px solid rgba(139, 30, 255, 0.3);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.preset-btn span {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

.preset-btn.is-active {
  border-color: var(--gold);
  background: rgba(139, 30, 255, 0.25);
}

.palette-swatch-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  background: #140a27;
  border: 1px solid rgba(139, 30, 255, 0.3);
  color: var(--text-main);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.palette-swatch-btn:hover {
  border-color: var(--gold);
}

.swatch-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.swatch-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.color-picker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-main);
  cursor: pointer;
}

.color-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hex-label {
  font-family: Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
}

input[type="color"] {
  width: 34px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.ctrl-range {
  width: 100%;
  accent-color: var(--gold);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-main);
  margin-top: 8px;
  cursor: pointer;
}

.check-row input {
  accent-color: var(--gold);
}

.btn-danger-outline {
  width: 100%;
  appearance: none;
  background: transparent;
  color: #ff8aa5;
  border: 1px solid rgba(255, 110, 127, 0.5);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-danger-outline:hover,
.btn-danger-outline.is-confirming {
  background: rgba(255, 92, 128, 0.2);
  color: #ffd3de;
  border-color: #ff6e7f;
}

/* Toasts */
.toast-container {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: #140826;
  color: #ffffff;
  border: 1px solid var(--gold);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  font-size: 12.5px;
  font-weight: 600;
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--border-subtle);
  }
}
