:root {
  --paper: #f5f2ea;
  --sheet: #fffdf8;
  --ink: #222;
  --editor-blue: #2d6f9f;
  --hand: 'Patrick Hand', 'Comic Sans MS', cursive;
  --type: 'Courier Prime', 'Courier New', Courier, monospace;
  --wob: 255px 12px 225px 12px / 12px 225px 12px 255px;
  --scribble: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 6' preserveAspectRatio='none'%3E%3Cpath d='M1 4 Q 20 1.5 45 3.6 T 99 2.4' fill='none' stroke='%23222' stroke-width='1.5' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  --line: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 6' preserveAspectRatio='none'%3E%3Cpath d='M0 3.4 Q 30 2.2 60 3.6 T 100 2.8' fill='none' stroke='%23222' stroke-opacity='.25' stroke-width='1' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); font: 19px/1.35 var(--hand); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
::selection { background: rgba(34, 34, 34, .14); }
::highlight(script-commands) { color: var(--editor-blue); }

button, #back {
  font: inherit; color: inherit; background: none; border: 0; padding: .15em .45em;
  cursor: pointer; opacity: .5; transition: opacity .15s;
}
button:hover, button.on, #back:hover { opacity: 1; }
button.on { background: var(--scribble) center bottom / 100% 6px no-repeat; }
button svg { width: 18px; height: 20px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
input, textarea { font: inherit; color: inherit; background: none; border: 0; outline: 0; width: 100%; padding: 0; resize: none; }
::placeholder { color: inherit; opacity: .3; }

/* borde dibujado a mano */
.sk { position: relative; }
.sk::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 1.5px solid var(--ink); border-radius: var(--wob); filter: url(#rough);
}
.pic { display: block; aspect-ratio: 16 / 9; background: var(--sheet) center / cover no-repeat; }

/* ---------- inicio ---------- */

/* menú (esc): proyectos arriba, ia abajo */
#home { max-width: 620px; margin: 0 auto; padding: 10vh 16px 64px; }
#home .top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 40px; }
#home h1 { font-weight: 400; font-size: 46px; margin: 0; }
#resume { font-size: 17px; opacity: .6; }
#resume:hover { opacity: 1; }
#home h2 { font-weight: 400; font-size: 15px; letter-spacing: .08em; text-transform: uppercase; opacity: .4; margin: 0 0 12px; }
#home .block + .block { margin-top: 48px; padding-top: 28px; background: var(--line) center top / 100% 6px no-repeat; }
#home .note { font-size: 14px; opacity: .5; margin: 4px 0 10px; max-width: 48ch; }
#home .foot { margin-top: 56px; text-align: center; max-width: none; }
.row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.opts { display: inline-flex; flex-wrap: wrap; gap: 0 2px; }
.opt { margin: 4px 0; }
.opt .lbl { width: 64px; opacity: .45; }
button:disabled { opacity: .15; cursor: default; }
button.quiet { opacity: .35; }
#list { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 14px; }
#list li { display: flex; align-items: center; gap: 8px; }
#list a { flex: 1; min-width: 0; display: flex; align-items: center; gap: 18px; }
#list a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .pic { width: 96px; flex: none; }
#list .x { opacity: 0; }
#list li:hover .x { opacity: .5; }
#new { padding-left: 0; }
#ia-state { font-size: 16px !important; opacity: .75 !important; margin-bottom: 12px !important; }
#plan-box, #keys-box { margin: 10px 0 18px; }
#acct .who { font-weight: 400; }
#acct a, #gate a { opacity: .6; text-decoration: underline; }
#home input, #gate input { font: 15px var(--type); background: var(--line) left bottom / 100% 6px no-repeat; padding-bottom: 4px; }
#acct input { width: 260px; }
#keys { display: grid; gap: 6px; }
#keys .key { display: flex; align-items: baseline; gap: 10px; }
#keys a { width: 80px; flex: none; opacity: .6; }
#keys a:hover { opacity: 1; text-decoration: underline; }
#keys input { flex: 1; max-width: 340px; }
#keys button { opacity: .35; }

/* panel que pide clave o plan la primera vez que se usa la ia */
#gate { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; padding: 16px; background: rgba(245, 242, 234, .86); }
#gate .card { width: min(560px, 100%); background: var(--sheet); padding: 28px 28px 18px; }
#gate h3 { font-weight: 400; font-size: 26px; margin: 0 0 18px; }
#gate h4 { font-weight: 400; font-size: 18px; margin: 0; }
#gate .ways { display: grid; gap: 22px; margin-bottom: 14px; }
#gate .way .note { font-size: 14px; opacity: .5; margin: 2px 0 8px; }
#gate .way .row { margin: 6px 0; }
#gate input { flex: 1; min-width: 200px; }
#gate .opts button:first-child { padding-left: 0; }
#gate > .card > button.quiet { display: block; margin: 0 auto; }

/* ---------- barra ---------- */

.bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
#back { padding-left: 0; }
#title { flex: 1; min-width: 0; font-size: 23px; }
.bar nav { display: flex; }
#play { font-size: 15px; }
#file { font-size: 15px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#file.on { background: none; opacity: .4; }
#file.on::before { content: '✓ '; }
#file.on:hover { opacity: 1; }

/* ---------- storyboard ---------- */

#board {
  display: grid; grid-template-columns: minmax(0, 1fr) 250px; grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px 36px; padding: 4px 24px 12px; height: calc(100dvh - 58px);
}
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; gap: 6px; }
.sheet { width: min(100%, calc((100dvh - 250px) * 16 / 9)); aspect-ratio: 16 / 9; background: var(--sheet); }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#canvas[data-tool=eraser] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23222' stroke-opacity='.5'/%3E%3C/svg%3E") 12 12, cell; }
.tools { display: flex; gap: 4px; }
.tools { position: relative; }
.tools button { font-size: 17px; }
#ai.busy { opacity: 1; animation: pulse 1s ease-in-out infinite alternate; pointer-events: none; }
@keyframes pulse { to { opacity: .25; } }
#msg { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); width: max-content; max-width: min(60ch, 90vw); text-align: center; font-size: 15px; opacity: .7; padding-top: 4px; }

