/* KIDSTUDIO AI · 1.0
   Sin fuentes, frameworks ni recursos externos.
   Cambia las variables de :root para personalizar el estudio. */
:root {
  color-scheme: dark;
  --bg: #090d18;
  --sidebar: #0d1220;
  --surface: #121a2b;
  --surface-raised: #182238;
  --field: #0c1322;
  --border: #2b3750;
  --text: #f2f5ff;
  --muted: #abb8d1;
  --violet: #a18aff;
  --blue: #78baff;
  --primary: #7447df;
  --success: #91e7c0;
  --warning: #f5cf86;
  --danger: #ffb2be;
  --radius: 20px;
  --radius-sm: 11px;
  --sidebar-width: 256px;
  --shadow: 0 14px 42px rgb(0 0 0 / 20%);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Base y accesibilidad. hidden debe conservar prioridad sobre grid/flex. */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; scroll-behavior: smooth; scroll-padding-top: 24px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
::selection { background: #6247a8; color: white; }
a { color: var(--blue); text-decoration: none; text-underline-offset: 4px; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, a, input, textarea, select, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }
main:focus { outline: none; }
button:disabled, input:disabled, select:disabled, textarea:disabled {
  opacity: .48;
  cursor: not-allowed;
}
h1, h2, h3, h4 { margin: 0 0 12px; color: var(--text); line-height: 1.25; overflow-wrap: anywhere; }
h1 { font-size: clamp(1.55rem, 2.5vw, 2.1rem); letter-spacing: -.045em; }
h2 { font-size: clamp(1.35rem, 2vw, 1.75rem); letter-spacing: -.035em; }
h3 { font-size: 1.08rem; letter-spacing: -.015em; }
h4 { font-size: .93rem; }
p { margin: 0 0 16px; color: var(--muted); overflow-wrap: anywhere; }
small { font-size: .76rem; }
svg { flex-shrink: 0; }
img, video { max-width: 100%; }
.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  transform: translateY(-180%);
}
.skip-link:focus { transform: translateY(0); }
noscript, #startup-notice {
  display: block;
  margin: 0;
  padding: 12px 24px;
  border-bottom: 1px solid #6e5832;
  background: #292218;
  color: var(--warning);
  font-size: .85rem;
}

/* Estructura: menú lateral estable, área central con ancho limitado. */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100svh; }
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  height: 100svh;
  padding: 28px 16px 20px;
  overflow-y: auto;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--text); font-weight: 800; letter-spacing: -.04em; }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--violet); filter: drop-shadow(0 0 10px rgb(161 138 255 / 20%)); }
