/* camille — archivo de videoensayos. Distribución heredada de notas8 (texto a
   la izquierda, meta-líneas diminutas en minúsculas con opacidad baja,
   separación por aire, CERO border-radius, botones = texto que se ilumina),
   pero con paleta propia: papel crema, tinta y terracota — luz de página
   impresa en vez del negro/ámbar de notas. Los ensayos van en SERIFA; las
   meta-líneas y la interfaz, en mono pequeña. */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #f6f1e8;
  --surface: #ede5d6;
  --border: #d9cdba;
  --hairline: #e5dbc9;
  --text: #2b2622;
  --text-dim: #6f6255;
  --muted: #a2917f;
  --accent: #b0512f;
  --accent-dim: #8f4226;
  --danger: #a33d2f;
  --mono: 'JetBrains Mono', 'Menlo', monospace;
  --serif: 'Iowan Old Style', 'Palatino', 'Georgia', serif;
}

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

/* el atributo hidden SIEMPRE gana, aunque el elemento tenga display propio */
[hidden] { display: none !important; }

/* lector = solo lectura: todo lo que escribe lleva .writer-only y
   desaparece. El server lo re-valida igual (403). */
body.reader .writer-only { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
}

/* ---------- layout: columna 2/3 pegada a la izquierda ---------- */

.page {
  width: min(66vw, 105ch);
  margin: 0;
  padding: 24px 0 30vh 40px;
}

@media (max-width: 720px) {
  .page { width: auto; padding: 16px 12px 30vh; }
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 14px 40px 10px;
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  z-index: 10;
}

@media (max-width: 720px) {
  .topbar { padding: 12px 12px 8px; }
}

.topbar h1 { font-size: 16px; font-weight: 600; color: var(--accent); }
.cursor { animation: blink 1.2s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* cuaderno ↔ galería */
.view-toggle { display: flex; gap: 14px; align-items: baseline; }
.view-toggle button {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
}
.view-toggle button.active { color: var(--accent); }

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: baseline;
  margin-left: auto;
}

/* ---------- controles: minimal de verdad ---------- */

button, input, textarea {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
}

/* botón = texto en minúsculas que se ilumina. sin borde, sin fondo, sin radius */
button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-dim);
  text-transform: lowercase;
}
button:hover:not(:disabled) { color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }

input[type="text"], input[type="search"], input[type="password"], textarea {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--hairline);
  padding: 6px 0;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus { border-bottom-color: var(--accent-dim); }
input[type="search"] { width: 160px; }

textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.7;
  border: 1px solid var(--hairline);
  padding: 8px 10px;
}

/* textarea que crece con el contenido (autoGrow en app.js):
   sin scroll interno ni asa de resize — el texto largo se lee entero */
textarea.grow { resize: none; overflow: hidden; }

/* ---------- login ---------- */

.login-page { display: grid; place-items: start; min-height: 100vh; padding: 20vh 40px; }
.login-box { width: min(90vw, 320px); display: grid; gap: 16px; }
.login-box h1 { color: var(--accent); font-size: 20px; }
.login-box form { display: grid; gap: 12px; }
.login-box button { justify-self: start; color: var(--accent); }
.error { color: var(--danger); font-size: 13px; }

/* ---------- composer ---------- */

.composer {
  display: grid;
  gap: 18px;
  padding-bottom: 28px;
  margin-bottom: 44px;
  border-bottom: 1px solid var(--hairline);
}

/* en móvil el composer es la zona de trabajo: dedos, no ratón.
   16px en inputs además evita el auto-zoom de iOS al enfocar. */
@media (max-width: 720px) {
  .composer { gap: 22px; padding: 10px 0 34px; }
  .composer input, .composer textarea { font-size: 16px; }
  .composer-bar { gap: 12px 26px; }
  .composer-bar button { font-size: 16px; padding: 10px 0; }
  .draft-block .meta button { padding: 8px 12px; }
}

.composer-bar { display: flex; gap: 12px 18px; align-items: baseline; flex-wrap: wrap; }
.composer-bar button { white-space: nowrap; } /* «● grabar» no se parte en dos líneas */
.spacer { flex: 1; }

/* «● grabar» abre la cámara: acento siempre, es el gesto central de la app */
.record-btn { color: var(--accent); }

.publish-btn { color: var(--accent); }

.draft-blocks { display: grid; gap: 14px; }
.draft-blocks:empty { display: none; }

.draft-block {
  display: grid;
  gap: 6px;
  padding-left: 12px;
  border-left: 2px solid var(--hairline);
}
.draft-block .meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.05em;
}
.draft-block .status { color: var(--accent-dim); }

