:root {
  --bg: #14142b;
  --bg2: #1d1d3a;
  --card: #25254a;
  --line: #34346a;
  --text: #ecebff;
  --muted: #a5a3cc;
  --accent: #ffcf6b;
  --accent-ink: #2a1f00;
  --good: #7fd1a8;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin: 18px 0 8px; color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
label { display: block; color: var(--muted); font-size: .92rem; }
label > input, label > textarea, label > select { margin-top: 6px; }

.screen { display: none; max-width: 760px; margin: 0 auto; padding-bottom: 96px; }
.screen.active { display: block; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
}
.top h1, .top h2 { flex: 1; }
.pad { padding: 0 16px; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 10px 18px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: .88rem; }
.btn:disabled { opacity: .6; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card); font-size: 1.15rem;
  display: grid; place-items: center; flex: none;
}
.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 14px 26px; font-weight: 700; box-shadow: 0 8px 30px #0008; z-index: 6;
}
.file-btn {
  display: inline-block; border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; color: var(--text); cursor: pointer;
}

/* Biblioteca */
.cards { display: grid; gap: 14px; padding: 0 16px; }
.card { display: flex; gap: 14px; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.cover { width: 112px; min-height: 112px; object-fit: cover; background: var(--bg2); flex: none; }
.card-body { padding: 12px 12px 12px 0; flex: 1; min-width: 0; }
.card h3 { margin: 0; color: var(--text); font-size: 1.05rem; }
.meta, .progress { margin: 4px 0; color: var(--muted); font-size: .85rem; }
.progress { color: var(--accent); }
.progress:empty { display: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.card-actions .btn { padding: 7px 14px; font-size: .9rem; }

/* Formularios */
.form { display: grid; gap: 14px; padding: 0 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ai-box { background: var(--card); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 10px; }
.ai-box[open] { display: grid; }
.ai-box summary { font-weight: 700; cursor: pointer; }
.ai-box > * + * { margin-top: 10px; }

.style-pick { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.style-pick legend { color: var(--muted); font-size: .92rem; margin-bottom: 6px; }
.style-opt {
  display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 2px solid transparent;
  border-radius: 14px; padding: 10px 12px; cursor: pointer; color: var(--text);
}
.style-opt:has(input:checked) { border-color: var(--accent); }
.style-opt input { width: auto; margin-top: 4px; accent-color: var(--accent); }
.style-opt span { display: grid; gap: 2px; }
.style-opt small { color: var(--muted); font-size: .82rem; }
.review-style { display: flex; gap: 10px; align-items: flex-end; margin: 6px 0 4px; }
.review-style label { flex: 1; }
.review-style[hidden] { display: none; }

.switch-row { display: flex; gap: 10px; align-items: flex-start; color: var(--text); }
.switch-row input { width: auto; margin-top: 5px; accent-color: var(--accent); }
.switch-row span { display: grid; gap: 2px; }
.switch-row small { color: var(--muted); font-size: .82rem; }

/* Preparando */
.center { text-align: center; padding: 60px 16px; }
.moon-spin { font-size: 3rem; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px) rotate(-8deg); } }
.bar { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin: 18px auto; max-width: 420px; }
#prep-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin: 20px 0; }
.thumb {
  aspect-ratio: 1; border-radius: 12px; background: var(--bg2) center/cover; display: flex; align-items: flex-end;
  font-size: .7rem; color: #fff; overflow: hidden;
}
.thumb span { background: #0009; width: 100%; padding: 2px 4px; }

/* Revisar */
.chars { display: grid; gap: 8px; }
.char b { color: var(--text); }
.review-lines { list-style: none; margin: 10px 0; padding: 0 16px; display: grid; gap: 4px; }
.review-lines li { border-bottom: 1px solid var(--line); padding: 10px 0; }
.line-text { margin: 4px 0; }
.num { display: inline-block; min-width: 26px; color: var(--muted); font-size: .8rem; }
.line-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.snd-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--accent); }
.snd-edit select { width: auto; padding: 6px 8px; }
.snd-edit input { width: 7em; padding: 6px 8px; }
.scene-card { display: grid; grid-template-columns: 120px 1fr; gap: 10px; background: var(--card); border-radius: 12px; padding: 8px; margin-bottom: 6px; }
.scene-card img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; background: var(--bg2); }
.scene-card img.missing { outline: 2px dashed #ff8a8a; }
.scene-card div { display: grid; gap: 6px; align-content: start; }
.scene-card textarea { font-size: .8rem; }

/* Ajustes */
.sound-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 12px; font-size: .88rem; }
.grid-title { width: 100%; margin: 10px 0 0; font-size: .85rem; opacity: .8; }
.my-sounds { list-style: none; padding: 0; }

