:root {
  --bg: #17132a;
  --panel: rgba(26, 20, 46, 0.9);
  --panel-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.09);
  --text: #eeebf8;
  --muted: #a7a0c4;
  --accent: #8b6cff;
  --accent-2: #c3b3ff;
  --ok: #3fd68a;
  --warn: #ffb547;
  --err: #ff6b6b;
  --pixel: "Pixelify Sans", ui-monospace, monospace;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui); overflow: hidden; }
button { font: inherit; color: inherit; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 18px 50px rgba(5, 2, 15, 0.45); }

.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 16px; line-height: 1; transition: background .15s, transform .1s; flex: none; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.icon-btn:active { transform: scale(.95); }

/* barra superior */
.topbar { position: fixed; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; pointer-events: none; z-index: 5; }
.topbar > * { pointer-events: auto; }
.brand { font-family: var(--pixel); font-weight: 600; font-size: 20px; padding: 6px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(14px); white-space: nowrap; }
.brand.big { font-size: 30px; background: none; border: 0; padding: 0; text-align: center; }
.salas { display: flex; gap: 6px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(14px); overflow-x: auto; max-width: 60vw; }
.salas button { border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; font-family: var(--pixel); font-size: 15px; color: var(--muted); white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.salas button.on { background: var(--accent); color: #fff; }
.salas .badge { background: var(--err); color: #fff; font-family: var(--ui); font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 6px; }
.spacer { flex: 1; }
.tools { display: flex; gap: 6px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(14px); }
.only-mobile { display: none; }

/* equipo */
.roster { position: fixed; top: 68px; left: 12px; width: 286px; max-height: calc(100vh - 84px); display: flex; flex-direction: column; z-index: 4; overflow: hidden; }
.roster-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px 8px; font-family: var(--pixel); font-size: 17px; }
.roster-head small { color: var(--muted); font-family: var(--ui); font-size: 12px; }
.roster ul { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; }
.roster li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 11px; cursor: pointer; transition: background .15s; }
.roster li:hover { background: var(--panel-2); }
.roster li.active { background: rgba(139, 108, 255, 0.2); }
.roster li canvas { width: 36px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, 0.07); image-rendering: pixelated; flex: none; }
.roster .info { min-width: 0; flex: 1; }
.roster .nm { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster .nm .puesto { font-weight: 400; color: var(--muted); font-size: 12px; }
.roster .st { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster .st.working { color: var(--accent-2); }
.roster .st.unread { color: var(--ok); }
.roster .st.error { color: var(--err); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); flex: none; }
.dot.working { background: var(--accent); box-shadow: 0 0 0 0 rgba(139, 108, 255, .7); animation: ping 1.6s infinite; }
.dot.unread { background: var(--ok); animation: ping-ok 1.6s infinite; }
.dot.error { background: var(--err); }
@keyframes ping { 70% { box-shadow: 0 0 0 7px rgba(139, 108, 255, 0); } 100% { box-shadow: 0 0 0 0 rgba(139, 108, 255, 0); } }
@keyframes ping-ok { 0% { box-shadow: 0 0 0 0 rgba(63, 214, 138, .7); } 70% { box-shadow: 0 0 0 7px rgba(63, 214, 138, 0); } 100% { box-shadow: 0 0 0 0 rgba(63, 214, 138, 0); } }
.hint { margin: 0; padding: 10px 16px 14px; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); }