.notes { display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow-y: auto; padding: 4px 6px 4px 0; scrollbar-width: thin; }
#num { font-size: 22px; }
.notes label > span { display: block; font-size: 14px; opacity: .45; margin-bottom: 1px; }
.notes textarea { font-size: 17px; line-height: 1.3; }
.notes textarea, .notes input, #chips {
  background: var(--line) left bottom / 100% 6px no-repeat; padding-bottom: 5px; field-sizing: content; min-height: 1.6em;
}
.notes textarea { max-height: 9em; }
#chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; cursor: text; }
#chips input { background: none; padding: 0; flex: 1; min-width: 40px; width: auto; }
.chip, .tag { text-transform: uppercase; letter-spacing: .03em; border-radius: var(--wob); box-shadow: inset 0 -.5em rgba(34, 34, 34, .08); }
.chip { font-size: 16px; padding: 0 .3em; cursor: pointer; }
.chip:hover { text-decoration: line-through; }

#first { display: none; grid-column: 1 / -1; place-self: center; font-size: 26px; }
#board.empty #first { display: block; }
#board.empty .stage, #board.empty .notes { display: none; }

#strip { grid-column: 1 / -1; display: flex; align-items: center; overflow-x: auto; padding: 6px 2px 4px; scrollbar-width: none; }
#strip::-webkit-scrollbar { display: none; }
.thumb { flex: none; width: 108px; padding: 4px 4px 0; background: none !important; }
.thumb small { display: block; font-size: 13px; text-align: center; }
.thumb.on .pic::before { border-width: 2.4px; }
.gap { flex: none; opacity: 0; padding: 0 5px; font-size: 18px; }
.gap:hover, #strip:hover .gap:last-child { opacity: .6; }

/* ---------- guion ---------- */

#script { padding: 0 16px 40vh; }
.fmt {
  position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
  padding: 6px 0; background: var(--paper); opacity: .55; transition: opacity .2s;
}
.fmt:hover, .fmt:focus-within { opacity: 1; }
.fmt button { font-size: 17px; }
.fmt [data-cmd] { font-family: var(--type); font-size: 16px; min-width: 30px; }
.fmt .sp { width: 16px; }

#doc { max-width: 62ch; margin: 28px auto 0; font: 16px/1.7 var(--type); outline: 0; min-height: 60vh; counter-reset: scene chapter; caret-color: var(--ink); }
#doc p { margin: 0 0 1em; }
#doc b, #doc strong { font-weight: 700; }
.tag { padding: 0 .15em; }

