:root {
  --bg: #07090f;
  --bg-soft: #0d1118;
  --card: #121826;
  --card-hover: #182034;
  --border: #1f2937;
  --text: #e7ecf4;
  --muted: #8b94a7;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --live: #f43f5e;
  --radius: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(56, 189, 248, 0.08), transparent 60%),
    radial-gradient(900px 500px at 10% 110%, rgba(129, 140, 248, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- PIN ---------- */
.pin-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px;
  text-align: center;
}

.brand-badge {
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.08);
  padding: 7px 16px;
  border-radius: 999px;
}

.pin-screen h1 {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.pin-screen .by { color: var(--muted); font-size: 15px; margin-top: -16px; }

.pin-form { display: flex; gap: 10px; }

.pin-form input {
  width: 220px;
  padding: 14px 18px;
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s;
}

.pin-form input:focus { border-color: var(--accent); }

.btn {
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 600;
  color: #06121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s, opacity 0.2s;
}

.btn:hover { transform: translateY(-1px); opacity: 0.92; }
.btn:disabled { opacity: 0.5; cursor: wait; }

.pin-error { color: var(--live); font-size: 14px; min-height: 20px; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--border);
  background: rgba(7, 9, 15, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .title { font-weight: 700; font-size: 16px; }
.topbar .title span { color: var(--accent); }
.topbar .sub { color: var(--muted); font-size: 13px; }

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: #fff;
  background: var(--live);
  padding: 6px 14px;
  border-radius: 999px;
}

.live-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #fff;
  animation: pulse 1.4s infinite;
}

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Live player ---------- */
.live-wrap {
  height: calc(100vh - 71px);
  display: flex;
  flex-direction: column;
}

.live-wrap iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #000;
}

/* ---------- Replays grid ---------- */
.content { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1280px; margin: 0 auto; }

.section-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; }
.section-title small { display: block; color: var(--muted); font-weight: 400; font-size: 14px; margin-top: 4px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.18s, background 0.18s;
}

.card:hover { transform: translateY(-4px); border-color: rgba(56, 189, 248, 0.5); background: var(--card-hover); }

.thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb .play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.18s;
}

.card:hover .play { opacity: 1; }

.play svg { width: 54px; height: 54px; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5)); }

.thumb .duration {
  position: absolute; right: 8px; bottom: 8px;
  font-size: 12px; font-weight: 600;
  background: rgba(0, 0, 0, 0.75);
  padding: 3px 8px;
  border-radius: 6px;
}

.card-body { padding: 14px 16px 16px; }
.card-body h3 { font-size: 15px; font-weight: 600; }
.card-body p { color: var(--muted); font-size: 13px; margin-top: 5px; }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 80px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 15px;
}

/* ---------- Modal player ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 5, 9, 0.92);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: clamp(8px, 3vw, 40px);
}

.modal-inner { width: min(1100px, 100%); }

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { font-size: 16px; }

.close-btn {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-size: 14px;
}
.close-btn:hover { border-color: var(--accent); }

.player-box { aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; }
.player-box iframe { width: 100%; height: 100%; border: none; }

/* ---------- Admin ---------- */
.admin-content { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 860px; margin: 0 auto; display: grid; gap: 22px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.panel h2 { font-size: 15px; font-weight: 700; margin-bottom: 14px; letter-spacing: 0.3px; }
.panel h2 span { color: var(--muted); font-weight: 400; font-size: 13px; }

.big-toggle {
  width: 100%;
  padding: 20px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: #fff;
  transition: opacity 0.2s;
}
.big-toggle.start { background: linear-gradient(135deg, #10b981, #059669); }
.big-toggle.stop { background: linear-gradient(135deg, var(--live), #be123c); }
.big-toggle:hover { opacity: 0.9; }
.big-toggle:disabled { opacity: 0.5; cursor: wait; }

.field-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.field-row label { width: 130px; color: var(--muted); font-size: 13px; flex-shrink: 0; }

.field-row input, .field-row select {
  flex: 1;
  min-width: 160px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  font-family: inherit;
}
.field-row input:focus, .field-row select:focus { border-color: var(--accent); }

.mono { font-family: Consolas, monospace; font-size: 13px !important; }

.mini-btn {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }

.status-line { color: var(--muted); font-size: 13px; margin-top: 10px; }
.status-line b.ok { color: #10b981; }
.status-line b.off { color: var(--muted); }

.session-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.session-row:first-of-type { border-top: none; }

/* ---------- Chat ---------- */
.live-wrap { flex-direction: row; }
.live-wrap iframe { min-width: 0; }

.chat {
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  width: 340px;
  flex-shrink: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.chat-title { font-size: 14px; font-weight: 700; }

.chat-close {
  background: none; border: none; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 4px 8px;
}
.chat-close:hover { color: var(--text); }

.chat-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }

.chat-off {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; text-align: center; padding: 24px;
}

.chat-msg { font-size: 14px; }
.chat-msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.chat-msg-name { font-weight: 700; font-size: 13px; color: var(--accent); }
.chat-msg.is-admin .chat-msg-name { color: var(--accent-2); }
.chat-msg-time { color: var(--muted); font-size: 11px; }
.chat-msg-text { color: var(--text); line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; }
.chat-msg-img {
  display: block; max-width: 100%; max-height: 160px;
  border-radius: 10px; margin-top: 6px; border: 1px solid var(--border);
}

.chat-name-form { padding: 18px 16px; display: grid; gap: 12px; }
.chat-name-form p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.chat-name-input {
  padding: 11px 14px; font-size: 14px; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; outline: none;
}
.chat-name-input:focus { border-color: var(--accent); }
.chat-name-btn { padding: 11px; font-size: 14px; border-radius: 10px; }

.chat-composer { border-top: 1px solid var(--border); padding: 10px 12px; }

.chat-preview { position: relative; display: inline-block; margin-bottom: 8px; }
.chat-preview img { max-height: 70px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.chat-preview-x {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--live); color: #fff; border: none;
  font-size: 10px; cursor: pointer; line-height: 1;
}

.chat-form { display: flex; gap: 8px; align-items: center; }

.chat-input {
  flex: 1; min-width: 0;
  padding: 10px 12px; font-size: 14px; color: var(--text);
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; outline: none;
}
.chat-input:focus { border-color: var(--accent); }

.chat-attach, .chat-send {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); color: var(--text);
  cursor: pointer; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.chat-attach:hover { border-color: var(--accent); }
.chat-send { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #06121a; border: none; }
.chat-send:disabled { opacity: 0.5; }

/* botón flotante para abrir el chat (alumnos) */
.chat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 40;
  width: 54px; height: 54px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

@media (max-width: 820px) {
  .chat {
    position: fixed; inset: 0 0 0 auto; z-index: 45;
    width: min(100%, 340px);
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
  }
}

/* chat en el panel de admin */
.admin-wrap { display: grid; gap: 22px; padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1400px; margin: 0 auto; }
@media (min-width: 1100px) {
  .admin-wrap { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .admin-chat-col { position: sticky; top: 95px; }
}
.admin-chat {
  height: min(72vh, 720px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  width: auto;
  border-left: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 100;
}