/* chat */
.chat { position: fixed; top: 68px; right: 12px; bottom: 12px; width: min(460px, calc(100vw - 24px)); display: flex; flex-direction: column; z-index: 6; transform: translateX(calc(100% + 24px)); transition: transform .28s cubic-bezier(.2, .8, .2, 1); overflow: hidden; }
.chat.open { transform: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head canvas { width: 44px; height: 44px; border-radius: 12px; background: rgba(255, 255, 255, 0.07); image-rendering: pixelated; flex: none; }
.who { flex: 1; min-width: 0; }
.who .name { font-family: var(--pixel); font-size: 18px; }
.who .role { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 13.5px; max-width: 300px; line-height: 1.5; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant > :first-child { margin-top: 0; }
.msg.assistant > :last-child { margin-bottom: 0; }
.msg.assistant p { margin: .45em 0; }
.msg.assistant ul, .msg.assistant ol { margin: .4em 0; padding-left: 1.3em; }
.msg.assistant code { background: rgba(0, 0, 0, .3); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.msg.assistant pre { background: rgba(0, 0, 0, .35); padding: 10px; border-radius: 9px; overflow-x: auto; }
.msg.assistant pre code { background: none; padding: 0; }
.msg.assistant table { border-collapse: collapse; font-size: 12.5px; display: block; overflow-x: auto; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--line); padding: 4px 7px; text-align: left; }
.msg.assistant a { color: var(--accent-2); }
.msg .files { margin-top: 6px; font-size: 12px; opacity: .85; }
.tools-group { align-self: flex-start; max-width: 92%; font-size: 12.5px; color: var(--muted); }
.tools-group summary { cursor: pointer; list-style: none; padding: 4px 10px; border-radius: 99px; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); display: inline-block; }
.tools-group summary::-webkit-details-marker { display: none; }
.tools-group ol { margin: 6px 0 0; padding-left: 22px; }
.tools-group li { margin: 2px 0; overflow-wrap: anywhere; }
.tools-group b { color: var(--text); font-weight: 600; }
.meta { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 10px; }
.meta.err { color: var(--err); }
.divider { align-self: stretch; text-align: center; color: var(--muted); font-size: 12px; border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 6px; }
.working { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--accent-2); }
.working[hidden] { display: none; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: ping 1.6s infinite; flex: none; }
#workingText { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop { border: 1px solid rgba(255, 107, 107, .4); background: rgba(255, 107, 107, .12); color: #ffb3b3; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 12.5px; }
.composer { border-top: 1px solid var(--line); padding: 10px; }
.composer .row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; max-height: 180px; min-height: 38px; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); color: var(--text); font: 14px/1.4 var(--ui); outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.send { width: 38px; height: 38px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer; font-size: 15px; flex: none; }
.send:disabled { opacity: .5; }
.attach { cursor: pointer; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:not(:empty) { margin-bottom: 8px; }
.chip { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 3px 4px 3px 10px; display: flex; align-items: center; gap: 4px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; }
.chat.drop { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* avisos */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 8; width: min(420px, calc(100vw - 24px)); }
.toast { display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; animation: rise .3s cubic-bezier(.2, .8, .2, 1); }
.toast canvas { width: 38px; height: 38px; border-radius: 10px; image-rendering: pixelated; background: rgba(255, 255, 255, .07); flex: none; }
.toast .tt { font-weight: 600; font-size: 13.5px; }
.toast .tb { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toast.err { border-color: rgba(255, 107, 107, .5); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 6, 22, .7); z-index: 20; padding: 16px; }
.login[hidden] { display: none; }
.login form { width: min(340px, 100%); padding: 26px; display: flex; flex-direction: column; gap: 12px; }
.login p { margin: 0; color: var(--muted); text-align: center; font-size: 14px; }
.login input { padding: 11px 13px; border-radius: 11px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: var(--text); font-size: 15px; }
.login button { padding: 11px; border: 0; border-radius: 11px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.login small { color: var(--err); text-align: center; min-height: 1em; }

@media (max-width: 720px) {
  .topbar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  .brand span { display: none; }
  .brand { padding: 6px 10px; }
  .salas { max-width: none; flex: 1; }
  .spacer { display: none; }
  .only-mobile { display: inline-grid; background: var(--panel); }
  .roster { top: 58px; left: 8px; right: 8px; width: auto; max-height: 60vh; display: none; }
  .roster.show { display: flex; }
  .chat { top: 0; right: 0; bottom: 0; width: 100vw; border-radius: 0; z-index: 10; }
  .tools #zoomOut, .tools #zoomIn { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
