@font-face { font-family: 'Poppins'; font-weight: 400; src: url('../fonts/Poppins-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Poppins'; font-weight: 500; src: url('../fonts/Poppins-Medium.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Poppins'; font-weight: 700; src: url('../fonts/Poppins-Bold.ttf') format('truetype'); font-display: swap; }

:root {
  --ink: #1e1240; --plum: #2b1a63; --violet: #6a35f0; --violet-soft: #e9e2ff; --wash: #f5f2fd; --paper: #ffffff;
  --lemon: #ffd23a; --mint: #0e8a6b; --mint-soft: #dff6ef; --rose: #c9264a; --rose-soft: #fde8ec;
  --muted: #655c84; --line: #dcd5ef; --on-dark: #f3eeff; --on-dark-2: #bcaee8;
  --r: 10px; --r-lg: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--wash); color: var(--ink); font: 400 15px/1.55 Poppins, system-ui, sans-serif; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.hidden { display: none !important; }
.engine-frame { position: fixed; width: 1px; height: 1px; left: -10px; top: -10px; border: 0; opacity: 0; pointer-events: none; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 430px; min-height: 100vh; }
.work { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 14px 28px; background: var(--paper); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--ink); position: relative; flex: none; }
.brand-mark::after { content: ''; position: absolute; left: 11px; top: 8px; border-left: 12px solid var(--lemon); border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.title-input { flex: 1; min-width: 140px; border: 1px solid transparent; background: transparent; padding: 6px 10px; border-radius: 8px; font-weight: 500; }
.title-input:hover, .title-input:focus { border-color: var(--line); background: var(--wash); }

.stepper { display: flex; gap: 6px; padding: 16px 28px 0; }
.step-tab { flex: 1; display: flex; align-items: center; gap: 10px; padding: 11px 12px; background: transparent; border: 0; border-bottom: 3px solid var(--line); font-weight: 500; color: var(--muted); text-align: left; min-width: 0; }
.step-tab .n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--violet-soft); color: var(--violet); font-size: 13px; font-weight: 700; }
.step-tab[aria-current='step'] { color: var(--ink); border-color: var(--violet); }
.step-tab[aria-current='step'] .n { background: var(--violet); color: #fff; }
.step-tab.done .n { background: var(--mint); color: #fff; }
.step-tab span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel { padding: 24px 28px 64px; max-width: 880px; width: 100%; }
.panel h2 { font-size: 25px; font-weight: 700; line-height: 1.2; letter-spacing: -.015em; margin-bottom: 6px; }
.lead { color: var(--muted); margin-bottom: 22px; max-width: 62ch; }
.block { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; margin-bottom: 16px; }
.block h3 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 6px; }
input[type=text], input[type=password], select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--paper); }
textarea { resize: vertical; min-height: 84px; }
textarea.code { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height: 130px; }
.hint { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--paper); font-weight: 500; min-height: 42px; }
.btn:hover:not(:disabled) { border-color: var(--violet); color: var(--violet); }
.btn.primary { background: var(--violet); color: #fff; border-color: var(--violet); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: #5623d6; color: #fff; }
.btn.go { background: var(--lemon); border-color: var(--lemon); color: var(--ink); font-weight: 700; }
.btn.go:hover:not(:disabled) { background: #ffc400; color: var(--ink); border-color: #ffc400; }
.btn.small { padding: 6px 11px; min-height: 34px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--violet); padding: 6px 0; min-height: 0; text-decoration: underline; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-weight: 500; font-size: 14px; }
.chip[aria-pressed='true'] { background: var(--ink); color: #fff; border-color: var(--ink); }

.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 12px; }
.style-card { align-self: start; padding: 0; border: 2px solid transparent; border-radius: 12px; background: none; text-align: left; font-size: 13px; }
.style-card canvas { display: block; width: 100%; aspect-ratio: 9/14; border-radius: 10px; background: var(--ink); object-fit: cover; }
.style-card b { display: block; margin: 6px 4px 0; font-weight: 700; line-height: 1.25; }
.style-card small { display: block; margin: 2px 4px 6px; color: var(--muted); font-size: 12px; line-height: 1.3; }
.style-card[aria-pressed='true'] { border-color: var(--violet); background: var(--violet-soft); }

.exchange { border-left: 3px solid var(--violet); padding-left: 14px; }
.ex-step { display: flex; gap: 10px; margin-bottom: 12px; }
.ex-n { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.ex-step > div:not(.ex-n) { flex: 1; min-width: 0; }
.msg { padding: 10px 12px; border-radius: var(--r); font-size: 14px; margin-top: 10px; }
.msg.err { background: var(--rose-soft); color: var(--rose); }
.msg.ok { background: var(--mint-soft); color: var(--mint); }
.msg.info { background: var(--violet-soft); color: #43219f; }

.ideas { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.idea { text-align: left; padding: 14px; background: var(--paper); border: 2px solid var(--line); border-radius: var(--r-lg); }
.idea:hover { border-color: var(--violet); }
.idea[aria-pressed='true'] { border-color: var(--violet); background: var(--violet-soft); }
.idea b { display: block; margin-bottom: 6px; line-height: 1.3; }
.idea q { display: block; quotes: none; font-weight: 500; margin-bottom: 8px; font-size: 14px; }
.idea p { color: var(--muted); font-size: 13px; }

.scene-row { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.scene-row:first-child { border-top: 0; padding-top: 0; }
.scene-n { width: 28px; height: 28px; border: 0; border-radius: 8px; background: var(--violet-soft); color: var(--violet); font-weight: 700; display: grid; place-items: center; }
.scene-row textarea { min-height: 62px; }
.scene-meta { display: grid; grid-template-columns: 1fr 96px 110px; gap: 8px; margin-top: 8px; }
.scene-visual { font-size: 13px; color: var(--muted); margin-top: 6px; }

.wave-wrap { position: relative; touch-action: none; user-select: none; }
.wave { width: 100%; height: 112px; display: block; background: var(--wash); border-radius: var(--r); }
.cut { position: absolute; top: 0; bottom: 0; width: 22px; margin-left: -11px; cursor: ew-resize; background: none; border: 0; padding: 0; touch-action: none; }
.cut::before { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--ink); }
.cut::after { content: ''; position: absolute; left: 6px; bottom: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--ink); }
.timings { margin-top: 12px; }
.timing { display: grid; grid-template-columns: 34px 96px 1fr; gap: 8px; padding: 6px 0; font-size: 13px; align-items: center; border-top: 1px solid var(--wash); }
.timing span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.group-card { padding: 14px; border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 12px; background: var(--paper); }
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 700; }
.badge { font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--wash); color: var(--muted); white-space: nowrap; }
.badge.done { background: var(--mint-soft); color: var(--mint); }
.badge.bad { background: var(--rose-soft); color: var(--rose); }
.progress { height: 10px; background: var(--wash); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--violet); width: 0; }
input[type=range] { width: 100%; accent-color: var(--violet); }
.copy-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; }
.copy-row > textarea, .copy-row > input { flex: 1; min-width: 0; }

