/* Subtitle Translator: plain CSS, mobile first. Colours are tokens; dark theme overrides them. */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef2ff;
  --on-brand: #ffffff;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --error: #b91c1c;
  --error-soft: #fef2f2;
  --focus: #6366f1;
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08), 0 8px 24px rgb(15 23 42 / 0.06);
  --radius: 12px;
  --header-h: 64px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #0f172a;
  --border: #1f2937;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --brand: #818cf8;
  --brand-hover: #a5b4fc;
  --brand-soft: #1e1b4b;
  --on-brand: #0b1120;
  --success: #4ade80;
  --success-soft: #052e16;
  --error: #f87171;
  --error-soft: #2a0f12;
  --focus: #a5b4fc;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
p { margin: 0; }
a { color: var(--brand); }
[hidden] { display: none !important; }

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

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 16px; top: -48px; z-index: 100;
  padding: 8px 16px; border-radius: 8px;
  background: var(--brand); color: var(--on-brand); text-decoration: none;
}
.skip-link:focus { top: 8px; }

.container { width: 100%; max-width: 72rem; margin: 0 auto; padding: 0 16px; }
.container.narrow { max-width: 48rem; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-row {
  height: var(--header-h);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.05rem;
  min-height: 44px;
}
.brand-icon { color: var(--brand); flex: none; }

.nav-desktop { display: none; justify-content: center; gap: 4px; }
.nav-link {
  padding: 8px 12px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none; font-weight: 500;
  transition: color .15s, background-color .15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-alt); }

.header-actions { display: flex; align-items: center; gap: 4px; justify-self: end; }
.lang-switch { display: flex; gap: 4px; }
.lang-switch-desktop { display: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-muted);
  cursor: pointer; transition: color .15s, background-color .15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-alt); }
.icon-btn.small { width: 44px; height: 44px; }

.flag-btn { font-size: 1.35rem; line-height: 1; opacity: .55; }
.flag-btn[aria-pressed="true"] { opacity: 1; background: var(--brand-soft); }

.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

.mobile-menu { border-top: 1px solid var(--border); background: var(--surface); padding: 8px 0 16px; }
.mobile-menu nav { display: flex; flex-direction: column; }
.mobile-link {
  display: block; padding: 12px 8px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.mobile-link:hover { background: var(--surface-alt); }
.mobile-menu .lang-switch { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.flag-btn-wide {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--text); font: inherit; font-size: 1rem; cursor: pointer;
  opacity: 1;
}
.flag-btn-wide[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }

@media (min-width: 768px) {
  .nav-desktop { display: flex; }
  .lang-switch-desktop { display: flex; }
  .burger { display: none; }
  .mobile-menu { display: none !important; }
}

/* ---------- hero and sections ---------- */
.hero { padding: 48px 0 8px; text-align: center; }
.hero h1 { font-size: clamp(1.75rem, 5vw, 2.75rem); letter-spacing: -0.02em; }
.lead { margin: 16px auto 0; max-width: 40rem; color: var(--text-muted); font-size: 1.075rem; }

.section { padding: 32px 0 64px; }
.section-alt { background: var(--surface-alt); border-top: 1px solid var(--border); padding: 64px 0; }
.section-title { font-size: 1.6rem; text-align: center; }

@media (min-width: 768px) {
  .hero { padding: 72px 0 8px; }
  .section { padding: 40px 0 96px; }
  .section-alt { padding: 96px 0; }
}

/* ---------- card and form ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 24px; }
.card:focus { outline: none; }
.card-title { font-size: 1.25rem; }
@media (min-width: 640px) { .card { padding: 32px; } }

.form { margin-top: 20px; display: grid; gap: 20px; }
.field { display: grid; gap: 8px; }
.label { font-weight: 600; }
.req { color: var(--error); }
.hint { color: var(--text-muted); font-size: .875rem; }
.hint.center { text-align: center; min-height: 1.4em; }
.field-error { color: var(--error); font-size: .875rem; font-weight: 500; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 160px; padding: 24px 16px; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface-alt); cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--brand); background: var(--brand-soft); }
.dropzone:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone.invalid { border-color: var(--error); }
.dropzone-icon { color: var(--brand); }
.dropzone-text { font-weight: 500; }

.file-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 2px 2px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-alt);
}
.file-chip > svg { color: var(--brand); flex: none; }
.file-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-muted); font-size: .875rem; margin-left: auto; flex: none; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%;
  width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg); pointer-events: none;
}
select {
  width: 100%; min-height: 48px; padding: 10px 40px 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
  appearance: none; -webkit-appearance: none; cursor: pointer;
}
select:disabled { opacity: .6; cursor: progress; }
select.invalid { border-color: var(--error); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn:disabled { opacity: .7; cursor: progress; }
.btn-block { width: 100%; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: .875rem; }

.spinner {
  display: none; width: 18px; height: 18px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- alerts and toasts ---------- */
.alert {
  display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap;
  margin-top: 16px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid currentColor;
}
.alert p { flex: 1 1 12rem; color: var(--text); }
.alert-error { color: var(--error); background: var(--error-soft); }
.alert-icon { flex: none; margin-top: 2px; }

.toasts {
  position: fixed; z-index: 60; top: calc(var(--header-h) + 8px); left: 16px; right: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 8px;
  width: 100%; max-width: 24rem; padding: 8px 8px 8px 16px;
  border-radius: 10px; border: 1px solid var(--border); border-left: 4px solid;
  background: var(--surface); box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast p { flex: 1; }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--error); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }
@media (min-width: 768px) {
  .toasts { left: auto; right: 24px; align-items: flex-end; }
}

/* ---------- result ---------- */
.result-head { display: flex; align-items: flex-start; gap: 12px; }
.result-icon { color: var(--success); flex: none; }
.subhead { margin: 24px 0 8px; font-size: .875rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }

.preview { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.preview-row {
  display: grid; grid-template-columns: 1fr; gap: 4px;
  padding: 12px 14px; border-top: 1px solid var(--border);
}
.preview-row:first-child { border-top: 0; }
.preview-header { display: none; }
.preview-time { color: var(--text-muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.preview-original { color: var(--text-muted); white-space: pre-line; }
.preview-translated { font-weight: 500; white-space: pre-line; }
@media (min-width: 640px) {
  .preview-row { grid-template-columns: 5.5rem 1fr 1fr; gap: 16px; }
  .preview-header {
    display: grid; background: var(--surface-alt);
    font-size: .8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em;
  }
}

.actions { display: flex; flex-direction: column-reverse; gap: 12px; margin-top: 24px; }
@media (min-width: 640px) { .actions { flex-direction: row; justify-content: flex-end; } }

/* ---------- how it works ---------- */
.steps {
  list-style: none; margin: 32px 0 0; padding: 0;
  display: grid; gap: 16px;
}
@media (min-width: 768px) { .steps { grid-template-columns: repeat(3, 1fr); gap: 24px; } }
.step {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
}
.step h3 { font-size: 1.1rem; margin-top: 12px; }
.step p { margin-top: 6px; color: var(--text-muted); }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
}
.note { margin: 32px auto 0; max-width: 42rem; text-align: center; color: var(--text-muted); font-size: .9rem; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 24px 0; }
.footer-row {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 12px;
  color: var(--text-muted); font-size: .9rem; text-align: center;
}
.footer-row a { font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
