:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f6f6f7;
  --surface-2: #ececee;
  --line: #d9d9de;
  --text: #1c1c20;
  --muted: #62626c;
  --accent: #e5484d;
  --accent-hover: #cf3b40;
  --on-accent: #ffffff;
  --error: #b3261e;
  --notice: #fff4e5;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Un nombre o un título sin espacios no debe ensanchar la página. */
  overflow-wrap: anywhere;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
h1 { font-size: 1.6rem; line-height: 1.25; }
h2 { font-size: 1.05rem; line-height: 1.3; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.5em; }

button, .button {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--surface); }
button.primary, button.danger { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover, button.danger:hover { background: var(--accent-hover); }
button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
button.quiet:hover { background: var(--surface); color: var(--text); }
button.big { padding: 12px 22px; font-size: 1.05rem; }

input[type='text'], input[type='password'], input[type='search'], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

label { display: block; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; color: inherit; font-weight: 700; text-decoration: none; }
.top-actions { display: flex; gap: 8px; }
body.capturing .top-actions { display: none; }

main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 28px 24px; }
.foot { padding: 12px 24px; text-align: center; font-size: 0.85rem; }

.card { display: grid; gap: 14px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.narrow { max-width: 400px; margin: 40px auto; }
.card-part { display: grid; gap: 14px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.center { justify-content: center; }

.heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 22px; }
.empty { display: grid; justify-items: center; gap: 14px; padding: 60px 16px; color: var(--muted); }

.pending { display: grid; gap: 10px; margin-bottom: 24px; padding: 16px; border-radius: var(--radius); background: var(--notice); }
.pending ul { display: grid; gap: 8px; }
.pending li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; margin-bottom: 20px; }
.search { position: relative; flex: 0 1 300px; }
.search svg { position: absolute; left: 11px; top: 50%; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.search input { padding-left: 36px; }
.sort { display: inline-flex; align-items: center; gap: 8px; }
.menu-anchor { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: grid;
  min-width: 230px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.16);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; border-radius: 8px; background: transparent; text-align: left; white-space: nowrap; }
.menu button:hover, .menu button:focus-visible { background: var(--surface); }
.menu button.danger-item { color: var(--error); }
.menu .spacer { width: 18px; flex: none; }

