/* =========================================================================
 * Quiz Canvas Studio — Responsive & Overlap-Free Design System
 * ========================================================================= */
:root {
  --bg: hsl(232 28% 7%);
  --bg-2: hsl(232 24% 11%);
  --glass: hsla(230 30% 18% / 0.55);
  --glass-strong: hsla(230 30% 14% / 0.85);
  --line: hsla(225 40% 80% / 0.10);
  --line-strong: hsla(225 40% 80% / 0.18);
  --text: hsl(225 30% 94%);
  --muted: hsl(225 14% 64%);
  --primary: hsl(152 68% 45%);
  --primary-2: hsl(168 80% 40%);
  --violet: hsl(258 90% 66%);
  --rose: hsl(352 85% 58%);
  --amber: hsl(42 95% 58%);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  --ui: 'Outfit', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  min-height: 100%;
  width: 100%;
}
body {
  margin: 0;
  font-family: var(--ui);
  color: var(--text);
  background: radial-gradient(1200px 700px at 15% -10%, hsl(258 60% 18%), transparent 60%),
              radial-gradient(1000px 600px at 110% 110%, hsl(160 60% 12%), transparent 60%),
              var(--bg);
  overflow-x: hidden;
  overflow-y: auto;
}

/* Floating ambient orbs */
.bg-orbs span {
  position: fixed; border-radius: 50%; filter: blur(80px); opacity: 0.35; z-index: 0; pointer-events: none;
  animation: float 18s ease-in-out infinite alternate;
}
.bg-orbs span:nth-child(1) { width: 420px; height: 420px; background: var(--violet); top: -120px; left: 30%; }
.bg-orbs span:nth-child(2) { width: 360px; height: 360px; background: var(--primary); bottom: -140px; right: 10%; animation-delay: -6s; }
.bg-orbs span:nth-child(3) { width: 280px; height: 280px; background: var(--rose); top: 40%; left: -100px; opacity: 0.18; animation-delay: -12s; }
@keyframes float { to { transform: translate(60px, 40px) scale(1.15); } }