.brand strong { color: var(--violet); }
.brand small { display: block; color: var(--muted); letter-spacing: .02em; font-weight: 400; margin-top: 3px; }
.sidebar nav { display: grid; gap: 6px; margin: 36px 0; }
.sidebar nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: .86rem;
  font-weight: 550;
  transition: color .18s ease, background-color .18s ease, border-color .18s ease;
}
/* Marcas geométricas decorativas: las etiquetas siguen siendo el nombre accesible. */
.sidebar nav a::before {
  content: "";
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border: 1.5px solid currentColor;
  border-radius: 4px;
  opacity: .8;
}
.sidebar nav a[data-view="generator"]::before { border-radius: 2px 8px 2px 8px; }
.sidebar nav a[data-view="director"]::before { border-radius: 50%; }
.sidebar nav a[data-view="animation"]::before { transform: rotate(45deg); border-radius: 2px; }
.sidebar nav a[data-view="voice"]::before { width: 9px; flex-basis: 9px; margin-inline: 2px; height: 17px; border-radius: 8px; }
.sidebar nav a[data-view="renderer"]::before { border-radius: 50% 50% 3px 3px; }
.sidebar nav a[data-view="settings"]::before { border-style: double; border-width: 4px; border-radius: 50%; }
.sidebar nav a:hover { color: var(--text); background: #172034; text-decoration: none; }
.sidebar nav a[aria-current="page"] {
  color: #e1d7ff;
  border-color: #534078;
  background: linear-gradient(100deg, #30234d, #1c1c35);
  box-shadow: inset 3px 0 0 var(--violet);
}
.sidebar-note { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid var(--border); }
.sidebar-note p { font-size: .77rem; line-height: 1.7; margin: 12px 0 0; }
main {
  width: 100%;
  max-width: 1540px;
  min-width: 0;
  margin-inline: auto;
  padding: 32px clamp(20px, 3.5vw, 56px) 0;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.topbar h1 { margin: 0; }
.eyebrow { color: var(--violet); font-size: .72rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; margin-bottom: 10px; }
.topbar .eyebrow { color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 0; }
.topbar > .toolbar { justify-content: flex-end; }
.view { min-width: 0; animation: view-enter .24s ease-out; }
.view > h2 { margin-bottom: 24px; }
.view > .card + .card, #director-content > .card + h3 { margin-top: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin: 28px 0 18px; }
.section-heading h2, .section-heading h3 { margin: 0; }
.section-heading > a { font-size: .85rem; }

/* Componentes compartidos. */
.card {
  min-width: 0;
  padding: clamp(20px, 2.5vw, 30px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #151d30, var(--surface));
  box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }
button, .button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 17px;
  border: 1px solid #3b4964;
  border-radius: var(--radius-sm);
  background: #1b263c;
  color: var(--text);
  font-size: .85rem;
  line-height: 1.4;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  overflow-wrap: anywhere;
  transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
button:not(:disabled):hover, .button:not([aria-disabled="true"]):hover {
  background: #26334e;
  border-color: #7184a9;
  text-decoration: none;
}
button:not(:disabled):active, .button:not([aria-disabled="true"]):active { transform: translateY(1px); }
button.primary, .button.primary {
  border-color: #9975f2;
  background: linear-gradient(110deg, var(--primary), #4a59cd);
  color: white;
  box-shadow: 0 5px 22px rgb(104 69 214 / 20%);
}
button.primary:not(:disabled):hover, .button.primary:not([aria-disabled="true"]):hover {
  background: linear-gradient(110deg, #8254ec, #5867dc);
  border-color: #c4aaff;
  box-shadow: 0 7px 25px rgb(104 69 214 / 30%);
}
.button[aria-disabled="true"] { opacity: .48; cursor: not-allowed; }
button[data-action^="delete"] { color: var(--danger); background: #2b1e2e; border-color: #654051; }
button[data-action^="delete"]:not(:disabled):hover { background: #422536; border-color: #b57286; }
.badge {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 5px 10px;
  border: 1px solid #494064;
  border-radius: 999px;
  background: #231f38;
  color: #d2c4f9;
  font-size: .7rem;
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.badge[data-state="success"], .badge.success { color: var(--success); border-color: #326953; background: #142e28; }
.badge[data-state="error"], .badge.error { color: var(--danger); border-color: #764555; background: #341f2a; }
.badge[data-state="warning"], .badge.warning { color: var(--warning); border-color: #6e5832; background: #302819; }
.hint { color: var(--muted); font-size: .81rem; line-height: 1.75; margin-top: 12px; }
.empty-state {
  padding: 38px 24px;
  border: 1px dashed #40516d;
  border-radius: var(--radius);
  background: #0e1524;
  text-align: center;
  font-size: .88rem;
}
.project-grid:empty, .scene-list:empty { display: none; }
#app-message:empty { display: none; }
#app-message, #app-error {
  padding: 14px 18px;
  margin-bottom: 22px;
  border: 1px solid #3c5f84;
  border-radius: var(--radius-sm);
  background: #17283b;
  color: #d4e7ff;
  overflow-wrap: anywhere;
}
#app-error { border-color: #804b5c; background: #321f2b; color: #ffcad4; }
.project-context { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 24px; padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #101a2a; }
#active-project-name { overflow-wrap: anywhere; min-width: 0; }
#save-status { font-size: .78rem; color: var(--muted); margin-left: auto; }

/* Panel principal: decoración abstracta, sin estadísticas ni medios ficticios. */
.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: clamp(28px, 4.5vw, 60px);
  background: radial-gradient(ellipse at 95% 0%, #273569 0%, transparent 55%),
    radial-gradient(ellipse at 60% 100%, #32214f 0%, transparent 65%), #131a2d;
  border-color: #423d69;
}
.hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  right: -70px;
  top: 35px;
  width: 280px;
  height: 280px;
  border: 1px solid rgb(161 138 255 / 20%);
  border-radius: 70px;
  box-shadow: 0 0 0 35px rgb(161 138 255 / 4%), 0 0 0 70px rgb(120 186 255 / 3%);
  transform: rotate(-24deg);
  pointer-events: none;
}
.hero h2 { max-width: 740px; font-size: clamp(2rem, 3.7vw, 3.65rem); line-height: 1.12; letter-spacing: -.055em; margin: 18px 0 22px; }
.hero > p:not(.eyebrow) { max-width: 610px; }
.hero .toolbar { margin: 26px 0 18px; }
.hero .hint { max-width: 640px; font-size: .75rem; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 22px; }
.stats-grid .card { box-shadow: none; }
.stats-grid h3 { color: var(--muted); font-size: .78rem; font-weight: 500; margin-bottom: 18px; }
.stats-grid strong { display: block; font-size: clamp(1.8rem, 3vw, 2.5rem); line-height: 1; font-weight: 650; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }

/* Formularios: campos de 16px para evitar el zoom automático en móvil. */
label { display: block; color: #dce4f7; font-size: .86rem; font-weight: 550; margin: 16px 0 8px; }
form > label:first-child { margin-top: 0; }
input:not([type="checkbox"]):not([type="range"]), select, textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid #3d4b66;
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.55;
  transition: border-color .18s ease, box-shadow .18s ease;
}
textarea { resize: vertical; min-height: 100px; }
textarea::placeholder, input::placeholder { color: #8797b3; opacity: 1; }
input:not([type="range"]):not([type="checkbox"]):focus, textarea:focus, select:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgb(161 138 255 / 13%);
}
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); }
select { cursor: pointer; }
option { background: var(--field); color: var(--text); }
option:disabled { color: #8995aa; }
label > input, label > select, label > textarea { margin-top: 8px; }
#story-prompt { min-height: 190px; padding: 18px; line-height: 1.8; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 22px; row-gap: 2px; margin: 16px 0 24px; }
.form-grid > * { min-width: 0; }
.form-grid > label { margin-bottom: 0; }
.check-row { display: flex; align-items: flex-start; gap: 10px; margin: 20px 0 14px; font-weight: 400; cursor: pointer; }
input[type="checkbox"] { flex: 0 0 19px; width: 19px; height: 19px; margin: 2px 0 0; accent-color: var(--violet); cursor: pointer; }
input[type="range"] { display: block; width: 100%; height: 32px; margin: 8px 0 18px; accent-color: var(--violet); cursor: pointer; }
input[type="file"] { font-size: .82rem !important; }
input[type="file"]::file-selector-button {
  border: 1px solid #555078;
  border-radius: 7px;
  padding: 8px 12px;
  margin-right: 12px;
  background: #28233e;
  color: #e5dcff;
  font: inherit;
  cursor: pointer;
}
form > .toolbar { margin-top: 24px; }
#generation-status { margin-top: 22px; border-left: 3px solid var(--violet); }
#generation-stage { color: var(--text); }

/* Historias, tarjetas de proyecto y edición. */
.project-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr)); gap: 18px; margin-bottom: 24px; }
.project-card { display: flex; flex-direction: column; align-items: flex-start; }
.project-card h3 { margin-top: 18px; }
.project-card .toolbar { margin-top: auto; padding-top: 10px; }
.project-card [data-field="updated"] { font-size: .76rem; }
.project-card button { padding: 9px 12px; font-size: .78rem; }
.scene-list { display: grid; gap: 22px; }
.scene-card > .section-heading { margin-top: 0; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.scene-card [data-action="move-up"], .scene-card [data-action="move-down"] { min-width: 44px; padding-inline: 12px; font-size: 1.1rem; }
.scene-card [data-field="audio-status"] { margin-top: 10px; font-size: .8rem; }
.scene-card > .toolbar { margin-top: 18px; }
#story-title { font-size: 1.55rem; }
#story-moral { border-left: 3px solid var(--violet); padding-left: 16px; }
#character-list { margin-top: 18px; }
details.card { margin: 24px 0; padding: 20px 24px; }
summary { cursor: pointer; color: #e0d6ff; font-size: .9rem; font-weight: 600; }
details[open] summary { margin-bottom: 18px; }
pre {
  max-height: 460px;
  overflow: auto;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #080e19;
  color: #cbdcf6;
  font: .79rem/1.8 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

/* Canvas: conserva la resolución interna y la proporción del video. */
.canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 12px;
  margin-bottom: 22px;
  overflow: hidden;
  border: 1px solid #34435d;
  border-radius: 14px;
  background: #070b13;
  background-image: radial-gradient(#1d293d 1px, transparent 1px);
  background-size: 20px 20px;
}
#preview-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 65svh;
  object-fit: contain;
  background: #0c1322;
  border-radius: 6px;
  box-shadow: 0 8px 32px rgb(0 0 0 / 30%);
}
#playback-time { margin-left: auto; color: var(--muted); font: .82rem/1.5 ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.caption { min-height: 1.5em; color: #e0e7fa; text-align: center; font-size: .9rem; }
.caption:empty { display: none; }
#voice .card { margin-bottom: 22px; }
#audio-summary { color: var(--blue); margin-top: 16px; }

/* Exportación: el progreso se alimenta únicamente del tiempo renderizado real. */
dl { display: grid; grid-template-columns: minmax(140px, .7fr) minmax(0, 1fr); margin: 22px 0; }
dt, dd { padding: 12px 0; border-bottom: 1px solid var(--border); font-size: .86rem; }
dt { color: var(--muted); }
dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
#render-progress-wrap { margin-top: 24px; }
progress { display: block; appearance: none; width: 100%; height: 10px; overflow: hidden; border: 0; border-radius: 999px; background: #29334a; accent-color: var(--violet); }
progress::-webkit-progress-bar { background: #29334a; border-radius: 999px; }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--primary), var(--blue)); border-radius: 999px; }
progress::-moz-progress-bar { background: linear-gradient(90deg, var(--primary), var(--blue)); border-radius: 999px; }
#render-status { font-size: .82rem; margin-top: 12px; }
#exported-video { display: block; width: 100%; max-height: 65svh; margin: 18px 0; border: 1px solid var(--border); border-radius: 12px; background: #05070b; object-fit: contain; }
#export-file-info { font-size: .85rem; }
#recorder-support { color: var(--blue); }
.app-footer { margin-top: 48px; padding: 22px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: .74rem; text-align: center; }

@keyframes view-enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Tabletas y computadores pequeños. */
@media (max-width: 1180px) {
  :root { --sidebar-width: 226px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 18px; }
  .topbar > .toolbar { justify-content: flex-start; }
  .brand { font-size: .88rem; }
  .sidebar nav a { font-size: .8rem; padding-inline: 10px; }
  .stats-grid { gap: 12px; }
  .stats-grid .card { padding: 20px; }
}

/* En móvil, el menú se convierte en una barra desplazable sin necesitar JavaScript. */
@media (max-width: 800px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 18px 20px 0; border-right: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  .brand { font-size: 1rem; width: fit-content; }
  .sidebar nav { display: flex; overflow-x: auto; gap: 8px; margin: 18px -20px 0; padding: 0 20px 14px; scrollbar-width: thin; }
  .sidebar nav a { flex: 0 0 auto; white-space: nowrap; font-size: .8rem; min-height: 44px; }
  .sidebar nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--violet); }
  .sidebar-note { display: none; }
  main { padding: 24px 20px 0; }
  .topbar { margin-bottom: 24px; }
  .hero { padding: 30px; }
  .hero h2 { font-size: clamp(2rem, 6.5vw, 3rem); }
  .hero::after { opacity: .5; }
  .canvas-wrap { padding: 6px; }
}
@media (max-width: 520px) {
  main { padding-inline: 14px; }
  .card { border-radius: 16px; padding: 20px 16px; }
  .hero { padding: 28px 20px; }
  .hero .eyebrow { font-size: .65rem; }
  .hero .toolbar > * { width: 100%; }
  .stats-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 16px; }
  .stats-grid .card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px; }
  .stats-grid h3 { margin: 0; max-width: 65%; }
  .stats-grid strong { font-size: 1.6rem; white-space: nowrap; }
  .form-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .section-heading { align-items: flex-start; gap: 12px; }
  .scene-card > .section-heading { flex-direction: column; }
  .toolbar { gap: 8px; }
  .topbar > .toolbar { width: 100%; }
  #connection-status { flex-basis: 100%; width: fit-content; max-width: fit-content; }
  button, .button { padding: 10px 13px; font-size: .8rem; }
  #playback-time { width: 100%; margin: 6px 0; }
  #save-status { width: 100%; margin-left: 0; }
  dl { grid-template-columns: minmax(0, 1fr); }
  dt { border-bottom: 0; padding-bottom: 0; }
  dd { padding-top: 4px; }
  details.card { padding: 18px 16px; }
  #startup-notice, noscript { padding-inline: 16px; }
}

/* Respeta las preferencias de accesibilidad sin modificar el video producido. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .card, .badge, button, .button, .sidebar nav a[aria-current="page"] { border: 1px solid CanvasText; }
  .hero::after { display: none; }
  .sidebar nav a[aria-current="page"] { outline: 2px solid Highlight; }
  button:disabled { color: GrayText; opacity: 1; }
}
