/* ImageReady stylesheet.
 *
 * The original single-file styles live in the `legacy` layer. The `app` layer below holds the
 * BG11 shell (top bar, canvas, settings drawer, action bar, cards) and the light/dark theme.
 * Anything in `app` beats anything in `legacy` no matter how specific the legacy rule is, so
 * the older rules can keep styling the settings fields, modals and crop editor untouched.
 */
@layer legacy, app;

@layer legacy {
  :root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #111827;
    /* Was #64748b, which is under 4.5:1 on the tinted surfaces this sits on. */
    --muted: #5b6879;
    /* Green as text, rather than as a dot or a border: the status green is far too light. */
    --ok-text: #166534;
    --line: #dbe2ea;
    --line-strong: #cbd5e1;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --accent-soft: #eff6ff;
    --success: #15803d;
    --success-soft: #f0fdf4;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --shadow: 0 16px 45px rgba(15, 23, 42, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --max: 1440px;
  }

  * {
    box-sizing: border-box;
  }

  html {
    color-scheme: light;
  }

  body {
    margin: 0;
    min-width: 320px;
    background:
      radial-gradient(
        circle at 15% 0%,
        rgba(37, 99, 235, 0.06),
        transparent 28rem
      ),
      var(--bg);
    color: var(--text);
    font-family:
      ui-sans-serif,
      system-ui,
      -apple-system,
      BlinkMacSystemFont,
      "Segoe UI",
      sans-serif;
    line-height: 1.5;
  }

  button,
  input,
  select {
    font: inherit;
  }

  button {
    cursor: pointer;
  }

  button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
  }

  .app-shell {
    width: min(var(--max), calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 56px;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--text);
    color: #fff;
    font-weight: 800;
    letter-spacing: -0.03em;
  }

  .brand-copy strong {
    display: block;
    font-size: 17px;
    line-height: 1.2;
  }

  .brand-copy span {
    color: var(--muted);
    font-size: 13px;
  }

  .privacy-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #bbf7d0;
    background: var(--success-soft);
    color: #166534;
    border-radius: 999px;
    padding: 8px 11px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
  }

  .privacy-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
  }

  .hero {
    padding: 34px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
  }

  .eyebrow {
    color: var(--accent);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 800;
    margin-bottom: 7px;
  }

  h1 {
    margin: 0;
    font-size: clamp(31px, 4vw, 54px);
    line-height: 1.03;
    letter-spacing: -0.045em;
    max-width: 880px;
  }

  .hero p {
    max-width: 780px;
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 17px;
  }

  .drop-zone {
    margin-top: 26px;
    border: 2px dashed var(--line-strong);
    border-radius: 12px;
    background: var(--surface-2);
    min-height: 220px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 28px;
    transition: 0.18s ease;
    outline: none;
  }

  .drop-zone.dragover,
  .drop-zone:focus-visible {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.09);
  }

  .drop-icon {
    width: 52px;
    height: 52px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    display: grid;
    place-items: center;
    margin: 0 auto 14px;
    font-size: 25px;
  }

  .drop-zone strong {
    display: block;
    font-size: 18px;
    margin-bottom: 5px;
  }

  .drop-zone small {
    display: block;
    color: var(--muted);
    margin-top: 9px;
  }

  .browse-btn {
    margin-top: 14px;
    border: 0;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    font-weight: 750;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
  }

  .left-column {
    min-width: 0;
    display: grid;
    gap: 18px;
  }

  .left-column .hero {
    margin-bottom: 0;
  }

  .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }

  .panel-header {
    min-height: 65px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
  }

  .panel-header h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: -0.02em;
  }

  .panel-header span {
    color: var(--muted);
    font-size: 13px;
  }

  .queue-actions {
    display: flex;
    gap: 8px;
  }

  .text-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 7px;
    padding: 7px 9px;
    font-size: 13px;
    font-weight: 700;
  }

  .text-btn:hover {
    background: var(--surface-2);
    color: var(--text);
  }

  .queue-empty {
    min-height: 330px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 35px;
    color: var(--muted);
  }

  .file-list {
    display: grid;
  }

  .file-card {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--line);
  }

  .file-card:last-child {
    border-bottom: 0;
  }

  .thumb {
    width: 78px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
    background: #e5e7eb;
    border: 1px solid var(--line);
  }

  .file-info {
    min-width: 0;
  }

  .file-name {
    font-weight: 750;
    font-size: 14px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-bottom: 3px;
  }

  .file-meta,
  .result-meta {
    color: var(--muted);
    font-size: 12px;
  }

  .result-meta {
    margin-top: 5px;
  }

  .saving {
    color: var(--success);
    font-weight: 800;
  }

  .status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 7px;
    padding: 4px 7px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
  }

  .status.waiting {
    background: #f1f5f9;
    color: #475569;
  }

  .status.processing {
    background: var(--accent-soft);
    color: var(--accent-dark);
  }

  .status.done {
    background: var(--success-soft);
    color: var(--success);
  }

  .status.error {
    background: var(--danger-soft);
    color: var(--danger);
  }

  .file-buttons {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .icon-btn {
    min-width: 36px;
    min-height: 36px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    font-weight: 800;
    padding: 7px 9px;
  }

  .icon-btn:hover {
    background: var(--surface-2);
    border-color: var(--line-strong);
  }

  .download-btn {
    border-color: #bfdbfe;
    background: var(--accent-soft);
    color: var(--accent-dark);
  }

  .settings {
    position: sticky;
    top: 18px;
    overflow: hidden;
  }

  .settings-body {
    padding: 17px;
  }

  .settings-section {
    padding: 0 0 18px;
    margin: 0 0 18px;
    border-bottom: 1px solid var(--line);
  }

  .settings-section:last-of-type {
    border-bottom: 0;
    margin-bottom: 8px;
  }

  .section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 850;
    color: #475569;
    margin-bottom: 11px;
  }

  label {
    display: block;
    color: #334155;
    font-size: 12px;
    font-weight: 750;
    margin: 0 0 6px;
  }

  .field {
    margin-bottom: 12px;
  }

  .field:last-child {
    margin-bottom: 0;
  }

  input[type="number"],
  input[type="text"],
  input[type="color"],
  select {
    width: 100%;
    height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 0 11px;
    outline: none;
  }

  input:focus,
  select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.09);
  }

  .two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .inline-check {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin-top: 10px;
    color: #334155;
    font-size: 12px;
    font-weight: 650;
  }

  .inline-check input {
    margin: 2px 0 0;
    flex: 0 0 auto;
  }

  .range-row {
    display: grid;
    grid-template-columns: 1fr 58px;
    align-items: center;
    gap: 10px;
  }

  input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
  }

  .quality-value {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface-2);
    padding: 5px 6px;
    text-align: center;
    font-size: 12px;
    font-weight: 800;
  }

  .notice {
    display: none;
    margin-top: 10px;
    border-radius: 8px;
    padding: 9px 10px;
    font-size: 11px;
    line-height: 1.45;
  }

  .notice.show {
    display: block;
  }

  .notice.warning {
    background: var(--warning-soft);
    color: #92400e;
    border: 1px solid #fde68a;
  }

  .notice.info {
    background: var(--accent-soft);
    color: #1e40af;
    border: 1px solid #bfdbfe;
  }

  .enhance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .feature-note {
    margin-top: 10px;
    padding: 10px 11px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
    line-height: 1.45;
  }

  .ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 5px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #ede9fe;
    color: #6d28d9;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.05em;
    vertical-align: 1px;
  }

  .preview-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(5px);
  }

  .preview-modal.open {
    display: flex;
  }

  .preview-dialog {
    width: min(1120px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
  }

  .preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--line);
  }

  .preview-head strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--line);
  }

  .preview-pane {
    min-width: 0;
    background: #fff;
    padding: 16px;
  }

  .preview-pane h3 {
    margin: 0 0 10px;
    font-size: 13px;
  }

  .preview-image-wrap {
    display: grid;
    place-items: center;
    min-height: 360px;
    border-radius: 8px;
    background: repeating-conic-gradient(#e5e7eb 0% 25%, #f8fafc 0% 50%) 50% /
      20px 20px;
    overflow: hidden;
  }

  .preview-image-wrap img {
    display: block;
    max-width: 100%;
    max-height: 65vh;
    object-fit: contain;
  }

  .preview-stats {
    margin-top: 9px;
    color: var(--muted);
    font-size: 12px;
  }

  @media (max-width: 760px) {
    .preview-modal {
      padding: 10px;
    }
    .preview-grid {
      grid-template-columns: 1fr;
    }
    .preview-image-wrap {
      min-height: 220px;
    }
    .enhance-grid {
      grid-template-columns: 1fr;
    }
  }

  .primary-btn {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    padding: 12px 16px;
    font-weight: 850;
    box-shadow: 0 7px 18px rgba(37, 99, 235, 0.2);
  }

  .primary-btn:hover:not(:disabled) {
    background: var(--accent-dark);
  }

  .secondary-btn {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: #fff;
    color: var(--text);
    padding: 10px 14px;
    font-weight: 800;
    margin-top: 9px;
  }

  .secondary-btn:hover:not(:disabled) {
    background: var(--surface-2);
  }

  .processing-bar {
    height: 4px;
    background: #e2e8f0;
    overflow: hidden;
    display: none;
  }

  .processing-bar.show {
    display: block;
  }

  .processing-bar span {
    display: block;
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s ease;
  }

  /* Bulk controls + detailed processing status */
  .bulk-toolbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: #fbfdff;
  }

  .bulk-toolbar.show {
    display: flex;
  }

  .bulk-select {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin: 0;
    font-size: 12px;
    font-weight: 800;
    color: #334155;
    white-space: nowrap;
  }

  .bulk-select input,
  .file-check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
  }

  .bulk-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  .bulk-btn {
    border: 1px solid var(--line);
    background: #fff;
    color: #334155;
    border-radius: 7px;
    min-height: 32px;
    padding: 6px 9px;
    font-size: 11px;
    font-weight: 800;
  }

  .bulk-btn:hover:not(:disabled) {
    border-color: var(--line-strong);
    background: var(--surface-2);
    color: var(--text);
  }

  .bulk-btn.danger:hover:not(:disabled) {
    border-color: #fecaca;
    background: var(--danger-soft);
    color: var(--danger);
  }

  .batch-status {
    display: none;
    padding: 14px 16px 13px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(90deg, #f8fbff, #fff);
  }

  .batch-status.show {
    display: block;
  }
  .batch-status.success {
    background: linear-gradient(90deg, #f0fdf4, #fff);
  }
  .batch-status.warning {
    background: linear-gradient(90deg, #fffbeb, #fff);
  }

  .batch-status-main {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
  }

  .batch-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #dbeafe;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: toolspin 0.72s linear infinite;
  }

  .batch-status.success .batch-spinner {
    animation: none;
    border: 0;
    display: grid;
    place-items: center;
    background: #dcfce7;
    color: var(--success);
    font-size: 16px;
    font-weight: 900;
  }

  .batch-status.success .batch-spinner::after {
    content: "✓";
  }

  .batch-status.warning .batch-spinner {
    animation: none;
    border: 0;
    display: grid;
    place-items: center;
    background: #fef3c7;
    color: #b45309;
    font-size: 16px;
    font-weight: 900;
  }

  .batch-status.warning .batch-spinner::after {
    content: "!";
  }

  @keyframes toolspin {
    to {
      transform: rotate(360deg);
    }
  }

  .batch-status-copy {
    min-width: 0;
  }

  .batch-status-title {
    font-size: 13px;
    font-weight: 850;
    line-height: 1.25;
    color: var(--text);
  }

  .batch-status-detail {
    margin-top: 2px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
    font-size: 11px;
  }

  .batch-status-meta {
    margin-top: 6px;
    color: #475569;
    font-size: 11px;
    font-weight: 750;
  }

  .cancel-btn {
    border: 1px solid var(--line-strong);
    background: #fff;
    color: #334155;
    border-radius: 7px;
    padding: 7px 9px;
    font-size: 11px;
    font-weight: 800;
  }

  .cancel-btn:hover:not(:disabled) {
    border-color: #fecaca;
    background: var(--danger-soft);
    color: var(--danger);
  }

  .batch-progress-track {
    height: 7px;
    margin-top: 11px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
  }

  .batch-progress-track span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.16s linear;
  }

  .batch-progress-track.indeterminate span {
    width: 38%;
    animation: indeterminate 1.15s ease-in-out infinite;
  }

  @keyframes indeterminate {
    0% {
      transform: translateX(-120%);
    }
    100% {
      transform: translateX(310%);
    }
  }

  .file-card {
    grid-template-columns: 26px 78px minmax(0, 1fr) auto;
    transition:
      opacity 0.15s ease,
      background 0.15s ease;
  }

  .file-card.is-unselected {
    opacity: 0.8;
    background: #fbfcfd;
  }

  .file-check {
    display: grid;
    place-items: center;
    margin: 0;
  }

  .file-progress {
    display: none;
    align-items: center;
    gap: 7px;
    margin-top: 7px;
  }

  .file-progress.show {
    display: flex;
  }

  .file-progress-track {
    flex: 1;
    min-width: 90px;
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
  }

  .file-progress-track span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.14s linear;
  }

  .file-progress.done .file-progress-track span {
    background: #22c55e;
  }

  .file-progress-label {
    width: 34px;
    text-align: right;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
  }

  .status.loading {
    background: #f1f5f9;
    color: #475569;
  }

  .batch-name-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-bottom: 10px;
  }

  .mini-field {
    margin-top: 8px;
    max-width: 120px;
  }

  @media (max-width: 680px) {
    .bulk-toolbar {
      align-items: flex-start;
      flex-direction: column;
    }

    .bulk-actions {
      justify-content: flex-start;
    }

    .batch-status-main {
      grid-template-columns: 32px minmax(0, 1fr);
    }

    .cancel-btn {
      grid-column: 1 / -1;
      width: 100%;
    }

    .file-card {
      grid-template-columns: 26px 64px minmax(0, 1fr);
    }

    .file-buttons {
      grid-column: 1 / -1;
    }
    .batch-name-grid {
      grid-template-columns: 1fr;
    }
  }

  .footer {
    margin-top: 18px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    padding: 10px;
  }

  .footer strong {
    color: #475569;
  }

  .hidden {
    display: none !important;
  }

  @media (max-width: 980px) {
    .workspace {
      grid-template-columns: 1fr;
    }

    .settings {
      position: static;
    }

    .settings-body {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0 18px;
    }

    .settings-section {
      min-width: 0;
    }

    .settings-actions {
      grid-column: 1 / -1;
    }
  }

  @media (max-width: 680px) {
    .app-shell {
      width: min(100% - 20px, var(--max));
      padding-top: 12px;
    }

    .topbar {
      align-items: flex-start;
    }

    .brand-copy span {
      display: none;
    }

    .privacy-pill {
      font-size: 11px;
      padding: 7px 9px;
    }

    .hero {
      padding: 22px 16px 16px;
    }

    .hero p {
      font-size: 15px;
    }

    .drop-zone {
      min-height: 190px;
      padding: 20px 14px;
    }

    .file-card {
      grid-template-columns: 26px 64px minmax(0, 1fr);
      gap: 11px;
      padding: 13px;
    }

    .thumb {
      width: 64px;
      height: 58px;
    }

    .file-buttons {
      grid-column: 1 / -1;
      justify-content: flex-end;
    }

    .settings-body {
      display: block;
    }

    .two-col {
      grid-template-columns: 1fr 1fr;
    }
  }

  /* Smart Auto, crop/transform, watermark, saved presets, folder import, compare preview */
  .settings-row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }
  .mini-btn {
    min-height: 38px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 800;
  }
  .mini-btn:hover:not(:disabled) {
    background: var(--surface-2);
  }
  .mini-btn.danger {
    color: var(--danger);
  }
  .smart-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 7px;
    padding: 5px 8px;
    border-radius: 7px;
    background: var(--success-soft);
    color: var(--success);
    font-size: 11px;
    font-weight: 800;
  }
  .file-picker-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 12px;
  }
  .folder-btn {
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-weight: 800;
  }
  .folder-btn:hover {
    background: var(--surface-2);
  }
  .watermark-logo-preview {
    display: none;
    align-items: center;
    gap: 9px;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
  }
  .watermark-logo-preview.show {
    display: flex;
  }
  .watermark-logo-preview img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
  }
  .watermark-logo-preview span {
    min-width: 0;
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .compare-stage {
    position: relative;
    min-height: 520px;
    overflow: auto;
    background:
      linear-gradient(45deg, #eef2f7 25%, transparent 25%),
      linear-gradient(-45deg, #eef2f7 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #eef2f7 75%),
      linear-gradient(-45deg, transparent 75%, #eef2f7 75%);
    background-size: 24px 24px;
    background-position:
      0 0,
      0 12px,
      12px -12px,
      -12px 0;
    border-bottom: 1px solid var(--line);
  }
  .compare-canvas {
    position: relative;
    width: 100%;
    min-height: 520px;
    display: grid;
    place-items: center;
    overflow: hidden;
  }
  .compare-layer {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    pointer-events: none;
  }
  .compare-layer img {
    display: block;
    max-width: 100%;
    max-height: 74vh;
    object-fit: contain;
    transform-origin: center center;
    user-select: none;
    -webkit-user-drag: none;
  }
  .compare-after {
    clip-path: inset(0 0 0 50%);
  }
  .compare-divider {
    position: absolute;
    z-index: 5;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.35);
    pointer-events: none;
  }
  .compare-divider::after {
    content: "↔";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow);
    font-weight: 900;
  }
  .compare-range {
    position: absolute;
    z-index: 8;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: ew-resize;
  }
  .compare-label {
    position: absolute;
    z-index: 6;
    top: 12px;
    padding: 6px 9px;
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.78);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    pointer-events: none;
  }
  .compare-label.before {
    left: 12px;
  }
  .compare-label.after {
    right: 12px;
  }
  .preview-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
  }
  .preview-controls .stats-pair {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 12px;
  }
  .zoom-control {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
  }
  .zoom-control label {
    margin: 0;
  }
  .zoom-control select {
    width: auto;
    min-width: 94px;
    height: 34px;
  }
  .compare-stage.zoom-100 .compare-layer img {
    max-width: none;
    max-height: none;
  }
  .compare-stage.zoom-200 .compare-layer img {
    max-width: none;
    max-height: none;
    transform: scale(2);
    transform-origin: top center;
  }
  @media (max-width: 680px) {
    .file-picker-row,
    .settings-row-actions {
      grid-template-columns: 1fr;
    }
    .compare-stage,
    .compare-canvas {
      min-height: 360px;
    }
    .preview-controls {
      align-items: flex-start;
      flex-direction: column;
    }
  }

  /* Compact settings sidebar */
  .settings {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .settings > .panel-header {
    flex: 0 0 auto;
  }

  .settings-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 10px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    flex: 0 0 auto;
  }

  .settings-tab {
    min-width: 0;
    min-height: 38px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--muted);
    border-radius: 8px;
    padding: 7px 6px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
  }

  .settings-tab:hover {
    color: var(--text);
    border-color: var(--line-strong);
  }

  .settings-tab.active {
    color: var(--accent-dark);
    background: var(--accent-soft);
    border-color: #bfdbfe;
  }

  .settings-body {
    padding: 14px 14px 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    min-height: 0;
  }

  .settings-section[data-settings-group] {
    display: none;
  }

  .settings-section[data-settings-group].settings-section-active {
    display: block;
  }

  .settings-section {
    padding-bottom: 15px;
    margin-bottom: 15px;
  }

  .settings-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin: 0 -14px;
    padding: 12px 14px 14px;
    background: linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.84),
      #fff 18px
    );
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 22px rgba(15, 23, 42, 0.05);
  }

  .settings-group-intro {
    margin: 0 0 14px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
    line-height: 1.45;
  }

  @media (max-width: 980px) {
    .settings {
      position: static;
      max-height: none;
      display: block;
    }

    .settings-body {
      overflow: visible;
      padding-bottom: 0;
    }

    .settings-actions {
      position: static;
      margin: 0 -14px;
    }
  }

  @media (max-width: 520px) {
    .settings-tabs {
      grid-template-columns: repeat(3, 1fr);
    }
  }

  /* Visual crop editor */
  .visual-crop-note {
    margin-top: 10px;
    padding: 10px 11px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: var(--accent-soft);
    color: #1e40af;
    font-size: 11px;
    line-height: 1.45;
  }

  .crop-dialog {
    width: min(1180px, 100%);
    max-height: calc(100vh - 32px);
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
  }

  .crop-toolbar {
    display: flex;
    align-items: end;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    flex-wrap: wrap;
  }

  .crop-toolbar .field {
    margin: 0;
    min-width: 170px;
  }

  .crop-toolbar .field.grow {
    flex: 1 1 220px;
  }

  .crop-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .crop-stage {
    position: relative;
    min-height: 560px;
    flex: 1 1 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    background:
      linear-gradient(
        45deg,
        #111827 25%,
        #0f172a 25%,
        #0f172a 75%,
        #111827 75%
      ),
      linear-gradient(45deg, #111827 25%, #0f172a 25%, #0f172a 75%, #111827 75%);
    background-size: 24px 24px;
    background-position:
      0 0,
      12px 12px;
    touch-action: none;
    user-select: none;
  }

  .crop-stage img {
    display: block;
    max-width: calc(100% - 36px);
    max-height: calc(100vh - 230px);
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
  }

  .crop-box {
    position: absolute;
    display: none;
    border: 2px solid #fff;
    box-shadow:
      0 0 0 1px rgba(15, 23, 42, 0.8),
      0 0 0 9999px rgba(2, 6, 23, 0.62);
    cursor: move;
    touch-action: none;
    z-index: 5;
  }

  .crop-box.show {
    display: block;
  }

  .crop-box::before,
  .crop-box::after {
    content: "";
    position: absolute;
    pointer-events: none;
    opacity: 0.65;
  }

  .crop-box::before {
    left: 33.333%;
    right: 33.333%;
    top: 0;
    bottom: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.8);
    border-right: 1px solid rgba(255, 255, 255, 0.8);
  }

  .crop-box::after {
    top: 33.333%;
    bottom: 33.333%;
    left: 0;
    right: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.8);
  }

  .crop-handle {
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid #fff;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 7;
  }

  .crop-handle[data-handle="nw"] {
    left: -10px;
    top: -10px;
    cursor: nwse-resize;
  }
  .crop-handle[data-handle="ne"] {
    right: -10px;
    top: -10px;
    cursor: nesw-resize;
  }
  .crop-handle[data-handle="sw"] {
    left: -10px;
    bottom: -10px;
    cursor: nesw-resize;
  }
  .crop-handle[data-handle="se"] {
    right: -10px;
    bottom: -10px;
    cursor: nwse-resize;
  }

  .crop-size-badge {
    position: absolute;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    z-index: 8;
    background: rgba(15, 23, 42, 0.8);
    color: #fff;
    border-radius: 6px;
    padding: 4px 7px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
    pointer-events: none;
  }

  .crop-help {
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    background: #fff;
    font-size: 11px;
    flex: 0 0 auto;
  }

  .crop-applied {
    color: var(--accent-dark);
    font-weight: 800;
  }

  @media (max-width: 760px) {
    .crop-dialog {
      max-height: calc(100vh - 18px);
    }

    .crop-toolbar {
      align-items: stretch;
    }

    .crop-toolbar .field {
      min-width: calc(50% - 6px);
      flex: 1 1 calc(50% - 6px);
    }

    .crop-actions {
      width: 100%;
      margin-left: 0;
    }

    .crop-actions button {
      flex: 1 1 auto;
    }

    .crop-stage {
      min-height: 420px;
    }

    .crop-stage img {
      max-width: calc(100% - 18px);
      max-height: calc(100vh - 310px);
    }
  }

  /* Pro workflow additions */
  .settings-tabs {
    grid-template-columns: repeat(3, 1fr);
  }
  .settings-tab {
    padding-left: 4px;
    padding-right: 4px;
  }
  .settings-section[data-settings-group="adjust"],
  .settings-section[data-settings-group="advanced"] {
    display: none;
  }
  .settings-section[data-settings-group].settings-section-active {
    display: block;
  }

  .feature-stack {
    display: grid;
    gap: 10px;
  }
  .feature-card {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 11px;
    background: var(--surface-2);
  }
  .feature-card strong {
    display: block;
    font-size: 12px;
    margin-bottom: 3px;
  }
  .feature-card p {
    margin: 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.45;
  }
  .output-recipe-badge {
    display: inline-flex;
    margin-top: 8px;
    padding: 5px 8px;
    border-radius: 7px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 11px;
    font-weight: 800;
  }

  .custom-variant-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
  }
  .custom-variant-row {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px;
    background: #fff;
    display: grid;
    gap: 8px;
  }
  .variant-row-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 7px;
    align-items: end;
  }
  .variant-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }
  .variant-grid.three {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .remove-variant-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--danger);
    font-weight: 900;
  }

  .asset-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 7px;
    margin-top: 7px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }
  .asset-preview.show {
    display: flex;
  }
  .asset-preview img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
  }
  .asset-preview span {
    font-size: 11px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .output-count {
    display: inline-flex;
    align-items: center;
    padding: 3px 6px;
    border-radius: 6px;
    background: #eef2ff;
    color: #4338ca;
    font-size: 11px;
    font-weight: 850;
  }
  .file-buttons {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .icon-btn.copy-btn {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
  }
  .icon-btn.history-btn {
    border-color: #ddd6fe;
    background: #f5f3ff;
    color: #6d28d9;
  }

  .tool-modal-dialog {
    width: min(920px, 100%);
    max-height: calc(100vh - 32px);
    overflow: hidden;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
  }
  .tool-modal-body {
    overflow: auto;
    padding: 14px 16px 18px;
  }
  .output-list {
    display: grid;
    gap: 9px;
  }
  .output-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-2);
  }
  .output-row-name {
    font-size: 13px;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .output-row-meta {
    color: var(--muted);
    font-size: 11px;
    margin-top: 3px;
  }
  .output-row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .modal-actionbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
  }

  .metadata-grid {
    display: grid;
    grid-template-columns: minmax(120px, 0.65fr) minmax(0, 1.35fr);
    border: 1px solid var(--line);
    border-radius: 9px;
    overflow: hidden;
  }
  .metadata-grid div {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    min-width: 0;
    font-size: 12px;
  }
  .metadata-grid div:nth-child(odd) {
    font-weight: 800;
    background: var(--surface-2);
  }
  .metadata-grid div:nth-last-child(-n + 2) {
    border-bottom: 0;
  }
  .metadata-value {
    overflow-wrap: anywhere;
  }

  .history-list {
    display: grid;
    gap: 9px;
  }
  .history-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
  }

  .contact-result {
    display: none;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    background: #f0fdf4;
    color: #166534;
    font-size: 11px;
  }
  .contact-result.show {
    display: block;
  }

  .warning-inline {
    padding: 9px 10px;
    border: 1px solid #fde68a;
    background: #fffbeb;
    color: #92400e;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.45;
  }
  .success-inline {
    padding: 9px 10px;
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #166534;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.45;
  }

  @media (max-width: 1120px) {
    .settings-tabs {
      grid-template-columns: repeat(3, 1fr);
    }
  }
  @media (max-width: 680px) {
    .variant-grid,
    .variant-grid.three {
      grid-template-columns: 1fr;
    }
    .output-row {
      grid-template-columns: 1fr;
    }
    .output-row-actions {
      justify-content: flex-start;
    }
    .metadata-grid {
      grid-template-columns: 1fr;
    }
    .metadata-grid div:nth-child(odd) {
      border-bottom: 0;
    }
    .metadata-grid div:nth-last-child(-n + 2) {
      border-bottom: 1px solid var(--line);
    }
  }

  .file-error-message {
    display: none;
    margin-top: 7px;
    padding: 8px 9px;
    border: 1px solid #fecaca;
    border-radius: 7px;
    background: #fef2f2;
    color: #991b1b;
    font-size: 11px;
    line-height: 1.45;
    overflow-wrap: anywhere;
  }
  .file-error-message.show {
    display: block;
  }
  .retry-btn {
    border-color: #fecaca !important;
    background: #fff7f7 !important;
    color: #991b1b !important;
  }

  /* ---- Added in BG9 ---- */

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.001ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.001ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* Toast notifications (replace alert()) */
  .toast-stack {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(420px, calc(100% - 32px));
    pointer-events: none;
  }
  .toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #111827;
    color: #fff;
    padding: 12px 14px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
    font-size: 14px;
    line-height: 1.4;
    animation: toast-in 0.18s ease-out;
  }
  .toast.leaving {
    opacity: 0;
    transform: translateY(6px);
    transition:
      opacity 0.2s,
      transform 0.2s;
  }
  .toast-warning {
    background: var(--warning);
  }
  .toast-danger {
    background: var(--danger);
  }
  .toast-success {
    background: var(--success);
  }
  .toast-close {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: inherit;
    font-size: 18px;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.8;
  }
  .toast-close:hover {
    opacity: 1;
  }
  @keyframes toast-in {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  /* Text prompt dialog (replaces prompt()) */
  .prompt-dialog {
    width: min(440px, calc(100% - 32px));
    max-width: 440px;
  }
  .prompt-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
  }
  .prompt-form input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font: inherit;
  }
  .prompt-form input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
  }
  .prompt-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
  }
  .prompt-cancel {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-weight: 600;
  }
  .prompt-confirm {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-weight: 700;
  }
  .prompt-confirm:hover {
    background: var(--accent-dark);
  }

  /* FAQ / how it works */
  .faq {
    margin-top: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
  }
  .faq h2 {
    margin: 0 0 6px;
    font-size: 22px;
  }
  .faq-intro {
    color: var(--muted);
    margin: 0 0 22px;
    max-width: 70ch;
  }
  .faq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px 32px;
  }
  .faq-item h3 {
    margin: 0 0 6px;
    font-size: 15px;
  }
  .faq-item p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
  }
  @media (max-width: 680px) {
    .faq {
      padding: 20px;
    }
  }
}