#doc .sep { display: flex; align-items: center; gap: 14px; margin: 2.4em 0 1.1em; font: 19px var(--hand); user-select: none; }
#doc .sep::after { content: ''; flex: 1; height: 6px; background: var(--line) center / 100% 6px no-repeat; }
#doc .sep[data-k=scene] { counter-increment: scene; }
#doc .sep[data-k=scene]::before { content: 'escena ' counter(scene); }
#doc .sep[data-k=chapter] { counter-increment: chapter; flex-direction: column; gap: 4px; margin-top: 3.4em; font-size: 28px; }
#doc .sep[data-k=chapter]::before { content: 'capítulo ' counter(chapter); }
#doc .sep[data-k=chapter]::after { flex: none; width: 100%; background-image: var(--scribble); opacity: .5; }

#doc figure { display: flex; align-items: center; justify-content: flex-end; height: 36px; margin: .45em 0; cursor: pointer; user-select: none; }
#doc figure .pic, #doc figure figcaption { display: none; }
.frame-marker { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--editor-blue); border-radius: 50%; color: var(--editor-blue); font: 13px var(--type); opacity: .65; }
#doc figure:hover .frame-marker { opacity: 1; }
#doc figcaption { font: 17px/1.35 var(--hand); padding-top: 2px; }
#doc figcaption b { display: block; font-weight: 400; opacity: .45; }
#frame-deck { position: fixed; top: 0; height: 100dvh; z-index: 1; opacity: 0; pointer-events: none; transition: opacity 160ms ease; }
#frame-deck.visible { opacity: 1; }
.deck-frame { position: absolute; left: 0; width: 100%; padding: 0; opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(5px); transition: opacity 160ms ease, transform 160ms ease, visibility 160ms; }
.deck-frame.active { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0); }
#frame-deck:not(.visible) .deck-frame { pointer-events: none; }
.deck-frame .pic { width: 100%; }
.deck-frame > span { display: block; height: 28px; padding-top: 4px; font-size: 14px; opacity: .55; text-align: left; }
.deck-frame svg { position: absolute; left: -24px; width: 24px; pointer-events: none; overflow: visible; }
.deck-frame path { fill: none; stroke: var(--editor-blue); stroke-width: 1; opacity: .25; }
@media (prefers-reduced-motion: reduce) { #frame-deck, .deck-frame { transition: none; } }

#pop {
  position: fixed; z-index: 5; list-style: none; margin: 0; padding: 4px 0; min-width: 120px;
  background: var(--sheet); border: 1.5px solid var(--ink); border-radius: var(--wob); font-size: 17px;
}
#cmd { position: fixed; z-index: 5; font-size: 15px; opacity: .45; pointer-events: none; }
#cmd.on { opacity: .8; }
#cmd.busy { color: var(--editor-blue); opacity: .8; }
#cmd.error { max-width: min(360px, 80vw); color: #8a3434; opacity: .8; }
#cmd.commands {
  min-width: min(390px, calc(100vw - 24px)); padding: 5px 0; opacity: 1; pointer-events: auto;
  background: var(--sheet); border: 1.5px solid var(--ink); border-radius: var(--wob);
}
.cmd-item { display: grid; grid-template-columns: 82px 1fr; gap: 8px; padding: 4px 12px; cursor: pointer; opacity: .55; }
.cmd-item.on { opacity: 1; background: rgba(45, 111, 159, .08); }
.cmd-item b { color: var(--editor-blue); font-weight: 400; }
.cmd-item span { font-family: var(--hand); }
#doc figure.busy .pic { animation: pulse 1s ease-in-out infinite alternate; }
#doc figure.busy figcaption b::after { content: ' · dibujando…'; }
#doc figure[data-err] figcaption::after { content: attr(data-err); display: block; font-size: 14px; opacity: .5; }
#pop li { padding: 1px 12px; text-transform: uppercase; cursor: pointer; opacity: .5; }
#pop li.on { opacity: 1; }

/* ---------- personajes ---------- */

