:root {
  --bg: #0C0E16;
  --panel: #171B29;
  --violet: #7C3AED;
  --sky: #38BDF8;
  --text: #F5F7FA;
  --muted: #A7B0C0;
  --line: rgba(167, 176, 192, 0.18);
  --warn: #FBBF24;
  --danger: #F87171;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
}

main { flex: 1; }

h1, h2, p { margin: 0; overflow-wrap: anywhere; }

a { color: inherit; }

.container {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding-inline: 20px;
}

/* Fokus */
:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 3px;
  border-radius: 6px;
}
[tabindex="-1"]:focus { outline: none; }

:root { color-scheme: dark; }

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  padding: 10px 14px;
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  z-index: 10;
}
.skip-link:focus { top: 12px; }

/* Header */
.site-header { border-bottom: 1px solid var(--line); }

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding-block: 14px;
}

.brand {
  display: inline-flex;
  flex: none;
  align-items: center;
  text-decoration: none;
}

/* Logo: atrofidagi bo'sh joy kesiladi, nisbat saqlanadi */
.brand-logo {
  display: none;
  position: relative;
  height: 36px;
  aspect-ratio: 1465 / 358;
  overflow: hidden;
}
.brand-logo img {
  position: absolute;
  width: 148.3%;
  height: auto;
  left: -23.9%;
  top: -53%;
  max-width: none;
  mix-blend-mode: lighten; /* logo fonidagi sezilar-sezilmas farq sayt foniga singadi */
}
.brand.has-logo .brand-logo { display: block; }
.brand.has-logo .brand-text { display: none; }

.brand-text {
  font-size: 1.5rem;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.main-nav { display: flex; gap: 4px; min-width: 0; }

.main-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  white-space: nowrap;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}
.main-nav a:hover { color: var(--text); background: var(--panel); }
.main-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--sky);
}

/* Tanishtiruv */
.hero { padding: 48px 0 32px; }

.hero h1, .section-head h1 {
  font-size: clamp(2rem, 6vw, 3.25rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-weight: 700;
  max-width: 20ch;
}

.lead {
  margin: 16px 0 28px;
  max-width: 52ch;
  font-size: 1.125rem;
  color: var(--muted);
}

/* Tugmalar */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 22px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--violet); color: #fff; }
.btn-sky { background: var(--sky); color: var(--bg); }
.btn-ghost {
  min-height: 44px;
  padding: 8px 16px;
  border-color: var(--line);
  color: var(--text);
  background: transparent;
}
.btn-ghost:hover { background: var(--panel); filter: none; }

/* Kartalar */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding-bottom: 72px;
}

.card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--violet);
  border-radius: var(--radius);
}
.card-photo { border-top-color: var(--sky); }

.card h2 { font-size: 1.375rem; line-height: 1.3; }
.card p { color: var(--muted); }
.card .btn { margin-top: auto; }
.card p + .btn { margin-top: 12px; }

.badge {
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8125rem;
  color: var(--sky);
}

/* Bosh sahifa */
.hero h1 { max-width: none; font-size: clamp(2rem, 7.5vw, 3.25rem); line-height: 1.1; }
.hero h1 .line { display: block; }
.hero .lead { margin: 14px 0 24px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }

.grid.home-grid { padding-bottom: 24px; }
.tool-visual {
  position: relative;
  align-self: stretch;
  height: 84px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.tool-visual svg { display: block; height: 100%; width: auto; max-width: 100%; }
.tool-visual .badge { position: absolute; top: 10px; right: 10px; background: var(--panel); }
.card-audio .wave { stroke: var(--violet); }
.card-photo .subject { fill: var(--sky); }
.card-photo .frame { stroke: var(--sky); }

.home-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 64ch;
  padding-bottom: 64px;
  font-size: 0.9375rem;
  color: var(--muted);
}
.home-note svg { flex: none; margin-top: 4px; color: var(--sky); }

/* Bo'lim sarlavhasi */
.section-head { padding: 40px 0 32px; }
.section-head h1 { margin-top: 28px; }
.section-head .lead { margin-bottom: 0; }

/* Matndan ovoz */
.tool {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding-bottom: 72px;
}
.tool > * { min-width: 0; }

.panel { align-items: stretch; gap: 20px; }
.panel .badge { align-self: flex-start; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-weight: 600; }