/* acciones del bloque a la derecha: «editar» (solo vídeo) + la × de quitar. El
   primer botón absorbe el hueco (margin-left:auto) y arrastra el grupo. */
.draft-block .meta button {
  padding: 0 6px;
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
}
.draft-block .meta button:first-of-type { margin-left: auto; }
.draft-block .meta .edit-media { font-size: 11px; }
.draft-block .meta .edit-media:hover:not(:disabled) { color: var(--accent); }
.draft-block .meta .del:hover:not(:disabled) { color: var(--danger); }
/* ---------- player de audio (portado de twoitter) ----------
   Mismo diseño que el feed de twoitter: botón play accent, barra de progreso
   y tiempo tabular. Radius hardcoded (twoitter usa --radius-sm/md: 4/6px;
   aquí no hay vars de radius). El <audio> interno va oculto: solo aporta
   src/duration, la reproducción real es Web Audio (audio-player.js). */

.audio-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}
.audio-player > audio { display: none; }

.audio-player .ap-play {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  transition: background 120ms ease, transform 80ms ease;
}
.audio-player .ap-play:hover { background: var(--accent-dim); }
.audio-player .ap-play:active { transform: scale(0.96); }
.audio-player .ap-icon-play,
.audio-player .ap-icon-pause { display: none; }
.audio-player[data-state="paused"]  .ap-icon-play  { display: inline; }
.audio-player[data-state="playing"] .ap-icon-pause { display: inline; font-size: 0.7rem; letter-spacing: -1px; }

.audio-player .ap-progress {
  flex: 1 1 auto;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.audio-player .ap-progress:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.audio-player .ap-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 80ms linear;
}

.audio-player .ap-time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.audio-player .ap-time-sep { opacity: 0.5; }
.audio-player .ap-time-dur { color: var(--text-dim); }

.draft-block .audio-player { margin-top: 4px; }

/* preview de imagen/vídeo en el borrador: contenido, sin recuadros ni radius */
.draft-block .media-preview {
  display: block;
  max-width: 100%;
  max-height: 40vh;
  margin-top: 4px;
  object-fit: contain;
}

/* ---------- tags ---------- */

.tagbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 28px;
  font-size: 12px;
}
.tagbar:empty { display: none; }
.tag { color: var(--muted); font-size: 12px; }
.tag:hover { color: var(--accent); }
.tag.active { color: var(--accent); }

/* ---------- feed: notas separadas por aire, como notas5 ---------- */

.feed { display: grid; gap: 120px; }

/* meta de cada nota: diminuta, minúsculas, casi transparente (notas5) */
.note-head {
  display: flex;
  gap: 14px;
  align-items: baseline;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.5;
  text-transform: lowercase;
  letter-spacing: 0.05em;
  transition: opacity 0.15s;
}
.note:hover .note-head { opacity: 0.9; }
.note-num { color: var(--accent); font-weight: 600; }
.note-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-transform: none;
}
.note-head button { font-size: 11px; }

/* edición inline del título en la cabecera (writer): input + guardar/cancelar */
.note-head.title-editing { opacity: 1; }
.note-head .title-edit { flex: 1; font-size: 13px; padding: 2px 0; }
.note-head .save { color: var(--accent); }

/* pie de la entrada: comentarios (de todos), después del último bloque —
   así comentar implica haber pasado por toda ella */
.note-foot {
  display: flex;
  gap: 18px;
  align-items: baseline;
  margin-top: 14px;
  font-size: 11px;
  text-transform: lowercase;
  letter-spacing: 0.05em;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.note:hover .note-foot { opacity: 1; }
.note-foot button { font-size: 11px; color: var(--muted); }
.note-foot button:hover:not(:disabled) { color: var(--accent); }

/* bloques: el ensayo va en serifa, más grande que la interfaz — es la voz
   de la story puesta en página */
.block { margin-bottom: 1.2em; }
.block:last-child { margin-bottom: 0; }

.block-body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.75;
}

/* el transcript también se corrige en serifa (composer y edición inline) */
.draft-block textarea,
.block-body textarea.editing {
  font-family: var(--serif);
  font-size: 16px;
}

.block-body p { margin: 0 0 1em; white-space: pre-wrap; }
.block-body p:last-child { margin-bottom: 0; }
.block-body .hashtag { color: var(--accent-dim); cursor: pointer; }

