/* Pixelroom Widgets — design system
   Deep violet dark stage (native to OBS/streaming), pastel gradient accent
   echoing the widgets themselves. Display: Bricolage Grotesque.
   Body/UI: Instrument Sans. Code/URLs: JetBrains Mono. */

@property --ring {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

:root {
  --bg: #0e0b18;
  --surface: #161123;
  --surface-2: #1d1730;
  --line: rgba(214, 200, 255, 0.10);
  --text: #f1edfa;
  --muted: #9b91b8;
  --acc-1: #b49cff;
  --acc-2: #f9a8d4;
  --acc-3: #fde68a;
  --grad: linear-gradient(120deg, var(--acc-1), var(--acc-2) 55%, var(--acc-3));
  --danger: #ff7b8a;
  --ok: #7be0a8;
  --radius: 14px;
  --font-display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
  --font-body: 'Instrument Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(180, 156, 255, 0.10), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(249, 168, 212, 0.07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

a { color: var(--acc-1); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.86em; color: var(--acc-2); }

:focus-visible {
  outline: 2px solid var(--acc-1);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Top bar / footer ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.01em;
  color: var(--text);
}
.wordmark:hover { text-decoration: none; }
.wordmark em { font-style: normal; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.wordmark-badge {
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 2.5px solid var(--acc-1);
  box-shadow: inset 0 0 0 2.5px var(--bg), inset 0 0 0 7px var(--acc-2);
}

.topnav { display: flex; align-items: center; gap: 20px; }
.topnav a { color: var(--muted); font-weight: 500; }
.topnav a.active, .topnav a:hover { color: var(--text); text-decoration: none; }
.inline-form { display: inline; }

.main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 48px) 64px; }

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  justify-content: space-between;
  padding: 20px clamp(16px, 4vw, 48px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Type ---------- */

h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(26px, 4.5vw, 44px);
  line-height: 1.06;
  letter-spacing: -0.015em;
  margin: 0 0 12px;
}

h2 { font-family: var(--font-display); font-weight: 600; font-size: 18px; margin: 0; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--acc-2);
  margin: 0 0 10px;
}

/* ---------- Gallery ---------- */

.hero { padding: clamp(36px, 7vw, 72px) 0 36px; max-width: 640px; }
.hero-sub { color: var(--muted); font-size: 16px; margin: 14px 0 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 22px;
  padding-bottom: 24px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.card:hover {
  text-decoration: none;
  transform: translateY(-3px);
  border-color: rgba(180, 156, 255, 0.45);
  box-shadow: 0 14px 40px -18px rgba(180, 156, 255, 0.35);
}

.card-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background:
    repeating-conic-gradient(#161227 0% 25%, #1b1530 0% 50%);
  background-size: 22px 22px;
}
.card-stage iframe {
  position: absolute;
  top: 0; left: 0;
  width: 1920px; height: 1080px;
  border: 0;
  transform-origin: top left;
  /* scaled to card width via inline JS-free trick: card is ~380px -> use scale from container query fallback */
  transform: scale(0.208);
  pointer-events: none;
}

.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 6px; }
.card-body p { margin: 0; color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-cta {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--acc-1);
}

.empty { color: var(--muted); }

.chip {
  position: absolute;
  top: 10px; right: 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
}
.chip-draft { background: rgba(253, 230, 138, 0.14); color: var(--acc-3); border: 1px solid rgba(253, 230, 138, 0.35); position: static; }
.card-stage .chip-draft { position: absolute; }
.chip-live { background: rgba(123, 224, 168, 0.12); color: var(--ok); border: 1px solid rgba(123, 224, 168, 0.3); position: static; }

/* ---------- Customizer ---------- */

.customizer {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  padding-top: 28px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel-head h1 { font-size: 24px; }
.panel-desc { color: var(--muted); font-size: 13.5px; margin: 4px 0 6px; }

.group {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}
.group summary {
  cursor: pointer;
  list-style: none;
  padding: 11px 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.group summary::-webkit-details-marker { display: none; }
.group summary::after {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  margin-right: 2px;
}
.group[open] summary::after { transform: rotate(225deg); }
.group-fields { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--muted); }

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  width: 100%;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row output {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--acc-3);
  min-width: 42px;
  text-align: right;
}

input[type="range"] {
  flex: 1;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--acc-1), var(--acc-2));
  outline-offset: 6px;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--acc-1), 0 2px 8px rgba(0,0,0,0.5);
  cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--acc-1);
  cursor: grab;
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: linear-gradient(90deg, var(--acc-1), var(--acc-2)); }

.color-row { display: flex; align-items: center; gap: 10px; }
input[type="color"] {
  appearance: none;
  width: 44px; height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }
.color-code { font-size: 12px; color: var(--muted); }

.field-check { flex-direction: row; align-items: center; gap: 8px; }
.field-check input { width: auto; }
.field-check label { color: var(--text); font-size: 13.5px; }