textarea, select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}
textarea { min-height: 160px; resize: vertical; }
textarea::placeholder { color: var(--muted); }
select { min-height: 48px; }
textarea:hover, select:hover { border-color: var(--muted); }
textarea:focus-visible, select:focus-visible { border-color: var(--sky); }

.counter { align-self: flex-end; font-size: 0.875rem; color: var(--muted); }
.counter.is-warn { color: var(--warn); font-weight: 700; }
.hint { font-size: 0.875rem; color: var(--muted); }

.btn-row { display: flex; flex-wrap: wrap; gap: 12px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn[hidden] { display: none; }
#tts-cancel:focus-visible, #bg-cancel:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

/* "hidden" atributi display beruvchi sinflardan ustun bo'lsin */
[hidden] { display: none !important; }

.status {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
  border-left: 3px solid var(--sky);
  background: var(--bg);
  border-radius: 6px;
  color: var(--text);
}
.card .status p { color: var(--text); }
.card .status .hint { color: var(--muted); }
.status-label { margin-right: 6px; color: var(--sky); }
.status[data-state="busy"] { border-left-color: var(--violet); }
.status[data-state="busy"] .status-label { color: var(--text); }
.status[data-state="done"] { border-left-color: var(--sky); }
.status[data-state="error"] { border-left-color: var(--danger); }
.status[data-state="error"] .status-label { color: var(--danger); }

progress {
  width: 100%;
  height: 8px;
  accent-color: var(--violet);
}

/* Natija */
.result { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.result .hint + .hint { margin-top: -6px; }
.result audio { width: 100%; }
.card .result .btn { margin-top: 0; align-self: flex-start; }

/* Fonni olib tashlash */
.file-input {
  width: 100%;
  min-height: 56px;
  padding: 8px;
  background: var(--bg);
  color: var(--muted);
  border: 1px dashed var(--muted);
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}
.file-input:hover { border-color: var(--sky); }
.file-input:focus-visible { border-color: var(--sky); }
.file-input::file-selector-button {
  min-height: 40px;
  margin-right: 12px;
  padding: 0 16px;
  background: var(--sky);
  color: var(--bg);
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.preview { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.preview-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.preview-frame img {
  display: block;
  max-width: 100%;
  max-height: min(360px, 60vh);
  width: auto;
  height: auto;
  object-fit: contain;
}
/* Shaffoflik katakchalari faqat panel fonida; rasmning o'ziga chizilmaydi */
.preview-frame.checker {
  background-color: #1B2030;
  background-image: conic-gradient(#272D40 25%, transparent 0 50%, #272D40 0 75%, transparent 0);
  background-size: 20px 20px;
}
/* Oldin / Keyin taqqoslash: asl rasm pastda, natija tepada (clip-path bilan ochiladi) */
.compare {
  --pos: 50%;
  --ar: 1;
  position: relative;
  width: min(100%, calc(var(--ar) * min(420px, 60vh)));
  aspect-ratio: var(--ar);
  margin-inline: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.compare-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill; /* ikkala rasm bir xil nisbatda; cho'zilmaydi */
  display: block;
  pointer-events: none;
}
.compare-before { position: absolute; inset: 0; clip-path: inset(0 calc(100% - var(--pos)) 0 0); pointer-events: none; }
.compare-label.is-hidden { visibility: hidden; }
.compare-after { position: absolute; inset: 0; clip-path: inset(0 0 0 var(--pos)); }
.compare-after.checker {
  background-color: #1B2030;
  background-image: conic-gradient(#272D40 25%, transparent 0 50%, #272D40 0 75%, transparent 0);
  background-size: 20px 20px;
}
.compare-label {
  position: absolute;
  top: 10px;
  padding: 2px 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
  background: rgba(12, 14, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  pointer-events: none;
}
.compare-label-before { left: 10px; }
.compare-label-after { right: 10px; }
.compare-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 2px;
  transform: translateX(-50%);
  background: var(--sky);
  pointer-events: none;
}
.compare-handle {
  position: absolute;
  top: 50%;
  left: var(--pos);
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sky);
  background: var(--panel);
  border: 2px solid var(--sky);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.18), 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.15s;
  pointer-events: none;
}
.compare:hover .compare-handle { box-shadow: 0 0 0 6px rgba(56, 189, 248, 0.28), 0 2px 8px rgba(0, 0, 0, 0.5); }
/* Haqiqiy (ko'rinmas) range input butun ramkani qoplaydi: sichqoncha, sensor va klaviatura */
.compare-range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: ew-resize;
  touch-action: pan-y; /* vertikal aylantirish ishlayveradi */
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.compare-range::-webkit-slider-runnable-track { height: 100%; background: transparent; }
.compare-range::-moz-range-track { height: 100%; background: transparent; }
.compare-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 1px; height: 100%; border: 0; background: transparent; }
.compare-range::-moz-range-thumb { width: 1px; height: 100%; border: 0; background: transparent; }
.compare:has(.compare-range:focus-visible) .compare-handle { outline: 2px solid var(--text); outline-offset: 3px; }

/* Fon rangi tanlash */
.swatches { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.swatches[hidden] { display: none; }
.swatches legend { padding: 0; margin-bottom: 8px; font-weight: 600; }
.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.swatch { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.swatch-label { position: relative; display: inline-flex; }
.swatch input[type="radio"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.swatch-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.swatch-chip {
  flex: none;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(245, 247, 250, 0.35);
  border-radius: 6px;
}
.chip-white { background: #FFFFFF; }
.chip-black { background: #000000; }
.chip-transparent {
  background-color: #1B2030;
  background-image: conic-gradient(#3A4157 25%, transparent 0 50%, #3A4157 0 75%, transparent 0);
  background-size: 8px 8px;
}
#bg-custom-chip { background: #7c3aed; }
.swatch input:hover + .swatch-box { border-color: var(--sky); }
.swatch input:checked + .swatch-box {
  border: 2px solid var(--sky);
  padding: 5px 11px 5px 7px;
  background: rgba(56, 189, 248, 0.14);
  font-weight: 700;
}
.swatch input:checked + .swatch-box .swatch-text::before { content: "✓ "; color: var(--sky); }
.swatch input:focus-visible + .swatch-box { outline: 2px solid var(--text); outline-offset: 2px; }
.color-input {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.color-input:hover { border-color: var(--sky); }
.card .result .btn[aria-disabled="true"] { opacity: 0.5; cursor: progress; }
.file-meta { display: flex; flex-direction: column; gap: 2px; }
.card .file-meta .file-name { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }

/* Footer */
.site-footer {
  padding: 32px 0;
  border-top: 1px solid var(--line);
}
.site-footer strong { font-size: 1.125rem; }
.site-footer p { color: var(--muted); }

/* Kompyuter */
@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .hero { padding-top: 72px; }
}

/* Forma va natija yonma-yon: faqat yetarli kenglikda (planshet va telefon landshaftida ustma-ust) */
@media (min-width: 900px) {
  .tool { grid-template-columns: 3fr 2fr; align-items: start; }
}

/* Telefon: navigatsiya logodan pastda, to'liq kenglikda */
@media (max-width: 520px) {
  .header-inner { gap: 4px 16px; padding-block: 10px; }
  .brand-logo { height: 32px; }
  .main-nav { width: 100%; }
  .main-nav a { flex: 1 1 auto; justify-content: center; padding: 0 8px; }
  .hero { padding: 28px 0 24px; }
  .lead { margin: 12px 0 20px; font-size: 1.0625rem; }
  .hero .lead { margin: 12px 0 20px; }
  .hero-actions .btn { flex: 1 1 100%; }
  .home-note { padding-bottom: 40px; }
  .section-head { padding: 24px 0 20px; }
  .section-head h1 { margin-top: 16px; }
  .grid, .tool { gap: 16px; padding-bottom: 40px; }
  .card { padding: 20px; }
  .panel { gap: 16px; }
  .swatch-row { display: grid; grid-template-columns: 1fr 1fr; }
  .swatch { display: flex; min-width: 0; }
  .swatch-label { flex: 1; min-width: 0; }
  .swatch-box { width: 100%; }
  .swatch-custom { grid-column: 1 / -1; }
  .btn-primary, .btn-sky { width: 100%; }
  .card .btn { width: 100%; }
  .btn-row .btn { flex: 1 1 100%; }
  .card .result .btn { align-self: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
