:root {
  --bg: #0b0f14;
  --panel: #121922;
  --panel2: #18212d;
  --line: #243142;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --red: #ff3b5c;
  --green: #3ddc97;
  --amber: #ffb547;
  --cyan: #4cc9f0;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.screen { height: 100vh; height: 100dvh; }
input { font-size: 16px; } /* evita zoom en iOS */
.intro-screen { position:relative; display:grid; place-items:center; overflow:hidden; background-image:linear-gradient(rgba(5,8,13,.18),rgba(5,8,13,.58)),url("network.svg"),radial-gradient(circle at 50% 42%,#132d3c 0%,#05080d 72%); background-size:cover,cover,cover; isolation:isolate; }
.intro-hacker { position:absolute; width:min(1100px,145vw); max-width:none; height:auto; left:50%; top:50%; transform:translate(-50%,-50%); opacity:.82; filter:drop-shadow(0 0 42px rgba(255,59,92,.7)) saturate(1.45); animation:introFloat 6s ease-in-out infinite; }
.intro-shade { position:absolute; inset:0; z-index:1; background:radial-gradient(circle at 50% 42%,rgba(7,18,28,.02),rgba(5,8,13,.52) 54%,rgba(5,8,13,.96) 100%),linear-gradient(180deg,rgba(5,8,13,.1),rgba(5,8,13,.78)); }
.intro-content { position:relative; z-index:2; text-align:center; margin-top:clamp(210px,38vh,360px); padding:20px; text-shadow:0 3px 18px #05080d; }
.intro-content .logo { font-size:clamp(44px,10vw,78px); }
.intro-content .sub { margin:2px 0 12px; color:var(--cyan); }
.intro-content p { color:#e6edf3; font:600 clamp(16px,3vw,22px) var(--mono); letter-spacing:2px; }
.intro-content .btn { min-width:230px; margin:10px 0 16px; font-size:18px; box-shadow:0 0 26px rgba(255,59,92,.55); }
.intro-content .howto { display:block; color:#c4d0de; }
@keyframes introFloat { 0%,100% { transform:translate(-50%,-50%) scale(1); } 50% { transform:translate(-50%,-51%) scale(1.035); } }
@media (prefers-reduced-motion:reduce) { .intro-hacker { animation:none; } }

.btn { border: 0; border-radius: 10px; padding: 13px 18px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--red); color: #fff; }
.btn:active { transform: scale(.97); }
.err { color: var(--red); min-height: 1.4em; margin-top: 10px; }

/* ---------- Ingreso ---------- */
#join { display: grid; place-items: center; padding: 16px; overflow: hidden;
  background-image: linear-gradient(rgba(11,15,20,.22),rgba(11,15,20,.58)), url("network.svg"), radial-gradient(circle at 50% 0%, #2a0f18 0%, var(--bg) 60%);
  background-size:cover,cover,cover; }
.join-box { width: 100%; max-width: 380px; text-align: center; position:relative; z-index:1; }
.hero-hacker { display:block; position:absolute; z-index:0; pointer-events:none; width:min(650px,145vw); max-width:none; height:auto; left:50%; top:-155px; transform:translateX(-50%); opacity:.42; filter:drop-shadow(0 0 28px rgba(255,72,95,.6)) saturate(1.25); }
.join-box::before { content:""; position:absolute; z-index:0; inset:-24px -34px -24px; border-radius:28px; background:linear-gradient(180deg,rgba(11,15,20,.18),rgba(11,15,20,.96) 38%,rgba(11,15,20,.98)); box-shadow:0 0 80px rgba(40,190,220,.08); pointer-events:none; }
.join-box > :not(.hero-hacker) { position:relative; z-index:1; }
.logo { font-family: var(--mono); font-size: 44px; font-weight: 800; letter-spacing: -1px; }
.logo span { color: var(--red); }
.sub { font-family: var(--mono); color: var(--muted); letter-spacing: 4px; font-size: 12px; margin-bottom: 18px; }
.lead { color: #c4d0de; line-height: 1.5; font-size: 15px; }
#joinForm { display: grid; gap: 10px; margin-top: 18px; }
#joinForm input, #joinForm select { padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-align: center; font-family: var(--mono); }

/* ---------- Juego ---------- */
#game { display: flex; flex-direction: column; position:relative; background-image:linear-gradient(rgba(11,15,20,.7),rgba(11,15,20,.82)),url("network.svg"); background-size:cover; }
.screen::after { content:""; position:absolute; inset:0; pointer-events:none; opacity:.18; background:radial-gradient(circle at 15% 20%,rgba(76,201,240,.2),transparent 28%),radial-gradient(circle at 85% 70%,rgba(255,59,92,.16),transparent 30%); mix-blend-mode:screen; }
#join > *, #game > * { position:relative; z-index:1; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line); }
.me { font-family: var(--mono); font-weight: 700; color: var(--red); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me::before { content: "● "; color: var(--green); }
.stats { display: flex; align-items: baseline; gap: 6px; font-family: var(--mono); }
.stats #meRank { color: var(--muted); font-size: 14px; margin-right: 4px; }
.stats b { font-size: 22px; color: var(--amber); transition: transform .3s; }
.stats b.bump { transform: scale(1.4); }
.stats small { color: var(--muted); }
.logout-btn { border:1px solid var(--line); border-radius:7px; padding:5px 8px; background:transparent; color:var(--muted); cursor:pointer; font-size:12px; margin-left:6px; }
.logout-btn:hover { color:#fff; border-color:var(--red); }

main { flex: 1; min-height: 0; position: relative; }
.tab { display: none; height: 100%; overflow-y: auto; padding: 14px 16px 20px; }
.tab.active { display: block; }

.tabs { position: sticky; bottom: 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #1b2633; border-top: 2px solid #33465c; padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; border: 0; color: #c4d0de; padding: 9px 0 10px; font-size: 13px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabs button i { font-style: normal; font-size: 24px; }
.tabs button.active { color: #fff; background: #2a1520; box-shadow: inset 0 3px 0 var(--red); }


/* Misión */
.progress { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
#progBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--red), var(--amber)); transition: width .6s; }
.story-card { background: linear-gradient(135deg, #24131a, var(--panel)); border: 1px solid #553040; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.story-card .chapter { color: var(--amber); font: 700 11px var(--mono); text-transform: uppercase; letter-spacing: 1px; }
.story-card h2 { margin: 3px 0 4px; font-size: 17px; }
.story-card p { margin: 0; color: #c4d0de; font-size: 13px; line-height: 1.4; }
.mission-map { display: flex; gap: 4px; margin: 0 0 10px; overflow-x: auto; padding: 2px 1px 5px; }
.mission-map .node { flex: 0 0 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--panel2); border: 2px solid var(--line); color: var(--muted); font: 700 11px var(--mono); position: relative; }
.mission-map .node.done { background: #123d2d; border-color: var(--green); color: var(--green); }
.mission-map .node.current { border-color: var(--amber); color: var(--amber); box-shadow: 0 0 0 3px #ffb54733; }
.mission-map .node:not(:last-child)::after { content: ''; position: absolute; left: 28px; top: 12px; width: 6px; height: 2px; background: var(--line); }
.mission-map .node.done:not(:last-child)::after { background: var(--green); }
.achievements { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; min-height: 30px; }
.badge { flex: none; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; font-size: 12px; color: var(--muted); }
.badge.earned { color: var(--amber); border-color: #806128; background: #2a2210; }
.rank-badge { font: 700 12px var(--mono); color: var(--cyan); margin-left: 5px; }
.flag-form { display: flex; gap: 8px; }
.flag-form input { flex: 1; min-width: 0; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--green); font-family: var(--mono); }
.msg { min-height: 1.3em; margin: 8px 0 12px; font-size: 14px; }
.msg.ok { color: var(--green); } .msg.bad { color: var(--red); }

.phase { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.phase.done { border-color: #1f5e44; background: linear-gradient(180deg, #10241c, var(--panel)); }
.phase h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.phase h3 .n { font-family: var(--mono); color: var(--muted); font-size: 13px; }
.phase h3 .st { margin-left: auto; font-size: 13px; font-family: var(--mono); color: var(--muted); }
.phase.done h3 .st { color: var(--green); }
.phase .skill { font-size: 12px; color: var(--cyan); margin: 4px 0 8px; font-family: var(--mono); }
.phase p { margin: 0 0 8px; color: #c4d0de; font-size: 14px; line-height: 1.45; }
.phase .hint { background: #2a2210; border-left: 3px solid var(--amber); padding: 8px 10px; border-radius: 6px; font-size: 13px; margin: 6px 0; color: #f3dfb5; font-family: var(--mono); word-break: break-word; }
.phase .hint-btn { background: none; border: 1px solid #4a3c1a; color: var(--amber); padding: 7px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.rules { color: var(--muted); font-size: 12px; text-align: center; margin-top: 16px; }

/* Terminal */
#tab-terminal.active { display: flex; flex-direction: column; padding: 0; background: #05080b; }
.term-out { flex: 1; overflow: auto; padding: 12px; font-family: var(--mono); font-size: 13px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; color: #cfe3d6; }
.term-out .tbl { white-space: pre; overflow-x: auto; overflow-wrap: normal; }
.term-out .cmd { color: var(--text); }
.term-out .cmd .p { color: var(--green); }
.term-out .sys { color: var(--muted); }
.flag { color: #0b0f14; background: var(--amber); border-radius: 3px; padding: 0 3px; cursor: pointer; font-weight: 700; }
.chips { display: flex; gap: 6px; padding: 6px 10px; overflow-x: auto; border-top: 1px solid var(--line); background: var(--panel); }
.chips button { flex: none; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 6px 11px; font-family: var(--mono); font-size: 12px; cursor: pointer; }
.term-in { display: flex; align-items: center; padding: 8px 10px; background: #05080b; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 14px; }
.term-in span { color: var(--green); white-space: nowrap; }
.term-in input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font-family: var(--mono); padding: 6px 4px; }

/* Navegador */
#tab-web.active { display: flex; flex-direction: column; padding: 0; }
.urlbar { display: flex; gap: 6px; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.urlbar input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 18px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-family: var(--mono); font-size: 14px; }
.urlbar .icon { width: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 20px; cursor: pointer; }
.urlbar .go { background: var(--red); border-color: var(--red); }
.web-status { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 3px 10px; background: var(--panel); }
#webFrame { flex: 1; width: 100%; border: 0; background: #fff; }

/* Ranking */
.h { margin: 0 0 12px; font-size: 18px; }
.rank { list-style: none; padding: 0; margin: 0; counter-reset: r; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 11px 12px; background: var(--panel); border-radius: 10px; margin-bottom: 6px; font-family: var(--mono); counter-increment: r; }
.rank li::before { content: counter(r); width: 26px; color: var(--muted); font-size: 13px; }
.rank li:nth-child(1)::before { content: "🥇"; } .rank li:nth-child(2)::before { content: "🥈"; } .rank li:nth-child(3)::before { content: "🥉"; }
.rank li .a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li .f { color: var(--muted); font-size: 12px; }
.rank li b { color: var(--amber); min-width: 40px; text-align: right; }
.rank li.mine { outline: 1px solid var(--red); }

/* Notificaciones */
#toasts { position: fixed; bottom: calc(132px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(92vw, 420px); z-index: 50; display: grid; gap: 8px; pointer-events: none; }
.toast { background: #1d0d12; border: 1px solid var(--red); color: var(--text); padding: 11px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 30px #000a; animation: tin .35s ease-out; }
.toast.good { background: #0d1d16; border-color: var(--green); }
@keyframes tin { from { transform: translateY(14px); opacity: 0; } }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.quick button { background: var(--panel2); color: var(--text); border: 1px solid #33465c; border-radius: 12px; padding: 14px 8px; font-size: 15px; font-weight: 600; cursor: pointer; }
.quick button span { display: block; font-size: 26px; margin-bottom: 4px; }

/* Equipos */
.team-help { color: var(--muted); font-size: 13px; margin-top: -2px; }
.team-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-height: 120px; overflow-y: auto; }
.team-chips button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 6px 11px; font-size: 13px; cursor: pointer; }
.team-chips button small { color: var(--muted); margin-left: 4px; }
.me { display: flex; flex-direction: column; min-width: 0; }
.me small { color: var(--cyan); font-size: 12px; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.team-box b { color: var(--cyan); }
.team-box .role-pill { color: var(--amber); font-family: var(--mono); font-size: 12px; }
.team-box .mem { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.team-box .mem span { background: var(--panel2); border-radius: 10px; padding: 3px 9px; font-family: var(--mono); font-size: 12px; }
.team-box .mem span.you { outline: 1px solid var(--red); }
.phase .by { font-size: 12px; color: var(--green); margin-top: 4px; }
.rank li .m { color: var(--muted); font-size: 12px; }
#teamFields { display: grid; gap: 10px; }
#teamFields input { padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); text-align: center; font-family: var(--mono); }
.howto { display: inline-block; margin-top: 14px; color: var(--cyan); text-decoration: none; font-size: 15px; }

/* Temporizador */
.timer { font-family: var(--mono); font-size: 14px; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 7px; margin-right: 6px; }
.timer.low { color: #fff; background: #5a1020; border-color: var(--red); animation: pulse 1s infinite; }
.timer.over { color: var(--muted); }
@keyframes pulse { 50% { opacity: .55; } }
.timeup-banner { background: #2a1520; border: 1px solid var(--red); color: var(--text); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; text-align: center; }

/* Resultado final */
.final { position: fixed; inset: 0; z-index: 60; background: #000c; display: grid; place-items: center; padding: 16px; }
.final-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--amber); border-radius: 16px; padding: 22px 18px; text-align: center; animation: tin .4s; }
.final-trophy { font-size: 54px; }
.final-pos { font-family: var(--mono); font-size: 30px; font-weight: 800; color: var(--amber); margin-top: 6px; }
.final-sub { color: #c4d0de; margin: 6px 0 14px; }
.final-top { list-style: none; padding: 0; margin: 0 0 16px; text-align: left; }
.final-top li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; background: var(--panel2); border-radius: 8px; margin-bottom: 6px; font-family: var(--mono); }
.final-top li b { color: var(--amber); }
.final .btn { width: 100%; }

/* ---------- Blue team ---------- */
body.blue #join { background: radial-gradient(circle at 50% 0%, #0d2236 0%, var(--bg) 60%); }
body.blue .logo span, body.blue .me { color: var(--cyan); }
body.blue .btn.primary, body.blue .urlbar .go { background: #1673b8; }
body.blue .tabs button.active { background: #10233a; box-shadow: inset 0 3px 0 var(--cyan); }
body.blue #progBar { background: linear-gradient(90deg, var(--cyan), var(--green)); }
body.blue .story-card { background: linear-gradient(135deg, #102b43, var(--panel)); border-color: #1d5b83; }
body.blue .story-card .chapter { color: var(--cyan); }
body.blue .toast { background: #0d1824; border-color: var(--cyan); }
body.blue .toast.good { background: #0d1d16; border-color: var(--green); }
body.blue .rank li.mine, body.blue .team-box .mem span.you { outline-color: var(--cyan); }
.quick.one { grid-template-columns: 1fr; }
.briefing { background: #0d1824; border: 1px solid #1d4466; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; line-height: 1.5; color: #c4d0de; }
.briefing b { color: var(--cyan); }
.answer-form { display: flex; gap: 8px; margin-top: 8px; }
.answer-form input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--green); font-family: var(--mono); }
.answer-form .btn { padding: 10px 14px; font-size: 15px; }
.phase .ans { font-family: var(--mono); color: var(--green); font-size: 13px; margin-top: 4px; word-break: break-all; }
.phase .go-logs { background: #10233a; border: 1px solid #1d4466; color: var(--cyan); padding: 8px 12px; border-radius: 8px; font-size: 13px; cursor: pointer; margin-right: 6px; }
.phase .pmsg { font-size: 13px; margin: 6px 0 0; min-height: 0; }

/* Logs */
#tab-logs.active { display: flex; flex-direction: column; padding: 0; background: #05080b; }
.logs-bar { background: var(--panel); border-bottom: 1px solid var(--line); }
.logs-bar input { width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: var(--bg); color: var(--text); font-family: var(--mono); font-size: 16px; outline: 0; }
.logs-bar .chips { border-top: 0; align-items: center; }
.logs-bar .chips button.on { background: #1673b8; border-color: #1673b8; color: #fff; }
#logCount { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; flex: none; }
.log-list { flex: 1; overflow-y: auto; padding: 6px 0 20px; }
.log-line { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid #111a24; color: #cfe3d6; font-family: var(--mono); font-size: 12px; line-height: 1.45; padding: 7px 12px 7px 10px; overflow-wrap: anywhere; cursor: pointer; }
.log-line:active { background: #10233a; }
.log-line .src { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 4px; margin-right: 6px; background: #1d2b3a; color: var(--muted); text-transform: uppercase; }
.log-line .src.ssh { background: #2b2140; color: #c8b5ff; }
.log-line.found { background: #10241c; border-left: 3px solid var(--green); }
.log-line.found .tag { color: var(--green); font-weight: 700; margin-left: 6px; }
.log-line mark { background: var(--amber); color: #000; border-radius: 2px; }
.log-empty { color: var(--muted); text-align: center; padding: 30px 16px; font-size: 14px; }

.sheet { position: fixed; inset: 0; z-index: 55; background: #000b; display: flex; align-items: flex-end; justify-content: center; }
.sheet-box { width: 100%; max-width: 520px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: tin .25s; max-height: 90dvh; overflow-y: auto; }
.sheet-t { font-weight: 700; margin-bottom: 8px; }
.sheet-line { background: #05080b; color: #cfe3d6; border-radius: 8px; padding: 10px; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 12px; max-height: 30vh; overflow-y: auto; }
.sheet-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-opts button { background: var(--panel2); color: var(--text); border: 1px solid #33465c; border-radius: 10px; padding: 12px 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.sheet-opts button:disabled { opacity: .4; }
.sheet-opts button small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; margin-top: 2px; }
.sheet .btn.sec { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line); margin-top: 4px; }

/* Ataque y defensa */
.briefing .blocked { margin-top: 8px; padding: 7px 10px; border-radius: 8px; background: #2a1520; border: 1px solid var(--red); color: var(--text); font-family: var(--mono); font-size: 13px; }
.briefing .blocked.ok { background: #0d1d16; border-color: var(--green); }
.tabs button[data-unread]::after { content: attr(data-unread); position: absolute; margin-left: 26px; margin-top: -4px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; border-radius: 9px; padding: 0 6px; min-width: 18px; }
.tabs button { position: relative; }
.phase .early { color: var(--cyan); font-size: 12px; margin-top: 4px; }
.briefing .round { display: inline-block; font-family: var(--mono); font-size: 12px; background: #2a2210; color: var(--amber); border-radius: 6px; padding: 1px 7px; margin: 0 2px; }
