:root {
  --bg: #f6f7fb; --bg-alt: #ffffff; --panel: #ffffff;
  --border: #e3e7f0; --border-strong: #cdd4e3;
  --text: #12151d; --muted: #616b80;
  --accent: #2f6bff; --accent-soft: #e8efff;
  --shadow: 0 18px 40px -24px rgba(18,21,29,.35);
  --radius: 14px; --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}
html[data-theme="dark"] {
  --bg: #0b0d12; --bg-alt: #0f121a; --panel: #12161f;
  --border: #1f2533; --border-strong: #2b3346;
  --text: #e9eef8; --muted: #93a0b8;
  --accent: #5b8dff; --accent-soft: #17233d;
  --shadow: 0 20px 50px -26px rgba(0,0,0,.9);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--text); font-family: var(--sans);
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
  background: radial-gradient(1200px 700px at 76% -10%, var(--accent-soft), transparent 60%), var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.app { max-width: 1200px; margin: 0 auto; padding: 26px 22px 40px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; flex: 0 0 auto; }
.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: -.2px; }
.brand-text p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.ghost-link { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ghost-link:hover { color: var(--accent); text-decoration: none; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; transition: .18s ease;
}
.icon-btn:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }
.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 400px; padding: 34px 22px; text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--bg-alt); cursor: pointer; transition: .18s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { width: 46px; height: 46px; color: var(--accent); }
.dz-title { margin: 8px 0 0; font-size: 17px; font-weight: 600; }
.dz-sub { margin: 0; color: var(--muted); font-size: 13.5px; }
.dz-hint { margin-top: 14px; font-size: 12px; color: var(--muted); opacity: .8; }

.canvas-wrap {
  display: grid; gap: 9px; padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-alt); box-shadow: var(--shadow);
}
.canvas-wrap canvas {
  display: block; width: 100%; height: auto; max-height: 62vh; object-fit: contain;
  border-radius: 8px; background: #10131a;
}
.canvas-meta { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 9px 15px; border-radius: 10px; font: inherit; font-size: 13.5px; font-weight: 550;
  cursor: pointer; transition: .16s ease;
}
.btn:hover:not(:disabled) { border-color: var(--border-strong); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-accent { background: #17a673; border-color: #17a673; color: #fff; }
.btn-accent:hover:not(:disabled) { filter: brightness(1.07); }

.inline-field { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.inline-field select, .inline-field input[type="range"] { accent-color: var(--accent); }
.inline-field input[type="range"] { width: 86px; }
.inline-field output { font-family: var(--mono); color: var(--text); }

select, input[type="text"], input[type="number"] {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg-alt);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 9px; width: 100%;
}
select:focus, input[type="text"]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type="range"] { accent-color: var(--accent); }

.panel {
  position: sticky; top: 22px; display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel); box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 15px; }
.link-btn { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; padding: 0; }
.link-btn:hover { color: var(--accent); }

.field { display: grid; gap: 5px; min-width: 0; }
.field-label { font-size: 11px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.field-label output { font-family: var(--mono); font-weight: 600; color: var(--text); letter-spacing: 0; text-transform: none; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.color-field { display: flex; align-items: center; gap: 8px; }
.color-field input[type="color"] {
  width: 38px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-alt); cursor: pointer;
}
.color-field output { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.position-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px;
  padding: 5px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-alt);
}
.position-grid button {
  aspect-ratio: 16 / 10; border-radius: 7px; border: 1px solid var(--border);
  background: var(--panel); cursor: pointer; position: relative; transition: .14s;
}
.position-grid button::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 12px; height: 3px;
  border-radius: 2px; background: var(--muted); transform: translate(-50%, -50%);
}
.position-grid button:hover { border-color: var(--accent); }
.position-grid button.is-active { background: var(--accent); border-color: var(--accent); }
.position-grid button.is-active::after { background: #fff; }
.position-grid button[data-pos$="left"]::after { left: 26%; }
.position-grid button[data-pos$="right"]::after { left: 74%; }
.position-grid button[data-pos^="top"]::after { top: 28%; }
.position-grid button[data-pos^="bottom"]::after { top: 72%; }
.position-grid button[data-pos="center"]::after { width: 16px; }

.toggles { display: flex; flex-wrap: wrap; gap: 14px; padding-top: 2px; }
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.panel-note { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

.footer { margin-top: 34px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px);
  background: var(--text); color: var(--bg); font-size: 13px; font-weight: 550;
  padding: 9px 17px; border-radius: 99px; opacity: 0; pointer-events: none; transition: .22s ease; z-index: 40;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.is-hidden { display: none !important; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .panel { position: static; }
  .dropzone { min-height: 300px; }
}
@media (max-width: 560px) {
  .app { padding: 18px 14px 30px; }
  .brand-text p { display: none; }
  .ghost-link { display: none; }
  .field-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
