:root {
  --bg: #0b0b0c;
  --bar: #151517;
  --line: #2a2a2e;
  --text: #f5f5f2;
  --muted: #8d8d93;
  --accent: #ffd23f;
  --veil: rgba(11, 11, 12, 0.72);
  --size: 64px;
  --gutter: clamp(20px, 4vw, 64px);
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
}

/* Fondo blanco con letra negra */
:root[data-theme="light"] {
  --bg: #ffffff;
  --bar: #f3f3f1;
  --line: #d6d6d2;
  --text: #0b0b0c;
  --muted: #66666c;
  --accent: #e6a700;
  --veil: rgba(255, 255, 255, 0.78);
}
:root[data-theme="light"] .text-btn[aria-pressed="true"] { color: var(--text); }
:root[data-theme="light"] .main-btn { background: #ffd23f; }

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

/* ---------- Barra de avance ---------- */
.progress {
  height: 3px;
  background: transparent;
  flex: none;
}
#progress {
  height: 100%;
  width: 0;
  background: var(--accent);
}

/* ---------- Área principal ---------- */
.area {
  flex: 1;
  min-height: 0;
  position: relative;
}

#editor,
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#editor {
  display: block;
  border: 0;
  outline: 0;
  resize: none;
  background: var(--bg);
  color: var(--text);
  /* misma letra que en la lectura, para ver el tamaño desde antes de iniciar */
  font: 600 var(--size) / 1.45 var(--font);
  letter-spacing: -0.01em;
  padding: clamp(20px, 4vh, 48px) var(--gutter);
  touch-action: pan-y;
}
#editor::placeholder { color: var(--muted); }

#stage {
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#script {
  padding: 0 var(--gutter) 0 calc(var(--gutter) + 28px);
  font-size: var(--size);
  line-height: 1.45;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  will-change: transform;
}

/* Marca de la línea que se está leyendo */
#guide {
  position: absolute;
  left: calc(var(--gutter) - 4px);
  top: calc(40% + var(--size) * 0.725);
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 16px solid var(--accent);
  z-index: 2;
}

/* Degradados arriba y abajo para enfocar la línea activa */
#stage::before,
#stage::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  z-index: 1;
  pointer-events: none;
}
#stage::before {
  top: 0;
  height: 22%;
  background: linear-gradient(var(--bg), transparent);
}
#stage::after {
  bottom: 0;
  height: 30%;
  background: linear-gradient(transparent, var(--bg));
}

#count {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: min(40vh, 40vw);
  font-weight: 700;
  color: var(--accent);
  background: var(--veil);
}
#count.on { display: flex; }

body[data-mode="edit"] #stage { display: none; }
body[data-mode="read"] #editor { display: none; }
body[data-mode="edit"] .only-read { display: none; }

/* ---------- Barra de controles ---------- */
.bar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: var(--bar);
  border-top: 1px solid var(--line);
  font-size: 15px;
}

.group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.group:has(#info) { gap: 6px; }

.label { color: var(--muted); margin-right: 4px; }

output {
  min-width: 2.4em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.step {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
}
.step:hover { border-color: var(--muted); }
.step:active { background: var(--line); }

.text-btn {
  color: var(--muted);
  padding: 8px 0;
}
.text-btn:hover { color: var(--text); }
.text-btn[aria-pressed="true"] {
  color: var(--accent);
  font-weight: 600;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  border-radius: 50%;
}
.icon-btn:hover { opacity: 0.7; }
.icon-btn svg { display: block; }

.info {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 24px;
}

.main-btn {
  background: var(--accent);
  color: #111;
  font-weight: 700;
  padding: 10px 26px;
  border-radius: 8px;
  min-width: 128px;
}
.main-btn:hover { filter: brightness(1.08); }

/* Aviso breve encima de la barra */
#toast {
  display: none;
  flex: none;
  padding: 12px var(--gutter);
  background: var(--bar);
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}
#toast.on { display: block; }

/* En pantallas grandes las opciones van directo en la barra */
.options { display: contents; }
#menu { display: none; }

/* ---------- Móvil: las opciones viven en el menú de tres rayas ---------- */
@media (max-width: 720px), (pointer: coarse) and (max-width: 950px) {
  .bar {
    position: relative;
    flex-wrap: nowrap;
    gap: 18px;
    font-size: 15px;
  }
  #menu { display: inline-flex; }

  .options {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    z-index: 5;
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding: 18px var(--gutter);
    background: var(--bar);
    border-top: 1px solid var(--line);
  }
  body.menu-open .options { display: flex; }

  .label { min-width: 84px; }
  .step { width: 44px; height: 44px; }
  .bar > #full { margin-left: -6px; }
  .actions { margin-left: auto; gap: 20px; }

  #script { padding-left: calc(var(--gutter) + 20px); }
  #guide {
    border-top-width: 7px;
    border-bottom-width: 7px;
    border-left-width: 11px;
  }
}
