:root {
  /* Flat, native-Twitch palette — no gradients */
  --bg: #0e0e10;          /* page background (Twitch app dark) */
  --bg-2: #18181b;        /* chat / surface */
  --panel: #1f1f23;       /* card surface (Twitch panel) */
  --panel-2: #26262c;     /* raised element */
  --panel-solid: #1f1f23;
  --border: #2a2a2d;      /* Twitch hairline */
  --border-strong: #3a3a3d;
  --text: #efeff1;        /* Twitch text */
  --text-dim: #adadb8;    /* Twitch muted text */
  --accent: #9147ff;      /* Twitch purple */
  --accent-2: #a970ff;
  --accent-hover: #772ce8;
  --good: #29b473;
  --warn: #f5a623;
  --bad: #e0453e;
  --radius: 6px;
  --checker: #2a2a2d;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over the component display rules below. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Roobert", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 18px;
  gap: 16px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .logo {
  font-size: 30px;
}
.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}
.tagline { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }
.specs-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius);
  white-space: nowrap;
  cursor: default;
}

/* ---------- Workspace ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  min-height: 0;
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- Editor ---------- */
.editor-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.tool-btn:hover { background: rgba(255, 255, 255, 0.12); }
.tool-btn:active { transform: translateY(1px); }

.dropzone {
  flex: 1;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(145, 71, 255, 0.08);
}
.dropzone-inner { text-align: center; color: var(--text-dim); }
.dz-icon { font-size: 40px; opacity: 0.7; }
.dz-title { font-size: 18px; color: var(--text); margin: 12px 0 4px; font-weight: 600; }
.dz-sub { font-size: 12px; margin: 0 0 16px; }
.dz-browse {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.dz-browse:hover { background: var(--accent-hover); }
.dz-paste { font-size: 11px; margin-top: 14px; opacity: 0.6; }

.editor-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 320px;
  position: relative;
}
#editor-canvas {
  max-width: 100%;
  max-height: calc(100vh - 320px);
  border-radius: var(--radius);
  /* checkerboard so transparency is visible */
  background-color: var(--panel-solid);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  cursor: grab;
  touch-action: none;
}
#editor-canvas.grabbing { cursor: grabbing; }
.stage-hint { font-size: 12px; color: var(--text-dim); text-align: center; }

/* Width / height stretch sliders */
.stretch-controls {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 520px;
}
.stretch-ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
  flex: 1;
  min-width: 200px;
}
.stretch-label { white-space: nowrap; font-weight: 600; }
.stretch-val { font-variant-numeric: tabular-nums; width: 40px; text-align: right; color: var(--text); }
.stretch-ctl input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  outline: none;
}
.stretch-ctl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #1f1f23;
}
.stretch-ctl input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #1f1f23;
}

/* ---------- Progress ---------- */
.progress { margin-top: 12px; }
.progress-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s;
}

/* ---------- Twitch chat ---------- */
.chat-panel { padding-bottom: 16px; }
.chat-meta { font-size: 12px; color: var(--text-dim); }
.twitch-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #18181b;              /* real Twitch chat bg */
  border: 1px solid #2a2a2d;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 320px;
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  font-family: "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.4;
}
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb { background: #3a3a3d; border-radius: 4px; }

.chat-line {
  padding: 5px 6px;
  border-radius: 4px;
  word-wrap: break-word;
  color: #efeff1;
}
.chat-line:hover { background: rgba(255, 255, 255, 0.04); }
.chat-line.highlight { background: rgba(145, 71, 255, 0.12); }
.chat-time { color: #adadb8; font-size: 11px; margin-right: 5px; }
.chat-badge {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 3px;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.chat-user { font-weight: 700; }
.chat-user::after { content: ":"; color: #efeff1; font-weight: 400; }
.chat-msg { color: #efeff1; }
.chat-emote {
  vertical-align: middle;
  margin: -2px 2px;
  image-rendering: auto;
}

/* ---------- Export bar ---------- */
.exportbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  flex-wrap: wrap;
}
.export-info { display: flex; flex-direction: column; gap: 4px; }
.export-dims { display: flex; align-items: baseline; gap: 10px; }
.dims-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.dims-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dims-ratio { font-size: 12px; color: var(--text-dim); }
.export-warn { font-size: 12px; color: var(--warn); font-weight: 600; }
.export-warn.bad { color: var(--bad); }

.export-actions { display: flex; align-items: center; gap: 10px; }
.format-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}
.fmt-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}
.fmt-btn.active { background: var(--accent); color: #fff; }
.export-btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.export-btn.primary { background: var(--accent); color: #fff; }
.export-btn.primary:hover { background: var(--accent-hover); }
.export-btn.secondary { background: rgba(255, 255, 255, 0.08); color: var(--text); border: 1px solid var(--border-strong); }
.export-btn.secondary:hover { background: rgba(255, 255, 255, 0.14); }
.export-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--bad); }
