/* Google Material Design 3 (GM3) Design System for TVBS 批次浮水印助手
 * Seed #0B57D0 (Google Blue) · Cool Charcoal Slate Dark Theme · Strict CSP External Stylesheet
 * WCAG 2.2 AA contrast, Forced Colors fallback, reduced-motion & native dialog/popover best practices.
 */

:root {
  color-scheme: light dark;

  /* M3 Light Baseline Tokens (Seed #0B57D0) */
  --md-sys-color-primary: #0b57d0;
  --md-sys-color-primary-hover: #0842a0;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #d3e3fd;
  --md-sys-color-on-primary-container: #041e49;
  --md-sys-color-secondary-container: #c2e7ff;
  --md-sys-color-on-secondary-container: #001d35;
  --md-sys-color-surface: #f8fafd;
  --md-sys-color-surface-canvas: #e9eef6;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f0f4f9;
  --md-sys-color-surface-container: #e9eef6;
  --md-sys-color-surface-container-high: #dde3ea;
  --md-sys-color-on-surface: #1f1f1f;
  --md-sys-color-on-surface-variant: #444746;
  --md-sys-color-outline: #747775;
  --md-sys-color-outline-variant: #c4c7c5;
  --md-sys-color-error: #b3261e;
  --md-sys-color-error-container: #fce8e6;
  --md-sys-color-on-error-container: #8c1d18;
  --md-sys-color-success: #146c2e;
  --md-sys-color-success-container: #e6f4ea;
  --md-sys-color-on-success-container: #0d5223;
  --md-sys-color-warning-container: #fef7e0;
  --md-sys-color-on-warning-container: #7a4f01;
  --md-sys-elevation-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --md-sys-elevation-2: 0 4px 14px rgba(15, 23, 42, .09), 0 1px 3px rgba(15, 23, 42, .06);
  --md-sys-elevation-3: 0 12px 32px rgba(15, 23, 42, .16), 0 2px 6px rgba(15, 23, 42, .08);

  /* M3 Official 6-Tier Shape Scale */
  --md-sys-shape-xs: 4px;
  --md-sys-shape-sm: 8px;
  --md-sys-shape-md: 12px;
  --md-sys-shape-lg: 16px;
  --md-sys-shape-xl: 20px;
  --md-sys-shape-full: 9999px;

  /* M3 Typography Scale (rem root-relative, >= 0.75rem floor) */
  --md-sys-typescale-title-lg: 1.25rem;
  --md-sys-typescale-title-md: 1.0625rem;
  --md-sys-typescale-title-sm: 0.875rem;
  --md-sys-typescale-body-md: 0.875rem;
  --md-sys-typescale-label-lg: 0.875rem;
  --md-sys-typescale-label-md: 0.8125rem;
  --md-sys-typescale-body-sm: 0.75rem;

  accent-color: var(--md-sys-color-primary);
}

