:root {
  --bg: #f6f6fb;
  --card: #ffffff;
  --ink: #16151f;
  --muted: #6b6a7b;
  --line: #e4e3ee;
  --accent: #5b4cf0;
  --accent-ink: #ffffff;
  --accent-soft: #eceafe;
  --ok: #1e9e5a;
  --danger: #d6324a;
  --code-bg: #15141d;
  --code-ink: #e6e4f5;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(30, 20, 90, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111018;
    --card: #1b1a25;
    --ink: #f1f0f7;
    --muted: #9998ab;
    --line: #2d2b3b;
    --accent: #7c6ff5;
    --accent-soft: #28244a;
    --code-bg: #0c0b12;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 20px; }
h1, h2, h3 { letter-spacing: -0.01em; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 24px;
  max-width: 1180px; width: 100%; margin: 0 auto; padding: 16px 20px; min-height: 76px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: inherit; text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #b44cf0); flex: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 999px; font-weight: 500; }
.nav a:hover, .nav a.current { color: var(--ink); background: var(--card); }
.top .right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.credit-badge {
  background: var(--accent-soft); color: var(--accent); font-weight: 600; text-decoration: none;
  padding: 7px 14px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}

/* ---------- buttons & inputs ---------- */
button, .btn, .file-btn, .color-btn {
  font: inherit; cursor: pointer; border-radius: 999px; border: 1px solid transparent;
  padding: 10px 20px; transition: transform .1s, background .15s, border-color .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; line-height: 1.3;
}
button:active, .btn:active { transform: scale(.97); }
button:disabled, label.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover { filter: brightness(1.08); }
.primary.big { font-size: 20px; padding: 16px 40px; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent); }
.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.ghost:hover, .ghost.active { border-color: var(--accent); color: var(--accent); }
.ghost.active { background: var(--accent-soft); }
.danger-btn { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.linkish { background: none; border: 0; padding: 8px 10px; color: var(--ink); font-weight: 500; }
.linkish:hover { color: var(--accent); }
.small { padding: 7px 14px; font-size: 14px; }
.block { width: 100%; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 12px; font-family: inherit; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], select {
  font: inherit; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: inherit; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }

/* ---------- landing ---------- */
.landing {
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center;
  padding-block: 40px 56px;
}
.hero-text h1 { font-size: clamp(36px, 6vw, 60px); line-height: 1.05; margin: 0 0 16px; letter-spacing: -0.02em; }
.hero-text p { font-size: 19px; color: var(--muted); margin: 0; max-width: 30ch; }
.accent { color: var(--accent); }
.upload-card {
  background: var(--card); border-radius: 28px; box-shadow: var(--shadow);
  padding: 48px 32px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.url-form { display: flex; gap: 8px; width: 100%; max-width: 380px; }
.url-form input { flex: 1; min-width: 0; border-radius: 999px; padding: 9px 16px; background: transparent; }
.hd-toggle { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; }
.hd-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.features { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; padding-bottom: 48px; }
.feature { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.feature b { display: block; margin-bottom: 4px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 24px; padding-block: 8px 40px; align-items: start; }
.stage-wrap { min-width: 0; }
.stage {
  position: relative; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  min-height: 420px; display: grid; place-items: center; overflow: hidden; padding: 16px;
}
.checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e6e6ec 25%, transparent 25%),
    linear-gradient(-45deg, #e6e6ec 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6e6ec 75%),
    linear-gradient(-45deg, transparent 75%, #e6e6ec 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
#view { max-width: 100%; max-height: 68vh; display: block; border-radius: 6px; touch-action: none; }
#view.brush { cursor: none; }
.brush-cursor {
  position: absolute; pointer-events: none; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.5); transform: translate(-50%, -50%);
}
.before-clip { position: absolute; pointer-events: none; overflow: hidden; }
.before-clip canvas { position: absolute; left: 0; top: 0; display: block; }
.divider { position: absolute; width: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); pointer-events: none; }
.divider span {
  position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.divider span::before { content: "‹ ›"; position: absolute; inset: 0; display: grid; place-items: center; color: #333; font-weight: 700; letter-spacing: 2px; }
.compare { position: absolute; margin: 0; opacity: 0; cursor: ew-resize; }
.stage-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.stage-bar .row { gap: 6px; }

.busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--card) 72%, transparent); backdrop-filter: blur(3px); font-weight: 600; text-align: center; padding: 16px;
}
.busy p { margin: 0; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%; margin-bottom: 12px;
  border: 4px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error {
  position: absolute; left: 16px; right: 16px; bottom: 16px; padding: 12px 16px; border-radius: 12px;
  background: var(--danger); color: #fff; font-weight: 500;
}

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.panel h3:first-child { margin-top: 0; }
.dl-option { display: grid; gap: 2px; }
.dl-option .note { font-size: 12px; color: var(--muted); text-align: center; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 999px; margin: 18px 0 4px; }
.tabs button { flex: 1; padding: 7px 8px; font-size: 13px; background: transparent; color: var(--muted); }
.tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 10px; }
.swatch {
  aspect-ratio: 1; border-radius: 10px; padding: 0; border: 2px solid var(--line); cursor: pointer; background-size: cover; background-position: center;
}
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.swatch.checker { background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0; }
.color-btn { padding: 4px; }
.color-btn input { width: 26px; height: 22px; border: 0; padding: 0; background: none; cursor: pointer; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { padding: 7px 6px; font-size: 13px; }
.field { display: grid; gap: 4px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.field .val { float: right; color: var(--ink); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }
.switch-row input { accent-color: var(--accent); width: 18px; height: 18px; }

.history { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.history .thumb, .history .add {
  aspect-ratio: 1; border-radius: 10px; border: 2px solid var(--line); padding: 0; overflow: hidden; position: relative; background-color: var(--bg);
}
.history .thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.history .thumb.active { border-color: var(--accent); }
.history .thumb.pending::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--card) 60%, transparent); }
.history .thumb.failed { border-color: var(--danger); }
.history .add { font-size: 24px; color: var(--muted); border-style: dashed; background: transparent; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 85%, transparent); color: #fff; font-size: 32px; font-weight: 700;
}
.drop-overlay p { border: 3px dashed #fff; border-radius: 24px; padding: 60px 80px; margin: 20px; text-align: center; }

/* ---------- modal / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 8, 25, .45); display: grid; place-items: center; padding: 16px;
  animation: fade .15s;
}
.modal { position: relative; background: var(--card); border-radius: 20px; padding: 28px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 4px; }
.modal-x { position: absolute; right: 10px; top: 10px; padding: 4px 10px; background: none; color: var(--muted); font-size: 22px; }
.auth-form { display: grid; gap: 12px; }
.auth-form label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.auth-form .bonus { margin: 0 0 4px; }
.auth-form .bonus:empty { display: none; }
.auth-form .switch { justify-self: center; font-weight: 400; color: var(--muted); }
.form-error { color: var(--danger); margin: 0; font-size: 14px; }
#toasts { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); animation: fade .2s; transition: opacity .3s; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }
@keyframes fade { from { opacity: 0; } }

/* ---------- pages ---------- */
.page { padding-block: 24px 56px; }
.page-head { text-align: center; max-width: 640px; margin: 0 auto 36px; }
.page-head h1 { font-size: clamp(30px, 5vw, 44px); margin: 0 0 10px; line-height: 1.1; }
.page-head p { color: var(--muted); font-size: 17px; margin: 0; }

.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.plan { display: flex; flex-direction: column; gap: 6px; position: relative; }
.plan.best { outline: 2px solid var(--accent); }
.plan .tag { position: absolute; top: -11px; right: 16px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.plan .amount { font-size: 30px; font-weight: 700; margin: 0; }
.plan .price { font-size: 20px; font-weight: 600; }
.plan ul { padding-left: 18px; margin: 8px 0 16px; color: var(--muted); font-size: 14px; flex: 1; }
.faq { max-width: 760px; margin: 48px auto 0; }
.faq details { background: var(--card); border-radius: 12px; padding: 14px 18px; margin-bottom: 10px; box-shadow: var(--shadow); }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { color: var(--muted); margin: 8px 0 0; }

.acct { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; align-items: start; }
.acct .wide { grid-column: 1 / -1; }
.acct h2 { font-size: 18px; margin: 0 0 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { background: var(--bg); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.hero { background: var(--accent); color: #fff; }
.stat.hero span { color: rgba(255,255,255,.8); }
.buy-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.buy-row button { flex-direction: column; gap: 0; padding: 12px; border-radius: 14px; }
.buy-row button small { opacity: .75; font-weight: 400; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.plus { color: var(--ok); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
:not(pre) > code { background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; }
.new-key { background: var(--accent-soft); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.new-key code { display: block; word-break: break-all; background: var(--card); padding: 10px; border-radius: 8px; margin: 8px 0; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; }
.inline-form input { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; max-width: 380px; }
.empty { color: var(--muted); text-align: center; padding: 16px; }

/* docs */
.docs { display: grid; grid-template-columns: 200px 1fr; gap: 32px; align-items: start; }
.toc { position: sticky; top: 16px; display: grid; gap: 2px; font-size: 14px; }
.toc a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.toc a:hover { background: var(--card); color: var(--ink); }
.doc { min-width: 0; }
.doc section { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.doc h2 { margin-top: 0; font-size: 22px; }
.doc pre { background: var(--code-bg); color: var(--code-ink); padding: 16px; border-radius: 12px; overflow-x: auto; line-height: 1.55; margin: 12px 0; }
.code-tabs { display: flex; gap: 4px; margin-top: 12px; }
.code-tabs button { padding: 5px 12px; font-size: 13px; }
.params td { white-space: normal; vertical-align: top; }
.params td:first-child { font-family: ui-monospace, Menlo, monospace; font-size: 13px; white-space: nowrap; }
.method { font-weight: 700; color: var(--ok); margin-right: 6px; }

.foot { text-align: center; padding: 24px 20px; font-size: 13px; color: var(--muted); }
.foot a { color: inherit; }

@media (max-width: 900px) {
  .landing { grid-template-columns: 1fr; gap: 28px; padding-block: 16px 36px; text-align: center; }
  .hero-text p { margin: 0 auto; }
  .features { grid-template-columns: 1fr 1fr; }
  .editor { grid-template-columns: 1fr; }
  .stage { min-height: 220px; }
  .docs { grid-template-columns: 1fr; }
  .toc { display: none; }
}
@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px 12px; padding-block: 12px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .nav a { padding: 6px 10px; white-space: nowrap; }
  .top .right .btn.ghost { display: none; }
  .features { grid-template-columns: 1fr; }
}