@layer app {
  /* ---------------------------------------------------------------- tokens */
  :root {
    color-scheme: light;

    --bg: #f5f7fa;
    --surface: #ffffff;
    --surface-2: #f1f4f8;
    --surface-3: #e6ebf2;
    --text: #0f172a;
    --text-2: #46536b;
    --text-3: #5b6880;
    --line: #e3e8ef;
    --line-strong: #cdd5e0;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-text: #1d4ed8;
    --accent-soft: #eaf1fe;
    --on-accent: #ffffff;

    --success: #157f3d;
    --success-soft: #e8f8ee;
    --on-success: #ffffff;
    --on-warning: #ffffff;
    --warning: #9a5b06;
    --warning-soft: #fdf4e3;
    --danger: #b42318;
    --danger-soft: #fdeceb;

    --shadow-sm:
      0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07);
    --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.16);
    --ring: 0 0 0 3px rgba(37, 99, 235, 0.28);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --topbar-h: 60px;
    --sidebar-w: 344px;
    --gutter: 20px;
    --max: 1560px;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;

    /* The light theme's muted grey was being reused here, where it lands at 2.7:1 against the
       lighter surfaces: below the 4.5:1 a reader needs, and every secondary line on the site
       uses it. This clears 5:1 against the lightest of them. */
    --muted: #94a3b8;
    --ok-text: #4ade80;

    --bg: #0e1320;
    --surface: #161c2a;
    --surface-2: #1e2534;
    --surface-3: #283143;
    --text: #e8ecf4;
    --text-2: #a7b2c6;
    --text-3: #8b98b0;
    --line: #262f40;
    --line-strong: #3a4558;

    --accent: #5b8def;
    --accent-hover: #7aa3ff;
    --accent-text: #9dbcff;
    --accent-soft: #1a2439;
    --on-accent: #0b1220;

    --success: #5ed492;
    --on-success: #0b1220;
    --on-warning: #2a1f08;
    --success-soft: #122a1f;
    --warning: #f0b445;
    --warning-soft: #2c2211;
    --danger: #f58b82;
    --danger-soft: #2e1a1a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.6);
    --ring: 0 0 0 3px rgba(91, 141, 239, 0.4);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;

      --muted: #94a3b8;
      --ok-text: #4ade80;

      --bg: #0e1320;
      --surface: #161c2a;
      --surface-2: #1e2534;
      --surface-3: #283143;
      --text: #e8ecf4;
      --text-2: #a7b2c6;
      --text-3: #8b98b0;
      --line: #262f40;
      --line-strong: #3a4558;

      --accent: #5b8def;
      --accent-hover: #7aa3ff;
      --accent-text: #9dbcff;
      --accent-soft: #1a2439;
      --on-accent: #0b1220;

      --success: #5ed492;
      --on-success: #0b1220;
      --on-warning: #2a1f08;
      --success-soft: #122a1f;
      --warning: #f0b445;
      --warning-soft: #2c2211;
      --danger: #f58b82;
      --danger-soft: #2e1a1a;

      --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
      --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
      --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.6);
      --ring: 0 0 0 3px rgba(91, 141, 239, 0.4);
    }
  }

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

  html {
    color-scheme: inherit;
  }

  body {
    margin: 0;
    min-width: 320px;
    background: var(--bg);
    color: var(--text);
    font-family:
      ui-sans-serif,
      system-ui,
      -apple-system,
      BlinkMacSystemFont,
      "Segoe UI",
      sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  body.has-action-bar {
    padding-bottom: 88px;
  }

  body.no-scroll {
    overflow: hidden;
  }

  h1,
  h2,
  h3 {
    color: var(--text);
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }

  button {
    cursor: pointer;
  }

  button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
  }

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

  .hidden,
  [hidden] {
    display: none !important;
  }

  .skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 200;
    background: var(--surface);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 0 0 var(--radius) 0;
    box-shadow: var(--shadow-md);
  }

  .skip-link:focus {
    left: 0;
  }

  /* ---------------------------------------------------------------- top bar */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(150%) blur(12px);
    border-bottom: 1px solid var(--line);
  }

  .topbar-inner {
    width: min(var(--max), calc(100% - 32px));
    margin: 0 auto;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    min-width: 0;
  }

  .brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: var(--text);
    color: var(--surface);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.02em;
    flex: none;
  }

  .brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .brand-copy strong {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
  }

  .brand-sub {
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .view-toggle {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 2px;
    gap: 2px;
  }

  .view-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 28px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-3);
  }

  .view-btn svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
  }

  .view-btn[aria-pressed="true"] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
  }

  .privacy-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    border-radius: 999px;
    background: var(--success-soft);
    color: var(--success);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
  }

  .privacy-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
  }

  .icon-button {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-2);
  }

  .icon-button:hover {
    background: var(--surface-2);
    color: var(--text);
  }

  .icon-button.subtle {
    border-color: transparent;
    background: transparent;
    font-size: 20px;
    line-height: 1;
  }

  .icon-button svg {
    width: 17px;
    height: 17px;
  }

  .theme-icon-dark {
    display: none;
  }

  :root[data-theme="dark"] .theme-icon-light {
    display: none;
  }

  :root[data-theme="dark"] .theme-icon-dark {
    display: block;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-icon-light {
      display: none;
    }

    :root:not([data-theme="light"]) .theme-icon-dark {
      display: block;
    }
  }

  @media (max-width: 720px) {
    .privacy-text {
      display: none;
    }

    .privacy-pill {
      padding: 7px;
    }
  }

  /* ---------------------------------------------------------------- shell */
  .workspace {
    width: min(var(--max), calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 32px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
    gap: var(--gutter);
    align-items: start;
  }

  .canvas {
    min-width: 0;
  }

  /* ---------------------------------------------------------------- hero */
  .hero {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 40px;
  }

  .eyebrow {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--accent-text);
    margin-bottom: 12px;
  }

  .hero h1 {
    margin: 0 0 14px;
    font-size: clamp(28px, 3.4vw, 42px);
    line-height: 1.1;
    letter-spacing: -0.02em;
    font-weight: 800;
  }

  .hero p {
    margin: 0 0 28px;
    color: var(--text-2);
    font-size: 16px;
    max-width: 62ch;
  }

  .drop-zone {
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-2);
    padding: 40px 24px;
    text-align: center;
    transition:
      border-color 0.15s ease,
      background 0.15s ease;
  }

  .drop-zone:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .drop-icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    margin: 0 auto 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--accent);
  }

  .drop-icon svg {
    width: 22px;
    height: 22px;
  }

  .drop-zone strong {
    display: block;
    font-size: 17px;
    font-weight: 700;
  }

  .drop-sub {
    color: var(--text-3);
    font-size: 14px;
    margin-top: 4px;
  }

  .drop-zone small {
    display: block;
    margin-top: 14px;
    color: var(--text-3);
    font-size: 12px;
  }

  .file-picker-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
  }

  .browse-btn,
  .folder-btn {
    border-radius: 10px;
    padding: 11px 20px;
    font-weight: 650;
    font-size: 15px;
    border: 1px solid transparent;
  }

  .browse-btn {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
  }

  .browse-btn:hover {
    background: var(--accent-hover);
  }

  .folder-btn {
    background: var(--surface);
    color: var(--text);
    border-color: var(--line-strong);
  }

  .folder-btn:hover {
    background: var(--surface-2);
  }

  @media (max-width: 680px) {
    .hero {
      padding: 26px 20px;
    }

    .drop-zone {
      padding: 28px 16px;
    }

    .file-picker-row {
      flex-direction: column;
    }
  }

  /* ---------------------------------------------------------------- queue toolbar */
  .queue-region {
    display: block;
  }

  .queue-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: calc(var(--topbar-h) + 8px);
    z-index: 30;
  }

  .bulk-select {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    cursor: pointer;
  }

  .bulk-select input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
  }

  .queue-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }

  .toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--line);
    margin: 0 2px;
  }

  .ghost-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-2);
    border-radius: 8px;
    padding: 7px 11px;
    font-size: 13px;
    font-weight: 600;
  }

  .ghost-btn svg {
    width: 13px;
    height: 13px;
  }

  .ghost-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }

  .ghost-btn.accent {
    color: var(--accent-text);
    border-color: var(--line);
  }

  .ghost-btn.accent:hover:not(:disabled) {
    background: var(--accent-soft);
  }

  .ghost-btn.danger:hover:not(:disabled) {
    background: var(--danger-soft);
    color: var(--danger);
  }

  #bulkDownloadBtn {
    display: none;
  }

  .queue-summary {
    margin-top: 14px;
    font-size: 12px;
    color: var(--text-3);
  }

  /* ---------------------------------------------------------------- cards */
  .file-list.is-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
    gap: 16px;
  }

  .file-list.is-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .file-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition:
      border-color 0.15s ease,
      box-shadow 0.15s ease,
      opacity 0.15s ease;
  }

  .file-card:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-md);
  }

  /* Excluded cards read as excluded through the thumbnail and surface, not by fading the whole
     card: dimming the text took it under the contrast minimum, error messages worst of all. */
  .file-card.is-unselected {
    /* The legacy layer fades the whole card; that must stay off or the text fails contrast. */
    opacity: 1;
    background: var(--surface-2);
    border-style: dashed;
  }

  .file-card.is-unselected .card-media,
  .file-card.is-unselected .card-primary {
    opacity: 0.55;
  }

  .file-card.is-unselected .card-badge {
    opacity: 0.8;
  }

  .file-card.is-error {
    border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  }

  .card-media {
    position: relative;
    aspect-ratio: 4 / 3;
    background: var(--surface-2);
    overflow: hidden;
  }

  .card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .card-check {
    position: absolute;
    top: 8px;
    left: 8px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    backdrop-filter: blur(6px);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
  }

  .card-check input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
    margin: 0;
  }

  .card-badge {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 5px 9px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: -0.01em;
    background: var(--success);
    color: var(--on-success);
    box-shadow: var(--shadow-sm);
  }

  .card-badge.is-larger {
    background: var(--warning);
    color: var(--on-warning);
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .card-media .file-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: blur(6px);
  }

  .card-media .file-progress.show {
    display: flex;
  }

  .card-media .file-progress.done {
    display: none;
  }

  .file-progress-track {
    flex: 1;
    height: 4px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
  }

  .file-progress-track span {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.2s ease;
  }

  .file-progress-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-2);
    min-width: 30px;
    text-align: right;
  }

  .card-body {
    padding: 12px 13px 0;
    min-width: 0;
    flex: 1;
  }

  .file-name {
    font-size: 14px;
    font-weight: 650;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .file-meta {
    margin-top: 3px;
    font-size: 12px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .result-meta {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
  }

  .result-meta .arrow {
    color: var(--text-3);
    margin: 0 3px;
  }

  .result-meta strong {
    font-weight: 700;
    color: var(--text);
  }

  .status {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 6px;
    margin-top: 8px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    font-size: 11.5px;
    font-weight: 650;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-3);
  }

  .status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
  }

  .status.waiting {
    color: var(--text-3);
  }

  .status.processing {
    color: var(--accent-text);
  }

  .status.done {
    color: var(--success);
  }

  .status.error {
    color: var(--danger);
  }

  .file-error-message {
    display: none;
    margin-top: 7px;
    padding: 7px 9px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 12px;
    line-height: 1.4;
  }

  .file-error-message.show {
    display: block;
  }

  .card-actions {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 12px 13px;
  }

  .card-primary {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--on-accent);
    border-radius: 9px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-weight: 650;
    white-space: nowrap;
  }

  .card-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
  }

  .card-primary.is-quiet {
    background: var(--surface);
    color: var(--text-2);
    border-color: var(--line-strong);
  }

  .card-primary.is-quiet:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }

  .card-icon-btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: none;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text-2);
    font-size: 16px;
    line-height: 1;
  }

  .card-icon-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }

  /* list view overrides */
  .file-list.is-list .file-card {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 9px 12px;
  }

  .file-list.is-list .card-media {
    width: 76px;
    height: 58px;
    aspect-ratio: auto;
    flex: none;
    border-radius: var(--radius-sm);
  }

  .file-list.is-list .card-badge {
    display: none;
  }

  .file-list.is-list .card-check {
    position: static;
    background: transparent;
    backdrop-filter: none;
    box-shadow: none;
    width: auto;
    height: auto;
  }

  .file-list.is-list .card-body {
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
  }

  .file-list.is-list .card-body > * {
    max-width: 100%;
  }

  .file-list.is-list .status {
    margin-top: 5px;
  }

  .file-list.is-list .card-actions {
    padding: 0;
    flex: none;
  }

  .file-list.is-list .card-primary {
    flex: none;
  }

  .file-list.is-list .card-media .file-progress {
    display: none !important;
  }

  .file-list.is-list .list-progress {
    display: none;
    width: 110px;
    flex: none;
  }

  .file-list.is-list .list-progress.show {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .file-list.is-list .list-progress.done {
    display: none;
  }

  @media (max-width: 560px) {
    .file-list.is-list .file-card {
      flex-wrap: wrap;
    }

    .file-list.is-list .card-body {
      flex: 1 1 140px;
    }
  }

  /* ---------------------------------------------------------------- row menu */
  .card-menu {
    position: fixed;
    z-index: 120;
    min-width: 196px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
  }

  .card-menu button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    font-size: 13.5px;
    font-weight: 550;
  }

  .card-menu button:hover {
    background: var(--surface-2);
  }

  .card-menu button.danger {
    color: var(--danger);
  }

  .card-menu button.danger:hover {
    background: var(--danger-soft);
  }

  .card-menu hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 5px 2px;
  }

  /* ---------------------------------------------------------------- settings */
  .settings-panel {
    position: sticky;
    top: calc(var(--topbar-h) + 24px);
    max-height: calc(100dvh - var(--topbar-h) - 48px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  .settings-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--line);
  }

  .settings-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
  }

  .settings-sub {
    font-size: 12px;
    color: var(--text-3);
  }

  #settingsClose {
    display: none;
  }

  .settings-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
  }

  .settings-tab {
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-2);
    border-radius: 8px;
    padding: 7px 4px;
    font-size: 12.5px;
    font-weight: 650;
  }

  .settings-tab:hover {
    background: var(--surface-2);
    color: var(--text);
  }

  .settings-tab.active {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    color: var(--accent-text);
  }

  .settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px 20px;
    overscroll-behavior: contain;
  }

  .settings-group-intro {
    margin-bottom: 16px;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-size: 12.5px;
    line-height: 1.45;
  }

  .settings-section {
    border: 0;
    padding: 0 0 20px;
    margin: 0;
  }

  .section-title {
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-bottom: 12px;
  }

  .settings-panel label {
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
  }

  .settings-panel select,
  .settings-panel input[type="text"],
  .settings-panel input[type="number"],
  .settings-panel input[type="color"] {
    background: var(--surface);
    border: 1px solid var(--line-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
  }

  .settings-panel select:focus,
  .settings-panel input:focus {
    border-color: var(--accent);
    box-shadow: var(--ring);
    outline: none;
  }

  .settings-panel .notice {
    border-radius: var(--radius-sm);
  }

  .settings-panel .notice.info {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 28%, transparent);
    color: var(--accent-text);
  }

  .settings-panel .notice.warning {
    background: var(--warning-soft);
    border-color: color-mix(in srgb, var(--warning) 35%, transparent);
    color: var(--warning);
  }

  .settings-panel .feature-note,
  .settings-panel .smart-badge {
    border-radius: var(--radius-sm);
  }

  .settings-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(8, 12, 22, 0.5);
    backdrop-filter: blur(2px);
  }

  @media (max-width: 1080px) {
    .workspace {
      grid-template-columns: minmax(0, 1fr);
    }

    .settings-panel {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: auto;
      z-index: 100;
      width: min(400px, 92vw);
      max-height: none;
      border-radius: 0;
      border-width: 0 0 0 1px;
      box-shadow: var(--shadow-lg);
      transform: translateX(101%);
      transition: transform 0.22s ease;
    }

    .settings-panel.is-open {
      transform: none;
    }

    #settingsClose {
      display: grid;
    }

    .settings-tabs {
      grid-template-columns: repeat(3, 1fr);
    }
  }

  @media (min-width: 1081px) {
    .settings-backdrop {
      display: none !important;
    }

    .settings-toggle {
      display: none !important;
    }
  }

  /* ---------------------------------------------------------------- action bar */
  .action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(150%) blur(12px);
    border-top: 1px solid var(--line);
    padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  }

  .action-bar-inner {
    width: min(var(--max), calc(100% - 32px));
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
  }

  .action-summary {
    font-size: 13px;
    color: var(--text-2);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .action-summary strong {
    color: var(--text);
    font-weight: 700;
  }

  .action-bar-buttons {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: none;
  }

  .primary-btn,
  .secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 10px;
    padding: 11px 18px;
    font-size: 14.5px;
    font-weight: 680;
    white-space: nowrap;
    border: 1px solid transparent;
    width: auto;
    margin: 0;
  }

  .primary-btn svg,
  .secondary-btn svg {
    width: 16px;
    height: 16px;
  }

  .primary-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--shadow-sm);
  }

  .primary-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
  }

  .secondary-btn {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--text);
  }

  .secondary-btn:hover:not(:disabled) {
    background: var(--surface-2);
  }

  @media (max-width: 680px) {
    .action-summary {
      display: none;
    }

    .action-bar-inner {
      justify-content: stretch;
    }

    .action-bar-buttons {
      flex: 1;
      min-width: 0;
    }

    .primary-btn {
      flex: 1;
      min-width: 0;
    }

    .secondary-btn {
      padding: 11px 14px;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  /* Several labelled buttons do not fit a phone, so the settings button drops to its icon and
     "Save to folder" gives way to the ZIP button, which does the same job everywhere. */
  @media (max-width: 720px) {
    #saveFolderBtn {
      display: none !important;
    }
  }

  @media (max-width: 560px) {
    .settings-toggle span {
      display: none;
    }

    .settings-toggle {
      padding: 11px 13px;
      flex: none;
    }

    /* Four buttons do not fit one phone-width row, and the one that got pushed off the end was
       Process. The secondary actions share a row and the primary takes its own. */
    .action-bar-buttons {
      flex-wrap: wrap;
      gap: 8px;
    }

    .action-bar-buttons .primary-btn {
      flex: 1 0 100%;
      order: 2;
    }

    .action-bar-buttons .secondary-btn {
      flex: 1 1 auto;
      order: 1;
    }
  }

  .batch-status-detail,
  .batch-status-title {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  /* ---------------------------------------------------------------- batch status */
  .batch-status {
    display: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
  }

  .batch-status.show {
    display: block;
  }

  .batch-status.success {
    border-color: color-mix(in srgb, var(--success) 40%, var(--line));
    background: var(--success-soft);
  }

  .batch-status.warning {
    border-color: color-mix(in srgb, var(--warning) 40%, var(--line));
    background: var(--warning-soft);
  }

  .batch-status-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
  }

  .batch-status-detail {
    font-size: 12.5px;
    color: var(--text-2);
  }

  .batch-status-meta {
    font-size: 12px;
    color: var(--text-3);
  }

  .batch-progress-track {
    height: 4px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
    margin-top: 10px;
  }

  .batch-progress-track span {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.25s ease;
  }

  .batch-status.success .batch-progress-track span {
    background: var(--success);
  }

  .cancel-btn {
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text-2);
    border-radius: 9px;
    padding: 8px 13px;
    font-size: 13px;
    font-weight: 600;
  }

  .cancel-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }

  .processing-bar {
    display: none;
  }

  /* ---------------------------------------------------------------- drag overlay */
  .drag-overlay {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: grid;
    place-items: center;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(4px);
  }

  .drag-overlay-card {
    padding: 44px 60px;
    border-radius: var(--radius-lg);
    border: 2px dashed var(--accent);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    text-align: center;
    font-size: 18px;
    font-weight: 700;
  }

  /* ---------------------------------------------------------------- theme compatibility
   * The legacy layer hardcodes light hex values in about seventy places. These rules restate
   * them with tokens so every one of those components follows the active theme. */

  input[type="number"],
  input[type="text"],
  input[type="color"],
  select,
  textarea {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--text);
  }

  input::placeholder {
    color: var(--text-3);
  }

  label,
  .inline-check,
  .bulk-select {
    color: var(--text-2);
  }

  input[type="checkbox"],
  input[type="radio"],
  input[type="range"] {
    accent-color: var(--accent);
  }

  .notice.info,
  .visual-crop-note {
    background: var(--accent-soft);
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    color: var(--accent-text);
  }

  .notice.warning,
  .warning-inline {
    background: var(--warning-soft);
    border: 1px solid color-mix(in srgb, var(--warning) 38%, transparent);
    color: var(--warning);
  }

  .success-inline,
  .contact-result {
    background: var(--success-soft);
    border: 1px solid color-mix(in srgb, var(--success) 38%, transparent);
    color: var(--success);
  }

  .feature-note,
  .settings-group-intro {
    background: var(--surface-2);
    color: var(--text-3);
  }

  .smart-badge {
    background: var(--success-soft);
    color: var(--success);
  }

  .ai-badge,
  .output-recipe-badge,
  .output-count {
    background: var(--accent-soft);
    color: var(--accent-text);
  }

  .mini-btn,
  .prompt-cancel,
  .remove-variant-btn,
  .custom-variant-row,
  .asset-preview,
  .folder-btn {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--text);
  }

  .mini-btn:hover:not(:disabled),
  .prompt-cancel:hover,
  .remove-variant-btn:hover {
    background: var(--surface-2);
  }

  .mini-btn.danger {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 35%, var(--line-strong));
  }

  .prompt-confirm {
    background: var(--accent);
    color: var(--on-accent);
  }

  .prompt-confirm:hover {
    background: var(--accent-hover);
  }

  .prompt-form input {
    background: var(--surface);
    border-color: var(--line-strong);
    color: var(--text);
  }

  .icon-btn.copy-btn {
    background: var(--success-soft);
    border-color: color-mix(in srgb, var(--success) 35%, transparent);
    color: var(--success);
  }

  .icon-btn.history-btn {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 30%, transparent);
    color: var(--accent-text);
  }

  .batch-spinner {
    border-color: var(--surface-3);
    border-top-color: var(--accent);
  }

  .batch-status.success .batch-spinner {
    background: var(--success-soft);
    color: var(--success);
    border-color: transparent;
  }

  .batch-status.warning .batch-spinner {
    background: var(--warning-soft);
    color: var(--warning);
    border-color: transparent;
  }

  .file-progress.done .file-progress-track span {
    background: var(--success);
  }

  /* previews and the crop stage keep a checkerboard so transparency is obvious */
  .preview-pane,
  .crop-help,
  .watermark-logo-preview img,
  .asset-preview img {
    background: var(--surface);
    color: var(--text);
  }

  .preview-image-wrap,
  .compare-stage {
    background: repeating-conic-gradient(
        var(--surface-3) 0% 25%,
        var(--surface-2) 0% 50%
      )
      50% / 20px 20px;
  }

  .preview-stats,
  .preview-pane h3 {
    color: var(--text-2);
  }

  .compare-divider,
  .compare-divider::after {
    background: var(--surface);
  }

  .compare-label {
    background: color-mix(in srgb, var(--text) 82%, transparent);
    color: var(--bg);
  }

  .crop-stage {
    background:
      linear-gradient(45deg, var(--surface-3) 25%, transparent 25%),
      linear-gradient(-45deg, var(--surface-3) 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, var(--surface-3) 75%),
      linear-gradient(-45deg, transparent 75%, var(--surface-3) 75%)
        var(--surface-2);
    background-size: 22px 22px;
    background-position:
      0 0,
      0 11px,
      11px -11px,
      -11px 0;
  }

  .crop-help {
    border-top: 1px solid var(--line);
    color: var(--text-3);
  }

  .metadata-grid,
  .metadata-value,
  .history-list,
  .output-list {
    color: var(--text-2);
  }

  .thumb {
    background: var(--surface-2);
  }

  /* ---------------------------------------------------------------- modals, toasts, faq */
  .preview-modal {
    background: rgba(8, 12, 22, 0.62);
  }

  .preview-dialog,
  .tool-modal-dialog,
  .crop-dialog {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--text);
  }

  .preview-head {
    border-bottom: 1px solid var(--line);
  }

  .preview-head strong {
    color: var(--text);
  }

  .icon-btn {
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text-2);
    border-radius: 9px;
  }

  .icon-btn:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
  }

  .toast {
    background: var(--text);
    color: var(--bg);
  }

  .toast-warning {
    background: var(--warning);
    color: #fff;
  }

  .toast-danger {
    background: var(--danger);
    color: #fff;
  }

  .toast-success {
    background: var(--success);
    color: #fff;
  }

  .faq {
    width: min(var(--max), calc(100% - 32px));
    margin: 8px auto 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 32px;
  }

  .faq h2 {
    margin: 0 0 6px;
    font-size: 20px;
    letter-spacing: -0.01em;
  }

  .faq-intro {
    color: var(--text-2);
    margin: 0 0 24px;
  }

  .faq-item h3 {
    font-size: 14px;
    margin: 0 0 6px;
  }

  .faq-item p {
    color: var(--text-2);
    font-size: 13.5px;
    margin: 0;
  }

  .footer {
    width: min(var(--max), calc(100% - 32px));
    margin: 24px auto;
    padding: 0 0 12px;
    color: var(--text-3);
    font-size: 12px;
    line-height: 1.6;
    text-align: center;
  }

  .footer strong {
    color: var(--text-2);
  }

  .build-tag {
    margin-left: 8px;
    font-weight: 700;
    color: var(--text-2);
  }

  @media (max-width: 680px) {
    .faq {
      padding: 22px 18px;
    }
  }
}