.studio { background: var(--ink); color: var(--on-dark); padding: 22px 26px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.phone-shell { align-self: center; padding: 9px; background: #0d0724; border-radius: 34px; box-shadow: 0 0 0 1px #47348c; width: min(100%, 300px); }
.phone-shell canvas { display: block; width: 100%; aspect-ratio: 9/16; background: var(--plum); border-radius: 26px; }
.transport { display: flex; align-items: center; gap: 12px; }
.play { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--lemon); color: var(--ink); font-weight: 700; display: grid; place-items: center; }
.time { font-size: 13px; color: var(--on-dark-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.strip button { flex: none; min-width: 42px; height: 42px; padding: 0 8px; border-radius: 8px; border: 1px solid #47348c; background: var(--plum); color: var(--on-dark); font-size: 13px; font-weight: 500; }
.strip button.ready { background: #2b5b58; border-color: #3f8a7b; }
.strip button.err { background: #6a1f3b; border-color: #c9264a; }
.strip button.now { outline: 2px solid var(--lemon); outline-offset: 1px; }
.studio .note { font-size: 13px; color: var(--on-dark-2); }
.studio .btn.go { width: 100%; }
.studio select { color: var(--ink); }
.studio .err-note { background: #6a1f3b; color: #ffdbe3; padding: 10px 12px; border-radius: var(--r); font-size: 13px; }

dialog { border: 0; border-radius: var(--r-lg); padding: 22px; max-width: 480px; width: calc(100vw - 32px); color: var(--ink); }
dialog::backdrop { background: rgba(20, 10, 50, .55); }
dialog h3 { font-size: 18px; margin-bottom: 8px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 20; box-shadow: 0 0 0 1px #47348c; max-width: calc(100vw - 32px); }

@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; }
  .studio { position: static; height: auto; order: -1; padding: 16px; }
  .phone-shell { width: min(58vw, 240px); }
  .panel, .topbar { padding-left: 16px; padding-right: 16px; }
  .stepper { padding: 12px 16px 0; gap: 2px; }
}
@media (max-width: 560px) {
  .step-tab { flex-direction: column; gap: 4px; padding: 8px 2px; font-size: 12px; text-align: center; }
  .grid2 { grid-template-columns: 1fr; }
  .scene-meta { grid-template-columns: 1fr 1fr; }
  .scene-meta > :first-child { grid-column: 1 / -1; }
  .panel h2 { font-size: 22px; }
  .timing { grid-template-columns: 28px 86px 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