/* links de URL en los ensayos (los marca el linkify con .link) */
.block-body a.link {
  color: var(--accent-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.block-body a.link:hover { border-bottom-color: currentColor; }

/* meta-línea del bloque: audio · editado a las _ por _ · historial · corregir
   invisible casi siempre; aparece al pasar por encima del bloque */
.block-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  align-items: baseline;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.05em;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.block:hover .block-meta { opacity: 1; }
.block-meta button { font-size: 11px; color: var(--muted); }
.block-meta button:hover:not(:disabled) { color: var(--accent); }
.edit-info { color: var(--muted); }

.block .audio-player { margin-top: 6px; }

/* media en el feed: imagen/vídeo a lo ancho de la columna, altura contenida
   para que una foto vertical no ocupe toda la pantalla. Cero radius (como todo). */
.block-media {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 6px 0;
  object-fit: contain;
}

/* historial de versiones */
.history {
  margin-top: 8px;
  padding-left: 12px;
  border-left: 2px solid var(--hairline);
  display: grid;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.05em;
}
.history-row { display: flex; gap: 14px; align-items: baseline; }
.history-row button { font-size: 11px; }

.version-banner {
  font-size: 11px;
  color: var(--accent-dim);
  text-transform: lowercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.version-banner button { font-size: 11px; color: var(--accent); }

/* edición inline */
.block-body textarea.editing { width: 100%; margin-bottom: 0.6em; }
.edit-bar { display: flex; gap: 18px; margin-bottom: 1em; }
.edit-bar button:first-child { color: var(--accent); }

/* ---------- comentarios (port de las replies de twoitter) ----------
   Mismo lenguaje que el historial: sangría con barra fina a la izquierda,
   meta-líneas diminutas. El anidado repite la sangría por nivel. */

.comments {
  margin-top: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--hairline);
  display: grid;
  gap: 16px;
  font-size: 13px;
}
.comment-list { display: grid; gap: 14px; }
.comment-list:empty { display: none; }
.comment { display: grid; gap: 2px; }
.comment-meta {
  display: flex;
  gap: 14px;
  align-items: baseline;
  font-size: 11px;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.05em;
}
.comment-author { color: var(--text-dim); font-weight: 600; }
.comment-meta button { font-size: 11px; color: var(--muted); }
.comment-meta button:hover:not(:disabled) { color: var(--accent); }
/* los comentarios heredan la serifa de .block-body pero más pequeños */
.comment-body { font-size: 14px; }
.comment-body p { margin-bottom: 0.6em; }
.comment-deleted { font-size: 11px; color: var(--muted); font-style: italic; }
.comment-children {
  margin-top: 10px;
  padding-left: 12px;
  border-left: 2px solid var(--hairline);
  display: grid;
  gap: 14px;
}
.comment-composer { display: grid; gap: 8px; margin-top: 6px; }
.comment-composer textarea { min-height: 40px; font-size: 13px; }
.comment-composer button { justify-self: start; font-size: 12px; color: var(--accent); }

/* en móvil, comentar es con el dedo: inputs a 16px (sin auto-zoom de iOS) */
@media (max-width: 720px) {
  .comment-composer textarea { font-size: 16px; }
  .comment-composer button { padding: 8px 0; }
}

.more-btn { display: block; margin: 32px 0; }

/* ---------- galería: grid de stories ---------- */

/* en modo galería el cuaderno entero se aparta; el grid respira más ancho
   que la columna de lectura */
body.gallery-mode :is(#composer, #tagbar, #feed, #more) { display: none !important; }
body.gallery-mode .page { width: min(92vw, 1400px); }

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (max-width: 720px) {
  .gallery { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

/* tile = poster del vídeo, formato retrato (las stories son verticales) */
.gallery .tile {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: var(--surface);
  padding: 0;
  display: block;
}
.gallery .tile img,
.gallery .tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s;
}
.gallery .tile:hover img,
.gallery .tile:hover video { opacity: 0.85; }

.tile-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px 10px 8px;
  font-size: 11px;
  color: #f6f1e8;
  text-align: left;
  text-transform: lowercase;
  letter-spacing: 0.05em;
  background: linear-gradient(transparent, rgba(20, 15, 10, 0.6));
}

.gallery-empty { color: var(--muted); font-size: 13px; }

/* lightbox: el vídeo grande sobre un velo oscuro (aquí sí, oscuro: es sala
   de proyección). Colores hardcoded a propósito — no siguen el papel. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(24, 18, 13, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox figure { display: grid; gap: 12px; max-width: 92vw; }
.lightbox video {
  max-width: 92vw;
  max-height: 80vh;
  display: block;
  object-fit: contain;
}
.lightbox figcaption {
  display: flex;
  gap: 18px;
  align-items: baseline;
  font-size: 12px;
  color: #d8d2c4;
  text-transform: lowercase;
  letter-spacing: 0.05em;
}
.lightbox figcaption button { font-size: 12px; color: #e0a184; }
.lightbox figcaption button:hover:not(:disabled) { color: #f6f1e8; }
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 22px;
  font-size: 26px;
  color: #d8d2c4;
}
.lightbox-close:hover:not(:disabled) { color: #f6f1e8; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 40px;
  background: var(--surface);
  border-left: 2px solid var(--accent-dim);
  padding: 8px 14px;
  font-size: 12px;
  z-index: 100;
}
.toast.error { border-left-color: var(--danger); color: var(--danger); }

/* ---------- editor de vídeo (recorte temporal + espacial) ---------- */
/* Portado de twoitter, adaptado a la paleta minimal de notas (cero radius salvo
   los tiradores redondos, que son afordancias de agarre). */

.editor {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 95vw;
  max-height: 92vh;
}
.editor-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}
.editor-media {
  max-width: 95vw;
  max-height: 74vh;
  display: block;
  object-fit: contain;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}
/* audio: sin caja de recorte, solo el reproductor nativo + la pista de trim. */
.editor audio { width: min(95vw, 640px); display: block; }
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}
.editor-toolbar .grow { flex: 1; }
.editor-toolbar .editor-apply { color: var(--accent); }
body.editor-open { overflow: hidden; }

/* caja de recorte: overlay sobre el contenido + rect con 8 tiradores. El área
   fuera del rect se atenúa con un box-shadow gigante recortado por el overflow
   del overlay. touch-action:none para que arrastrar no scrollee la página. */
.cropbox-overlay {
  position: absolute;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}
.cropbox-rect {
  position: absolute;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  cursor: move;
  touch-action: none;
}
.cropbox-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  touch-action: none;
}
.cropbox-nw { top: -8px; left: -8px; cursor: nwse-resize; }
.cropbox-n  { top: -8px; left: 50%; margin-left: -8px; cursor: ns-resize; }
.cropbox-ne { top: -8px; right: -8px; cursor: nesw-resize; }
.cropbox-e  { top: 50%; right: -8px; margin-top: -8px; cursor: ew-resize; }
.cropbox-se { bottom: -8px; right: -8px; cursor: nwse-resize; }
.cropbox-s  { bottom: -8px; left: 50%; margin-left: -8px; cursor: ns-resize; }
.cropbox-sw { bottom: -8px; left: -8px; cursor: nesw-resize; }
.cropbox-w  { top: 50%; left: -8px; margin-top: -8px; cursor: ew-resize; }