.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
.video { position: relative; display: grid; align-content: start; min-width: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.video.menu-open { z-index: 5; }
.video.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.video-body { display: grid; gap: 4px; padding: 12px 14px 14px; }
.video h2 { overflow-wrap: anywhere; }
.facts { font-size: 0.88rem; }
.stats { display: flex; align-items: center; gap: 14px; margin-top: 6px; color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.stat { display: inline-flex; align-items: center; gap: 5px; }
.stat svg { width: 17px; height: 17px; stroke-width: 1.7; }
.thumb-wrap { position: relative; }
.thumb { position: relative; display: block; aspect-ratio: 16 / 10; overflow: hidden; border-radius: 13px 13px 0 0; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb::after { content: ''; position: absolute; inset: 0; background: rgb(0 0 0 / 0.42); opacity: 0; transition: opacity 0.12s; pointer-events: none; }
.length, .state {
  position: absolute;
  z-index: 1;
  padding: 2px 8px;
  border-radius: 7px;
  background: rgb(0 0 0 / 0.72);
  color: #ffffff;
  font-size: 0.82rem;
  pointer-events: none;
}
.length { right: 8px; bottom: 8px; }
.state { left: 38px; top: 8px; }

.icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.card-actions { position: absolute; top: 8px; right: 8px; z-index: 2; display: grid; gap: 5px; opacity: 0; transition: opacity 0.12s; }
.card-actions .icon-button { width: 28px; height: 28px; border-color: transparent; border-radius: 7px; background: #ffffff; color: #1c1c20; box-shadow: 0 1px 3px rgb(0 0 0 / 0.22); }
.card-actions svg { width: 16px; height: 16px; stroke-width: 1.7; }
.card-actions .icon-button:hover { background: var(--surface-2); }
.pick { position: absolute; top: 8px; left: 8px; z-index: 2; display: block; width: 22px; height: 22px; cursor: pointer; opacity: 0; transition: opacity 0.12s; }
.pick input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.pick-box { display: block; width: 100%; height: 100%; border: 1.5px solid #ffffff; border-radius: 6px; background: rgb(0 0 0 / 0.25); }
.pick input:checked + .pick-box { background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 80% no-repeat; border-color: var(--accent); }
.pick input:focus-visible + .pick-box { outline: 2px solid var(--accent); outline-offset: 2px; }

.video:hover .thumb::after, .video:focus-within .thumb::after, .video.menu-open .thumb::after, .video.selected .thumb::after { opacity: 1; }
.video:hover .card-actions, .video:focus-within .card-actions, .video.menu-open .card-actions { opacity: 1; }
.video:hover .pick, .video:focus-within .pick, .video.selected .pick, .videos.selecting .pick { opacity: 1; }
.video.pinned .card-actions { opacity: 1; }
.video.pinned:not(:hover, :focus-within, .menu-open) .card-actions > :not(.pin) { opacity: 0; pointer-events: none; }
.icon-button.pin.active { background: var(--accent); color: #ffffff; }
.icon-button.pin.active svg { fill: currentColor; }
@media (hover: none) {
  .card-actions, .pick { opacity: 1; }
  /* Sin cursor se pulsa con el dedo: necesita más superficie. */
  .card-actions .icon-button { width: 34px; height: 34px; }
}

.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  width: min(900px, calc(100% - 32px));
  padding: 10px 12px 10px 20px;
  border-radius: 16px;
  background: #1c1c20;
  color: #ffffff;
  box-shadow: 0 10px 34px rgb(0 0 0 / 0.35);
  transform: translateX(-50%);
}
.selection-bar .bar-text { padding: 6px 12px; border-color: #55555c; background: transparent; color: #ffffff; }
.selection-bar .bar-text:hover { background: #33333a; }
.selection-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.selection-actions .icon-button { width: 40px; height: 40px; border-color: transparent; background: transparent; color: #ffffff; }
.selection-actions .icon-button:hover { background: #33333a; }
.selection-actions .danger-icon { background: var(--accent); }
.selection-actions .danger-icon:hover { background: var(--accent-hover); }
main:has(#library:not([hidden])) { max-width: 1320px; padding-bottom: 96px; }
body:has(#selection-bar:not([hidden])) .foot { visibility: hidden; }

dialog { width: min(420px, calc(100% - 32px)); padding: 0; border: none; border-radius: var(--radius); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h3 { margin: 0; font-size: 1rem; }
.top-actions { align-items: center; }
.short-label { display: none; }
.dialog-foot { padding-top: 12px; border-top: 1px solid var(--line); }

.notice { margin-bottom: 16px; padding: 10px 14px; border-radius: 10px; background: var(--notice); }

[data-step] > h1 { margin-bottom: 18px; }
.studio-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: center; }
.corners { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin: 0; padding: 0; border: none; font-size: 0.92rem; }
.corners legend { margin-bottom: 6px; padding: 0; font-weight: 600; }
.corners label { display: flex; align-items: center; gap: 6px; }
.corners input { accent-color: var(--accent); }
.bubble-stage { display: grid; place-items: center; min-height: 240px; }
.bubble { width: 240px; height: 240px; border-radius: 50%; object-fit: cover; background: var(--surface-2); transform: scaleX(-1); box-shadow: 0 6px 24px rgb(0 0 0 / 0.18); }
.capture { display: block; width: 100%; max-height: 56vh; margin-bottom: 10px; border-radius: 12px; background: #000000; }
[data-step='ready'] .row { margin-top: 16px; }

.countdown, .recording { display: grid; justify-items: center; gap: 18px; padding-top: 40px; }
.count { font-size: 11rem; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.live { display: flex; align-items: center; gap: 14px; font-size: 4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); animation: blink 1.4s infinite; }
#time.paused { color: var(--muted); }
#live-corner { width: auto; }
@keyframes blink { 50% { opacity: 0.3; } }

progress { width: 100%; height: 8px; accent-color: var(--accent); }
[data-step='finished'] > .row { margin-top: 16px; }

/* Panel flotante */
.panel { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; height: 100vh; padding: 8px; background: #1c1c20; color: #ffffff; }
.panel-count { font-size: 5rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.panel-time { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.panel-buttons { display: flex; gap: 8px; }
.panel-buttons button { padding: 6px 12px; border-color: #55555c; background: transparent; color: #ffffff; }
.panel-buttons button:hover { background: #33333a; }
.panel-buttons .stop { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.panel-buttons .stop:hover { background: var(--accent-hover); }

/* Página pública */
.watch { background: var(--surface); }
.watch-main { display: grid; align-content: start; gap: 8px; }
.watch-main.missing { justify-items: center; padding-top: 80px; text-align: center; }
.watch video { width: 100%; max-height: 78vh; margin-top: 10px; border-radius: 12px; background: #000000; }
.watch-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; }
.watch-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-left: auto; }
.toggle { position: relative; display: inline-flex; align-items: center; gap: 9px; font-size: 0.95rem; cursor: pointer; }
.toggle input { position: absolute; width: 38px; height: 22px; margin: 0; opacity: 0; cursor: pointer; }
.toggle-track { position: relative; flex: none; width: 38px; height: 22px; border-radius: 11px; background: var(--line); transition: background 0.12s; }
.toggle-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #ffffff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.12s; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.comments-locked { padding: 10px 14px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
textarea { display: block; resize: vertical; }
.comments { display: grid; gap: 16px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.comment-form { display: grid; gap: 12px; }
.comment-send { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.comment-list { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; }
.comment { display: grid; gap: 4px; }
.comment-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.comment-time { padding: 1px 8px; border-color: transparent; border-radius: 7px; background: var(--surface-2); color: var(--accent-hover); font-weight: 600; font-variant-numeric: tabular-nums; }
.comment-time:hover { background: var(--line); }
.comment-edited { font-size: 0.82rem; }
.comment-badge { padding: 1px 8px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 0.78rem; font-weight: 600; }
.panel-warning { max-width: 100%; color: #ffb4b4; font-size: 0.8rem; line-height: 1.3; text-align: center; }
.comment-actions { display: flex; gap: 2px; margin-left: auto; }
.comment-actions .icon-button { width: 30px; height: 30px; border-color: transparent; background: transparent; color: var(--muted); }
.comment-actions .icon-button:hover { background: var(--surface-2); color: var(--text); }
.comment-actions .comment-remove:hover { color: var(--error); }
.comment-editor { display: grid; gap: 8px; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.speeds { display: flex; gap: 4px; }
.speeds button { padding: 5px 10px; }
.speeds button[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); }
.preparing { display: grid; justify-items: center; gap: 14px; margin-top: 10px; padding: 90px 16px; border-radius: 12px; background: var(--surface-2); text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  /* Cerrar sesión sigue en Ajustes; así cabe la cabecera en un móvil. */
  #logout, .long-label { display: none; }
  .short-label { display: inline; }
}

@media (max-width: 720px) {
  .top { padding: 12px 16px; }
  main { padding: 20px 16px; }
  .studio-grid { grid-template-columns: minmax(0, 1fr); }
  .count { font-size: 8rem; }
  .search { flex: 1 1 100%; }
}
