/* Català ASR — la mateixa lectura que Subtítol Live, adaptada al mòbil.
   Paper #FAFAFA / tinta #111 (clar per defecte), Inter Medium, tracking -0,031em,
   interlineat 1,25, text ancorat a baix que s'esvaeix en sortir per dalt, cursor quiet
   i el camp de soroll taronja com a panell decoratiu.
   Vertical (iPhone): shader a dalt, lectura a sota. Horitzontal: com l'app, 68 / 32. */

@font-face {
  font-family: "Inter";
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  src: url("/fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Inter";
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  src: url("/fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* ReadingTheme.light */
  --ink: #111111;
  --paper: #fafafa;
  --canvas: #f2f2f2;
  --pitch: 1.25;               /* AppVisualMetrics.lineHeightRatio */
  --fs: clamp(32px, 9.9vw, 64px);
  --deco: #ff6b00;             /* color de reserva del shader */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

:root[data-theme="dark"] {
  /* ReadingTheme.dark */
  --ink: #f2f2f2;
  --paper: #121212;
  --canvas: #0b0b0b;
}

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

html, body {
  height: 100%;
  background: var(--paper);
}

body {
  color: var(--ink);
  font-family: "Inter", -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ------------------------------------------------------------------ */
/*  Disposició                                                         */
/* ------------------------------------------------------------------ */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: clamp(150px, 30%, 320px) minmax(0, 1fr);
  grid-template-areas: "deco" "reader";
  background: var(--paper);
  cursor: pointer;
}

#reader {
  grid-area: reader;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--paper);
  font-size: var(--fs);
  /* el text s'esvaeix quan el roll-up l'empeny fora: 0,75 línies de banda (exitBand) */
  padding:
    calc(var(--fs) * 0.6)
    calc(max(24px, 6vw) + var(--safe-r))
    calc(max(var(--safe-b), 12px) + 11vh)
    calc(max(24px, 6vw) + var(--safe-l));
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--fs) * 1.3));
  mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--fs) * 1.3));
}

#deco {
  grid-area: deco;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--deco);
}

#viz {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

@media (orientation: landscape) {
  :root { --fs: clamp(30px, min(5vw, 7.8vh), 84px); }

  #app {
    grid-template-rows: 1fr;
    grid-template-columns: minmax(0, 68fr) minmax(0, 32fr); /* 870 / 1280 */
    grid-template-areas: "reader deco";
  }

  #reader {
    padding:
      max(24px, 12vh)
      max(28px, 5.5vw)
      calc(max(var(--safe-b), 16px) + 12vh)
      calc(max(28px, 5.5vw) + var(--safe-l));
  }
}

/* ------------------------------------------------------------------ */
/*  Lectura                                                            */
/* ------------------------------------------------------------------ */

#lines {
  font-size: 1em;
  font-weight: 500;                    /* Inter Medium */
  line-height: var(--pitch);
  letter-spacing: -0.031em;
  word-spacing: 0.04em;                /* ~0,27em entre paraules, com l'app */
  font-feature-settings: "kern" 1, "calt" 1;
  overflow-wrap: break-word;
  hyphens: manual;
  will-change: transform;
}

#lines.rolling {
  transition: transform 240ms ease-out;
}

.status {
  opacity: 0.55;
}

.w-new {
  animation: appear 110ms linear both;
}

@keyframes appear {
  from { opacity: 0; }
}

/* cursor quiet: no parpelleja. És un inline no atòmic amb un U+2060 (word joiner)
   a dins, així mai no pot quedar sol en una línia nova. 0,05em × ~0,78em. */
.caret {
  display: inline;
  font-size: 0.64em;
  margin-left: 0.12em;
  border-left: 0.078em solid var(--ink);
  opacity: 0.45;
  vertical-align: 0.02em;
}

.caret[hidden] { display: none; }

/* ------------------------------------------------------------------ */
/*  Controls sobre el shader (com el menú de perfil de l'app)          */
/* ------------------------------------------------------------------ */

.controls {
  position: absolute;
  top: calc(var(--safe-t) + 14px);
  right: calc(var(--safe-r) + 14px);
  display: flex;
  gap: 8px;
  align-items: center;
}

@media (orientation: landscape) {
  .controls { top: calc(var(--safe-t) + 20px); right: calc(var(--safe-r) + 20px); }
}

.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  color: color-mix(in srgb, var(--ink) 72%, transparent);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 999px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: transform 120ms ease-out;
}

/* zona tàctil de 44 pt sense engrandir la píndola */
.pill::after {
  content: "";
  position: absolute;
  inset: -6px -4px;
}

.pill:active { transform: scale(0.96); }

.pill:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.pill.round {
  width: 32px;
  padding: 0;
  justify-content: center;
}

/* icona de tema: mig disc */
.pill.round span {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

.dot {
  display: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  transition: opacity 120ms linear, background-color 120ms linear;
}

.pill[data-state="live"] .dot,
.pill[data-state="sending"] .dot,
.pill[data-state="connecting"] .dot {
  display: block;
}

.pill[data-state="sending"] .dot {
  opacity: 1;
  background: #ff5a00;
}

.pill[data-state="connecting"] .dot {
  animation: pulse 900ms ease-in-out infinite alternate;
}

@keyframes pulse {
  to { opacity: 0.9; }
}

/* ------------------------------------------------------------------ */
/*  Diagnòstic (?debug)                                               */
/* ------------------------------------------------------------------ */

#debug {
  position: fixed;
  left: calc(var(--safe-l) + 8px);
  top: calc(var(--safe-t) + 56px);
  max-width: calc(100vw - 16px);
  padding: 8px 10px;
  font: 11px/1.35 ui-monospace, "SF Mono", Menlo, monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 8px;
  white-space: pre-wrap;
  pointer-events: none;
  z-index: 10;
}

#debug[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  #lines.rolling { transition: none; }
  .w-new { animation: none; }
}
