/* ==========================================================================
   PixelCut - stylesheet
   Minimal, fast, mobile-first. Light + dark theme.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d3d6dd;
  --text: #0e1117;
  --muted: #5b6472;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-2: #8b5cf6;
  --on-accent: #ffffff;
  --ring: rgba(79, 70, 229, .35);
  --success: #047857;
  --success-soft: #ecfdf5;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(16, 24, 40, .07);
  --maxw: 1180px;
  --header-h: 62px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --checker: #e2e4e9;
  --checker-2: #f4f5f8;
}

html[data-theme="dark"] {
  --bg: #0b0d12;
  --bg-soft: #0f1218;
  --surface: #14171f;
  --surface-2: #1b1f29;
  --border: #242a36;
  --border-strong: #333a48;
  --text: #e9ecf3;
  --muted: #9aa3b2;
  --accent: #6366f1;
  --accent-hover: #7c7ff5;
  --accent-soft: #1c1f38;
  --on-accent: #ffffff;
  --ring: rgba(99, 102, 241, .45);
  --success: #34d399;
  --success-soft: #10221c;
  --danger: #f87171;
  --danger-soft: #2a1618;
  --shadow-sm: none;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --checker: #262b36;
  --checker-2: #1a1e27;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0b0d12;
    --bg-soft: #0f1218;
    --surface: #14171f;
    --surface-2: #1b1f29;
    --border: #242a36;
    --border-strong: #333a48;
    --text: #e9ecf3;
    --muted: #9aa3b2;
    --accent: #6366f1;
    --accent-hover: #7c7ff5;
    --accent-soft: #1c1f38;
    --on-accent: #ffffff;
    --ring: rgba(99, 102, 241, .45);
    --success: #34d399;
    --success-soft: #10221c;
    --danger: #f87171;
    --danger-soft: #2a1618;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    --checker: #262b36;
    --checker-2: #1a1e27;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

img, svg, canvas { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.02em; }
h1 { font-size: clamp(1.6rem, 4.6vw, 2.6rem); font-weight: 800; }
h2 { font-size: clamp(1.25rem, 3vw, 1.7rem); font-weight: 700; margin-top: 2.2rem; }
h3 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 1rem; }
ul, ol { padding-left: 1.2rem; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--header-h);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; letter-spacing: -.02em; color: var(--text);
  font-size: 1.05rem; text-decoration: none; flex: 0 0 auto;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 9px; }
.brand-name span { color: var(--accent); }

.nav { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.nav a {
  color: var(--muted); font-weight: 550; font-size: .925rem;
  padding: 8px 10px; border-radius: 8px; text-decoration: none;
}
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-toggle {
  display: none; margin-left: auto;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 8px 10px; cursor: pointer; line-height: 0;
}
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 10px 16px; border-radius: 11px;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: transform .06s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 18px -6px var(--ring);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: .85rem; border-radius: 9px; }
.btn-icon { padding: 8px; min-height: 38px; min-width: 38px; }
.btn-block { width: 100%; }

/* ---------- hero ---------- */
.hero { padding: 44px 0 26px; text-align: center; }
.hero h1 { max-width: 22ch; margin-inline: auto; }
.hero .lead { font-size: clamp(1rem, 2.4vw, 1.15rem); color: var(--muted); max-width: 62ch; margin: 0 auto 18px; }
.hero .lead b { color: var(--text); font-weight: 650; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 0 0 8px; padding: 0; list-style: none; }
.badges li {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 550;
}
.badges svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--accent); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.workspace { margin: 8px 0 26px; }

/* ---------- dropzone ---------- */
.dropzone {
  position: relative;
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--bg-soft); padding: 30px 18px; text-align: center; cursor: pointer;
  transition: border-color .15s ease, background .15s ease, padding .15s ease;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.is-compact { padding: 16px 14px; }
.dropzone.is-compact .dropzone-icon { width: 34px; height: 34px; margin-bottom: 6px; border-radius: 11px; }
.dropzone.is-compact .dropzone-icon svg { width: 18px; height: 18px; }
.dropzone.is-compact h2 { font-size: .98rem; }
.dropzone-icon {
  width: 46px; height: 46px; margin: 0 auto 10px; border-radius: 14px;
  display: grid; place-items: center; color: var(--on-accent);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
}
.dropzone-icon svg { width: 24px; height: 24px; }
.dropzone h2 { font-size: 1.1rem; margin: 0 0 4px; }
.dropzone p { margin: 0; color: var(--muted); font-size: .9rem; }
.dropzone .formats-line { font-size: .8rem; color: var(--muted); margin-top: 8px; }

