/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #14181f;
  --text-soft: #545b68;
  --border: #e2e6ee;
  --accent: #2547c8;
  --accent-hover: #1c3aa8;
  --accent-2: #0d9488;
  --success: #16a34a;
  --success-bg: #ecfdf3;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning-bg: #fffbeb;
  --warning-text: #92620a;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 31, 0.06);
  --shadow: 0 8px 30px rgba(20, 24, 31, 0.08);
  --shadow-lg: 0 20px 60px rgba(20, 24, 31, 0.18);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Manrope", var(--sans);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --container: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1e2330;
    --text: #eef1f6;
    --text-soft: #a2a9b8;
    --border: #2a3040;
    --accent: #6f8bff;
    --accent-hover: #8ba0ff;
    --accent-2: #2dd4bf;
    --success: #4ade80;
    --success-bg: #123023;
    --danger: #f87171;
    --danger-bg: #34191b;
    --warning-bg: #2e2510;
    --warning-text: #f2c94c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; overflow-x: clip; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
}
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
input, select { font: inherit; color: inherit; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { font-family: var(--display); text-wrap: balance; line-height: 1.12; letter-spacing: -0.01em; font-weight: 800; }
::selection { background: var(--accent); color: #fff; }

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

/* =============================================================
   3. Utilities
   ============================================================= */
.container { max-width: var(--container); margin-inline: auto; padding-inline: 1.25rem; }
.container--prose { max-width: 760px; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--text); color: var(--bg);
  z-index: 9999; border-radius: 8px; font-weight: 600;
  transition: top .2s var(--ease-out);
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   4. Typography
   ============================================================= */
h2 { font-size: clamp(1.5rem, 3vw, 2.1rem); margin-bottom: .5rem; }
h3 { font-size: 1.15rem; margin-bottom: .4rem; }
.section > .container > h2 { text-align: center; margin-bottom: 2rem; }
.container--prose h2 { text-align: left; }

/* =============================================================
   5. Components
   ============================================================= */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .85rem 1.4rem; border-radius: var(--radius-sm);
  font-weight: 700; font-size: .98rem;
  transition: transform .15s var(--ease-out), background .15s var(--ease-out), opacity .15s;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:active { transform: scale(0.98); }
.btn--primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn--ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.btn--block { width: 100%; }

.btn-small {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .45rem .8rem; border-radius: 999px; font-size: .82rem; font-weight: 600;
  border: 1px solid var(--border); color: var(--text-soft); white-space: nowrap;
  transition: background .15s var(--ease-out), color .15s var(--ease-out);
}
.btn-small:hover { background: var(--surface-2); }
.btn-small--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-small--primary:hover { background: var(--accent-hover); }

/* Header */
.site-header { padding-block: 1.1rem; border-bottom: 1px solid var(--border); }
.site-header__inner { display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 800; font-size: 1.15rem; }
.site-nav { display: flex; gap: 1.6rem; font-size: .92rem; font-weight: 600; color: var(--text-soft); }
.site-nav a:hover { color: var(--text); }
@media (max-width: 539px) { .site-nav { display: none; } }

/* Hero */
.hero { padding-block: 2.4rem 1rem; text-align: center; }
.hero h1 { font-size: clamp(1.9rem, 4.6vw, 2.9rem); max-width: 18ch; margin-inline: auto; }
.hero__sub { color: var(--text-soft); font-size: 1.08rem; max-width: 46ch; margin: .9rem auto 0; }

/* Tool card */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.6rem;
  margin: 1.8rem auto 0;
  max-width: 620px;
  text-align: left;
}
.tool-card__panel[hidden] { display: none; }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: 2rem 1.2rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .18s var(--ease-out), background .18s var(--ease-out);
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface-2)); }
.dropzone__icon { color: var(--accent); }
.dropzone__title { font-weight: 700; font-size: 1.02rem; }
.dropzone__sub { color: var(--text-soft); font-size: .86rem; max-width: 34ch; }

.selected-files {
  margin-top: .9rem;
  display: flex; flex-wrap: wrap; gap: .4rem;
  font-size: .84rem; color: var(--text-soft);
}
.selected-files[hidden] { display: none; }
.selected-files__chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: .3rem .7rem;
}