@layer app {
  .output-spec {
    margin-top: 4px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent-soft);
    border-radius: 6px;
    padding: 3px 7px;
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .item-settings-dialog {
    width: min(560px, calc(100% - 32px));
  }

  .item-settings-note {
    margin: 0 0 18px;
    padding: 10px 12px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.5;
  }

  .item-settings-form .field {
    margin-bottom: 14px;
  }

  .item-settings-form input[type="number"],
  .item-settings-form select {
    width: 100%;
    padding: 9px 11px;
  }

  .item-settings-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
  }

  .item-settings-actions .spacer {
    flex: 1;
  }
}

@layer app {
  .queue-filters {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 1 1 320px;
    min-width: 0;
  }

  .queue-search {
    flex: 1 1 140px;
    min-width: 110px;
    padding: 7px 11px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
  }

  .queue-filters select {
    padding: 7px 9px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    max-width: 148px;
  }

  .queue-none {
    grid-column: 1 / -1;
    padding: 36px 20px;
    text-align: center;
    color: var(--text-3);
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
  }

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

  .shortcuts-dialog {
    width: min(760px, calc(100% - 32px));
  }

  .shortcut-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 24px;
  }

  .shortcut-group h3 {
    margin: 0 0 10px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
  }

  .shortcut-group dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    align-items: baseline;
  }

  .shortcut-group dt {
    display: flex;
    gap: 3px;
    white-space: nowrap;
  }

  .shortcut-group dd {
    margin: 0;
    font-size: 13px;
    color: var(--text-2);
  }

  kbd {
    display: inline-block;
    min-width: 20px;
    padding: 2px 6px;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    text-align: center;
  }

  .shortcut-note {
    margin: 22px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--text-3);
    font-size: 12.5px;
  }

  @media (max-width: 720px) {
    .queue-filters {
      flex: 1 1 100%;
      order: 3;
    }

    .queue-filters select {
      flex: 1;
      max-width: none;
    }
  }
}