/* ---------------- Top Bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 18px;
  height: 64px; padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: hsla(232 30% 8% / 0.75);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex-shrink: 0;
  background: conic-gradient(from 200deg, var(--primary), var(--violet), var(--rose), var(--primary));
  box-shadow: 0 8px 24px -6px hsla(258 90% 60% / 0.6);
}
.brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.2px; white-space: nowrap; }
.brand p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.status-pills { display: flex; gap: 8px; flex-shrink: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--glass); color: var(--muted);
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: hsl(225 10% 45%); }
.pill.ok i { background: var(--primary); box-shadow: 0 0 10px var(--primary); }
.pill.warn i { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.pill.err i { background: var(--rose); box-shadow: 0 0 10px var(--rose); }
.pill.ok, .pill.warn { color: var(--text); }

/* ---------------- Workspace Grid (Responsive, No Overlap) ---------------- */
.workspace {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 330px minmax(380px, 1fr) 320px;
  gap: 16px;
  min-height: calc(100vh - 64px);
  padding: 16px;
  box-sizing: border-box;
  align-items: start;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  max-height: calc(100vh - 94px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.card {
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(16px); padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; min-height: 0;
  flex-shrink: 0;
  animation: rise 0.5s cubic-bezier(.2,.8,.2,1) both;
}
.panel .card:nth-child(2) { animation-delay: 0.06s; }
.panel .card:nth-child(3) { animation-delay: 0.12s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.grow-card { flex: 1; min-height: 240px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.head-actions { margin-left: auto; display: flex; gap: 6px; }
.step {
  width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #04140c; flex-shrink: 0;
}
.muted { color: var(--muted); font-size: 11.5px; margin-left: auto; }
.small { font-size: 11.5px; margin: 0; }
.tag { margin-left: auto; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: hsla(152 68% 45% / 0.15); color: var(--primary); }
.tag.warn { background: hsla(42 95% 58% / 0.15); color: var(--amber); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  font: 600 13px var(--ui); color: var(--text); cursor: pointer; text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s;
  white-space: nowrap; flex-shrink: 0;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #03140b; box-shadow: 0 8px 22px -8px hsla(152 68% 45% / 0.8); }
.btn.primary:hover:not(:disabled) { box-shadow: 0 12px 28px -8px hsla(152 68% 45% / 0.95); }
.btn.secondary { background: hsla(258 90% 66% / 0.16); border-color: hsla(258 90% 66% / 0.35); color: hsl(258 100% 86%); }
.btn.secondary:hover:not(:disabled) { background: hsla(258 90% 66% / 0.26); }
.btn.ghost { background: hsla(225 30% 90% / 0.05); border-color: var(--line-strong); }
.btn.ghost:hover:not(:disabled) { background: hsla(225 30% 90% / 0.1); }
.btn.record { background: linear-gradient(135deg, hsl(352 85% 58%), hsl(12 90% 58%)); color: #fff; box-shadow: 0 8px 24px -8px hsla(352 85% 58% / 0.9); }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
.icon-btn {
  width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line-strong); background: transparent;
  color: var(--muted); cursor: pointer; font: 600 12px var(--mono); transition: all 0.15s; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--text); background: hsla(225 30% 90% / 0.08); }
.round-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line-strong); cursor: pointer;
  display: grid; place-items: center; color: var(--text); background: var(--glass-strong); transition: all 0.2s; flex-shrink: 0;
}
.round-btn:hover { background: hsla(152 68% 45% / 0.2); border-color: var(--primary); color: var(--primary); transform: scale(1.06); }
#btn-play.playing { background: var(--primary); color: #03140b; }

/* ---------------- Dropzone ---------------- */
.dropzone {
  position: relative; display: grid; place-items: center; height: 160px; border-radius: 12px; cursor: pointer; overflow: hidden;
  border: 1.5px dashed hsla(152 68% 55% / 0.4); background: hsla(152 68% 45% / 0.05); transition: all 0.2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: hsla(152 68% 45% / 0.1); }
.dropzone img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; display: none; }
.dropzone.has-img img { display: block; }
.dropzone.has-img .dz-hint { opacity: 0; }
.dropzone.has-img:hover .dz-hint { opacity: 1; background: hsla(232 30% 8% / 0.8); }
.dz-hint { position: relative; inset: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); text-align: center; padding: 16px; border-radius: 12px; transition: opacity 0.2s; }
.dz-hint b { color: var(--text); font-weight: 600; font-size: 13px; }
.dz-hint span { font-size: 11.5px; }
.dz-hint svg { color: var(--primary); margin-bottom: 2px; }

/* WS Stepper */
.ws-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; counter-reset: s; }
.ws-steps li {
  position: relative; padding: 6px 10px 6px 32px; font-size: 12px; color: var(--muted);
  border-radius: 8px; background: hsla(225 30% 90% / 0.03); border: 1px solid transparent; transition: all 0.25s;
}
.ws-steps li::before {
  counter-increment: s; content: counter(s); position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 50%; font-size: 9.5px; display: grid; place-items: center;
  background: hsla(225 30% 90% / 0.08);
}
.ws-steps li.active { color: var(--text); border-color: hsla(258 90% 66% / 0.5); background: hsla(258 90% 66% / 0.12); }
.ws-steps li.active::before { content: ''; border: 2px solid var(--violet); border-top-color: transparent; background: none; animation: spin 0.8s linear infinite; }
.ws-steps li.done { color: var(--text); }
.ws-steps li.done::before { content: '✓'; background: var(--primary); color: #03140b; }
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

/* JSON Editor */
#json-editor {
  flex: 1; min-height: 140px; resize: none; width: 100%; border-radius: 10px; padding: 10px;
  font: 11.5px/1.5 var(--mono); color: hsl(160 60% 82%); background: hsla(232 40% 4% / 0.6);
  border: 1px solid var(--line-strong); outline: none; transition: border-color 0.2s;
}
#json-editor:focus { border-color: hsla(152 68% 45% / 0.6); }
#json-editor.invalid { border-color: var(--rose); }

