:root {
  --bg: #0b0b0f;
  --bg-2: #101017;
  --panel: #15151d;
  --line: #24242f;
  --fg: #ececf3;
  --muted: #9494a6;
  --accent: #7c5cff;
  --accent-2: #4ce0b3;
  --danger: #ff6b7a;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: 10px 14px; z-index: 100; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo { width: 30px; height: 30px; display: block; border-radius: 7px; }
.topbar h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.btn {
  background: var(--accent); color: #fff; border: 1px solid transparent;
  border-radius: 10px; padding: 9px 15px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: filter .15s ease, transform .05s ease;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--fg); }
.btn-ghost:hover { border-color: #3a3a4a; background: #1b1b25; }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 240px;
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}
.stage.dragging { cursor: grabbing; }
.canvas-host { position: absolute; inset: 0; }
.canvas-host canvas { display: block; width: 100% !important; height: 100% !important; }

.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 45%, rgba(0,0,0,.55) 100%);
}

.dropzone {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  text-align: center; padding: 24px; pointer-events: none;
  transition: opacity .25s ease;
}
.dropzone.hidden { opacity: 0; }
.dz-title { font-size: 17px; font-weight: 600; margin: 0; }
.dz-sub { font-size: 13px; color: var(--muted); margin: 0; max-width: 380px; line-height: 1.5; }

.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  font-size: 12px; color: var(--muted);
  background: rgba(8,8,12,.72); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px; pointer-events: none; white-space: nowrap;
  backdrop-filter: blur(6px);
}

.loader {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--muted);
  background: rgba(8,8,12,.8); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 999px;
}
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Control panel ---------- */
.panel {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.panel-toggle {
  display: none;
  width: 100%; background: none; border: 0; color: var(--fg);
  padding: 11px 14px; font-size: 13px; font-weight: 600;
  display: none; align-items: center; justify-content: space-between;
  cursor: pointer;
}
.panel-body {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 12px 16px;
}

.ctl { display: flex; align-items: center; gap: 9px; }
.ctl label { font-size: 12.5px; color: var(--muted); min-width: 42px; }
.ctl output { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 130px; height: 22px; background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: #2b2b38; }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: #2b2b38; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; margin-top: -5.5px; border-radius: 50%;
  background: var(--fg); border: 2px solid var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--fg); border: 2px solid var(--accent);
}

input[type=color] {
  width: 42px; height: 28px; padding: 0; border: 1px solid var(--line);
  border-radius: 8px; background: none; cursor: pointer;
}
.swatches { display: flex; gap: 5px; }
.sw {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--c); border: 1px solid rgba(255,255,255,.25);
  cursor: pointer; padding: 0;
}
.sw:hover { transform: scale(1.14); }

.ctl-checks { gap: 14px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.ctl-buttons { gap: 8px; margin-left: auto; }

/* ---------- Footer ---------- */
.footer {
  flex: 0 0 auto;
  padding: 10px 16px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.footer p { margin: 0; font-size: 11.5px; color: var(--muted); max-width: 62ch; line-height: 1.5; }
.footer-links { display: flex; gap: 14px; }
.footer-links a { color: var(--muted); font-size: 11.5px; text-decoration: none; }
.footer-links a:hover { color: var(--fg); text-decoration: underline; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(380px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  z-index: 40;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.drawer-head h2 { margin: 0; font-size: 15px; }
.icon-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.icon-btn:hover { color: var(--fg); }
.drawer-body { padding: 16px; overflow-y: auto; }
.drawer-body img {
  width: 100%; border-radius: var(--radius); display: block; margin-bottom: 14px;
  background: #000; border: 1px solid var(--line);
}
.meta { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 12.5px; margin: 0 0 16px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.note { font-size: 12px; color: var(--muted); line-height: 1.55; margin: 0 0 14px; }
.drawer-body h3 { font-size: 13px; margin: 18px 0 8px; }
.drawer-body ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }

.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30;
  backdrop-filter: blur(2px);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #1e1e29; border: 1px solid var(--line); color: var(--fg);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 60;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast.err { border-color: var(--danger); color: #ffd7db; }

/* ---------- Legal pages ---------- */
.doc {
  max-width: 760px; margin: 0 auto; padding: 34px 20px 60px; line-height: 1.7; font-size: 15px;
}
.doc h1 { font-size: 26px; margin: 0 0 6px; }
.doc h2 { font-size: 18px; margin: 28px 0 8px; }
.doc p, .doc li { color: #cfcfda; }
.doc .updated { color: var(--muted); font-size: 13px; margin: 0 0 26px; }
.doc a { color: var(--accent-2); }
.back { display: inline-block; margin-bottom: 18px; color: var(--muted); text-decoration: none; font-size: 13px; }
.back:hover { color: var(--fg); }

/* ---------- Mobile ---------- */
@media (max-width: 780px) {
  .panel-toggle { display: flex; }
  .panel-body {
    display: none;
    flex-direction: column; align-items: stretch; gap: 12px;
    padding: 4px 16px 16px;
  }
  .panel.open .panel-body { display: flex; }
  .panel-toggle .chev { transition: transform .2s ease; }
  .panel.open .panel-toggle .chev { transform: rotate(180deg); }
  .ctl { justify-content: space-between; }
  .ctl label { min-width: auto; }
  input[type=range] { flex: 1; width: auto; }
  .ctl output { min-width: 36px; }
  .ctl-buttons { margin-left: 0; }
  .ctl-buttons .btn { flex: 1; }
  .topbar h1 { font-size: 14px; }
  .footer { justify-content: center; text-align: center; }
  .drawer { width: 100vw; }
  .hint { font-size: 11px; }
}

@media (max-width: 420px) {
  .topbar { padding: 8px 10px; }
  .btn { padding: 8px 12px; font-size: 12.5px; }
  .footer-links { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  .drawer { transition: none; }
}