@layer app {
  .quality-lab-dialog {
    width: min(880px, calc(100% - 32px));
  }

  .quality-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .quality-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 6px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
  }

  .quality-option:hover:not(:disabled) {
    background: var(--surface-2);
  }

  .quality-option.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
    box-shadow: var(--ring);
  }

  .quality-option-q {
    font-weight: 750;
    font-size: 14px;
  }

  .quality-option-size {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
  }

  .quality-stage {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 300px;
    max-height: 56vh;
    padding: 10px;
    border-radius: var(--radius);
    background: repeating-conic-gradient(
        var(--surface-3) 0% 25%,
        var(--surface-2) 0% 50%
      )
      50% / 20px 20px;
    overflow: hidden;
  }

  .quality-stage img {
    max-width: 100%;
    max-height: 52vh;
    display: block;
    border-radius: var(--radius-sm);
  }

  .quality-busy {
    position: absolute;
    inset: auto 0 0 0;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
  }

  .quality-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 12px;
  }

  .quality-caption {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
  }

  @media (max-width: 560px) {
    .quality-options {
      grid-template-columns: repeat(2, 1fr);
    }
  }
}

@layer app {
  /* ---------------------------------------------------------------- tool nav
   * Shared by every tool page so they read as one product. With four tabs the strip is the
   * widest thing in the bar after the brand, so it scrolls sideways rather than pushing the
   * theme toggle off the edge on a small phone. */
  .tool-nav {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 3px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .tool-nav::-webkit-scrollbar {
    display: none;
  }

  .tool-link {
    padding: 6px 13px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 650;
    color: var(--text-2);
    text-decoration: none;
    white-space: nowrap;
    flex: none;
  }

  .tool-link:hover {
    color: var(--text);
    background: var(--surface);
  }

  .tool-link.is-current {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
  }

  /* The bar now carries a third group, so the brand gives way first and the least essential
     controls drop off before anything can overflow. */
  .brand-copy strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  @media (max-width: 860px) {
    .brand-copy {
      display: none;
    }
  }

  @media (max-width: 600px) {
    #shortcutsBtn {
      display: none;
    }

    .tool-link {
      padding: 6px 10px;
      font-size: 12.5px;
    }
  }

  /* On the narrowest phones the tab strip and the layout toggle are worth more than the
     privacy dot, which the footer and the FAQ both state anyway. */
  @media (max-width: 420px) {
    .privacy-pill {
      display: none;
    }
  }
}