/* ---------------- Center Stage & Canvas ---------------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.canvas-wrap {
  position: relative;
  aspect-ratio: 3 / 4;
  width: auto;
  max-width: 100%;
  max-height: min(640px, calc(100vh - 200px));
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 70px -16px rgba(0,0,0,0.75), 0 0 0 1px var(--line-strong), 0 0 50px -10px hsla(152 68% 45% / 0.22);
  animation: rise 0.6s cubic-bezier(.2,.8,.2,1) both;
}
#quiz-canvas { display: block; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.canvas-badge {
  position: absolute; top: 10px; left: 10px; padding: 3px 8px; border-radius: 6px; font: 500 10.5px var(--mono);
  background: rgba(10, 12, 20, 0.72); color: #cfd6e6; backdrop-filter: blur(6px); pointer-events: none;
}
.busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center;
  background: hsla(232 30% 6% / 0.75); backdrop-filter: blur(6px); font-weight: 500; font-size: 13.5px;
}
.busy[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3.5px solid hsla(225 30% 90% / 0.15); border-top-color: var(--primary); animation: spin2 0.9s linear infinite; }
@keyframes spin2 { to { transform: rotate(360deg); } }

/* Transport Bar (Flexible, Wrap-Protected) */
.transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
  max-width: 780px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  box-sizing: border-box;
}
.scrub {
  flex: 1 1 180px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 140px;
}
.scrub-time { display: flex; justify-content: space-between; font: 10.5px var(--mono); color: var(--muted); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 6px; background: hsla(225 30% 90% / 0.12); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px hsla(152 68% 45% / 0.25); cursor: pointer; }
.progress-line { width: 100%; max-width: 780px; height: 3px; border-radius: 3px; background: hsla(225 30% 90% / 0.06); overflow: hidden; }
#render-progress { height: 100%; width: 0; background: linear-gradient(90deg, var(--rose), var(--amber)); transition: width 0.1s linear; }

/* ---------------- Timeline List ---------------- */
.timeline-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; max-height: 220px; overflow-y: auto; }
.timeline-list li {
  display: grid; grid-template-columns: 58px 1fr; gap: 8px; align-items: center; padding: 6px 9px; border-radius: 8px;
  font-size: 12px; cursor: pointer; border: 1px solid transparent; transition: all 0.15s;
}
.timeline-list li:hover { background: hsla(225 30% 90% / 0.06); border-color: var(--line); }
.timeline-list li.now { background: hsla(152 68% 45% / 0.12); border-color: hsla(152 68% 45% / 0.4); }
.timeline-list time { font: 10.5px var(--mono); color: var(--primary); }
.timeline-list .q-head { grid-column: 1 / -1; font-weight: 600; color: var(--text); padding-top: 5px; cursor: default; }
.timeline-list .q-head:hover { background: none; border-color: transparent; }

/* ---------------- Output Video ---------------- */
#out-video { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 3 / 4; max-height: 260px; object-fit: contain; }

/* ---------------- Log ---------------- */
.log { flex: 1; min-height: 70px; max-height: 220px; overflow-y: auto; font: 11px/1.55 var(--mono); color: var(--muted); padding-right: 4px; }
.log div { padding: 2px 0; border-bottom: 1px dashed hsla(225 30% 90% / 0.05); word-break: break-word; }
.log .ok { color: hsl(152 60% 62%); }
.log .warn { color: var(--amber); }
.log .err { color: hsl(352 90% 70%); }
.log time { color: hsl(225 10% 45%); margin-right: 6px; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: hsla(225 30% 90% / 0.15); border-radius: 6px; }