#people { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 40px; max-width: 980px; margin: 0 auto; padding: 24px 24px 30vh; }
#people aside { position: sticky; top: 16px; align-self: start; }
#names { list-style: none; margin: 0 0 12px; padding: 0; }
#names button, #p-name, #pop li { text-transform: uppercase; letter-spacing: .03em; }
#names button { padding-left: 0; text-align: left; }
#newchar { font-size: 17px; }
#person { display: flex; flex-direction: column; gap: 22px; }
#p-name { font-size: 34px; }
#p-seen { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 4px; font-size: 15px; opacity: .6; margin-top: -16px; }
#p-seen button { font-size: 15px; padding: 0 .3em; opacity: .8; }
#person label > span, .refs > span { display: block; font-size: 15px; opacity: .45; margin-bottom: 4px; }
#person textarea { font: 16px/1.7 var(--type); background: var(--line) left bottom / 100% 6px no-repeat; padding-bottom: 6px; field-sizing: content; min-height: 3.4em; }
#photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.ref { margin: 0; display: flex; flex-direction: column; gap: 6px; }
#person .ref textarea { font: 15px/1.35 var(--hand); opacity: .7; field-sizing: content; min-height: 0; background: none !important; padding: 0 !important; }
#person .ref textarea:focus { opacity: 1; }
.ref small { font-size: 14px; opacity: .45; animation: pulse 1s ease-in-out infinite alternate; }
.ref > button { align-self: flex-start; padding-left: 0; font-size: 15px; }
.ph, #addphoto { aspect-ratio: 3 / 4; }
#addphoto { align-self: start; }
.ph { background: var(--sheet) center / cover no-repeat; filter: grayscale(1) contrast(.95); cursor: zoom-in; transition: filter .3s; }
.ph:hover { filter: none; }
.ph button { position: absolute; top: 2px; right: 2px; opacity: 0; background: var(--sheet); border-radius: 50%; line-height: 1; padding: 2px 7px; }
.ph:hover button { opacity: .8; }
#addphoto { display: grid; place-items: center; font-size: 30px; opacity: .4; cursor: pointer; }
#addphoto:hover { opacity: 1; }
#p-del { align-self: flex-start; padding-left: 0; font-size: 15px; opacity: .35; }
#nobody { display: none; grid-column: 1 / -1; text-align: center; opacity: .5; }
#people.empty #person { display: none; }
#people.empty #nobody { display: block; }
#doc .tag { cursor: pointer; }

#lightbox { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(245, 242, 234, .96); cursor: zoom-out; }
#lightbox img { max-width: 92vw; max-height: 92vh; }

/* ---------- sugerencias ---------- */

#tips { position: fixed; right: 16px; bottom: 16px; z-index: 6; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; width: min(300px, calc(100vw - 32px)); }
.tip { width: 100%; display: flex; align-items: flex-end; gap: 8px; background: var(--sheet); padding: 10px 8px 8px 16px; font-size: 16px; line-height: 1.3; animation: tipin .5s ease-out; }
.tip p { flex: 1; margin: 0; }
.tip b { font-weight: 400; box-shadow: inset 0 -.45em rgba(34, 34, 34, .08); }
.tip kbd { font: 700 13px var(--type); white-space: nowrap; }
.tip button { flex: none; font-size: 16px; opacity: .6; }
.tip button:hover { opacity: 1; }
#tips > .quiet { font-size: 13px; opacity: .3; padding: 0 2px; }
#tips > .quiet:hover { opacity: .7; }
@keyframes tipin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- zen ---------- */

.zen .bar, .zen .fmt { display: none; }
#script:fullscreen { overflow-y: auto; background: var(--paper); padding-top: 14vh; }
.zen #doc { margin-top: 14vh; }
#script:fullscreen #doc { margin-top: 0; }

/* ---------- presentar ---------- */

#present { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: #111; cursor: none; }
#present .pic { width: min(100vw, calc(100vh * 16 / 9)); }

/* ---------- móvil ---------- */

@media (max-width: 760px) {
  #board { display: block; height: auto; padding: 4px 16px 24px; }
  .sheet { width: 100%; }
  .notes { margin-top: 18px; }
  #strip { margin-top: 18px; }
  #first { margin: 30vh auto; }
  .gap { opacity: .35; }
  .bar nav button { font-size: 17px; padding: .15em .3em; }
  #doc figure .pic { width: 130px; }
  #people { grid-template-columns: 1fr; gap: 18px; padding: 8px 16px 30vh; }
  #people aside { position: static; }
  #names { display: flex; flex-wrap: wrap; gap: 0 12px; }
  .bar { gap: 6px; }
  #file { max-width: 64px; }
  .bar nav button { font-size: 16px; padding: .15em .25em; }
}
@media (hover: none) {
  .ph button { opacity: .8; }
}
@media (hover: none) {
  #list .x { opacity: .4; }
  .gap { opacity: .35; }
  .fmt { opacity: 1; }
}