@layer app {
  /* ---- Colour palette ---- */
  .palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 10px;
  }

  .palette-swatch {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    text-align: left;
    width: 100%;
  }

  .palette-swatch:hover {
    border-color: var(--accent);
  }

  .palette-chip {
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    /* A pale colour needs an edge of its own or it disappears into the card. */
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.16);
  }

  .palette-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  .palette-label strong {
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
  }

  .palette-label small {
    font-size: 11.5px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .palette-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
  }
}

@layer app {
  /* Undo and redo sit together in a toolbar, so they read as one control. */
  .undo-slot {
    display: inline-flex;
    gap: 4px;
  }
}

@layer app {
  /* The offer to restore the last session. It sits above the work, not over it. */
  .restore-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    padding: 11px 14px;
    margin-bottom: 14px;
    border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
    background: var(--accent-soft);
    border-radius: var(--radius);
  }

  .restore-text {
    flex: 1;
    min-width: 200px;
    font-size: 13.5px;
    color: var(--text-2);
  }

  .restore-text strong {
    color: var(--text);
  }

  .restore-actions {
    display: flex;
    gap: 8px;
    flex: none;
  }
}

@layer app {
  /* A note that is a caution rather than an explanation. */
  .feature-note.warn {
    color: var(--warning, #b45309);
    border-left: 3px solid var(--warning, #b45309);
    padding-left: 9px;
  }
}

@layer app {
  /* ---- The strip shown while recording ---- */
  .record-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    padding: 10px 14px;
    margin-bottom: 14px;
    border-radius: var(--radius);
    border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
    background: var(--danger-soft);
  }

  .record-bar strong {
    font-size: 13.5px;
  }

  .record-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--danger);
    flex: none;
    animation: record-pulse 1.4s ease-in-out infinite;
  }

  .record-bar.is-paused .record-dot {
    animation: none;
    opacity: 0.4;
  }

  @keyframes record-pulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.25;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .record-dot {
      animation: none;
    }
  }

  .record-time {
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    flex: none;
  }

  .record-preview {
    width: 140px;
    height: 79px;
    border-radius: 8px;
    background: #05070d;
    object-fit: contain;
    flex: none;
  }

  .record-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-wrap: wrap;
  }

  /* The buttons that begin a recording, in the drop zone and the toolbars. */
  .record-start-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
  }

  @media (max-width: 560px) {
    .record-preview {
      display: none;
    }

    .record-actions {
      margin-left: 0;
      width: 100%;
    }
  }
}