/* ---------------- Modal ---------------- */
.modal {
  width: min(600px, 94vw); padding: 0; border: 1px solid var(--line-strong); border-radius: 18px; color: var(--text);
  background: linear-gradient(180deg, hsl(232 26% 13%), hsl(232 28% 9%)); box-shadow: 0 40px 120px -20px rgba(0,0,0,0.8);
}
.modal::backdrop { background: rgba(4, 6, 12, 0.65); backdrop-filter: blur(6px); }
.modal[open] { animation: pop 0.22s cubic-bezier(.2,.9,.3,1.2); }
@keyframes pop { from { opacity: 0; transform: scale(0.95) translateY(8px); } }
.modal-inner { display: flex; flex-direction: column; }
.modal-head { padding: 18px 20px 0; }
.modal-head h2 { margin: 0 0 12px; font-size: 19px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: none; color: var(--muted); padding: 9px 12px; font: 600 12.5px var(--ui); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.tab-panel { display: none; padding: 16px 20px; gap: 11px; flex-direction: column; max-height: 60vh; overflow-y: auto; }
.tab-panel.active { display: flex; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field b { color: var(--primary); font-weight: 600; }
.field input[type=text], .field input[type=password], .field input[type=number], .field select {
  height: 38px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--line-strong); background: hsla(232 40% 4% / 0.5);
  color: var(--text); font: 13px var(--ui); outline: none;
}
.field input:focus, .field select:focus { border-color: var(--primary); }
.field input[type=color] { height: 38px; width: 100%; border: 1px solid var(--line-strong); border-radius: 9px; background: none; padding: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 9px 11px; border-radius: 9px; background: hsla(225 30% 90% / 0.04); }
.switch { -webkit-appearance: none; appearance: none; width: 40px; height: 22px; border-radius: 22px; background: hsla(225 30% 90% / 0.15); position: relative; cursor: pointer; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 2.5px; left: 2.5px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(18px); }
.note { margin: 0; font-size: 11.5px; color: var(--muted); padding: 9px 11px; border-radius: 9px; background: hsla(42 95% 58% / 0.07); border: 1px solid hsla(42 95% 58% / 0.18); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--line); }

/* ---------------- Toasts ---------------- */
.toast-host { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 7px; z-index: 50; pointer-events: none; }
.toast {
  padding: 10px 15px; border-radius: 11px; font-size: 13px; font-weight: 500; background: var(--glass-strong);
  border: 1px solid var(--line-strong); backdrop-filter: blur(14px); box-shadow: var(--shadow); animation: rise 0.25s both; pointer-events: auto;
}
.toast.ok { border-color: hsla(152 68% 45% / 0.6); }
.toast.err { border-color: hsla(352 85% 58% / 0.7); }
.toast.warn { border-color: hsla(42 95% 58% / 0.6); }

/* ================= RESPONSIVE BREAKPOINTS (Zero Overlap) ================= */

/* Medium Desktops & Laptops (1080px – 1280px) */
@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 300px minmax(340px, 1fr) 290px;
    gap: 12px;
    padding: 12px;
  }
  .btn {
    padding: 0 12px;
    font-size: 12.5px;
  }
}

/* Tablet / Dual Column (768px – 1079px) */
@media (max-width: 1079px) {
  .workspace {
    grid-template-columns: 320px 1fr;
    height: auto;
    min-height: auto;
  }
  .panel.right {
    grid-column: 1 / -1;
    max-height: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    overflow-y: visible;
  }
  .panel.left {
    max-height: none;
    overflow-y: visible;
  }
  .canvas-wrap {
    max-height: 540px;
  }
  .status-pills {
    display: none;
  }
}

/* Mobile Devices (< 768px) */
@media (max-width: 767px) {
  .topbar {
    height: 56px;
    padding: 0 12px;
  }
  .brand h1 {
    font-size: 15px;
  }
  .brand p {
    display: none;
  }
  .workspace {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 14px;
  }
  .panel.right {
    grid-template-columns: 1fr;
  }
  .panel {
    max-height: none;
    overflow-y: visible;
  }
  .canvas-wrap {
    width: 100%;
    max-width: 420px;
    max-height: 480px;
  }
  .transport {
    justify-content: center;
  }
  .scrub {
    flex-basis: 100%;
    order: 3;
  }
  .grid2 {
    grid-template-columns: 1fr;
  }
}