/* Contar */
.dim {
  position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 20;
  transition: opacity 4s ease;
}
#play.active { display: flex; flex-direction: column; height: 100dvh; padding: 0; max-width: none; }
.stage { position: relative; flex: none; height: 58dvh; background: #000; overflow: hidden; }
.frame { position: absolute; inset: 0; }
.pic {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0;
  transition: opacity 1.4s ease; animation: drift 24s ease-in-out infinite alternate;
}
.pic.show { opacity: 1; }
@keyframes drift { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.12) translate(-2%, -2%); } }
.pic-empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 4rem; opacity: .4; }
.pic-empty[hidden] { display: none; }
.stage .exit { position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 12px; background: #0007; }
.stage .snd { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; background: #0007; }
.again {
  position: absolute; top: calc(64px + env(safe-area-inset-top)); right: 12px; z-index: 2;
  border: 0; border-radius: 999px; padding: 8px 12px; background: #0007; color: #fff; font-size: .95rem;
}
.again[hidden] { display: none; }

/* Final especial */
.finale {
  position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity 6s ease;
  background: radial-gradient(ellipse at 50% 30%, #2b3170 0%, #141634 55%, #07081a 100%);
  display: grid; place-items: end center;
}
.finale p {
  margin: 0 0 18%; font-size: 1.9rem; font-weight: 700; color: #ffe9a8; letter-spacing: .02em;
  text-shadow: 0 0 18px #ffcf6b88;
}
.twinkle { position: absolute; inset: 0; }
.twinkle i {
  position: absolute; width: 4px; height: 4px; border-radius: 50%; background: #fff6d0;
  box-shadow: 0 0 8px #fff6d0; animation: twinkle 3s ease-in-out infinite;
}
.twinkle i:nth-child(3n) { width: 6px; height: 6px; }
@keyframes twinkle { 0%, 100% { opacity: .2; transform: scale(.7); } 50% { opacity: 1; transform: scale(1); } }
#play.ending .finale { opacity: 1; }
#play.ending .pic.show { opacity: 0; transition: opacity 8s ease; }
#play.ending .again, #play.ending .heard { display: none; }
@media (prefers-reduced-motion: reduce) { .twinkle i { animation: none; opacity: .7; } }
.heard {
  position: absolute; left: 12px; right: 12px; bottom: 10px; font-size: .78rem; color: #fff; opacity: 0;
  background: #0008; border-radius: 10px; padding: 4px 10px; transition: opacity .4s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.heard.show { opacity: .75; }
.suggest {
  position: absolute; left: 12px; right: 12px; bottom: 44px; background: var(--card); border-radius: 14px; padding: 10px 12px;
  display: flex; gap: 8px; align-items: center; box-shadow: 0 6px 24px #000a; font-size: .9rem;
}
.suggest[hidden] { display: none; }
.suggest span { flex: 1; }
.suggest button { border: 0; border-radius: 99px; padding: 6px 14px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.suggest .no { background: var(--bg2); color: var(--text); }

.lines {
  flex: 1; overflow-y: auto; margin: 0; padding: 30% 20px; list-style: none;
  font-size: 1.35rem; line-height: 1.45; scroll-behavior: smooth;
  mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent);
}
.lines li { padding: 8px 10px; border-radius: 12px; color: var(--muted); opacity: .45; transition: all .3s; cursor: pointer; }
.lines li.done { opacity: .3; }
.lines li.cur { color: var(--text); opacity: 1; background: #ffffff0d; font-weight: 600; }
.mark { color: var(--accent); font-size: .85em; }
.mark.played { opacity: .4; }

.controls {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 22px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--bg);
}
.ctl { width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--card); font-size: 1.3rem; }
.mic {
  width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 2rem; position: relative; display: grid; place-items: center;
}
.mic small {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: .7rem; color: var(--muted); margin-top: 2px;
}
.mic.on { background: #ff7b8a; animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #ff7b8a88; } 70% { box-shadow: 0 0 0 18px #ff7b8a00; } 100% { box-shadow: 0 0 0 0 #ff7b8a00; } }

@media (orientation: landscape) and (max-height: 600px) {
  #play.active { flex-direction: row; flex-wrap: wrap; }
  .stage { height: 100dvh; width: 55%; }
  .lines { width: 45%; height: calc(100dvh - 90px); flex: none; padding: 20% 14px; font-size: 1.15rem; }
  .controls { position: fixed; right: 0; bottom: 0; width: 45%; }
}

#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: calc(100% - 32px);
  transition: all .3s; z-index: 50; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .pic { animation: none; } }

.stage .icon-btn { z-index: 3; }

.backup-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; color: var(--accent-ink); background: var(--accent); border-radius: 99px; padding: 2px 10px; margin-bottom: 4px; }
