@layer reset, tokens, base, layout, components, modes, utilities, overrides;

/* ─────────────────────────────────────────────────────────────
   TOKENS — map brand → Material Design 3 system tokens
   ──────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Brand palette */
    --tarheel: #62C6F2;
    --tarheel-dark: #1f6d8f;
    --tarheel-light: #bbe0f0;
    --tarheel-grey: #7f8a8f;
    --tarheel-white: #edf6fa;
    --tarheel-electric: #00b1ff;
    --accent-yellow: #f2d662;
    --accent-strawberry: #f2627e;

    /* Role colors (app-level) */
    --surface: #ffffff;
    --on-surface: #0d2530;
    --border: color-mix(in oklab, var(--tarheel-light) 70%, #000 0%);
    --muted: color-mix(in oklab, var(--tarheel-grey) 70%, #000 0%);
    --success: #1a8f52;
    --success-bg: #1db954;

    /* MD3: typeface & state layers */
    --font-sans: 'Atkinson Hyperlegible', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --focus: var(--border-2) solid var(--tarheel-electric);

    /* Shape (square by default per repo policy) */
    /* IMPORTANT: keep corners square unless a component explicitly overrides it */
    --border-radius: 0 !important;

    /* Shadows / gradients */
    --card-shadow: 0 0.5rem 1.5rem rgba(0, 113, 170, .12);
    --drop-grad-top: #ffffff;
    --drop-grad-bot: var(--tarheel-white);

    /* Spacing */
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-7: 1.75rem;
    --space-8: 2rem;

    /* Layout */
    --container-max-width: 62.5rem;

    /* Unit tokens */
    --border-1: 0.0625rem;
    --border-2: 0.125rem;

    /* Logo text stroke thickness (≈2px at 16px root) */
    --logo-stroke: 0.125rem;

    /* Mode tokens */
    --mode: vertical;
    --columns-stats: 1;

    /* Overlay */
    --overlay-z: 1000;
    --overlay-backdrop: rgba(255, 255, 255, .96);

    /* ── Material Design 3 system tokens (light) ── */
    --md-ref-typeface-plain: var(--font-sans);

    --md-sys-color-primary:        var(--tarheel-dark);
    --md-sys-color-on-primary:     #ffffff;
    --md-sys-color-primary-container: color-mix(in oklab, var(--tarheel) 85%, #ffffff 15%);
    --md-sys-color-on-primary-container: #06202a;

    --md-sys-color-secondary:      color-mix(in oklab, var(--tarheel-grey) 70%, #000 0%);
    --md-sys-color-on-secondary:   #ffffff;
    --md-sys-color-secondary-container: color-mix(in oklab, var(--tarheel-grey) 15%, #ffffff 85%);
    --md-sys-color-on-secondary-container: #0d2530;

    --md-sys-color-surface:        var(--surface);
    --md-sys-color-on-surface:     var(--on-surface);
    --md-sys-color-surface-variant: color-mix(in oklab, var(--tarheel-light) 45%, #ffffff 55%);
    --md-sys-color-on-surface-variant: color-mix(in oklab, var(--tarheel-grey) 80%, #000 0%);

    --md-sys-color-outline:        color-mix(in oklab, var(--tarheel-light) 60%, #000 0%);
    --md-sys-color-outline-variant: color-mix(in oklab, var(--tarheel-light) 75%, #000 0%);

    --md-sys-state-hover-state-layer-opacity: .08;
    --md-sys-state-focus-state-layer-opacity: .12;
    --md-sys-state-pressed-state-layer-opacity: .10;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --surface: #0d2530;
      --on-surface: #e7f2f7;
      --muted: color-mix(in oklab, var(--tarheel-grey) 25%, #e7f2f7 75%);
      --overlay-backdrop: rgba(7, 18, 24, .8);

      --md-sys-color-primary:        #7dd0f7;
      --md-sys-color-on-primary:     #02232e;
      --md-sys-color-primary-container: #083243;
      --md-sys-color-on-primary-container: #a6e2ff;

      --md-sys-color-secondary:      #93a3a9;
      --md-sys-color-on-secondary:   #0b1a20;
      --md-sys-color-secondary-container: #0f2833;
      --md-sys-color-on-secondary-container: #cfe1e9;

      --md-sys-color-surface:        #0d2530;
      --md-sys-color-on-surface:     #e7f2f7;
      --md-sys-color-surface-variant:#153341;
      --md-sys-color-on-surface-variant:#a7bec7;

      --md-sys-color-outline:        #2a4755;
      --md-sys-color-outline-variant:#1f3b49;

      --card-shadow: 0 0.5rem 1.5rem rgba(0,0,0,.35);
    }
  }
}

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

@layer base {
  html, body { height: 100%; }
  /* MODIFIED: Scale all rem-based typography by +25% */
  html { font-size: 125%; }
  body {
    margin: 0;
    color: var(--on-surface);
    background:
      radial-gradient(1200px 400px at -20% -20%, #f1fbff 0%, transparent 60%),
      radial-gradient(1000px 380px at 120% -10%, #f5fff7 0%, transparent 55%),
      var(--tarheel-white);
    font: 400 1rem/1.55 var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  @media (prefers-color-scheme: dark) {
    body {
      background:
        radial-gradient(1200px 400px at -20% -20%, #0f2a36 0%, transparent 60%),
        radial-gradient(1000px 380px at 120% -10%, #0e2b23 0%, transparent 55%),
        var(--surface);
    }
  }
  a { color: var(--tarheel-dark); text-decoration: none; }
  a:hover { text-decoration: underline; }
  :focus-visible { outline: var(--focus); outline-offset: 0.125rem; border-radius: var(--border-radius) !important; }
  header h1 { margin: 0; font-size: clamp(3rem, 5vw, 4rem); font-weight: 900; letter-spacing: 0.0125em; }
  header p { margin: 0.5rem 0 0; color: var(--muted); }
}

@layer layout {
  .container { max-width: var(--container-max-width); margin-inline: auto; padding: var(--space-6); }

  /* FIX: Make settings grid layout robust and responsive */
  .settings-content-wrapper {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
  .settings-content-wrapper > * {
    min-inline-size: 0;
  }
  .settings-shell {
    overflow-x: hidden;
  }
}

@layer components {
  /* Header */
  .header-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
  .title-container { display: flex; align-items: center; gap: var(--space-3); }

  /* Image-filled H1 with outline */
  .logo-image-text {
    display: inline-block;
    background-image: url('/assets/favicon.jpg');
    background-size: cover;
    background-position: center;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    -webkit-text-stroke: var(--logo-stroke) var(--on-surface);
  }

  /* Fallback for browsers without background-clip: text support */
  @supports not (-webkit-background-clip: text) {
    .logo-image-text {
      color: var(--on-surface);
      background-image: none;
      -webkit-text-stroke: 0;
    }
  }
  
  /* Drop Zone */
  #drop-zone {
    margin-top: var(--space-4);
    border: var(--border-2) dashed var(--tarheel-light);
    border-radius: var(--border-radius);
    background: linear-gradient(180deg, var(--drop-grad-top) 0%, var(--drop-grad-bot) 100%);
    padding: 2.625rem var(--space-5);
    text-align: center;
    cursor: pointer;
    transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
    box-shadow: 0 0.25rem 0.875rem rgba(0, 113, 170, .08);
  }
  @media (prefers-color-scheme: dark) {
    #drop-zone {
      background: linear-gradient(180deg, color-mix(in oklab, #0d2530, #fff 2%) 0%, color-mix(in oklab, #0d2530, #fff 5%) 100%);
      border-color: color-mix(in oklab, var(--tarheel-light), #0d2530 65%);
      box-shadow: 0 0.25rem 0.875rem rgba(0,0,0,.4);
    }
  }
  #drop-zone p { margin: 0; color: var(--muted); }
  #drop-zone p strong { color: var(--on-surface); }
  #drop-zone a { font-weight: 800; color: var(--tarheel-dark); }
  #drop-zone.drag-over {
    border-color: var(--tarheel);
    background: linear-gradient(180deg, #f4fbff 0%, #eefaff 100%);
    box-shadow: 0 0.375rem 1.125rem rgba(0, 113, 170, .18);
  }
  @media (prefers-color-scheme: dark) {
    #drop-zone.drag-over {
      background: linear-gradient(180deg, color-mix(in oklab, #0f2a36, #fff 4%) 0%, color-mix(in oklab, #0f2a36, #fff 8%) 100%);
      border-color: var(--md-sys-color-primary);
      box-shadow: 0 0.375rem 1.125rem rgba(0,0,0,.55);
    }
  }

  /* File List + progress + buttons */
  #file-list { display: grid; gap: var(--space-3); }
  .file-item { display: grid; grid-template-columns: 1fr auto; gap: 0.875rem; padding: 0.875rem; border: var(--border-1) solid var(--border); background: var(--tarheel-white); box-shadow: 0 0.25rem 1rem rgba(0, 113, 170, .06); }
  @media (prefers-color-scheme: dark) {
    .file-item { background: color-mix(in oklab, var(--surface), #fff 4%); border-color: var(--md-sys-color-outline-variant); box-shadow: 0 0.25rem 1rem rgba(0,0,0,.45); }
  }
  .file-name { font-weight: 800; word-break: break-word; letter-spacing: .2px; color: var(--tarheel-dark); }
  @media (prefers-color-scheme: dark) { .file-name { color: var(--md-sys-color-primary); } }
  .file-size { margin-top: 0.5rem; font-size: 0.9rem; color: var(--muted); }
  .file-settings { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
  .file-progress { width: 100%; height: 0.625rem; background: #e8f5fd; overflow: hidden; margin-top: 0.625rem; outline: var(--border-1) solid var(--tarheel-light); }
  .file-progress-bar { width: 0; height: 100%; background: var(--tarheel-electric); transition: width .35s ease; }
  .file-progress-bar.complete { background: var(--tarheel); }

  .size-reduction {
    font-weight: 800;
    /*
      Set a fallback color using the existing --success variable.
      Then, override it with our dynamic oklch() color.
      The --savings-hue variable is set by JavaScript for each file.
    */
    color: var(--success);
    color: oklch(65% 0.15 var(--savings-hue, 140));
  }

  .error { color: var(--accent-strawberry); font-weight: 800; }
  .warning-text { color: #5b4d00; background: var(--accent-yellow); padding: 0.1875rem 0.5rem; border: var(--border-1) solid color-mix(in oklab, var(--accent-yellow), #000 12%); }

  .file-actions {
    display: flex;
    flex-direction: column;
    align-items: center; /* <-- FIX: Center the new square buttons */
    gap: var(--space-2);
    border-left: var(--border-1) dashed var(--border);
    padding-left: 0.75rem;
  }

  /*
    File action buttons: (Compare, Download, Remove)
    - Perfectly centered icons using CSS Grid.
    - Pointer cursor on hover for clear affordance.
    - Sharp square corners via the official --border-radius token.
    - Sized consistently for reliable tap targets.
    - Themed using Material Design system tokens for consistency.
  */
  .file-actions button {
    /* Sizing & Layout */
    inline-size: 2.5rem;              /* A generous, consistent tap target */
    block-size: 2.5rem;
    display: grid;                    /* The simplest, most robust centering method */
    place-items: center;
    padding: 0;

    /* Appearance & Theming */
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border: var(--border-1) solid var(--md-sys-color-outline-variant);
    border-radius: var(--border-radius); /* Use the official token for square corners */

    /* Interaction */
    cursor: pointer;                  /* Show the "hand" icon on hover */
    transition: transform 150ms ease, box-shadow 150ms ease; /* Add a subtle transition */
  }

  /* Keep the existing hover effect from the snapshot */
  .file-actions button:hover:not(:disabled) {
    background: #ffffff;
    box-shadow: 0 0.1875rem 0.625rem rgba(0, 113, 170, .14);
    transform: translateY(-0.0625rem);
  }

  /* Disabled state */
  .file-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
  }

  /* Keyboard focus style, consistent with the rest of the site */
  .file-actions button:focus-visible {
    outline: var(--focus);
    outline-offset: 0.125rem;
  }

  /*
    Ensure the Material Symbols glyph is optically centered and stable.
  */
  .file-actions .material-symbols-outlined {
    line-height: 1;                     /* Prevent vertical shift from baseline */
    font-size: 1.375rem;                /* Keep the established icon size */
    color: var(--tarheel-dark);         /* Keep icons the brand blue color */
    /* Lock font properties for rendering consistency */
    font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  }
  
  #processing-status { text-align: center; margin: 1rem 0 0.375rem; font-weight: 700; color: var(--muted); }

  /* Download buttons */
  .download-button-group { display: flex; box-shadow: 0 0.375rem 1.125rem rgba(242, 214, 98, .35); }
  #download-zip { flex-grow: 1; padding: 0.875rem 1rem; font-size: 1.05rem; font-weight: 900; color: #2f2a00; background: linear-gradient(180deg, #fff6c9 0%, var(--accent-yellow) 100%); border: var(--border-1) solid #e8cf55; border-right: none; cursor: pointer; }
  #download-zip:hover:not(:disabled) { filter: brightness(1.02); }
  #download-zip:disabled { opacity: 0.75; cursor: not-allowed; background: linear-gradient(180deg, #f2f6fb 0%, #e9f1f9 100%); color: #6b7280; border-color: #d1e3f5; box-shadow: none; }
  #auto-download-toggle { flex-shrink: 0; display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.875rem 1rem; font-size: .95rem; font-weight: 700; border: var(--border-1) solid #e8cf55; border-left: var(--border-1) solid rgba(232, 207, 85, 0.7); background: linear-gradient(180deg, #fff6c9 0%, var(--accent-yellow) 100%); color: #2f2a00; cursor: pointer; }
  #download-zip:disabled + #auto-download-toggle { background: linear-gradient(180deg, #f2f6fb 0%, #e9f1f9 100%); color: #6b7280; border-color: #d1e3f5; }
  .auto-toggle-icon { width: 1rem; height: 1rem; border: var(--border-2) solid #bba833; background: #fff; display: grid; place-items: center; }
  .auto-toggle-icon::before { content: ''; width: 0.5rem; height: 0.3125rem; border-left: var(--border-2) solid #fff; border-bottom: var(--border-2) solid #fff; transform: rotate(-45deg) translateY(-0.0625rem); opacity: 0; }
  #auto-download-toggle[aria-pressed="true"] .auto-toggle-icon { background: var(--success-bg); border-color: var(--success-bg); }
  #auto-download-toggle[aria-pressed="true"] .auto-toggle-icon::before { opacity: 1; }

  /* Floating settings gear */
  .settings-gear {
    position: fixed;
    top: 0.5rem;
    right: 0.5rem;
    z-index: calc(var(--overlay-z) + 1);
    background: var(--surface);
    box-shadow: 0 0.5rem 1.25rem rgba(0, 113, 170, .18);
    transform: translate(20%, -20%);
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
    opacity: 0.95;
  }
  .settings-gear:hover,
  .settings-gear:focus-visible {
    transform: translate(0, 0);
    box-shadow: 0 0.75rem 1.75rem rgba(0, 113, 170, .26);
    opacity: 1;
  }

  /* Spin animation (applied to the host; targets the inner md-icon) */
  @keyframes onlyjpg-spin {
    to { transform: rotate(360deg); }
  }
  .settings-gear.is-spinning md-icon {
    animation: onlyjpg-spin .45s linear;
  }

  /* Generic spinner for buttons */
  .result-action-compare[aria-busy="true"] .material-symbols-outlined {
    animation: onlyjpg-spin .8s linear infinite;
  }

  /* Settings as full-screen overlay */
  .settings-shell {
    position: fixed;
    inset: 0;
    z-index: var(--overlay-z);
    background: var(--overlay-backdrop);
    backdrop-filter: blur(0.375rem) saturate(1.08);
    display: grid;
    grid-template-rows: 1fr;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(10%, -10%) scale(.985);
    transition: opacity .22s ease, transform .22s ease, visibility 0s linear .22s;
    padding: clamp(0.75rem, 1.6vw, 1.25rem);
  }
  .settings-shell.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translate(0, 0) scale(1);
    transition: opacity .22s ease, transform .22s ease;
  }


  .settings-panel { min-height: 0; overflow: auto; background: transparent; }
  .settings-content-wrapper {
    min-height: 0;
    display: grid;
    gap: var(--space-4);
    max-width: var(--container-max-width);
    margin-inline: auto;
  }

  .settings-block {
    position: relative; /* Contain the overlay */
  }

  .settings-block h3,
  .settings-block h4,
  .settings-block legend {
    margin: 0 0 0.375rem;
    font-size: 1.05rem;
    font-weight: bold;
    padding: 0;
  }
  .settings-block h4.subheading { color: var(--muted); }
  .fieldset-preamble { margin: 0 0 0.625rem; color: var(--muted); font-size: .95rem; }
  .setting-with-switch { display: flex; align-items: center; justify-content: space-between; gap: 0.875rem; flex-wrap: wrap; }
  .setting-with-switch--divider { margin-top: 1rem; padding-top: 1rem; border-top: var(--border-1) solid var(--border); }
  .radio-group { display: grid; gap: 0.5rem; }
  .radio-group label { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; }
  .settings-block.is-disabled::before {
    content: '';
    position: absolute;
    inset: 0;
    background: color-mix(in oklab, var(--accent-yellow) 20%, transparent);
    border-radius: var(--border-radius);
    cursor: not-allowed;
    z-index: 1;
  }
  .disabled-reason-box:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--accent-yellow);
    color: #5b4d00;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.625rem var(--space-6);
    border-bottom: var(--border-1) solid color-mix(in oklab, var(--accent-yellow), #000 15%);
    position: relative;
    z-index: 2;
    margin: calc(var(--space-6) * -1) calc(var(--space-6) * -1) var(--space-5);
  }
  .subsection .disabled-reason-box:not([hidden]) {
      margin: 0 0 var(--space-5);
  }
  #quality-output { display: block; text-align: center; font-weight: 900; font-size: 2.2rem; color: var(--tarheel-dark); margin-bottom: 0.5rem; }
  @media (prefers-color-scheme: dark) { #quality-output { color: var(--md-sys-color-primary); } }
  #quality, #pdf-dpi { width: 100%; }
  .metadata-subsettings { padding-left: 1.25rem; margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.375rem; }
  .hint { font-size: 0.9rem; color: var(--muted); }
  .sub-hint { padding-left: 2rem; margin-top: -0.25rem; }

  /* Info Cards */
  .info-card {
    /* The background of md-elevated-card is controlled by the --md-elevated-card-container-color property */
    border: var(--border-1) solid var(--border);
    box-shadow: var(--card-shadow);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }
  .card-title { margin: 0 0 1rem; font-size: 1.75rem; font-weight: 800; color: var(--tarheel-dark); text-align: center; }
  @media (prefers-color-scheme: dark) { .card-title { color: var(--md-sys-color-primary); } }
  .info-card p { margin-top: 0; margin-bottom: 1em; }

  @media (prefers-color-scheme: dark) {
    main md-elevated-card { --md-elevated-card-container-color: var(--md-sys-color-surface-variant); }
  }
  .info-card ul { padding-left: 0; list-style: none; margin: 1em 0; }
  .info-card ul li { position: relative; padding-left: 1.5em; margin-bottom: .5em; }
  .info-card ul li::before { content: "✓"; position: absolute; left: 0; color: var(--tarheel-dark); font-weight: bold; }
  @media (prefers-color-scheme: dark) { .info-card ul li::before { color: var(--md-sys-color-primary); } }
  .card-divider { border: 0; border-top: var(--border-1) solid var(--border); margin: 1rem 0; }

  /* Compatibility Warning Card */
  .warning-card {
    --md-elevated-card-container-color: var(--accent-yellow);
    color: #5b4d00;
    border-color: color-mix(in oklab, var(--accent-yellow), #000 15%);
  }
  .warning-card .card-title {
    color: #5b4d00;
  }
  #compatibility-list li::before {
    content: "⚠️";
    color: inherit;
    font-weight: normal;
  }
  #drop-zone[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
  }

  /* Globe inside Stats Card */
  .globe-wrapper {
    display: block;
    position: relative;
    width: 100%;
    margin-bottom: var(--space-6);
    /* height is set by JS based on width */
  }
  .globe-canvas {
    display: block;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    /* width/height set by JS to ensure correct aspect ratio */
  }
  #stats-card {
    position: relative;
    overflow: hidden;
  }
  .globe-wrapper, .globe-canvas {
    pointer-events: none;
  }

  /* Stats */
  #stats-card .stats-grid { display: grid; grid-template-columns: repeat(var(--columns-stats), 1fr); gap: var(--space-5); }
  .stats-grid > div { text-align: center; }
  .stat-value { font-size: 1.25rem; font-weight: 900; color: var(--tarheel-dark); }
  @media (prefers-color-scheme: dark) { .stat-value { color: var(--md-sys-color-primary); } }
  .stat-label { color: var(--muted); }

  /* Thanks Card */
  .credits-list {
    display: block;
  }
  .credits-list dt {
    font-weight: 700;
    text-align: left;
  }
  .credits-list dd {
    margin: var(--space-2) auto var(--space-7);
    color: var(--on-surface);
    font-size: .95rem;
    text-align: left;
  }
  .credits-list dd:last-of-type {
    margin-bottom: 0;
  }

  /* Downstream Savings Panel */
  .savings-explanation {
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
    max-width: 60ch;
    margin-inline: auto;
    margin-block: 0 var(--space-4);
  }
  .savings-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: var(--border-1) solid var(--border);
  }
  .savings-tabs button {
    padding: .5rem;
    background: transparent;
    border: 0;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
  }
  .savings-tabs button[aria-selected="true"] {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
  }
  .savings-results {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: var(--border-1) solid var(--border);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
  }
  .result-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
  }
  .result-line span { color: var(--muted); }
  .result-line strong { font-weight: 700; color: var(--on-surface); }


  /* Contact */
  .contact-card { align-items: center; gap: var(--space-4); text-align: center; transition: transform .15s ease, box-shadow .15s ease; cursor: pointer; }
  .contact-card:hover { transform: translateY(-0.125rem); box-shadow: 0 0.75rem 1.75rem rgba(0, 113, 170, .18); }
  @media (prefers-color-scheme: dark) { .contact-card:hover { box-shadow: 0 0.75rem 1.75rem rgba(0,0,0,.45); } }
  #contact-email-display { font-size: 1.2rem; font-weight: 700; color: var(--muted); margin: 0; }
  .contact-feedback-prompt { font-size: 1.05rem; line-height: 1.6; color: var(--on-surface); margin: 0; max-width: 55ch; }

  /*
    START OF SYNTHESIZED COMPARE OVERLAY BLOCK
  */
  .compare-overlay {
    position: fixed;
    inset: 0;
    z-index: calc(var(--overlay-z) + 2);
    background: var(--overlay-backdrop);
    backdrop-filter: blur(0.375rem);
    display: flex;
    flex-direction: column;
    padding: 0; /* Fullscreen */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease-out, visibility 0s linear .2s;
  }
  .compare-overlay.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .2s ease-out;
  }
  .compare-close {
    position: absolute;
    right: var(--space-3);
    top: var(--space-3);
    z-index: 10;
  }
  .compare-stage {
    flex-grow: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
  }
  .compare-stage oj-compare {
    display: block;
    max-width: 100%;
    max-height: 100%;
    height: 100%; /* Height is needed for children to use flex-grow */
    width: 100%; /* Width will be constrained by aspect-ratio */
    box-shadow: var(--card-shadow);
  }

  /* The new wrapper for image + info bar. These are direct children of oj-compare. */
  .compare-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent content from spilling */
  }
  .compare-content figure {
    margin: 0;
    flex-grow: 1; /* Image container takes up available space */
    min-height: 0; /* Important for flexbox shrinking */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface); /* BG for letterboxing */
  }
  .compare-content img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  /* The info bar, now inside the slider */
  .compare-bar {
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    line-height: 1.2;
    flex-shrink: 0; /* Don't let it shrink */
  }
  .compare-bar--left {
    background: var(--surface);
    color: var(--tarheel-dark);
    text-align: left;
    border-top: var(--border-1) solid var(--border);
  }
  .compare-bar--right {
    background: var(--tarheel-dark);
    color: #fff;
    text-align: right;
    border-top: var(--border-1) solid var(--tarheel-dark);
  }
  @media(prefers-color-scheme: dark) {
    .compare-bar--right {
      background: var(--md-sys-color-primary);
      color: var(--md-sys-color-on-primary);
      border-top-color: var(--md-sys-color-primary);
    }
  }
  .compare-bar__name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .compare-bar__size { opacity: .9; font-size: .9rem; }
  /* END OF SYNTHESIZED COMPARE OVERLAY BLOCK */

  #processing-status, #file-list, .download-button-group {
    overflow: hidden;
    transition:
      opacity 0.25s ease-out,
      transform 0.25s ease-out,
      max-height 0.35s ease-in-out,
      margin-top 0.35s ease-in-out,
      padding-top 0.35s ease-in-out,
      padding-bottom 0.35s ease-in-out,
      border-width 0.35s ease-in-out,
      visibility 0s linear;
    will-change: transform, opacity, max-height;
  }
  .download-button-group, #processing-status { max-height: 20rem; }
  #processing-status, #file-list:not(:empty), .download-button-group, .info-card { margin-top: var(--space-8); }

  /*
    START OF UI POLISH FOR DISABLED SETTINGS
  */
  /* Indentation and grouping for the 'Single Long Image' options */
  #multipage-long-options {
    position: relative; /* For the ::before overlay */
    padding-inline-start: 1.5rem;
    margin-inline-start: 1rem;
    border-inline-start: var(--border-1) dashed var(--md-sys-color-outline-variant);
  }
  
  /* When the section is disabled, make it non-interactive and apply an overlay */
  #multipage-long-options.is-disabled {
    pointer-events: none;
    opacity: 0.6; /* Match existing disabled style for consistency */
  }

  #multipage-long-options.is-disabled::before {
    content: '';
    position: absolute;
    inset: 0;
    background: hsla(50, 100%, 50%, 0.08); /* Semi-transparent yellow overlay */
    z-index: 1; /* Sit below the reason box */
  }
  
  /* Ensure the warning box appears on top of the overlay */
  #multipage-long-options .disabled-reason-box {
    position: relative;
    z-index: 2;
  }
  /*
    END OF UI POLISH FOR DISABLED SETTINGS
  */

  .setting-with-switch.is-disabled-sub {
    opacity: .6;
  }
  /* Extra spacing between Normalize widths and Background */
  #pdf-long-options .setting-spaced {
    margin-block-start: var(--space-4);
  }
  /* DPI slider row */
  .range-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-end: var(--space-2);
    flex-wrap: wrap; /* FIX: Allow wrapping */
  }
  .range-header .small { color: var(--muted); }

  /* FIX: Prevent overflow from negative margins in disabled-reason-box on small screens */
  @media (max-width: 25rem) {
    .disabled-reason-box:not([hidden]) {
      margin-inline-start: calc(var(--space-6) * -1);
      margin-inline-end: calc(var(--space-6) * -1);
      padding-inline-start: var(--space-6);
      padding-inline-end: var(--space-6);
    }
  }

  /* NEW: Styles for improved settings controls */
  .setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }
  .stepper-row {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin: .25rem 0 .75rem 1.5rem;
  }
  .setting-spaced {
    margin-top: var(--space-4);
  }

  @media (prefers-reduced-motion: reduce) {
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
    .contact-card:hover { transform: none; box-shadow: var(--card-shadow); }
    .compare-overlay, .settings-shell { transition: none; }
  }
}

@layer modes {
  @media (min-width: 56rem) {
    :root { --mode: horizontal; --columns-stats: 3; }
    /* Button text can be a bit bigger on desktop */
    .file-actions button { font-size: 1rem; }
    @layer layout { .container { padding: var(--space-7); } }
    .file-actions {
      flex-direction: row;           /* back to side-by-side */
      align-items: center;
      gap: 0.375rem;
      border-top: 0;                 /* restore original divider */
      border-left: var(--border-1) dashed var(--border);
      padding-top: 0;
      padding-left: 0.75rem;
    }
  }
}

@layer utilities {
  .hidden {
    opacity: 0;
    transform: scaleY(0.9) translateY(-1rem);
    max-height: 0 !important;
    margin-top: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border-width: 0 !important;
    visibility: hidden;
    pointer-events: none;
    transition-delay: 0s, 0s, 0s, 0s, 0s, 0s, 0s, .35s; /* Delay visibility until after transitions */
  }

  .visually-hidden { border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; }
  .skip-link:focus { position: fixed; top: 0.625rem; left: 0.625rem; padding: 0.625rem 1rem; background: var(--tarheel-dark); color: #fff; z-index: 10001; clip: auto; width: auto; height: auto; margin: 0; }
  body.modal-open { overflow: hidden; }
}

@layer overrides {
  /* Belt-and-suspenders: keep the square token authoritative at the end of the cascade, too */
  :root { --border-radius: 0 !important; }

  /* MD3 shape tokens (when supported) */
  md-switch { --md-switch-track-shape: 0; --md-switch-handle-shape: 0; --md-switch-focus-ring-shape: 0; }
  md-slider { --md-slider-handle-shape: 0; --md-slider-track-shape: 0; --md-slider-focus-ring-shape: 0; }
  md-filled-button { --md-filled-button-container-shape: 0; --md-filled-button-focus-ring-shape: 0; }
  md-icon-button { --md-icon-button-container-shape: 0; --md-icon-button-focus-ring-shape: 0; }
  md-outlined-text-field { --md-outlined-field-container-shape: 12px; }
  md-filled-text-field { --md-filled-field-container-shape: 0; }

  /* Public ::part surfaces (future-proof if tokens change) */
  md-switch::part(track), md-switch::part(handle), md-switch::part(focus-ring), md-switch::part(container),
  md-checkbox::part(container), md-checkbox::part(focus-ring),
  md-slider::part(thumb), md-slider::part(tick), md-slider::part(active-track), md-slider::part(inactive-track), md-slider::part(focus-ring),
  md-icon-button::part(container), md-icon-button::part(focus-ring),
  md-filled-button::part(container), md-filled-button::part(focus-ring),
  md-elevated-card::part(container) { border-radius: var(--border-radius, 0) !important; }

  /* FIX: Ensure slider internals can shrink to prevent overflow */
  .settings-block md-slider::part(track),
  .settings-block md-slider::part(active-track),
  .settings-block md-slider::part(inactive-track) {
    min-inline-size: 0;
  }

  /* “Square radios” pattern for exclusive md-checkbox groups */
  .radio-group md-checkbox::part(container),
  .radio-group md-checkbox::part(focus-ring) { border-radius: var(--border-radius, 0) !important; }

  md-divider {
    --md-divider-color: var(--md-sys-color-outline-variant);
    --md-divider-thickness: var(--border-1);
  }

  md-elevated-card { --md-elevated-card-container-color: var(--md-sys-color-surface); }

  #file-input { display: none; }

  [hidden] { display: none !important; }
  md-elevated-card[hidden] { display: none !important; }
}