/* Mode tabs */
.mode-tabs { display: flex; gap: .4rem; margin-top: 1.1rem; background: var(--surface-2); padding: .3rem; border-radius: 999px; }
.mode-tab {
  flex: 1; padding: .55rem .8rem; border-radius: 999px; font-weight: 700; font-size: .9rem;
  color: var(--text-soft); transition: background .15s var(--ease-out), color .15s var(--ease-out);
}
.mode-tab.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.mode-panel { margin-top: 1.1rem; display: flex; flex-direction: column; gap: 1rem; }
.mode-panel[hidden] { display: none; }

.field-block label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .4rem; }
.field-block select, .field-block input[type="number"] {
  width: 100%; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.field-hint { font-size: .8rem; color: var(--text-soft); margin-top: .35rem; }
.field-hint--warning { color: var(--warning-text); background: var(--warning-bg); padding: .5rem .7rem; border-radius: var(--radius-sm); }

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

/* Switch */
.switch-row { display: flex; align-items: center; gap: .7rem; font-size: .9rem; cursor: pointer; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch__track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  transition: background .18s var(--ease-out);
}
.switch__track::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  background: #fff; border-radius: 50%; box-shadow: var(--shadow-sm);
  transition: transform .18s var(--ease-out);
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::before { transform: translateX(18px); }

.target-input-row { display: flex; gap: .5rem; }
.target-input-row input { flex: 1; }
.target-input-row select { width: 84px; }

.target-presets { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .7rem; }
.chip {
  padding: .4rem .8rem; border-radius: 999px; border: 1px solid var(--border);
  font-size: .82rem; font-weight: 600; color: var(--text-soft);
  transition: background .15s var(--ease-out), border-color .15s var(--ease-out), color .15s var(--ease-out);
}
.chip:hover, .chip.is-active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

.tool-card > .btn--block { margin-top: 1.3rem; }

/* Progress */
.progress-label { font-weight: 600; margin-bottom: .8rem; text-align: center; }
.progress-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-bar__fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s var(--ease-out); }
.progress-count { text-align: center; color: var(--text-soft); font-size: .84rem; margin-top: .6rem; }

/* Results */
.results-summary { font-weight: 700; margin-bottom: 1rem; text-align: center; font-size: 1.05rem; }
.results-summary .saved { color: var(--success); }
.results-table { display: flex; flex-direction: column; gap: .6rem; max-height: 420px; overflow-y: auto; }

.result-row {
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.result-row__thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: var(--border); }
.result-row__info { flex: 1; min-width: 0; }
.result-row__name { display: block; font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-row__sizes { display: flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--text-soft); flex-wrap: wrap; }
.result-row__sizes .new { color: var(--text); font-weight: 600; }
.result-row__sizes .saved { color: var(--success); font-weight: 700; background: var(--success-bg); padding: .1rem .45rem; border-radius: 999px; }
.result-row__sizes .grew { color: var(--danger); font-weight: 700; background: var(--danger-bg); padding: .1rem .45rem; border-radius: 999px; }
.result-row__actions { display: flex; gap: .4rem; flex-shrink: 0; }
.result-row.is-error { border-color: var(--danger); background: var(--danger-bg); }
.result-row__error-text { color: var(--danger); font-size: .82rem; }

.results-actions { display: flex; gap: .7rem; margin-top: 1.2rem; flex-wrap: wrap; }
.results-actions .btn { flex: 1; min-width: 160px; }

.error-message { text-align: center; color: var(--danger); font-weight: 600; margin-bottom: 1rem; }

/* Privacy strip */
.privacy-strip {
  max-width: 620px; margin: 1.1rem auto 0; text-align: center;
  display: flex; flex-direction: column; gap: .35rem;
  font-size: .84rem; color: var(--text-soft);
}
.privacy-badge { font-weight: 600; color: var(--text); }