.inline-action-row { display: flex; gap: 8px; }
.inline-action-row input { flex: 1; min-width: 0; }
.btn-apply {
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  padding: 0 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.btn-apply:hover { border-color: var(--acc-1); color: var(--acc-2); }
.btn-apply.applied { border-color: var(--ok); color: var(--ok); }

.field-hint { margin: 6px 0 0; color: var(--muted); font-size: 11.5px; }
.field-hint.pending { color: var(--acc-3); }
.field-hint.error { color: var(--danger); }

.save-actions { display: flex; flex-direction: column; gap: 6px; }
.save-actions[hidden] { display: none; }
.save-actions .field-hint { margin: 0; }

button:disabled { opacity: 0.55; cursor: default; }

.degraded-banner {
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 123, 138, 0.08);
  border: 1px solid rgba(255, 123, 138, 0.3);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.5;
}
.degraded-banner[hidden] { display: none; }

/* ---------- Preview stage ---------- */

.preview-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.stage-wrap { display: flex; flex-direction: column; gap: 8px; }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: repeating-conic-gradient(#151126 0% 25%, #1a1430 0% 50%);
  background-size: 26px 26px;
}
.stage iframe {
  position: absolute;
  top: 0; left: 0;
  width: 1920px;
  height: 1080px;
  border: 0;
  transform-origin: top left;
  /* actual scale set by JS to stage width / 1920 */
}

.stage-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
}
.stage-hint { color: var(--acc-3); opacity: 0.75; }

/* ---------- The signature: OBS URL bar ---------- */

.url-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
}
.url-label {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
}

.url-bar {
  position: relative;
  display: flex;
  gap: 0;
  border-radius: 11px;
  padding: 2px;
  background: conic-gradient(from var(--ring), var(--acc-1), var(--acc-2), var(--acc-3), var(--acc-1));
  animation: ring-spin 6s linear infinite;
}
@keyframes ring-spin { to { --ring: 360deg; } }

.url-bar input {
  flex: 1;
  border: 0;
  border-radius: 9px 0 0 9px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--acc-3);
  padding: 11px 12px;
  min-width: 0;
}
.url-bar button {
  border: 0;
  border-radius: 0 9px 9px 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  padding: 0 18px;
  cursor: pointer;
  border-left: 1px solid var(--line);
}
.url-bar button:hover { color: var(--acc-2); }
.url-bar button.copied { color: var(--ok); }

.url-help { margin: 10px 0 0; color: var(--muted); font-size: 12.5px; }
.url-help strong { color: var(--text); font-weight: 600; }

.status-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.status-list dt { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.status-list dd { margin: 2px 0 0; font-family: var(--font-mono); font-size: 13px; color: var(--acc-3); }
.status-empty { margin: 0; color: var(--muted); font-size: 12.5px; }

.commands-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.command-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.command-row code {
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 12.5px;
}
.command-desc { flex: 1; min-width: 140px; color: var(--muted); font-size: 13px; }
.btn-try {
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.btn-try:hover { border-color: var(--acc-1); color: var(--acc-2); }
.btn-try.tried { border-color: var(--ok); color: var(--ok); }

/* ---------- Buttons ---------- */

.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  padding: 10px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--grad); color: #17102a; }
.btn-primary:hover { filter: brightness(1.08); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--acc-1); text-decoration: none; }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(255, 123, 138, 0.35); }
.btn-danger:hover { background: rgba(255, 123, 138, 0.1); }

.linklike {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}
.linklike:hover { color: var(--text); text-decoration: underline; }

/* ---------- Login ---------- */

.login-wrap { display: flex; justify-content: center; padding: 12vh 0 0; }
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 26px; margin: 0; }
.login-card label { font-size: 12.5px; color: var(--muted); }

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  background: rgba(255, 123, 138, 0.08);
  border: 1px solid rgba(255, 123, 138, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
}

/* ---------- Admin list ---------- */

.admin-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(28px, 5vw, 48px) 0 20px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.admin-table th {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}
.admin-table tr:last-child td { border-bottom: 0; }
.row-name { color: var(--text); font-weight: 600; }
.cell-date { color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions a { margin-left: 14px; font-weight: 500; }

/* ---------- Admin editor ---------- */

.editor { padding-top: 28px; display: flex; flex-direction: column; gap: 22px; }

.editor-meta { display: flex; flex-direction: column; gap: 16px; }
.editor-meta h1 { font-size: 26px; }
.editor-meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.field-wide { grid-column: 1 / -1; }

.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.editor-code {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-2); color: var(--acc-2); border-color: var(--line); }

textarea.code {
  display: none;
  width: 100%;
  height: 460px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  tab-size: 2;
  white-space: pre;
}
textarea.code.active { display: block; }

.editor-hint { margin: 0; color: var(--muted); font-size: 12px; }

.editor-preview { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
.editor-actions { display: flex; gap: 10px; flex-wrap: wrap; }

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

@media (max-width: 960px) {
  .customizer { grid-template-columns: 1fr; }
  .editor-split { grid-template-columns: 1fr; }
  .editor-preview { position: static; }
  .editor-meta-fields { grid-template-columns: 1fr; }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .url-bar { animation: none; }
  .card { transition: none; }
  * { scroll-behavior: auto !important; }
}