@layer app {
  /* The button inside a toast, for an offer the reader can take or ignore. */
  .toast-action {
    flex: none;
    margin-left: 4px;
    padding: 4px 10px;
    border-radius: 7px;
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
  }

  .toast-action:hover {
    background: rgb(255 255 255 / 0.12);
  }
}

@layer app {
  /* The sound of the selected clip, under the preview, so a cut can be aimed by eye. */
  .clip-wave-strip {
    position: relative;
    height: 54px;
    margin-top: 10px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    overflow: hidden;
  }

  .clip-wave-strip canvas {
    display: block;
    width: 100%;
    height: 100%;
  }

  .clip-wave-note {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 12px;
    color: var(--text-3);
    background: var(--surface-2);
  }

  .clip-wave-note[hidden] {
    display: none;
  }
}

@layer app {
  /* A checkerboard behind every card thumbnail. An opaque picture covers it completely, so it
   * costs nothing there; a cut-out shows it through, which is the only way "transparent" reads
   * as transparent rather than as whatever colour the page happens to be. */
  .card-media {
    background-color: #ffffff;
    background-image:
      linear-gradient(45deg, #d7dbe2 25%, transparent 25%, transparent 75%, #d7dbe2 75%),
      linear-gradient(45deg, #d7dbe2 25%, transparent 25%, transparent 75%, #d7dbe2 75%);
    background-size: 16px 16px;
    background-position: 0 0, 8px 8px;
  }

  .card-media.shows-result::after {
    content: "result";
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: color-mix(in srgb, var(--text) 74%, transparent);
    color: var(--bg);
    pointer-events: none;
  }
}

@layer app {
  /* ---- Markup editor ---- */
  .markup-toolbar {
    flex-wrap: wrap;
    gap: 10px 14px;
    align-items: center;
  }

  .markup-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .markup-tool.is-on {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
  }

  .markup-options {
    display: flex;
    gap: 14px;
    align-items: center;
  }

  .markup-colour,
  .markup-strength {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-3);
  }

  .markup-colour input[type="color"] {
    width: 34px;
    height: 26px;
    padding: 2px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--surface);
  }

  .markup-strength input[type="range"] {
    width: 96px;
    accent-color: var(--accent);
  }

  .markup-straighten {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px 10px;
    flex-wrap: wrap;
  }

  .markup-straighten label {
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-3);
  }

  .markup-straighten input[type="range"] {
    flex: 1;
    min-width: 140px;
    accent-color: var(--accent);
  }

  .markup-stage {
    position: relative;
    display: grid;
    place-items: center;
    padding: 12px;
    background: var(--surface-2);
    max-height: 62vh;
    overflow: auto;
  }

  .markup-stage canvas {
    max-width: 100%;
    max-height: 58vh;
    display: block;
    cursor: crosshair;
    touch-action: none;
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    background: #fff;
  }

  .markup-hint {
    font-size: 12px;
    color: var(--text-3);
  }

  .markup-foot {
    padding: 10px 14px 14px;
  }
}