/* Reflect explicit <meta name="color-scheme"> override in CSS (dark-mode-toggle contract) */
:root:has(> head > meta[name="color-scheme"][content="light"]) {
  color-scheme: light;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) {
  color-scheme: dark;
  --md-sys-color-primary: #a8c7fa;
  --md-sys-color-primary-hover: #c2d9ff;
  --md-sys-color-on-primary: #062e6f;
  --md-sys-color-primary-container: #1b3d75;
  --md-sys-color-on-primary-container: #d7e6ff;
  --md-sys-color-secondary-container: #154b6e;
  --md-sys-color-on-secondary-container: #cdeaff;
  --md-sys-color-surface: #181b20;
  --md-sys-color-surface-canvas: #14171c;
  --md-sys-color-surface-container-lowest: #22262e;
  --md-sys-color-surface-container-low: #272c35;
  --md-sys-color-surface-container: #2e343f;
  --md-sys-color-surface-container-high: #373e4b;
  --md-sys-color-on-surface: #e3e6eb;
  --md-sys-color-on-surface-variant: #b8bec9;
  --md-sys-color-outline: #8b929e;
  --md-sys-color-outline-variant: #3b4250;
  --md-sys-color-error: #f2b8b5;
  --md-sys-color-error-container: #601410;
  --md-sys-color-on-error-container: #f9dedc;
  --md-sys-color-success: #81c995;
  --md-sys-color-success-container: #164428;
  --md-sys-color-on-success-container: #c4eed0;
  --md-sys-color-warning-container: #4a3500;
  --md-sys-color-on-warning-container: #fde293;
  --md-sys-elevation-1: 0 1px 2px rgba(0, 0, 0, .28), 0 1px 3px rgba(0, 0, 0, .22);
  --md-sys-elevation-2: 0 4px 16px rgba(0, 0, 0, .34);
  --md-sys-elevation-3: 0 14px 36px rgba(0, 0, 0, .48);
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) {
    color-scheme: dark;
    --md-sys-color-primary: #a8c7fa;
    --md-sys-color-primary-hover: #c2d9ff;
    --md-sys-color-on-primary: #062e6f;
    --md-sys-color-primary-container: #1b3d75;
    --md-sys-color-on-primary-container: #d7e6ff;
    --md-sys-color-secondary-container: #154b6e;
    --md-sys-color-on-secondary-container: #cdeaff;
    --md-sys-color-surface: #181b20;
    --md-sys-color-surface-canvas: #14171c;
    --md-sys-color-surface-container-lowest: #22262e;
    --md-sys-color-surface-container-low: #272c35;
    --md-sys-color-surface-container: #2e343f;
    --md-sys-color-surface-container-high: #373e4b;
    --md-sys-color-on-surface: #e3e6eb;
    --md-sys-color-on-surface-variant: #b8bec9;
    --md-sys-color-outline: #8b929e;
    --md-sys-color-outline-variant: #3b4250;
    --md-sys-color-error: #f2b8b5;
    --md-sys-color-error-container: #601410;
    --md-sys-color-on-error-container: #f9dedc;
    --md-sys-color-success: #81c995;
    --md-sys-color-success-container: #164428;
    --md-sys-color-on-success-container: #c4eed0;
    --md-sys-color-warning-container: #4a3500;
    --md-sys-color-on-warning-container: #fde293;
    --md-sys-elevation-1: 0 1px 2px rgba(0, 0, 0, .28), 0 1px 3px rgba(0, 0, 0, .22);
    --md-sys-elevation-2: 0 4px 16px rgba(0, 0, 0, .34);
    --md-sys-elevation-3: 0 14px 36px rgba(0, 0, 0, .48);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--md-sys-color-surface-canvas);
  color: var(--md-sys-color-on-surface);
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  font-size: var(--md-sys-typescale-body-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Unified M3 Top Bar (<= 60px, No Foreground Version) ── */
.gm3-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  min-height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.gm3-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.gm3-brand-logo {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--md-sys-shape-sm);
  object-fit: contain;
  background: #ffffff;
  padding: 2px;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.gm3-brand-copy {
  min-width: 0;
}

.gm3-brand-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gm3-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--md-sys-shape-full);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 600;
  white-space: nowrap;
}

.gm3-mode-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
}

.gm3-mode-pill[data-mode="watch"] {
  background: var(--md-sys-color-success-container);
  color: var(--md-sys-color-on-success-container);
}

.gm3-mode-pill[data-mode="watch"]::before {
  background: var(--md-sys-color-success);
}

.gm3-topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* 9-Dot App Switcher Trigger */
.gm3-menu-btn {
  min-inline-size: 40px;
  min-block-size: 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--md-sys-shape-full);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}

.gm3-menu-btn:hover {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-color: var(--md-sys-color-outline);
}

.gm3-menu-btn[aria-expanded="true"] {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

/* Native Popover App Switcher (viewport-aware-dropdowns compliant) */
.gm3-menu-popover {
  width: min(328px, calc(100vw - 24px));
  padding: 12px;
  border-radius: var(--md-sys-shape-xl);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-3);
}

@supports (position-area: block-end) {
  .gm3-menu-popover {
    inset: auto;
    margin: 0;
    margin-block-start: 8px;
    position-area: block-end span-inline-start;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  }
}

@supports not (position-area: block-end) {
  .gm3-menu-popover {
    position: fixed;
    top: 66px;
    right: 16px;
    left: auto;
    bottom: auto;
    margin: 0;
  }
}

@supports not selector(:popover-open) {
  .gm3-menu-popover:not(.\:popover-open) {
    display: none;
  }
}