/* ---------- editor layout ---------- */
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  margin-top: 16px;
}
.editor-stage { min-width: 0; }

.viewport {
  position: relative;
  height: clamp(320px, 56vh, 620px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  padding: 14px;
}
.stage {
  background-color: var(--checker-2);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  border-radius: 6px;
  overflow: hidden;
  line-height: 0;
  box-shadow: var(--shadow-sm);
}
#preview { display: block; max-width: none; }
#preview.is-brush { cursor: crosshair; }

/* ---------- stage toolbar ---------- */
.stage-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 10px;
}
.tool-group {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 4px;
}
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; color: var(--muted);
  border-radius: 8px; padding: 6px 10px; min-height: 32px;
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
}
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.is-active { background: var(--accent); color: var(--on-accent); }
.tool svg { width: 15px; height: 15px; }
.zoom-label {
  min-width: 52px; text-align: center; font-size: .82rem;
  font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted);
}
.brush-bar {
  display: grid; grid-template-columns: auto 1fr auto 1fr;
  align-items: center; gap: 8px 12px; margin-top: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 10px 12px;
  font-size: .82rem; color: var(--muted);
}
.brush-bar label { font-weight: 600; }
.brush-bar input[type="range"] { min-height: 20px; }

/* ---------- side panel ---------- */
.editor-side {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
  align-self: start;
  position: sticky;
  top: calc(var(--header-h) + 12px);
}
.editor-side .field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.editor-side .field > label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.editor-side .field > p { margin: 0; }

select, input[type="text"], input[type="number"], input[type="color"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="color"] { padding: 4px; min-height: 40px; cursor: pointer; }
select:focus-visible, input:focus-visible { outline: 3px solid var(--ring); outline-offset: 1px; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 24px; }
.range-value { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.trim-row { margin-top: 2px; }

/* segmented control */
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 4px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--muted);
  border-radius: 8px; padding: 8px 6px; min-height: 34px;
  font: inherit; font-size: .88rem; font-weight: 650; cursor: pointer;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--accent); color: var(--on-accent); }

/* fine tuning */
.tuning {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); padding: 10px 12px;
}
.tuning summary { cursor: pointer; font-weight: 650; font-size: .88rem; }
.tuning[open] summary { margin-bottom: 10px; }
.tuning .field { margin-bottom: 12px; }
.tuning .field:last-child { margin-bottom: 0; }

/* ai note */
.ai-note {
  background: var(--accent-soft); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.ai-note p { margin: 0 0 6px; }
.mini-progress { display: grid; gap: 6px; }
.mini-progress .progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.mini-progress .progress > span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit; transition: width .2s ease;
}

/* ---------- toolbar / controls ---------- */
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1 1 auto; }
.side-actions { margin-top: 2px; }

/* ---------- progress ---------- */
.progress-wrap { margin-top: 16px; }
.progress {
  height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
.progress > span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit; transition: width .18s ease;
}
.status-line { display: flex; justify-content: space-between; gap: 12px; font-size: .85rem; color: var(--muted); margin-top: 8px; }

/* ---------- file list ---------- */
.file-list { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 8px; }
.file-item {
  display: grid; grid-template-columns: 46px minmax(0, 1fr) auto auto;
  align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  cursor: pointer; transition: border-color .15s ease, background .15s ease;
}
.file-item:hover { border-color: var(--border-strong); }
.file-item.is-active { border-color: var(--accent); background: var(--accent-soft); }
.thumb {
  width: 46px; height: 46px; border-radius: 9px; background: var(--surface-2);
  object-fit: cover; display: grid; place-items: center; overflow: hidden; color: var(--muted);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-meta { min-width: 0; }
.file-name { font-weight: 600; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-sub { font-size: .78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px;
  padding: 1px 8px; font-size: .72rem; font-weight: 650; border: 1px solid transparent;
}
.pill-queued { background: var(--surface-2); color: var(--muted); }
.pill-working { background: var(--accent-soft); color: var(--accent); }
.pill-done { background: var(--success-soft); color: var(--success); }
.pill-error { background: var(--danger-soft); color: var(--danger); }
.file-actions { display: flex; gap: 6px; align-items: center; }

/* ---------- sticky mobile action bar ---------- */
.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: none; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--border);
}
.mobile-bar .btn { flex: 1; }