@layer app {
  /* ---------------------------------------------------------------- Edit view
     One dialog, four modes. The mode strip is the whole point of it: crop, marking
     up, the angle and colour were in four different places before, and three of them
     were behind a three dot menu that nobody opened. */

  .edit-dialog {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .edit-modes {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .edit-mode {
    position: relative;
    min-height: 36px;
    padding: 7px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
  }

  .edit-mode:hover {
    color: var(--text);
    border-color: var(--line-strong);
  }

  /* The same treatment the settings tabs get. Copying the light theme's accent here left dark
     blue text on a dark blue chip, at 2.6:1. */
  .edit-mode.is-on {
    color: var(--accent-text);
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  }

  /* A mode holding something says so on its own tab, so a crop does not go unnoticed
     because the editor happened to open on a different mode. */
  .edit-mode-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 7px;
    border-radius: 50%;
    background: var(--ok, #16a34a);
    vertical-align: middle;
  }

  .edit-panel {
    padding: 0;
  }

  .edit-panel[hidden] {
    display: none;
  }

  .edit-colour-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
    padding: 12px 14px 4px;
  }

  .edit-panel[data-edit-panel="colour"] .crop-actions,
  .edit-panel[data-edit-panel="colour"] .markup-hint {
    padding: 0 14px 10px;
  }

  .edit-panel[data-edit-panel="angle"] .markup-hint {
    padding: 0 14px 10px;
  }

  /* The mode strip costs height the crop editor used to have to itself, so both stages are
     bounded the same way and switching modes does not make the dialog jump. */
  .edit-dialog .crop-stage {
    min-height: 0;
    max-height: 62vh;
  }

  .edit-dialog .crop-stage img {
    max-height: calc(62vh - 26px);
  }

  .edit-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 10px 14px 14px;
    border-top: 1px solid var(--line);
  }

  .edit-foot .markup-foot {
    margin: 0;
    flex: 1 1 260px;
  }

  .edit-foot .crop-actions {
    flex: 0 0 auto;
  }

  @media (max-width: 680px) {
    .edit-colour-grid {
      grid-template-columns: 1fr;
    }

    .edit-modes {
      padding: 8px 10px;
    }

    .edit-mode {
      flex: 1 1 calc(50% - 3px);
      padding: 7px 8px;
      text-align: center;
    }
  }
}