.gm3-menu-popover:is(:popover-open, .\:popover-open) {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gm3-menu-section-title {
  padding: 2px 8px;
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
  letter-spacing: .04em;
}

.gm3-menu-apps {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gm3-app-tile,
.gm3-menu-item {
  width: 100%;
  min-block-size: 46px;
  padding: 8px 10px;
  border-radius: var(--md-sys-shape-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background .14s, border-color .14s;
}

.gm3-app-tile:hover,
.gm3-menu-item:hover {
  background: var(--md-sys-color-surface-container-low);
}

.gm3-app-tile[aria-current="page"] {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.gm3-menu-ico {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--md-sys-shape-sm);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.gm3-menu-ico:has(> img) {
  background: transparent;
  border: 0;
}

.gm3-menu-ico img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--md-sys-shape-sm);
  display: block;
}

.gm3-app-tile[aria-current="page"] .gm3-menu-ico {
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-primary);
}

.gm3-menu-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1 1 auto;
}

.gm3-menu-text strong {
  font-size: var(--md-sys-typescale-title-sm);
  font-weight: 700;
  line-height: 1.3;
  color: inherit;
}

.gm3-menu-text small {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gm3-app-tile[aria-current="page"] .gm3-menu-text small {
  color: var(--md-sys-color-on-primary-container);
  opacity: .86;
}

.gm3-current-badge {
  flex: none;
  padding: 2px 8px;
  border-radius: var(--md-sys-shape-full);
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 700;
}

.gm3-menu-divider {
  height: 1px;
  background: var(--md-sys-color-outline-variant);
  margin: 2px 0;
}

.gm3-menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 0;
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
}

.gm3-menu-footer kbd {
  padding: 2px 7px;
  border-radius: var(--md-sys-shape-xs);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
  font-family: inherit;
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 600;
}

/* Two-state Dark Mode icon branching via meta + prefers-color-scheme */
.gm3-theme-icon-light { display: none; }
.gm3-theme-icon-dark { display: block; }

:root:has(> head > meta[name="color-scheme"][content="dark"]) .gm3-theme-icon-light { display: block; }
:root:has(> head > meta[name="color-scheme"][content="dark"]) .gm3-theme-icon-dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .gm3-theme-icon-light { display: block; }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .gm3-theme-icon-dark { display: none; }
}

/* ── Main Layout ── */
.gm3-main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 22px 20px 44px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gm3-card {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-xl);
  padding: 22px 24px;
  box-shadow: var(--md-sys-elevation-1);
}

h2 {
  margin: 0;
  font-size: var(--md-sys-typescale-title-md);
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

h3 {
  margin: 0 0 8px;
  font-size: var(--md-sys-typescale-title-sm);
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

p {
  margin: 0;
}

.hint {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.55;
}

/* ── M3 Button Hierarchy (Single Primary CTA, Tonal, Outlined) ── */
button {
  font: inherit;
  font-size: var(--md-sys-typescale-label-lg);
  font-weight: 600;
  min-block-size: 40px;
  padding: 0 18px;
  border-radius: var(--md-sys-shape-full);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}

button:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-low);
  border-color: var(--md-sys-color-outline);
}

button:disabled {
  opacity: .42;
  cursor: not-allowed;
}

button.primary {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: transparent;
}

button.primary:hover:not(:disabled) {
  background: var(--md-sys-color-primary-hover);
  box-shadow: var(--md-sys-elevation-1);
}

button.gm3-btn-tonal,
button.tonal {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: transparent;
}

button.gm3-btn-tonal:hover:not(:disabled),
button.tonal:hover:not(:disabled) {
  filter: brightness(.96);
}

button.gm3-btn-outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-outline-variant);
}

button.gm3-btn-outlined:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-low);
  border-color: var(--md-sys-color-primary);
}

button.gm3-btn-danger {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border-color: transparent;
}

button.gm3-btn-compact {
  min-block-size: 36px;
  padding: 0 14px;
  font-size: var(--md-sys-typescale-label-md);
}

button:focus-visible,
input:focus-visible,
canvas:focus-visible,
summary:focus-visible,
#dropZone:focus-visible,
a:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ── Work Area Header & Toolbar ── */
.work-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px 20px;
  flex-wrap: wrap;
}

.work-title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.processing-summary {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Interactive Hero Drop Zone ── */
#dropZone {
  margin: 18px 0 14px;
  padding: 26px 20px;
  border-radius: var(--md-sys-shape-lg);
  border: 2px dashed var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  cursor: pointer;
  transition: background .16s, border-color .16s, padding .18s;
}

#dropZone:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container);
}

#dropZone.over {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

#dropZone.compact {
  flex-direction: row;
  justify-content: flex-start;
  text-align: left;
  padding: 13px 18px;
  gap: 12px;
}

.dropzone-ico {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: var(--md-sys-shape-full);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#dropZone.compact .dropzone-ico {
  width: 36px;
  height: 36px;
}

