:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --ink: #1f2a44;
  --muted: #6b7489;
  --line: #d9dee8;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 2px 10px rgba(20, 30, 60, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151f; --panel: #1b2130; --ink: #e8ecf4; --muted: #98a2b8;
    --line: #2e364a; --accent: #4f8cff; --shadow: 0 2px 10px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; touch-action: manipulation;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input[type=text], input[type=password], input[type=email], input:not([type]) , select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; }

/* ---------- Portada ---------- */
#home { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.home-card { width: 100%; max-width: 760px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand img { width: 28px; height: 28px; }
.brand.big { font-size: 40px; justify-content: center; }
.brand.big img { width: 52px; height: 52px; }
.tagline { text-align: center; color: var(--muted); font-size: 17px; margin: 8px 0 28px; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .home-grid { grid-template-columns: 1fr; } }
.home-box { background: var(--panel); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.home-box h2 { margin: 0; font-size: 20px; }
.home-box p { margin: 0 0 4px; color: var(--muted); }
#codeInput { text-transform: uppercase; letter-spacing: 3px; font-size: 20px; text-align: center; }
.my-rooms { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.my-rooms a { color: var(--accent); text-decoration: none; font-size: 14px; }
.my-rooms .title { color: var(--muted); font-size: 13px; }

/* ---------- Pizarra ---------- */
#board { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar, .pagebar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  overflow-x: auto; white-space: nowrap; flex: 0 0 auto;
  padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
}
.pagebar { border-top: 1px solid var(--line); border-bottom: 0; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.spacer { flex: 1; }
.chip { border-radius: 999px; padding: 5px 12px; }
.chip b { letter-spacing: 2px; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.badge.teacher { background: #fde68a; color: #78350f; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: 0 0 auto; }
.conn.on { background: var(--ok); }
button.icon { padding: 6px 10px; min-width: 38px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

.workspace { flex: 1; display: flex; min-height: 0; }
.toolbar {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 6px; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; flex: 0 0 auto; width: 62px;
}
.toolbar button { width: 46px; height: 42px; padding: 0; display: flex; align-items: center; justify-content: center; border-color: transparent; background: transparent; }
.toolbar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar button.active { background: var(--accent); color: var(--accent-ink); }
.toolbar button:disabled { opacity: .35; }
.toolbar .sep { width: 36px; height: 1px; background: var(--line); margin: 4px 0; flex: 0 0 auto; }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.colors button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); }
.colors button.active { outline: 2px solid var(--accent); outline-offset: 2px; }
#customColor { width: 44px; height: 28px; border: 0; padding: 0; background: none; cursor: pointer; }
.size-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#sizeRange { width: 50px; }
.size-dot { display: block; border-radius: 50%; background: var(--ink); }
.fill-wrap { font-size: 11px; display: flex; flex-direction: column; align-items: center; color: var(--muted); }

/* En pantallas estrechas la barra va abajo, en horizontal */
@media (max-width: 700px), (max-height: 520px) and (orientation: landscape) {
  .workspace { flex-direction: column-reverse; }
  .toolbar { flex-direction: row; width: auto; height: auto; overflow-x: auto; overflow-y: hidden; border-right: 0; border-top: 1px solid var(--line); }
  .toolbar .sep { width: 1px; height: 30px; margin: 0 4px; }
  .colors { grid-template-columns: repeat(8, 1fr); }
  .size-wrap { flex-direction: row; }
}

#stage { flex: 1; position: relative; overflow: hidden; background: #8c94a6; min-width: 0; }
@media (prefers-color-scheme: dark) { #stage { background: #0b0e15; } }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#editor {
  position: absolute; z-index: 5; resize: none; border: 2px dashed var(--accent); outline: none;
  background: rgba(255,255,255,.85); padding: 2px 4px; margin: 0; line-height: 1.25; overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
.view-only { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; padding: 4px 12px; border-radius: 999px; font-size: 13px; pointer-events: none; }

.thumbs { display: flex; gap: 6px; overflow-x: auto; }
.thumbs canvas { height: 40px; width: 71px; border: 2px solid var(--line); border-radius: 6px; cursor: pointer; background: #fff; flex: 0 0 auto; }
.thumbs canvas.active { border-color: var(--accent); }

/* Modo espectador: se ocultan herramientas */
body.no-draw .draw-only { display: none !important; }
body.role-student .teacher-only { display: none !important; }
body.role-teacher .student-only { display: none !important; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(10,15,30,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 16px; padding: 22px; width: 100%; max-width: 460px; position: relative; box-shadow: var(--shadow); max-height: 100%; overflow: auto; }
.modal-card h2 { margin: 0 0 8px; }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.modal-close { position: absolute; top: 10px; right: 10px; padding: 4px 10px; }
.share-code { font-size: 44px; font-weight: 800; letter-spacing: 8px; text-align: center; }
.qr { display: block; margin: 8px auto; width: 200px; height: 200px; background: #fff; border-radius: 8px; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; min-width: 0; font-size: 13px; }

.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 8px 16px; border-radius: 999px; z-index: 60; font-size: 14px; max-width: 90vw; text-align: center; }

/* ---------- Portada: extras ---------- */
.site-name { text-align: center; margin: 4px 0 0; color: var(--muted); font-weight: 600; }
.hello { margin: 0; font-size: 14px; color: var(--ink) !important; }
.button-link { color: var(--accent); text-align: center; font-size: 14px; }
.home-links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.home-links button, .home-links a { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--ink); text-decoration: none; }

/* ---------- Manual ---------- */
.modal-wide .modal-card { max-width: 980px; }
.help-card { display: flex; padding: 0; height: min(88vh, 760px); overflow: hidden; }
.help-nav { flex: 0 0 210px; border-right: 1px solid var(--line); padding: 20px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.help-nav h2 { font-size: 20px; margin: 0 8px 10px; }
.help-nav a { color: var(--ink); text-decoration: none; padding: 7px 10px; border-radius: 8px; font-size: 14px; }
.help-nav a:hover, .help-nav a.active { background: var(--bg); color: var(--accent); }
.help-body { flex: 1; overflow-y: auto; padding: 20px 28px 40px; line-height: 1.55; scroll-behavior: smooth; }
.help-body section { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.help-body section:last-child { border-bottom: 0; }
.help-body h3 { margin: 6px 0 10px; font-size: 19px; }
.help-body li { margin: 4px 0; }
.help-body .tip { background: var(--bg); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.help-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.help-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-table td:first-child { white-space: nowrap; }
kbd { background: var(--bg); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font-size: 12px; font-family: inherit; }
.help-body dt { font-weight: 700; margin-top: 10px; }
.help-body dd { margin: 2px 0 0 0; color: var(--muted); }
@media (max-width: 700px) {
  .help-card { flex-direction: column; height: 90vh; }
  .help-nav { flex: 0 0 auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 40px 10px 10px; white-space: nowrap; }
  .help-nav h2 { display: none; }
  .help-body { padding: 16px; }
}

/* ---------- Créditos ---------- */
.credits-card { text-align: left; }
.center { text-align: center; }
.credits-text { white-space: pre-line; background: var(--bg); border-radius: 10px; padding: 14px 16px; margin: 14px 0; font-size: 15px; }
.credits-card h3 { font-size: 15px; margin: 16px 0 6px; }
.libs { padding-left: 18px; font-size: 14px; margin: 0; }
.libs li { margin: 4px 0; }

/* ---------- GeoGebra ---------- */
.overlays { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.ggb-box { position: absolute; transform-origin: 0 0; pointer-events: auto; background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.25); border-radius: 6px; }
.ggb-bar { height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 12px; background: #eef1f6; border-bottom: 1px solid #d9dee8; border-radius: 6px 6px 0 0; font-size: 15px; color: #475569; user-select: none; -webkit-user-select: none; touch-action: none; }
.ggb-bar.editable { cursor: move; }
.ggb-bar:not(.editable) .ggb-actions { display: none; }
.ggb-bar button { padding: 2px 9px; background: #fff; color: #334155; }
.ggb-holder { position: relative; }
.ggb-loading { display: flex; align-items: center; justify-content: center; height: 300px; color: #64748b; font-size: 18px; text-align: center; padding: 20px; }
.ggb-blocker { position: absolute; left: 0; right: 0; top: 34px; bottom: 0; }
.ggb-resize { position: absolute; right: -10px; bottom: -10px; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); cursor: nwse-resize; touch-action: none; }
.ggb-blocker:not([hidden]) ~ .ggb-resize { display: none; }

/* ---------- QR grande ---------- */
.qr-big-btn { display: block; margin: 0 auto 6px; }
.qr-modal { background: rgba(255,255,255,.97); }
@media (prefers-color-scheme: dark) { .qr-modal { background: rgba(17,21,31,.97); } }
.qr-full { text-align: center; position: relative; width: 100%; }
.qr-full .modal-close { position: fixed; top: 16px; right: 16px; }
.qr-title { font-size: clamp(20px, 3.5vw, 36px); font-weight: 700; margin: 0 0 12px; }
#bigQRImg { width: min(62vh, 80vw); height: min(62vh, 80vw); image-rendering: pixelated; background: #fff; padding: 10px; border-radius: 12px; }
.qr-or { font-size: clamp(15px, 2vw, 22px); color: var(--muted); margin-top: 10px; }
.share-code.big { font-size: clamp(40px, 9vw, 96px); }

/* ---------- PDF ---------- */
.pdf-card { max-width: 820px; }
.pdf-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.pdf-tools label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: 14px; }
.pdf-tools input { width: 160px; }
.pdf-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; max-height: 46vh; overflow-y: auto; padding: 4px; background: var(--bg); border-radius: 10px; }
.pdf-page { display: flex !important; flex-direction: column; align-items: center; gap: 4px; padding: 6px; margin: 0 !important; border: 2px solid transparent; border-radius: 8px; cursor: pointer; background: var(--panel); position: relative; color: var(--ink) !important; }
.pdf-page.on { border-color: var(--accent); }
.pdf-page input { position: absolute; top: 6px; left: 6px; }
.pdf-page canvas { max-width: 100%; height: auto; box-shadow: 0 1px 4px rgba(0,0,0,.2); background: #fff; }
.pdf-where { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.pdf-where label { margin: 0 !important; color: var(--ink) !important; font-size: 14px !important; }
#pdfInsert { width: 100%; }

/* ---------- Acceso ---------- */
#auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { max-width: 460px; }
.auth-card .home-box { margin-top: 18px; }
.consent { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: flex-start; }
.consent a { color: var(--accent); }
.code-input { font-size: 28px !important; letter-spacing: 10px; text-align: center; }
button.plain { background: transparent; border: 0; color: var(--accent); padding: 4px; }
.or-sep { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin: 10px 0 2px; }
.or-sep::before, .or-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#googleBtn { display: flex; justify-content: center; min-height: 44px; }
@media (max-height: 860px) { .toolbar button { height: 36px; } .toolbar .sep { margin: 2px 0; } }
.oauth-btns { display: flex; flex-direction: column; gap: 8px; }
.oauth { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); text-decoration: none; font-weight: 600; font-size: 15px; }
.oauth:hover { border-color: var(--accent); }
.trial-box { margin-top: 14px; }
.trial-box p { font-size: 14px; }
.trial-badge { display: inline-flex; align-items: center; gap: 6px; background: #fef3c7; color: #78350f; border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; }
.trial-badge .chip { padding: 3px 10px; font-size: 12px; background: #f59e0b; color: #fff; border-color: #f59e0b; }
#authStep1, #authStep2 { display: flex; flex-direction: column; gap: 8px; }
#authStep1 input, #authStep2 input { width: 100%; }

/* ---------- Ventanas web ---------- */
.ggb-holder iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; border-radius: 0 0 6px 6px; }
body.tz-drag .ggb-holder iframe, body.tz-drag .ggb-holder { pointer-events: none; }
.ggb-grip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.web-open a { display: inline-block; padding: 2px 9px; margin-right: 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: #334155; text-decoration: none; }
.web-blocked { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 30px; text-align: center; color: #475569; background: #f8fafc; }
.web-host { font-size: 30px; font-weight: 700; color: #1f2a44; }
.web-blocked p { font-size: 20px; max-width: 640px; margin: 0; }
.web-btn { font-size: 22px; padding: 12px 22px; border-radius: 12px; background: var(--accent); color: #fff; text-decoration: none; font-weight: 600; }
#linkInput { flex: 1; min-width: 0; font-size: 16px; }
.ggb-box.ro .ggb-resize { display: none; }

/* ---------- Guardar y Mis pizarras ---------- */
.board-title { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.save-state { min-width: 80px; }
.home-card.wide { max-width: 1100px; }
.library { margin-top: 22px; background: var(--panel); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.lib-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.lib-head h2 { margin: 0; font-size: 20px; flex: 1; }
.lib-head input { width: 200px; }
.lib-folders { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0; }
.lib-folders .chip { display: inline-flex; gap: 6px; align-items: center; }
.lib-folders .chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.lib-folders .chip .n { opacity: .7; font-size: 12px; }
.lib-folders .fact { border: 0; background: transparent; padding: 0 2px; color: inherit; font-size: 13px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.lib-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; background: var(--panel); }
.lib-card .th { aspect-ratio: 16 / 9; background: #fff center / cover no-repeat; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 30px; }
.lib-card .info { padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.lib-card .ttl { font-weight: 600; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-card .meta { font-size: 12px; color: var(--muted); }
.lib-card .acts { display: flex; gap: 4px; align-items: center; }
.lib-card .acts select { flex: 1; min-width: 0; font-size: 12px; padding: 4px 6px; }
.lib-card .acts button { padding: 4px 8px; font-size: 13px; }
.lib-empty { color: var(--muted); padding: 20px; text-align: center; grid-column: 1 / -1; }
.toolbar .colors button { width: 20px; height: 20px; padding: 0; }
@media (max-width: 1360px) { #presence { display: none; } .board-title { max-width: 150px; } }
@media (max-width: 1100px) { .save-state { display: none; } .switch span { font-size: 12px; } }
