:root {
  --bg: #0e0f11;
  --bg-2: #141518;
  --panel: #18191d;
  --panel-2: #1f2025;
  --line: #2a2c33;
  --line-2: #363944;
  --text: #ecebe8;
  --muted: #8d8f99;
  --dim: #5f626d;
  --accent: #ff6b3d;
  --accent-2: #ff8a63;
  --accent-ink: #1a0d07;
  --ok: #4fd18b;
  --err: #ff5d6c;
  --radius: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
kbd {
  font: 12px var(--mono); padding: 1px 6px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line-2);
}
svg.lucide { width: 18px; height: 18px; stroke-width: 1.9; flex: none; }

/* ------------------------------------------------------------ topbar */
.topbar {
  height: 56px; flex: none; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 16px;
}
.brand-name { font-weight: 700; letter-spacing: -.01em; font-size: 16px; }
.brand-name em { font-style: normal; color: var(--muted); font-weight: 500; margin-left: 2px; }
.file-meta { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.file-meta .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32ch; }
.pill {
  font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 99px; white-space: nowrap;
}
.pill.kind { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.top-actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2);
  cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #272932; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.big { height: 46px; padding: 0 22px; font-size: 15px; border-radius: 10px; }
.btn.full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--line); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; background: transparent; }
.chip {
  height: 28px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line-2);
  background: var(--panel-2); cursor: pointer; font-size: 12.5px; color: var(--text); white-space: nowrap;
}
.chip:hover { border-color: var(--dim); }
.chip.on { background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); border-color: var(--accent); color: #fff; }

/* ------------------------------------------------------------ dropzone */
#app { flex: 1; min-height: 0; display: flex; }
.dropzone { flex: 1; display: grid; place-items: center; padding: 24px; overflow: auto; }
.drop-inner {
  width: min(720px, 100%); text-align: center; padding: 56px 32px; border-radius: 20px;
  border: 1.5px dashed var(--line-2);
  background: radial-gradient(ellipse at top, color-mix(in srgb, var(--accent) 9%, transparent), transparent 65%), var(--bg-2);
  transition: border-color .2s, background .2s;
}
.dropzone.drag .drop-inner { border-color: var(--accent); background-color: #1b1512; }
.drop-icons { display: flex; justify-content: center; gap: 12px; margin-bottom: 22px; }
.drop-icons span {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--accent-2);
}
.drop-icons span:nth-child(2) { transform: translateY(-6px); }
.drop-icons svg.lucide { width: 24px; height: 24px; }
.drop-inner h1 { font-size: clamp(26px, 4vw, 38px); line-height: 1.12; letter-spacing: -.025em; margin: 0 0 14px; }
.drop-inner h1 span { color: var(--accent); }
.drop-inner p { color: var(--muted); margin: 0 0 18px; }
.feature-list { list-style: none; padding: 0; margin: 34px 0 0; display: grid; gap: 8px; text-align: left; }
.feature-list li {
  font-size: 13px; color: var(--muted); padding: 10px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
}
.feature-list b { color: var(--text); margin-right: 8px; }
.upload-progress { margin: 18px auto 0; width: min(360px, 100%); display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .2s; }