.dropzone-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.dropzone-copy strong {
  font-size: var(--md-sys-typescale-title-sm);
  font-weight: 700;
}

.dropzone-copy span {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
}

#dropZone.over .dropzone-copy span {
  color: var(--md-sys-color-on-primary-container);
}

/* ── Status Strip (Non-Color-Only Semantic Indicator) ── */
#status {
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-md);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-body-md);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#status::before {
  content: "ℹ ";
  font-weight: 700;
  color: var(--md-sys-color-primary);
}

#status.error {
  background: var(--md-sys-color-error-container);
  border-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error-container);
}

#status.error::before {
  content: "⚠ ";
  color: var(--md-sys-color-on-error-container);
}

/* ── Results Header & Grid ── */
.results-heading {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.selection-actions {
  gap: 6px;
}

#selectedCount {
  margin-left: 4px;
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.empty-state {
  margin-top: 14px;
  padding: 28px 18px;
  border-radius: var(--md-sys-shape-lg);
  border: 1px dashed var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  font-size: var(--md-sys-typescale-body-md);
}

#grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(252px, 1fr));
  gap: 16px;
}

.card {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .15s, box-shadow .15s;
}

.card:hover {
  border-color: var(--md-sys-color-outline);
  box-shadow: var(--md-sys-elevation-1);
}

.card-media {
  position: relative;
  width: 100%;
  height: 172px;
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  overflow: hidden;
}

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

.card-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.filename {
  font-weight: 700;
  font-size: var(--md-sys-typescale-title-sm);
  color: var(--md-sys-color-on-surface);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.card-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  cursor: pointer;
  flex: none;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--md-sys-shape-full);
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 700;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
}

.badge.pending::before { content: "○"; }
.badge.processing { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.badge.processing::before { content: "⟳"; }
.badge.success { background: var(--md-sys-color-success-container); color: var(--md-sys-color-on-success-container); }
.badge.success::before { content: "✓"; }
.badge.error { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.badge.error::before { content: "✕"; }

.card-size {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.card-error {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-error-container);
  background: var(--md-sys-color-error-container);
  padding: 6px 10px;
  border-radius: var(--md-sys-shape-sm);
  overflow-wrap: anywhere;
}

.card-actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-actions button {
  min-block-size: 34px;
  padding: 0 12px;
  font-size: var(--md-sys-typescale-body-sm);
  flex: 1 1 auto;
}

/* ── Watermark Default Summary & Disclosure ── */
.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
}

.preset-summary-text {
  margin-top: 4px;
  font-size: var(--md-sys-typescale-body-md);
  color: var(--md-sys-color-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.gm3-disclosure {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.gm3-disclosure > summary {
  cursor: pointer;
  font-size: var(--md-sys-typescale-label-md);
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  width: fit-content;
}

.preset-summary {
  margin: 12px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.gm3-checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--md-sys-typescale-body-md);
}

/* ── Collapsible Optional Folder Watch Panel ── */
.gm3-folder-watch {
  padding: 0;
  overflow: hidden;
}

.folder-watch-summary {
  list-style: none;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  cursor: pointer;
}

.folder-watch-summary::-webkit-details-marker {
  display: none;
}

.folder-watch-summary:hover {
  background: var(--md-sys-color-surface-container-low);
}

.folder-watch-title {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.folder-watch-title h2 {
  font-size: var(--md-sys-typescale-title-sm);
}

.watch-badge {
  padding: 4px 12px;
  border-radius: var(--md-sys-shape-full);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 600;
}

.folder-watch-body {
  padding: 0 24px 22px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gm3-info-banner {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--md-sys-shape-md);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-size: var(--md-sys-typescale-body-md);
}

#setupProgress {
  margin-top: 14px;
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 600;
}

.folders {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.folder-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: start;
  padding: 16px;
  border-radius: var(--md-sys-shape-lg);
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.step {
  width: 28px;
  height: 28px;
  border-radius: var(--md-sys-shape-full);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--md-sys-typescale-label-md);
  font-weight: 800;
}

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

.folder-info h3 {
  margin: 0 0 4px;
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-on-surface-variant);
}

.folder-info strong {
  display: block;
  font-size: var(--md-sys-typescale-title-sm);
  overflow-wrap: anywhere;
  margin-bottom: 4px;
}

.output-creation-options {
  grid-column: 2 / -1;
  min-width: 0;
  padding-top: 10px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.output-creation-options summary {
  cursor: pointer;
  font-size: var(--md-sys-typescale-body-sm);
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
}

.output-creation-options p {
  margin: 6px 0 8px;
}

.output-creation-options button {
  white-space: normal;
  text-align: left;
  height: auto;
  padding: 8px 14px;
}

.desktop-suggestion {
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-md);
  border-left: 3px solid var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container-low);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--md-sys-typescale-body-sm);
}

