/* =============================================================================
   DESIGN TOKENS
   ========================================================================== */
:root {
  /* Superfícies e texto */
  --bg: #f7f5ef;
  --panel: #ffffff;
  --panel-alt: #f1eee3;
  --border: #e4e0d2;
  --text: #211f1a;
  --text-dim: #55524a;
  --text-faint: #a29d8c;
  --accent: #4338ca;
  --accent-soft: rgba(67, 56, 202, 0.1);
  --accent-border: rgba(67, 56, 202, 0.5);

  /* Player (tema escuro) */
  --video-bg: #000000;
  --video-panel: #14161b;
  --video-border: #262b38;
  --video-text: #9aa0ae;

  /* Marcações (highlights) */
  --mark-yellow: #fde68a;
  --mark-yellow-active: #fde68a;
  --mark-green: #dcfce7;
  --mark-green-active: #bbf7d0;
  --mark-pink: #fce7f3;
  --mark-pink-active: #fbcfe8;
  --mark-blue: #dbeafe;
  --mark-blue-active: #bfdbfe;

  /* Tipografia */
  --font-mono: "SF Mono", "Cascadia Code", "Consolas", ui-monospace, monospace;
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;

  --fs-2xs: 0.656rem; /* 10.5px */
  --fs-xs: 0.6875rem; /* 11px   */
  --fs-sm: 0.75rem; /* 12px   */
  --fs-sm-md: 0.78rem; /* 12.5px */
  --fs-md: 0.8125rem; /* 13px   */
  --fs-input: 1rem; /* 16px — evita zoom automático em iOS */
  --fs-body: 0.9375rem; /* 15px   */
  --lh-relaxed: 1.75;

  /* Escala de espaçamento (reduzida no mobile via media query) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;

  /* Raio de borda */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  /* Alvo de toque mínimo recomendado (WCAG 2.5.5 / diretrizes mobile) */
  --tap-min: 40px;
}

/* =============================================================================
   RESET & BASE
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* =============================================================================
   LAYOUT
   ========================================================================== */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* respeita a barra de endereço em navegadores mobile */
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr);
  min-height: 0;
}

@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
}

/* =============================================================================
   HEADER / TOOLBAR
   ========================================================================== */
header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
  flex-wrap: wrap;
}

header h1 {
  font-size: var(--fs-md);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  margin: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

.spacer {
  flex: 1;
}

.speed-group {
  display: flex;
  gap: 2px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}

.speed-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}

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

.speed-btn.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.pill-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text-dim);
  font-size: var(--fs-sm-md);
  font-family: var(--font-sans);
  padding: 7px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s,
    background 0.15s;
  white-space: nowrap;
}

.pill-btn.on {
  border-color: var(--accent-border);
  color: var(--accent);
  background: #fff;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.pill-btn.on .pill-dot {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-border);
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: var(--fs-sm);
  cursor: pointer;
  text-decoration: underline;
  padding: var(--space-1) 2px;
  font-family: var(--font-sans);
}

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

/* Alvo de toque maior em telas de toque, sem aumentar o espaçamento externo */
@media (max-width: 860px) {
  header {
    padding: var(--space-2) var(--space-3);
    padding-top: max(var(--space-2), env(safe-area-inset-top));
    gap: var(--space-2) 6px;
  }

  .speed-btn,
  .pill-btn,
  .text-btn {
    min-height: var(--tap-min);
  }

  .speed-btn {
    padding: 8px 11px;
  }

  .pill-btn {
    padding: 8px 12px;
  }
}

/* =============================================================================
   VIDEO PANE
   ========================================================================== */
.video-pane {
  background: var(--video-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.part-tabs {
  display: flex;
  gap: 2px;
  padding: var(--space-2) 10px;
  background: var(--video-panel);
  border-bottom: 1px solid var(--video-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.part-tab {
  border: none;
  background: transparent;
  color: var(--video-text);
  font-family: var(--font-sans);
  font-size: var(--fs-sm-md);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
  white-space: nowrap;
}

.part-tab:hover {
  color: #fff;
}

.part-tab.active {
  background: var(--video-border);
  color: #fff;
  font-weight: 600;
}

#vimeo-player-host {
  flex: 1;
  min-height: 0;
  background: var(--video-bg);
}

#vimeo-player {
  width: 100%;
  height: 100%;
  background: var(--video-bg);
}

#vimeo-player iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}

.video-meta {
  padding: 10px var(--space-4);
  font-size: var(--fs-sm);
  color: var(--video-text);
  font-family: var(--font-mono);
  background: var(--video-panel);
  border-top: 1px solid var(--video-border);
}

@media (max-width: 860px) {
  .video-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* aspect-ratio mantém o vídeo proporcional em qualquer largura de tela,
     em vez de uma min-height fixa que sobra ou falta espaço */
  #vimeo-player-host {
    flex: none;
    aspect-ratio: 16 / 9;
  }

  .part-tab {
    min-height: var(--tap-min);
    display: inline-flex;
    align-items: center;
  }

  .video-meta {
    padding: var(--space-2) var(--space-3);
  }
}

/* =============================================================================
   TRANSCRIPT PANE
   ========================================================================== */
.transcript-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
}