/* Ad slots */
.ad-slot {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.ad-slot__label { opacity: .55; }
.ad-slot--leaderboard { min-height: 90px; margin-block: 2.2rem; }
.ad-slot--incontent { min-height: 250px; margin-block: 2.4rem; max-width: 336px; margin-inline: auto; }
.ad-slot--popup { min-height: 250px; width: min(300px, 80vw); margin-bottom: 1rem; }
.ad-slot--toast { min-height: 90px; width: 260px; }

/* Steps */
.steps-grid { display: grid; gap: 1.2rem; grid-template-columns: 1fr; }
.step-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; }
.step-card__icon {
  width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent);
  margin-bottom: .9rem;
}

/* Usage ideas */
.uso-grid { display: grid; gap: 1.1rem; grid-template-columns: 1fr; }
.uso-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem; }
.uso-card h3 { color: var(--accent); }

/* FAQ */
.faq-item {
  border-bottom: 1px solid var(--border);
  padding-block: 1rem;
}
.faq-item summary {
  cursor: pointer; font-weight: 700; font-size: 1rem;
  list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-size: 1.3rem; color: var(--accent); flex-shrink: 0; }
.faq-item[open] summary::after { content: "\2212"; }
.faq-item p { margin-top: .7rem; color: var(--text-soft); }

/* Sections */
.section { padding-block: 3rem; }
.section--seo { background: var(--surface); }
.section--seo p { margin-bottom: 1rem; color: var(--text-soft); }
.section--seo h3 { margin-top: 1.6rem; color: var(--text); }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding-block: 2rem; margin-top: 1rem; }
.site-footer__inner { display: flex; flex-direction: column; gap: .6rem; align-items: center; text-align: center; font-size: .84rem; color: var(--text-soft); }
.footer-nav { display: flex; gap: 1.2rem; font-weight: 600; }
.footer-nav a:hover { color: var(--text); }
.footer-credits a { text-decoration: underline; }

/* =============================================================
   6. Dialogs (compare + ad popup)
   ============================================================= */
dialog {
  border: none; border-radius: var(--radius-lg); padding: 1.4rem;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  max-width: min(480px, 92vw);
  width: 100%;
}
dialog::backdrop { background: rgba(10, 12, 18, 0.55); backdrop-filter: blur(2px); }

.dialog-close {
  position: absolute; top: .8rem; right: .8rem;
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-size: 1.3rem; line-height: 1;
  transition: background .15s var(--ease-out);
}
.dialog-close:hover { background: var(--border); }

.compare-dialog { position: relative; }
.compare-dialog h3 { margin-bottom: 1rem; padding-right: 2rem; }
.compare-slider {
  position: relative; width: 100%; aspect-ratio: 4/3; border-radius: var(--radius);
  overflow: hidden; background: var(--surface-2); touch-action: pan-y;
}
.compare-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--surface-2); user-select: none; -webkit-user-drag: none; }
.compare-img--before { clip-path: inset(0 50% 0 0); }
.compare-handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15); transform: translateX(-50%); pointer-events: none;
}
.compare-handle::after {
  content: "⇔"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 34px; height: 34px; background: #fff; color: var(--text); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1rem; box-shadow: var(--shadow);
}
.compare-range {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  opacity: 0; cursor: ew-resize; appearance: none;
}
.compare-label {
  position: absolute; top: .6rem; padding: .25rem .6rem; border-radius: 999px;
  background: rgba(10,12,18,.6); color: #fff; font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  pointer-events: none;
}
.compare-label--before { left: .6rem; }
.compare-label--after { right: .6rem; }

.ad-popup { position: relative; text-align: center; }

/* =============================================================
   7. Ad toast (corner)
   ============================================================= */
.ad-toast {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .8rem;
  animation: toastIn .4s var(--ease-out);
}
.ad-toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.ad-toast__close {
  position: absolute; top: -10px; right: -10px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--text); color: var(--bg); font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* =============================================================
   8. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .steps-grid { grid-template-columns: repeat(3, 1fr); }
  .uso-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 720px) {
  .tool-card { padding: 2.2rem; }
}
@media (min-width: 960px) {
  .hero { padding-block: 3.4rem 1.4rem; }
}

/* =============================================================
   9. Reduced motion — only intrusive effects
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .ad-toast { animation: none; }
}