.desktop-suggestion details {
  margin-top: 4px;
}

.desktop-suggestion summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--md-sys-color-primary);
}

.folder-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-metric {
  margin: 10px 0 14px;
  font-size: var(--md-sys-typescale-body-md);
}

#settings .hint {
  margin-top: 12px;
}

/* ── Native Modal Dialogs (dialog guide compliant) ── */
dialog {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 24px;
  padding: 24px;
  max-width: calc(100vw - 28px);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-3);
}

/* Mandatory scroll containment on modal dialog & backdrop */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(12, 18, 28, .56);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}

#editorDialog {
  width: min(1240px, calc(100vw - 28px));
  max-height: 92dvh;
  overflow: auto;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.dialog-heading h1,
#confirmDialog h1 {
  margin: 0;
  font-size: var(--md-sys-typescale-title-lg);
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
  min-width: 0;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 22px;
  align-items: start;
}

.preview-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-lg);
  padding: 16px;
  min-height: 360px;
}

canvas {
  max-width: 100%;
  max-height: 64dvh;
  object-fit: contain;
  border-radius: var(--md-sys-shape-sm);
  background: repeating-conic-gradient(#d8dee6 0% 25%, #ffffff 0% 50%) 50% / 16px 16px;
  touch-action: none;
  display: block;
}

#preview[hidden],
#demoCanvas[hidden] {
  display: none !important;
}

.editor-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.corners {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.corners button {
  min-block-size: 38px;
  border-radius: var(--md-sys-shape-md);
}

.corners button.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.editor-sidebar > label {
  display: block;
  font-size: var(--md-sys-typescale-label-md);
  font-weight: 600;
}

.editor-sidebar output {
  float: right;
  color: var(--md-sys-color-primary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.editor-sidebar input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 8px;
}

.editor-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-actions > button {
  width: 100%;
}

.navigation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#editorMessage {
  font-size: var(--md-sys-typescale-body-sm);
  color: var(--md-sys-color-primary);
  font-weight: 600;
  min-height: 1.4em;
}

#confirmDialog {
  width: min(460px, calc(100vw - 28px));
}

#confirmText {
  margin: 12px 0 20px;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Responsive Mobile & Tablet ── */
@media (max-width: 960px) {
  .folders {
    grid-template-columns: 1fr;
  }
  .editor-layout {
    grid-template-columns: 1fr;
  }
  .preview-area {
    min-height: 220px;
  }
  canvas {
    max-height: 44dvh;
  }
}

@media (max-width: 640px) {
  .gm3-topbar {
    padding: 8px 12px;
    min-height: 56px;
  }
  .gm3-mode-pill {
    display: none;
  }
  .gm3-main {
    padding: 14px 12px 32px;
  }
  .gm3-card {
    padding: 16px;
    border-radius: var(--md-sys-shape-lg);
  }
  .folder-watch-summary {
    padding: 14px 16px;
  }
  .folder-watch-body {
    padding: 0 16px 16px;
  }
  .folder-card {
    grid-template-columns: 28px minmax(0, 1fr);
  }
  .folder-card > button {
    grid-column: 2;
    justify-self: start;
  }
  .main-actions {
    width: 100%;
  }
  .main-actions > button {
    min-block-size: 44px;
    flex: 1 1 auto;
  }
  .gm3-menu-btn {
    min-inline-size: 44px;
    min-block-size: 44px;
    width: 44px;
    height: 44px;
  }
  #grid {
    grid-template-columns: 1fr;
  }
  dialog {
    padding: 18px;
    border-radius: var(--md-sys-shape-xl);
  }
}

/* ── Reduced Motion & Forced Colors Accessibility ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}

@media (forced-colors: active) {
  .gm3-card,
  .card,
  .folder-card,
  .gm3-menu-popover,
  dialog,
  #status,
  #dropZone,
  button,
  .badge {
    border: 1px solid CanvasText;
    box-shadow: none;
  }
  button.primary,
  .gm3-current-badge,
  .gm3-app-tile[aria-current="page"] {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }
  button:disabled {
    border-color: GrayText;
    color: GrayText;
  }
}
