/* ============================================================
   Compressor — Clean, modern, consistent. One design language.
   ============================================================ */

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

/* ---------- Design tokens ---------- */
:root {
  --bg: #fafafa;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-2: #d1d5db;
  --hover: #f3f4f6;
  --primary: #2563eb;
  --primary-hi: #1d4ed8;
  --primary-soft: #eff6ff;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --red: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.1);
}

[data-theme="dark"] {
  --bg: #0f0f0f;
  --card: #1a1a1a;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #2a2a2a;
  --border-2: #3a3a3a;
  --hover: #222;
  --primary: #3b82f6;
  --primary-hi: #60a5fa;
  --primary-soft: #1a2744;
  --green: #22c55e;
  --green-soft: #0d2818;
  --red: #ef4444;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.5);
}

/* Per-section accent — color only, same shapes everywhere */
[data-section="image"] { --primary: #ea580c; --primary-hi: #c2410c; --primary-soft: #fff7ed; }
[data-section="video"] { --primary: #2563eb; --primary-hi: #1d4ed8; --primary-soft: #eff6ff; }
[data-section="audio"] { --primary: #059669; --primary-hi: #047857; --primary-soft: #ecfdf5; }
[data-section="code"]  { --primary: #7c3aed; --primary-hi: #6d28d9; --primary-soft: #f5f3ff; }
[data-section="tools"] { --primary: #0891b2; --primary-hi: #0e7490; --primary-soft: #ecfeff; }

[data-theme="dark"] [data-section="image"] { --primary: #f97316; --primary-hi: #fb923c; --primary-soft: #431a06; }
[data-theme="dark"] [data-section="video"] { --primary: #3b82f6; --primary-hi: #60a5fa; --primary-soft: #1e3a5f; }
[data-theme="dark"] [data-section="audio"] { --primary: #10b981; --primary-hi: #34d399; --primary-soft: #0d3328; }
[data-theme="dark"] [data-section="code"]  { --primary: #8b5cf6; --primary-hi: #a78bfa; --primary-soft: #2e1a4d; }
[data-theme="dark"] [data-section="tools"] { --primary: #22d3ee; --primary-hi: #67e8f9; --primary-soft: #0d3333; }

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- Icons ---------- */
.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-check { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Topbar (legal pages) ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.topbar .logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 18px; }
.topbar .logo svg { flex-shrink: 0; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

/* ---------- Header ---------- */
.header {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 10px 12px; position: relative; gap: 6px;
}
.header-left { display: none; }
.header-right {
  display: flex; align-items: center; gap: 6px;
}
.theme-btn {
  width: 38px; height: 38px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .1s, border-color .15s;
}
.theme-btn:hover { border-color: var(--border-2); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.theme-btn:active { transform: translateY(0); }
.theme-btn .ic { width: 20px; height: 20px; flex-shrink: 0; }
.theme-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.app-title { display: none; }
.app-subtitle { display: none; }
.lang-toggle { display: flex; gap: 2px; background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.lang-btn { border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 700; font-family: inherit; }
.lang-btn.active { background: var(--primary); color: #fff; }
.lang-btn:hover:not(.active) { color: var(--text); }

/* ---------- Main ---------- */
.main { max-width: 620px; margin: 0 auto; padding: 0 20px 60px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; margin-bottom: 20px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer; padding: 10px 8px; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; font-family: inherit;
  flex: 1; min-width: 0; transition: background .15s, color .15s;
}
.tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .ic { width: 16px; height: 16px; flex-shrink: 0; }
@media (min-width: 640px) {
  .tab { padding: 12px 10px; font-size: 15px; gap: 8px; }
  .tab .ic { width: 18px; height: 18px; }
}
.tab.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-md); }
.tab:hover:not(.active) { background: var(--hover); color: var(--text); }

/* ---------- Panels ---------- */
.panel { display: none; }
.panel.active { display: flex; flex-direction: column; animation: fadeIn .15s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border-2); border-radius: var(--radius-lg);
  background: var(--card); padding: 48px 24px; text-align: center; cursor: pointer;
  margin-bottom: 20px; transition: border-color .2s, transform .12s, background .2s;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.dropzone > * { position: relative; z-index: 1; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.dz-icon { width: 48px; height: 48px; color: var(--primary); margin: 0 auto 14px; display: block; }
.dz-text { font-size: 18px; font-weight: 600; }
.dz-sub { color: var(--muted); font-size: 14px; margin-top: 6px; }

/* Code section: terminal-style header bar on the dropzone */
[data-section="code"] .dropzone { text-align: left; padding: 52px 24px 28px; }
[data-section="code"] .dropzone::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 32px;
  background: var(--border); border-bottom: 1px solid var(--border);
  transition: none;
}
[data-section="code"] .dropzone::after {
  content: ""; position: absolute; top: 10px; left: 16px; width: 8px; height: 8px;
  border-radius: 50%; background: #ff5f57; box-shadow: 16px 0 #febc2e, 32px 0 #28c840;
  transition: none;
}

/* ---------- File info ---------- */
.file-info {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; margin-bottom: 16px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow);
}
.file-info::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }

/* ---------- Section label ---------- */
.section-label { font-size: 15px; font-weight: 700; margin-bottom: 10px; margin-top: 6px; }

/* ---------- Presets ---------- */
.presets { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.presets.row { flex-wrap: nowrap; }
.presets.row .preset { flex: 1; min-width: 0; }
.preset {
  border: 1px solid var(--border); background: var(--card); cursor: pointer;
  border-radius: var(--radius); padding: 18px 14px; text-align: center; font-family: inherit;
  transition: border-color .15s, box-shadow .15s, transform .1s;
  display: flex; flex-direction: column; gap: 4px; min-width: 88px; align-items: center;
  box-shadow: var(--shadow);
}
.preset:hover { border-color: var(--border-2); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.preset.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary); }
.preset-name { font-size: 15px; font-weight: 700; color: var(--text); }
.preset-hint { font-size: 12px; color: var(--muted); line-height: 1.35; }
.presets.compact { gap: 6px; margin-bottom: 16px; }
.presets.compact .preset { padding: 10px 18px; min-width: 64px; border-radius: var(--radius-sm); box-shadow: none; }
.presets.compact .preset.active { box-shadow: 0 0 0 1px var(--primary); }
.presets.compact .preset-name { font-size: 13px; font-weight: 600; }

/* ---------- Big input ---------- */
.big-input {
  width: 100%; height: 52px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); font-size: 18px; font-weight: 600;
  padding: 0 16px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.big-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.big-input::placeholder { color: var(--muted); }
.input-note { font-size: 13px; color: var(--muted); margin-top: 6px; margin-bottom: 20px; }

/* ---------- PNG depth slider ---------- */
.png-depth-wrap { margin-bottom: 8px; }
.png-depth-wrap .section-label { margin-bottom: 8px; }
.png-depth-wrap .slider-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.png-depth-wrap .slider-labels span { text-align: center; flex: 1; }

/* ---------- Slider ---------- */
.slider-row { margin-bottom: 24px; }
.slider-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.slider-head .section-label { margin: 0; }
.br-unit { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.fps-input {
  width: 72px; height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700; text-align: center; color: var(--primary);
  background: var(--card); padding: 0 6px; margin-left: 8px; outline: none; -moz-appearance: textfield;
  box-shadow: var(--shadow);
}
.fps-input::-webkit-outer-spin-button, .fps-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.fps-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.slider-value {
  font-size: 20px; font-weight: 800; color: var(--primary);
  background: var(--primary-soft); padding: 4px 14px; border-radius: 999px; min-width: 68px; text-align: center;
}
.big-slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; border-radius: 999px; cursor: pointer;
  background: transparent; margin: 0; padding: 0;
}
.big-slider::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px;
  background: linear-gradient(to right, var(--primary) 0%, var(--primary) var(--pct,50%), var(--border-2) var(--pct,50%), var(--border-2) 100%);
}
.big-slider::-moz-range-track {
  height: 8px; border-radius: 999px;
  background: linear-gradient(to right, var(--primary) 0%, var(--primary) var(--pct,50%), var(--border-2) var(--pct,50%), var(--border-2) 100%);
}
.big-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: var(--card);
  border: 3px solid var(--primary); cursor: grab; box-shadow: var(--shadow-md); transition: transform .12s;
}
.big-slider::-webkit-slider-thumb:active { transform: scale(1.15); }
.big-slider::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--card); border: 3px solid var(--primary); cursor: grab; box-shadow: var(--shadow-md); }
.slider-labels { display: grid; grid-template-columns: 1fr 1fr 1fr; margin-top: 6px; font-size: 12px; color: var(--muted); }
.slider-labels > *:nth-child(1) { text-align: left; }
.slider-labels > *:nth-child(2) { text-align: center; }
.slider-labels > *:nth-child(3) { text-align: right; }

/* ---------- Toggle ---------- */
.big-toggle {
  display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 16px; font-weight: 600;
  margin-bottom: 24px; user-select: none;
}
.big-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-box {
  width: 26px; height: 26px; flex: none; border-radius: var(--radius-sm); border: 2px solid var(--border-2);
  background: var(--card); display: grid; place-items: center; color: #fff; transition: border-color .15s, background .15s;
}
.toggle-box .ic-check { opacity: 0; transform: scale(.4); transition: opacity .12s, transform .12s; }
.big-toggle input:checked + .toggle-box { background: var(--primary); border-color: var(--primary); }
.big-toggle input:checked + .toggle-box .ic-check { opacity: 1; transform: scale(1); }

/* ---------- Buttons ---------- */
.btn-go {
  width: 100%; height: 56px; border: none; border-radius: var(--radius); cursor: pointer;
  background: var(--primary); color: #fff; font-size: 18px; font-weight: 700; font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: var(--shadow-md); transition: transform .15s, box-shadow .15s, background .15s;
}
.btn-go:hover { background: var(--primary-hi); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn-go:active { transform: translateY(0); }
.btn-go:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-again {
  width: 100%; height: 48px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
  background: var(--card); color: var(--muted); font-size: 16px; font-weight: 600; font-family: inherit;
  margin-top: 10px; transition: border-color .15s, color .15s; box-shadow: var(--shadow);
}
.btn-again:hover { border-color: var(--border-2); color: var(--text); }
.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .1s; box-shadow: var(--shadow);
}
.btn-secondary:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn-secondary:active { transform: translateY(0); }

/* ---------- Progress ---------- */
.progress { margin-top: 24px; }
.bar { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.progress-text { text-align: center; color: var(--muted); font-size: 15px; margin-top: 12px; font-weight: 500; }

/* ---------- Result ---------- */
.result { margin-top: 24px; animation: rise .3s ease; }
.stats { display: flex; align-items: stretch; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.stat { flex: 1 1 0; min-width: 0; text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 10px; box-shadow: var(--shadow); }
.stat-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-val { font-size: 20px; font-weight: 800; }
.stat-arrow { align-self: center; font-size: 22px; color: var(--muted); }
.stat-saved { background: var(--green-soft); border-color: var(--green); }
.stat-saved .stat-val { color: var(--green); }
.preview { margin-bottom: 20px; text-align: center; }
.preview img, .preview video { display: block; margin: 0 auto; max-width: 100%; max-height: 70vh; min-width: 280px; object-fit: contain; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }

/* ---------- FPS detected badge ---------- */
.fps-detected { display: inline-flex; align-items: center; margin-left: 8px; padding: 2px 8px; border-radius: 6px; background: var(--green-soft); color: var(--green); font-size: 12px; font-weight: 600; letter-spacing: .3px; white-space: nowrap; vertical-align: middle; line-height: 1.6; }

/* ---------- Slider placeholders ---------- */
.slider-placeholder { display: none; color: var(--muted); font-size: 14px; font-style: italic; opacity: .7; }
.panel:not([data-ready]) .slider-placeholder { display: block; }
.panel:not([data-ready]) .big-slider { opacity: .3; pointer-events: none; }
.panel:not([data-ready]) .slider-head .slider-value,
.panel:not([data-ready]) .br-unit { display: none; }
.panel:not([data-ready]) .slider-labels { display: none; }
.panel:not([data-ready]) .fps-input { display: none; }
.panel:not([data-ready]) .fps-detected { display: none; }

/* ---------- Footer ---------- */
.footer { text-align: center; padding: 28px 20px 48px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--border); }
.footer a { color: var(--primary); text-decoration: none; margin: 0 4px; }
.footer a:hover { text-decoration: underline; }
.footer-links { display: flex; gap: 12px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.footer-card {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); font-weight: 600; font-size: 14px;
  text-decoration: none; box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
}
.footer-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 99; background: var(--red); color: #fff; font-size: 16px; font-weight: 600; padding: 12px 22px; border-radius: var(--radius); box-shadow: var(--shadow-lg); animation: rise .2s ease; }

/* ---------- Code / text areas ---------- */
.code-wrap { margin-bottom: 20px; }
.code-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; }
.code-select { height: 40px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card); color: var(--text); font-family: inherit; font-size: 14px; padding: 0 12px; cursor: pointer; min-width: 120px; box-shadow: var(--shadow); }
.code-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.code-textarea { width: 100%; min-height: 200px; max-height: 60vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text); font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 14px; padding: 16px; resize: none; line-height: 1.55; tab-size: 4; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.code-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.code-textarea::placeholder { color: var(--muted); opacity: .5; }
.code-compress-slider { margin: 0 0 24px; }

/* ---------- Language popup ---------- */
.lang-popup { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.lang-popup.hidden { display: none; }
.lang-popup-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
.lang-popup-card { position: relative; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 320px; max-width: 90vw; max-height: 75vh; display: flex; flex-direction: column; padding: 16px; box-shadow: var(--shadow-lg); animation: rise .2s ease; }
.lang-search { width: 100%; height: 40px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font-family: inherit; font-size: 15px; padding: 0 14px; margin-bottom: 12px; outline: none; flex: none; transition: border-color .15s, box-shadow .15s; }
.lang-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.lang-search::placeholder { color: var(--muted); }
.lang-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.lang-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-radius: var(--radius-sm); cursor: pointer; border: none; background: transparent; font-family: inherit; text-align: left; color: var(--text); font-size: 15px; transition: background .1s; }
.lang-item:hover { background: var(--hover); }
.lang-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.lang-item-name { font-weight: 600; }
.lang-item-code { font-size: 12px; color: var(--muted); text-transform: uppercase; }

/* ---------- Motion ---------- */
/* Disable transitions during theme toggle to prevent flash */
html.theme-transitioning *, html.theme-transitioning *::before, html.theme-transitioning *::after { transition: none !important; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
.tab, .preset, .btn-go, .dropzone, .slider-value, .btn-again, .toggle-box, .btn-secondary { transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease, background .15s ease; }
.bar-fill { transition: width .25s ease; }

/* ---------- Touch ---------- */
button, label, .dropzone, .preset { touch-action: manipulation; }
input[type="range"] { touch-action: pan-y; }

/* ---------- Responsive ---------- */
@media (min-width: 768px) {
  .main { max-width: 760px; }
  .tab { font-size: 16px; padding: 14px 10px; }
  .dropzone { padding: 60px 32px; }
  .dz-text { font-size: 20px; }
  .preset { padding: 22px 16px; }
  .preset-name { font-size: 17px; }
}

@media (max-width: 767px) {
  .header { padding: 8px 12px; }
  .main { padding: 0 16px 50px; }
  .tab { font-size: 15px; padding: 12px 6px; gap: 6px; }
  .tab .ic { width: 18px; height: 18px; }
  .dropzone { padding: 36px 18px; }
  .dz-text { font-size: 17px; }
  .dz-sub { font-size: 13px; }
  .preset { padding: 14px 10px; }
  .preset-name { font-size: 14px; }
  .preset-hint { font-size: 11px; }
  .btn-go { height: 52px; font-size: 17px; }
  .section-label { font-size: 14px; }
  .slider-value { font-size: 18px; padding: 3px 12px; min-width: 60px; }
  .big-slider::-webkit-slider-thumb { width: 30px; height: 30px; }
  .big-slider::-moz-range-thumb { width: 30px; height: 30px; }
  .big-input { height: 48px; font-size: 17px; }
  .stats { flex-wrap: wrap; }
  .stat { min-width: calc(50% - 5px); padding: 14px 8px; }
  .stat-label { font-size: 11px; }
  .stat-val { font-size: 17px; }
  .stat-arrow { display: none; }
  .preview img, .preview video { min-width: 200px; }
  .toast { font-size: 14px; padding: 10px 18px; left: 16px; right: 16px; transform: none; text-align: center; }
}

@media (max-width: 479px) {
  .header { padding: 8px 10px; }
  .theme-btn { width: 32px; height: 32px; }
  .theme-btn .ic { width: 16px; height: 16px; }
  .main { padding: 0 12px 40px; }
  .tabs { gap: 2px; padding: 3px; }
  .tab { font-size: 12px; padding: 8px 2px; gap: 3px; flex-direction: column; min-width: 0; }
  .tab .ic { width: 16px; height: 16px; }
  .presets:not(.row) { flex-direction: column; gap: 8px; }
  .dropzone { padding: 28px 14px; border-width: 2px; }
  .dz-text { font-size: 16px; }
  .dz-sub { font-size: 12px; }
  .preset { padding: 12px 10px; flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
  .preset-name { font-size: 15px; }
  .preset-hint { font-size: 11px; }
  .btn-go { height: 50px; font-size: 16px; border-radius: var(--radius); }
  .btn-again { height: 44px; font-size: 15px; }
  .section-label { font-size: 14px; margin-bottom: 8px; }
  .slider-value { font-size: 16px; padding: 3px 10px; min-width: 52px; }
  .slider-labels { font-size: 11px; }
  .big-input { height: 46px; font-size: 16px; }
  .stats { gap: 8px; }
  .stat { min-width: calc(50% - 4px); padding: 10px 6px; border-radius: var(--radius-sm); }
  .stat-label { font-size: 10px; }
  .stat-val { font-size: 15px; }
  .preview img, .preview video { min-width: 140px; max-height: 50vh; border-radius: var(--radius-sm); }
  .footer { font-size: 13px; padding: 20px 16px 36px; }
  .toast { font-size: 13px; padding: 10px 14px; }
}

@media (max-width: 359px) {
  .tab span { display: none; }
  .tab { padding: 12px; }
  .tab .ic { width: 20px; height: 20px; }
  .preset { padding: 10px 8px; }
  .preset-name { font-size: 14px; }
  .preset-hint { font-size: 10px; }
}

/* ---------- Tools section ---------- */
.tool-tabs {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; margin-bottom: 20px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.tool-tab {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer; padding: 10px 14px; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
  font-family: inherit; white-space: nowrap; flex: 1 1 auto;
  text-decoration: none; transition: background .15s, color .15s;
}
.tool-tab .ic { width: 18px; height: 18px; flex: none; }
.tool-tab.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-md); }
.tool-tab:hover:not(.active) { background: var(--hover); color: var(--text); }
.tool-area { display: none; padding: 24px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.tool-area.active { display: flex; flex-direction: column; }
.tool-area .section-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 10px; }
.tool-area .dropzone { margin-bottom: 20px; }
.tool-mode-toggle { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; margin: 16px auto 20px; width: fit-content; max-width: 100%; box-shadow: var(--shadow); }
.tool-mode { flex: 0 0 auto; padding: 10px 28px; border: none; background: var(--bg); color: var(--muted); font-weight: 600; cursor: pointer; font-size: 14px; white-space: nowrap; font-family: inherit; transition: background .15s, color .15s; }
.tool-mode.active { background: var(--primary); color: #fff; }
.tool-mode:hover:not(.active) { background: var(--hover); color: var(--text); }
.tool-area .code-textarea { width: 100%; margin-bottom: 12px; min-height: 80px; max-height: 200px; }
.tool-area .btn-go { margin-bottom: 12px; }
.urlencode-result-wrap { position: relative; }
.btn-copy-sm { position: absolute; top: 10px; right: 10px; padding: 6px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card); color: var(--muted); font-weight: 600; cursor: pointer; font-size: 12px; transition: border-color .15s, background .15s, color .15s; z-index: 2; box-shadow: var(--shadow); }
.btn-copy-sm:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
#tool-stats { margin-bottom: 16px; }
#tool-download-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
#tool-download-btns .btn-go { flex: none; }

/* ---------- Preview overlay ---------- */
.preview-overlay {
  position: fixed; inset: 0; z-index: 9999; background: rgba(0,0,0,.88);
  display: none; flex-direction: column; backdrop-filter: blur(6px);
}
.preview-overlay.open { display: flex; }
.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: rgba(0,0,0,.5); border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}
.preview-toolbar-title { font-size: 14px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.preview-toolbar-actions { display: flex; gap: 6px; }
.preview-btn {
  width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.2); border-radius: var(--radius-sm);
  background: rgba(255,255,255,.08); color: #fff; cursor: pointer; font-size: 18px;
  display: grid; place-items: center; transition: border-color .15s, background .15s; font-family: inherit;
}
.preview-btn:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); }
.preview-btn.close-btn { background: rgba(239,68,68,.15); border-color: rgba(239,68,68,.35); }
.preview-btn.close-btn:hover { background: rgba(239,68,68,.35); }
.preview-viewport { flex: 1; overflow: hidden; cursor: grab; position: relative; touch-action: none; background: #0a0a0a; }
.preview-viewport.dragging { cursor: grabbing; }
#preview-content { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
#preview-content img { display: block; max-width: none; max-height: none; }
#preview-content svg { display: block; max-width: none; max-height: none; }
.preview-zoom-badge {
  position: absolute; bottom: 16px; right: 16px; padding: 6px 14px;
  background: rgba(0,0,0,.7); color: #fff; border-radius: var(--radius-sm); font-size: 13px;
  font-weight: 600; pointer-events: none; backdrop-filter: blur(4px);
}

/* ---------- Tool description ---------- */
.tool-desc {
  font-size: 14px; line-height: 1.6; color: var(--muted);
  margin: 28px 0 0; padding: 14px 0 0; border-top: 1px solid var(--border);
  order: 99;
}

/* ---------- URL Encode textarea ---------- */
.url-textarea {
  width: 100%; min-height: 120px; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
  font-size: 13px; line-height: 1.6; resize: none; outline: none; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.url-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.url-textarea[readonly] { opacity: .8; cursor: default; }
.url-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 16px 0 12px; }
.url-actions .btn-go, .url-actions .btn-secondary, .url-actions .btn-again {
  display: inline-flex; align-items: center; gap: 6px;
  width: auto; flex: 0 0 auto; height: 44px; font-size: 15px; padding: 0 20px;
}

/* ---------- Resolution row ---------- */
.resolution-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 16px; flex-wrap: wrap; }
.res-input {
  width: 100px; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-size: 14px; text-align: center; outline: none; -moz-appearance: textfield;
  box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.res-input::-webkit-outer-spin-button, .res-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.res-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.res-lock {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: opacity .15s, background .15s;
}
.res-lock:hover { background: var(--primary-soft); }
.res-lock .ic { width: 18px; height: 18px; }

/* ---------- Custom audio player ---------- */
.audio-player {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin: 0 auto; max-width: 460px;
  box-shadow: var(--shadow);
}
.audio-player .ap-btn {
  width: 44px; height: 44px; border: none; border-radius: 50%; flex: none;
  background: var(--primary); color: #fff; cursor: pointer;
  display: grid; place-items: center; box-shadow: var(--shadow-md);
  transition: transform .12s, box-shadow .15s;
}
.audio-player .ap-btn:hover { transform: scale(1.06); box-shadow: var(--shadow-lg); }
.audio-player .ap-btn:active { transform: scale(1); }
.audio-player .ap-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.audio-player .ap-track { height: 8px; background: var(--border); border-radius: 999px; cursor: pointer; position: relative; overflow: hidden; }
.audio-player .ap-progress { height: 100%; width: 0%; background: var(--primary); border-radius: 999px; }
.audio-player .ap-time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.res-unit { font-size: 13px; color: var(--muted); }

/* ---------- Categorized tool nav ---------- */
.tool-nav { margin-bottom: 20px; }
.tool-nav-group { margin-bottom: 12px; }
.tool-nav-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; padding-left: 4px; }
.tool-nav-group .tool-tabs { margin-bottom: 0; padding: 4px; }
.tool-nav-group .tool-tab { padding: 8px 12px; font-size: 13px; }
@media (max-width: 767px) {
  .tool-nav-group .tool-tab { padding: 6px 8px; font-size: 11px; gap: 4px; }
  .tool-nav-group .tool-tab .ic { width: 16px; height: 16px; }
  .tool-nav-label { font-size: 10px; margin-bottom: 4px; }
  .tool-nav-group .tool-tabs { gap: 4px; }
}
@media (max-width: 480px) {
  .tool-nav-group .tool-tab { padding: 6px 6px; font-size: 10px; }
  .tool-nav-group .tool-tab .ic { width: 14px; height: 14px; }
}
/* ---------- Tool page overrides (data-section="tools" only) ---------- */
/* Wider content area for text-based tools — original compressor pages keep 620px */
[data-section="tools"] { max-width: 760px; }
@media (min-width: 768px) {
  [data-section="tools"] { max-width: 820px; }
}

/* Stats grid: wrap to 3 columns on tool pages with 6+ stats */
[data-section="tools"] .stats { gap: 8px; }
[data-section="tools"] .stat { min-width: calc(33.333% - 6px); flex: 1 1 calc(33.333% - 6px); }
[data-section="tools"] .stat-label { line-height: 1.3; min-height: 2.6em; display: flex; align-items: center; justify-content: center; }

/* Tool description: closer to content, less isolated */
[data-section="tools"] .tool-desc {
  margin: 20px 0 0; padding: 12px 0 0; font-size: 13px; line-height: 1.55;
}

/* Action buttons: align right instead of centered floating */
[data-section="tools"] .url-actions {
  justify-content: flex-end; margin: 12px 0 8px;
}

/* Section labels on tool pages: slightly more spacing */
[data-section="tools"] .section-label { margin-top: 8px; }

/* Responsive stat wrapping for tool pages */
@media (max-width: 600px) {
  [data-section="tools"] .stat { min-width: calc(50% - 4px); flex: 1 1 calc(50% - 4px); }
  [data-section="tools"] .stat-label { font-size: 11px; }
  [data-section="tools"] .stat-val { font-size: 17px; }
}
@media (max-width: 400px) {
  [data-section="tools"] .stat { min-width: 100%; flex: 1 1 100%; }
}