@layer app {
  /* The hero used to describe a compressor, which is why nobody found the rest of it. */
  .hero-also {
    margin-top: 10px;
    max-width: 62ch;
    color: var(--muted);
    font-size: 14.5px;
    line-height: 1.6;
  }

  .hero-also strong {
    color: var(--text);
    font-weight: 650;
  }
}

@layer app {
  /* ------------------------------------------------- name tokens and preview */
  .section-subtitle {
    margin: 14px 0 6px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .token-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0 10px;
  }

  .token-row .mini-btn {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    padding: 5px 9px;
  }

  /* The point of the preview is to be read before the files exist, so it must not be the
     faintest thing in the panel. */
  .name-preview {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: var(--text);
    word-break: break-all;
  }

  .feature-note code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--surface-3, rgba(127, 127, 127, 0.15));
  }
}

@layer app {
  /* ------------------------------------------------------ duplicate groups */
  .dupe-groups {
    display: grid;
    gap: 16px;
  }

  .dupe-group {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface-2);
  }

  .dupe-group-title {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
  }

  .dupe-row {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .dupe-cell {
    flex: 0 0 150px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    background: var(--surface);
  }

  /* The one being kept is the only thing in the dialog a person has to find quickly. */
  .dupe-cell.is-keeper {
    border-color: var(--ok, #16a34a);
    box-shadow: 0 0 0 1px var(--ok, #16a34a) inset;
  }

  .dupe-cell img {
    display: block;
    width: 100%;
    height: 104px;
    object-fit: contain;
    border-radius: 6px;
    background: var(--surface-3, rgba(127, 127, 127, 0.12));
  }

  .dupe-cell figcaption {
    margin-top: 7px;
    font-size: 11.5px;
    line-height: 1.45;
    color: var(--muted);
    word-break: break-word;
  }

  .dupe-cell figcaption strong {
    color: var(--text);
    font-weight: 650;
  }

  .dupe-tag {
    color: var(--ok-text, #166534);
    font-weight: 700;
  }
}

@layer app {
  /* ------------------------------------------------------- installing it */
  .install-panel {
    max-width: 1180px;
    margin: 26px auto 0;
    padding: 20px 22px;
    display: flex;
    gap: 22px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
  }

  /* Nothing to offer and nothing to explain yet: do not take up the room. */
  .install-panel[data-install-state="unknown"] .install-actions {
    display: none;
  }

  .install-panel[data-install-state="installed"] {
    border-color: color-mix(in srgb, var(--ok, #16a34a) 45%, var(--line));
  }

  .install-copy {
    flex: 1 1 420px;
    min-width: 0;
  }

  .install-copy h2 {
    margin: 0 0 8px;
    font-size: 18px;
  }

  .install-copy p {
    margin: 0 0 8px;
    color: var(--muted);
    line-height: 1.6;
    max-width: 68ch;
  }

  .install-hint {
    font-weight: 600;
  }

  .install-actions .primary-btn {
    width: auto;
    min-height: 44px;
    padding: 11px 22px;
  }

  @media (max-width: 680px) {
    .install-panel {
      margin: 18px 16px 0;
      padding: 16px;
    }

    .install-actions {
      width: 100%;
    }

    .install-actions .primary-btn {
      width: 100%;
    }
  }
}

@layer app {
  /* The install link sits in the same strip as the tools but is not one, so a hairline keeps
     it slightly apart rather than reading as a seventh thing to edit pictures with. */
  .tool-link-aside {
    margin-left: 6px;
    padding-left: 14px;
    position: relative;
  }

  .tool-link-aside::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 16px;
    background: var(--line-strong);
  }
}