/* VÍDEO: la caja arranca inactiva (pointer-events:none → los controles nativos
   del vídeo sirven para previsualizar/scrub el trim). «recortar zona» la activa
   (.crop-on). */
.editor-stage.crop-video .cropbox-overlay { pointer-events: none; opacity: 0; }
.editor-stage.crop-video.crop-on .cropbox-overlay { pointer-events: auto; opacity: 1; }
.editor-crop-toggle[aria-pressed="true"] { color: var(--accent); }

/* pista de recorte temporal (trim): fila entre el stage y la toolbar. */
.editor-trim { display: flex; align-items: center; justify-content: center; }
.editor-trim:empty { display: none; }
.trimtrack {
  position: relative;
  width: min(95vw, 640px);
  height: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  touch-action: none;
  cursor: pointer;
}
.trimtrack-sel {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(176, 81, 47, 0.18); /* --accent al 18% */
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  cursor: move;
  touch-action: none;
}
.trimtrack-handle {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  margin-left: -7px;
  background: var(--accent);
  border: 1px solid rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  cursor: ew-resize;
  touch-action: none;
}
.trimtrack-label {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font: 11px var(--mono);
  color: var(--text-dim);
  pointer-events: none;
}

@media (max-width: 720px) {
  /* tiradores más grandes para el dedo */
  .cropbox-handle { width: 20px; height: 20px; }
  .cropbox-nw, .cropbox-sw, .cropbox-w { left: -10px; }
  .cropbox-ne, .cropbox-se, .cropbox-e { right: -10px; }
  .cropbox-nw, .cropbox-n, .cropbox-ne { top: -10px; }
  .cropbox-sw, .cropbox-s, .cropbox-se { bottom: -10px; }
  .cropbox-n, .cropbox-s { margin-left: -10px; }
  .cropbox-e, .cropbox-w { margin-top: -10px; }
  .trimtrack { height: 34px; }
  .trimtrack-handle { width: 20px; height: 20px; margin-top: -10px; margin-left: -10px; }
}

/* ---------- extras SOLO de la demo estática (docs/) ---------- */

.demo-chip {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: 0.05em;
}
.demo-chip:hover { color: var(--accent-dim); }

.demo-note {
  max-width: 62ch;
  margin-bottom: 44px;
  padding-left: 12px;
  border-left: 2px solid var(--hairline);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.03em;
}