.transcript-toolbar {
  padding: var(--space-3) 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.transcript-toolbar input {
  width: 100%;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  /* 16px evita o zoom automático do Safari/iOS ao focar o campo */
  font-size: var(--fs-input);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  outline: none;
  font-family: var(--font-sans);
}

.transcript-toolbar input::placeholder {
  color: var(--text-faint);
}

.transcript-toolbar input:focus {
  border-color: var(--accent-border);
}

.match-count {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  margin-top: 6px;
  font-family: var(--font-mono);
  min-height: 14px;
}

.transcript-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-5);
  padding-bottom: max(var(--space-5), env(safe-area-inset-bottom));
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  .transcript-list {
    scroll-behavior: auto;
  }
}

@media (max-width: 860px) {
  .transcript-toolbar {
    padding: var(--space-3) var(--space-3);
  }

  .transcript-list {
    padding: var(--space-4) var(--space-3);
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  }
}

/* ---------- texto corrido ---------- */
.para {
  margin: 0 0 var(--space-5) 0;
  font-size: var(--fs-body);
  line-height: var(--lh-relaxed);
  color: var(--text-dim);
}

@media (max-width: 860px) {
  .para {
    /* levemente maior no celular: compensa a distância de leitura e melhora
       a legibilidade em telas pequenas */
    font-size: 1rem; /* 16px */
    line-height: 1.7;
    margin-bottom: var(--space-4);
  }
}

.para-ts {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text-faint);
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 7px;
  margin-right: 9px;
  vertical-align: 2px;
  cursor: pointer;
  user-select: none;
}

.para-ts:hover {
  color: var(--accent);
  border-color: var(--accent-border);
}

.sentence {
  cursor: pointer;
  border-radius: 3px;
  transition:
    background-color 0.15s,
    color 0.15s;
}

.sentence:hover {
  background: var(--panel-alt);
}

.sentence:hover::after {
  content: "✎";
  margin-left: 4px;
  color: var(--text-faint);
  font-size: var(--fs-xs);
}

.sentence.hidden {
  display: none;
}

.sentence mark {
  background: var(--mark-yellow);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

.sentence.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

.sentence.mark-yellow {
  background: var(--mark-yellow);
}
.sentence.mark-green {
  background: var(--mark-green);
}
.sentence.mark-pink {
  background: var(--mark-pink);
}
.sentence.mark-blue {
  background: var(--mark-blue);
}

.sentence.active.mark-yellow {
  background: var(--mark-yellow-active);
}
.sentence.active.mark-green {
  background: var(--mark-green-active);
}
.sentence.active.mark-pink {
  background: var(--mark-pink-active);
}
.sentence.active.mark-blue {
  background: var(--mark-blue-active);
}

.transcript-list::-webkit-scrollbar {
  width: 8px;
}

.transcript-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.transcript-list::-webkit-scrollbar-track {
  background: transparent;
}

/* =============================================================================
   POPOVER DE MARCAÇÃO
   ========================================================================== */
.mark-popover {
  position: fixed;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 28px rgba(30, 25, 10, 0.16);
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 172px;
}

.mark-popover .swatches {
  display: flex;
  gap: 6px;
}

.mark-popover .swatch {
  width: 28px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  padding: 0;
}

.mark-popover .swatch:hover {
  transform: translateY(-1px);
}

.swatch.c-yellow {
  background: var(--mark-yellow-active);
}
.swatch.c-green {
  background: var(--mark-green-active);
}
.swatch.c-pink {
  background: var(--mark-pink-active);
}
.swatch.c-blue {
  background: var(--mark-blue-active);
}

.swatch.c-none {
  background: #fff;
  color: #b0aba0;
  font-size: var(--fs-xs);
  line-height: 16px;
}

.mark-popover .goto-btn {
  font-size: var(--fs-sm-md);
  border: none;
  background: var(--panel-alt);
  color: var(--text);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-sans);
}

.mark-popover .goto-btn:hover {
  background: var(--border);
}

/* Alvos de toque maiores para o popover em telas pequenas */
@media (max-width: 860px) {
  .mark-popover .swatch {
    width: 36px;
    height: 28px;
  }

  .mark-popover .goto-btn {
    padding: var(--space-2) var(--space-3);
    min-height: var(--tap-min);
  }
}