/* ------------------------------------------------------------ editor */
.editor { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px minmax(0, 1fr) 320px; }
.tools {
  border-right: 1px solid var(--line); background: var(--bg-2); overflow-y: auto; padding: 12px 10px 24px;
}
.tool-group + .tool-group { margin-top: 14px; }
.tool-group h4 {
  margin: 0 0 6px 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); font-weight: 700;
}
.tool-btn {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; cursor: pointer; text-align: left; color: #cfcfd3;
}
.tool-btn:hover { background: var(--panel-2); color: var(--text); }
.tool-btn.on { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: #fff; }
.tool-btn.on svg { color: var(--accent); }

.workspace { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.stage {
  flex: 1; min-height: 0; position: relative; display: grid; place-items: center; padding: 24px; overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, #1d1f24 1px, transparent 0);
  background-size: 22px 22px;
}
.media-wrap { position: relative; max-width: 100%; max-height: 100%; display: grid; place-items: center; line-height: 0; }
.media-wrap img, .media-wrap video {
  display: block; max-width: 100%; max-height: calc(100vh - 56px - 48px - var(--tl-h, 0px));
  border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.5); user-select: none; -webkit-user-drag: none;
  transition: filter .12s;
}
.media-wrap img.checker {
  background-color: #2a2b30;
  background-image: linear-gradient(45deg,#33343a 25%,transparent 25%),linear-gradient(-45deg,#33343a 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#33343a 75%),linear-gradient(-45deg,transparent 75%,#33343a 75%);
  background-size: 16px 16px; background-position: 0 0,0 8px,8px -8px,-8px 0;
}
.media-wrap video { cursor: pointer; background: #000; }
.audio-card {
  width: 520px; max-width: calc(100vw - 600px); min-width: 260px; line-height: 1.4; padding: 28px; border-radius: 16px; text-align: center;
  background: var(--panel); border: 1px solid var(--line);
}
.audio-card .disc {
  width: 88px; height: 88px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle, var(--bg) 18%, var(--accent) 19%, #b8411c 70%); color: var(--accent-ink);
  box-shadow: 0 8px 30px rgba(255,107,61,.25);
}
.audio-card.playing .disc { animation: spin 3s linear infinite; }
.audio-card .t { font-weight: 700; font-size: 16px; word-break: break-word; }
.audio-card .s { color: var(--muted); font-size: 13px; margin-top: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

.busy {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: rgba(10, 10, 12, .72); backdrop-filter: blur(3px); z-index: 20;
}
.busy .bar { width: 260px; }
.busy-text { font-weight: 600; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

/* crop overlay */
.crop-layer { position: absolute; inset: 0; overflow: hidden; border-radius: 4px; touch-action: none; }
.crop-box {
  position: absolute; border: 1.5px solid #fff; cursor: move; touch-action: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .58);
}
.crop-box::before, .crop-box::after { content: ""; position: absolute; pointer-events: none; border: 0 solid rgba(255,255,255,.4); }
.crop-box::before { left: 33.33%; right: 33.33%; top: 0; bottom: 0; border-left-width: 1px; border-right-width: 1px; }
.crop-box::after { top: 33.33%; bottom: 33.33%; left: 0; right: 0; border-top-width: 1px; border-bottom-width: 1px; }
.crop-box .ch { position: absolute; width: 16px; height: 16px; background: #fff; border-radius: 3px; border: 2px solid var(--accent); }
.crop-box .ch[data-h=nw] { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-box .ch[data-h=ne] { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-box .ch[data-h=sw] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-box .ch[data-h=se] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.crop-box .ch[data-h=n] { left: calc(50% - 8px); top: -8px; cursor: ns-resize; }
.crop-box .ch[data-h=s] { left: calc(50% - 8px); bottom: -8px; cursor: ns-resize; }
.crop-box .ch[data-h=w] { top: calc(50% - 8px); left: -8px; cursor: ew-resize; }
.crop-box .ch[data-h=e] { top: calc(50% - 8px); right: -8px; cursor: ew-resize; }
.crop-box .dims {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); line-height: 1;
  font: 600 11.5px var(--mono); background: rgba(0,0,0,.7); padding: 4px 7px; border-radius: 5px; pointer-events: none; white-space: nowrap;
}

/* ------------------------------------------------------------ timeline */
.timeline { flex: none; border-top: 1px solid var(--line); background: var(--bg-2); padding: 8px 14px 14px; }
.transport { display: flex; align-items: center; gap: 6px; height: 40px; flex-wrap: wrap; }
.transport .grow { flex: 1; }
.time { font: 13px var(--mono); color: var(--muted); margin-left: 6px; }
.sel-label { font: 12px var(--mono); color: var(--accent-2); margin-right: 6px; }
.track {
  position: relative; height: 88px; border-radius: 8px; background: #0b0c0e; border: 1px solid var(--line);
  cursor: crosshair; touch-action: none; overflow: hidden; margin-top: 6px;
}
.editor.audio-mode .track { height: 180px; }
#wave { position: absolute; inset: 0; width: 100%; height: 100%; }
.sel {
  position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-left: 2px solid var(--accent); border-right: 2px solid var(--accent); cursor: grab;
}
.sel .h { position: absolute; top: 0; bottom: 0; width: 14px; cursor: ew-resize; }
.sel .h::after {
  content: ""; position: absolute; top: 50%; width: 6px; height: 30px; transform: translateY(-50%);
  border-radius: 3px; background: var(--accent);
}
.sel .h[data-side=l] { left: -8px; } .sel .h[data-side=l]::after { left: 4px; }
.sel .h[data-side=r] { right: -8px; } .sel .h[data-side=r]::after { right: 4px; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; pointer-events: none; box-shadow: 0 0 6px rgba(255,255,255,.6); }
.playhead::before { content: ""; position: absolute; top: -1px; left: -5px; border: 6px solid transparent; border-top-color: #fff; }

/* ------------------------------------------------------------ panel */
.panel { border-left: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.tool-panel { padding: 18px 18px 8px; }
.tool-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.tool-head .ico {
  width: 38px; height: 38px; flex: none; border-radius: 10px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, var(--panel)); color: var(--accent);
}
.tool-head h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.tool-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.field { margin-bottom: 14px; }
.field > label, .field .lbl { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; color: #c4c4ca; margin-bottom: 6px; font-weight: 500; }
.field .val { font: 12px var(--mono); color: var(--accent-2); }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--panel); outline: none;
}
.field textarea { height: 70px; padding: 8px 10px; resize: vertical; font: inherit; color: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field input[type=color] { width: 100%; height: 36px; padding: 3px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; margin-bottom: 12px; color: #c4c4ca; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 18px; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.grid { display: grid; grid-template-columns: repeat(3, 1fr); }
.chips.grid .chip { padding: 0 4px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 16px; }
.quick .btn { justify-content: center; height: 40px; font-weight: 500; font-size: 13px; padding: 0 8px; }
.tool-actions { display: flex; gap: 8px; margin-top: 6px; }
.tool-actions .btn { flex: 1; justify-content: center; }
.note {
  font-size: 12.5px; color: var(--muted); padding: 10px 12px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); margin-bottom: 14px;
}
.note b { color: var(--text); }
.range-box { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.range-box .dur { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.file-pick { display: flex; gap: 8px; align-items: center; }
.file-pick .fname { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.history { margin-top: auto; padding: 14px 18px 18px; border-top: 1px solid var(--line); }
.history h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); }
.history svg.lucide { width: 14px; height: 14px; }
.history ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 200px; overflow-y: auto; }
.history li {
  display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted);
}
.history li:hover { background: var(--panel-2); color: var(--text); }
.history li .n { font: 11px var(--mono); color: var(--dim); width: 18px; }
.history li.on { color: #fff; background: var(--panel-2); }
.history li.on .n { color: var(--accent); }
.history li.future { opacity: .45; }

/* ------------------------------------------------------------ toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  min-width: 220px; max-width: 380px; padding: 11px 14px; border-radius: 10px; background: #222329; border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px rgba(0,0,0,.4); font-size: 13.5px; animation: pop .2s ease-out; border-left: 3px solid var(--muted);
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--err); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .editor { grid-template-columns: 200px minmax(0, 1fr) 280px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  #app { min-height: calc(100vh - 56px); }
  .editor { display: flex; flex-direction: column; }
  .tools { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; flex: none; }
  .tool-group { display: contents; }
  .tool-group h4 { display: none; }
  .tool-btn { width: auto; white-space: nowrap; flex: none; }
  .stage { min-height: 46vh; padding: 12px; }
  .media-wrap img, .media-wrap video { max-height: 50vh; }
  .audio-card { max-width: calc(100vw - 32px); }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .topbar { gap: 8px; padding: 0 10px; }
  .file-meta .pill:not(.kind) { display: none; }
  .btn span { display: none; }
  .btn { padding: 0 10px; }
}
