:root {
  /* Courbes d'Emil Kowalski */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* Palette monochrome claire */
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-subtle: #f3f3f4;
  --surface-hover: #ececee;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text: #111113;
  --text-secondary: #68686f;
  --text-tertiary: #94949c;
  --accent: #111113;
  --accent-fg: #ffffff;
  --danger: #d92d20;
  --danger-bg: rgba(217, 45, 32, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -4px rgba(0, 0, 0, 0.05);

  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0a;
    --surface: #121214;
    --surface-subtle: #1a1a1d;
    --surface-hover: #222226;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #f4f4f6;
    --text-secondary: #9898a0;
    --text-tertiary: #63636b;
    --accent: #f4f4f6;
    --accent-fg: #0a0a0a;
    --danger: #f97066;
    --danger-bg: rgba(249, 112, 102, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -8px rgba(0, 0, 0, 0.6);
  }
}

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

/* Baseline Mobile-Native */
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
  background-color: var(--bg);
}

input,
textarea,
select {
  font-size: 16px;
  font-family: inherit;
  color: inherit;
}

button,
a,
[role="button"],
[role="radio"] {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  font-family: inherit;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* Layout principal */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

.topbar {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem 0 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

.brand-icon {
  color: var(--text-secondary);
}

.brand-name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.ghost-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    transform 140ms var(--ease-out),
    color 150ms ease,
    background-color 150ms ease;
}

.ghost-btn:active {
  transform: scale(0.97);
}

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem 0 2.5rem;
  transition:
    filter 180ms var(--ease-out),
    opacity 180ms var(--ease-out),
    transform 180ms var(--ease-out);
}

/* Transition d'état adoucie par filter: blur(2px) */
.stage.is-transitioning {
  filter: blur(2px);
  opacity: 0.65;
  transform: scale(0.99);
}

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.375rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

.card-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.card-title {
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.card-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

/* Champs de saisie */
.input {
  width: 100%;
  height: 2.75rem;
  padding: 0 0.875rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, background-color 150ms ease;
}

.input:focus {
  border-color: var(--text);
  background: var(--surface);
}

/* Sélecteur segmenté 3 modes (Recette Emil Kowalski : liste dupliquée + clip-path) */
.mode-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.section-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.section-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.mode-spec {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  transition: filter 160ms ease, opacity 160ms ease;
}

.mode-spec.is-switching {
  filter: blur(2px);
  opacity: 0.6;
}

.segmented {
  position: relative;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.segmented-layer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  height: 2.25rem;
  padding: 0 0.5rem;
  border-radius: calc(var(--radius-md) - 3px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: transform 140ms var(--ease-out), color 150ms ease;
}

.seg-btn:active {
  transform: scale(0.97);
}

.seg-btn:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: -2px;
}

/* Liste d'onglets dupliquée par-dessus et découpée par clip-path */
.segmented-overlay {
  position: absolute;
  inset: 3px;
  pointer-events: none;
  background: var(--accent);
  border-radius: calc(var(--radius-md) - 3px);
  /* Par défaut sur l'onglet du milieu (Équilibré : 33.333% à gauche et à droite) */
  clip-path: inset(0% 33.333% 0% 33.333% round 7px);
  transition: clip-path 220ms var(--ease-in-out);
  will-change: clip-path;
}

.seg-btn-active {
  color: var(--accent-fg);
  font-weight: 600;
}

/* Zone de dépôt de fichier */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  padding: 1.75rem 1.25rem;
  text-align: center;
  cursor: pointer;
  outline: none;
  transition:
    transform 140ms var(--ease-out),
    border-color 150ms ease,
    background-color 150ms ease;
}

.dropzone:active {
  transform: scale(0.99);
}

.dropzone.is-dragover {
  border-color: var(--text);
  background: var(--surface-hover);
}

.dropzone:focus-visible {
  border-color: var(--text);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
}

.dropzone-icon {
  color: var(--text-secondary);
}

.dropzone-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.dropzone-primary {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.dropzone-secondary {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.file-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  text-align: left;
}

.file-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.file-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.icon-btn {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), color 150ms ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Boutons */
.btn {
  height: 2.75rem;
  padding: 0 1.125rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  text-decoration: none;
  transition:
    transform 140ms var(--ease-out),
    opacity 150ms ease,
    background-color 150ms ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-secondary {
  background: var(--surface-subtle);
  border-color: var(--border);
  color: var(--text);
}

.btn-full {
  width: 100%;
}

.btn-flex {
  flex: 1;
}

/* Vue Progression */
.working-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.working-file-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.phase-badge {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.working-filename {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.working-percent {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 180ms linear;
  will-change: transform;
}

.working-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Vue Résultat Avant / Après */
.stats-grid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.stat-value {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-value-strong {
  color: var(--text);
  font-weight: 600;
}

.stat-arrow {
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.stat-badge-wrap {
  margin-left: auto;
}

.saving-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.8125rem;
  font-weight: 600;
}

.player-wrap {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-video {
  width: 100%;
  height: 100%;
  max-height: 280px;
  object-fit: contain;
  display: block;
}

.actions-row {
  display: flex;
  gap: 0.625rem;
}

.error-msg {
  font-size: 0.8125rem;
  color: var(--danger);
  background: var(--danger-bg);
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
}

.footnote {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-align: center;
}

/* Gating des états :hover uniquement pour les pointeurs fins (évite les faux hovers sur mobile) */
@media (hover: hover) and (pointer: fine) {
  .ghost-btn:hover {
    color: var(--text);
    background: var(--surface-subtle);
  }

  .seg-btn:hover {
    color: var(--text);
  }

  .dropzone:hover {
    border-color: var(--text-secondary);
    background: var(--surface-hover);
  }

  .icon-btn:hover {
    color: var(--text);
    border-color: var(--border-strong);
  }

  .btn-primary:hover:not(:disabled) {
    opacity: 0.9;
  }

  .btn-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
  }
}

/* Accessibilité : réduction des mouvements */
@media (prefers-reduced-motion: reduce) {
  .segmented-overlay,
  .stage,
  .btn,
  .seg-btn,
  .dropzone,
  .progress-fill {
    transition-duration: 0.01ms !important;
  }

  .stage.is-transitioning {
    filter: none;
    transform: none;
  }
}