/* ---------- ads ---------- */
.ad-slot { margin: 22px 0; text-align: center; min-height: 90px; }
.ad-slot ins { display: block; }
.ad-placeholder {
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  color: var(--muted); font-size: .8rem; padding: 18px; background: var(--bg-soft);
}

/* ---------- features / info ---------- */
.grid-cards {
  display: grid; gap: 14px; margin: 22px 0;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.feature .ico {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 10px;
}
.feature .ico svg { width: 18px; height: 18px; }
.feature h3 { margin: 0 0 4px; }
.feature p { margin: 0; color: var(--muted); font-size: .9rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; min-width: 460px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-soft); font-weight: 650; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* ---------- faq ---------- */
.faq { display: grid; gap: 10px; margin: 18px 0 6px; }
.faq details {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.faq summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; margin-left: auto; color: var(--muted); font-weight: 700; }
.faq details[open] summary::after { content: "\2212"; }
.faq details p { margin: 10px 0 0; color: var(--muted); font-size: .92rem; }

/* ---------- toast ---------- */
.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: 18px; display: grid; gap: 8px; width: min(92vw, 420px);
}
.toast {
  background: var(--text); color: var(--bg); border-radius: 11px; padding: 10px 14px;
  font-size: .88rem; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: center;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }

/* ---------- install modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70; display: none;
  align-items: center; justify-content: center; padding: 18px;
  background: rgba(9, 11, 16, .55); backdrop-filter: blur(3px);
}
.modal[open], .modal.is-open { display: flex; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; width: min(100%, 460px); box-shadow: var(--shadow);
}
.modal-card h2 { margin-top: 0; font-size: 1.15rem; }
.modal-card ol { margin: 0 0 14px; padding-left: 1.15rem; color: var(--muted); }
.modal-card li { margin-bottom: 6px; }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 40px; border-top: 1px solid var(--border);
  background: var(--bg-soft); padding: 28px 0 34px; color: var(--muted); font-size: .88rem;
}
.footer-grid { display: grid; gap: 20px; grid-template-columns: 1.4fr 1fr 1fr; }
.footer-grid h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.footer-grid ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.footer-bottom { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }

/* ---------- content pages ---------- */
.prose { max-width: 68ch; }
.prose h2 { margin-top: 1.8rem; }
.prose ul li { margin-bottom: 6px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
}

@media (max-width: 860px) {
  .nav { display: none; }
  .nav.is-open {
    display: grid; position: absolute; left: 0; right: 0; top: var(--header-h);
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 10px 16px 16px; gap: 2px;
  }
  .nav.is-open a { padding: 12px 10px; font-size: 1rem; }
  .nav-toggle { display: inline-flex; }
  .footer-grid { grid-template-columns: 1fr; gap: 22px; }
}

@media (max-width: 640px) {
  .hero { padding: 28px 0 18px; }
  .card { padding: 14px; border-radius: 14px; }
  .dropzone { padding: 24px 14px; }
  .viewport { height: 44vh; padding: 8px; }
  .file-item { grid-template-columns: 42px minmax(0, 1fr) auto; }
  .file-item .file-actions .label { display: none; }
  .actions { display: none; }              /* the sticky bar is used on mobile */
  .mobile-bar.is-visible { display: flex; }
  body.has-mobile-bar { padding-bottom: 84px; }
  .toasts { bottom: 92px; }
  .header-actions .install-label { display: none; }
  .tool span { display: none; }
  .tool { padding: 6px 9px; }
  .brush-bar { grid-template-columns: auto 1fr; }
  .side-actions { display: flex; }
}

@media (min-width: 641px) {
  .mobile-bar { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

@media print {
  .site-header, .mobile-bar, .ad-slot, .site-footer, .toasts, .editor { display: none !important; }
}
