:root {
    --bg:        #05060a;
    --text:      #e8ecf6;
    --muted:     #8b94ad;
    --cyan:      #00e5ff;
    --violet:    #a060ff;
    --pink:      #ff3da6;
    --panel:     rgba(18, 22, 36, 0.6);
    --panel-brd: rgba(120, 160, 255, 0.18);
    --grad:      linear-gradient(110deg, var(--cyan), var(--violet) 55%, var(--pink));
    --font:      'Space Grotesk', system-ui, sans-serif;
    --mono:      'JetBrains Mono', ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#world { position: fixed; inset: 0; z-index: 1; width: 100%; height: 100%; display: block; touch-action: none; }
/* Capa del video de YouTube, detrás del canvas (se ve por el hueco del letrero). */
.video-layer { position: fixed !important; inset: 0; z-index: 0; pointer-events: none; }
/* Si el navegador bloquea el autoplay, tras tocar el cartel el video pasa delante para tocar su play. */
.video-layer.is-waiting { z-index: 2; }
.video-layer.is-waiting iframe { pointer-events: auto; }
/* iPhone: reproductor 2D. Oculto (pero cargado) hasta que se toca el cartel del video. */
.yt-card { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; z-index: 7; }
.yt-card.is-open {
    left: 50%; top: 50%; bottom: auto; transform: translate(-50%, -50%);
    width: min(92vw, 30rem); height: auto; opacity: 1; pointer-events: auto;
    display: grid; gap: .8rem; padding: 1rem; border-radius: 1.2rem;
    background: rgba(10, 13, 22, .92); border: 1px solid rgba(255, 61, 166, .6);
    box-shadow: 0 0 32px rgba(255, 61, 166, .35);
}
.yt-card__text { margin: 0; text-align: center; font-family: "JetBrains Mono", monospace; color: #fff; }
.yt-card__close { justify-self: center; padding: .5rem 1.2rem; border-radius: 999px; border: 1px solid rgba(255,255,255,.25); background: transparent; color: #fff; font: inherit; }

.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.hud { position: fixed; left: 0; right: 0; z-index: 2; padding: 1rem clamp(1rem, 4vw, 2rem); pointer-events: none; }
.hud a, .hud button { pointer-events: auto; }

.hud--top { top: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.hud__back {
    font-family: var(--mono); font-size: .9rem; color: var(--text); text-decoration: none;
    padding: .55rem 1rem; border: 1px solid var(--panel-brd); border-radius: 999px;
    background: var(--panel); backdrop-filter: blur(10px);
    transition: border-color .2s, box-shadow .2s;
}
.hud__back:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(0, 229, 255, .45); }
.hud__title { font-size: clamp(1.2rem, 3vw, 1.6rem); font-weight: 700; letter-spacing: -.3px; }

.hud--bottom { bottom: 0; text-align: center; font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.hud--bottom p + p { margin-top: .35rem; }
[data-model-note] { color: var(--cyan); }

.hud--loader {
    top: 50%; transform: translateY(-50%);
    display: flex; align-items: center; justify-content: center; gap: .7rem;
    font-family: var(--mono); font-size: .9rem; color: var(--muted);
    transition: opacity .4s;
}
.hud--loader.done { opacity: 0; }
.hud__spinner {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid var(--panel-brd); border-top-color: var(--cyan);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Joystick ---------- */
.joystick {
    position: fixed; z-index: 3;
    right: max(1.2rem, env(safe-area-inset-right)); bottom: calc(3.6rem + env(safe-area-inset-bottom));
    width: 120px; height: 120px; border-radius: 50%;
    border: 1px solid var(--panel-brd); background: var(--panel); backdrop-filter: blur(10px);
    box-shadow: inset 0 0 24px rgba(0, 229, 255, .12);
    touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
    display: grid; place-items: center;
    transition: border-color .2s, box-shadow .2s;
}
.joystick.active { border-color: var(--cyan); box-shadow: inset 0 0 24px rgba(0, 229, 255, .25), 0 0 18px rgba(0, 229, 255, .35); cursor: grabbing; }
.joystick__knob {
    width: 52px; height: 52px; border-radius: 50%; pointer-events: none;
    background: var(--grad); box-shadow: 0 0 18px rgba(0, 229, 255, .5);
}
.joystick:not(.active) .joystick__knob { transition: transform .15s ease-out; }

/* ---------- Botón de salto ---------- */
.jump-btn {
    position: fixed; z-index: 3;
    left: max(1.2rem, env(safe-area-inset-left)); bottom: calc(4.6rem + env(safe-area-inset-bottom));
    width: 84px; height: 84px; border-radius: 50%;
    border: 1px solid var(--panel-brd); background: var(--panel); backdrop-filter: blur(10px);
    color: var(--text); font-family: var(--mono); font-size: .85rem; cursor: pointer;
    touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
    transition: border-color .2s, box-shadow .2s, transform .1s;
}
.jump-btn:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(0, 229, 255, .45); }
.jump-btn:active { transform: scale(.94); }
.jump-btn[hidden] { display: none; }

/* ---------- Botón de correr (sobre el de salto) ---------- */
.run-btn {
    position: fixed; z-index: 3;
    left: max(1.2rem, env(safe-area-inset-left)); bottom: calc(10.6rem + env(safe-area-inset-bottom));
    width: 84px; height: 40px; border-radius: 999px;
    border: 1px solid var(--panel-brd); background: var(--panel); backdrop-filter: blur(10px);
    color: var(--text); font-family: var(--mono); font-size: .8rem; cursor: pointer;
    touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
    transition: border-color .2s, box-shadow .2s, background .2s;
}
.run-btn:hover, .run-btn[aria-pressed="true"] { border-color: var(--cyan); box-shadow: 0 0 16px rgba(0, 229, 255, .45); }
.run-btn[aria-pressed="true"] { color: var(--cyan); }

/* ---------- Botones de la esquina: mensaje y música ---------- */
.hud__actions { display: flex; gap: .5rem; }
.hud__icon {
    width: 42px; height: 42px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
    border: 1px solid var(--panel-brd); background: var(--panel); backdrop-filter: blur(10px);
    color: var(--text); transition: border-color .2s, box-shadow .2s;
}
.hud__icon:hover, .hud__icon[aria-expanded="true"] { border-color: var(--cyan); box-shadow: 0 0 16px rgba(0, 229, 255, .45); }

/* ---------- Aviso de enlace al pasar sobre un cartel ---------- */
.hud__link { color: var(--cyan); font-size: .9rem; margin-bottom: .35rem; }

/* En móvil los controles se explican solos: el texto de ayuda no tapa el joystick. */
@media (max-width: 600px) { .hud__hint { display: none; } }

/* ---------- Escribir un mensaje ---------- */
.chat {
    position: fixed; z-index: 4; left: 50%; transform: translateX(-50%);
    top: calc(4.6rem + env(safe-area-inset-top)); width: min(30rem, calc(100% - 2rem));
    display: flex; gap: .5rem; padding: .4rem;
    border: 1px solid var(--panel-brd); border-radius: 999px;
    background: var(--panel); backdrop-filter: blur(10px);
    box-shadow: 0 0 18px rgba(0, 229, 255, .25);
}
.chat[hidden] { display: none; }
.chat__input {
    flex: 1; min-width: 0; padding: .55rem .9rem; border: 0; outline: 0; background: transparent;
    color: var(--text); font-family: var(--mono); font-size: 16px;  /* 16px evita el zoom de iOS */
}
.chat__input::placeholder { color: var(--muted); }
.chat__send {
    padding: .55rem 1.1rem; border: 0; border-radius: 999px; cursor: pointer;
    background: var(--grad); color: #fff; font-family: var(--mono); font-size: .85rem; font-weight: 500;
}

/* ---------- Globo de texto sobre Ruddy ---------- */
.bubble {
    position: fixed; z-index: 2; left: 0; top: 0; pointer-events: none;
    max-width: min(16rem, 70vw); padding: .6rem .9rem; border-radius: 14px;
    background: rgba(255, 255, 255, .95); color: #111; text-align: center;
    font-family: var(--mono); font-size: .9rem; line-height: 1.35; overflow-wrap: anywhere;
    box-shadow: 0 0 18px rgba(0, 229, 255, .45);
    transition: opacity .25s;
}
.bubble::after {
    content: ''; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
    border: 8px solid transparent; border-bottom: 0; border-top-color: rgba(255, 255, 255, .95);
}
.bubble[hidden] { display: none; }
.bubble.fade { opacity: 0; }

/* ---------- Hablar con Ruddy (agente de voz ElevenLabs) ---------- */
.settings__item[aria-pressed="true"][data-talk], .settings.is-live > .hud__icon { border-color: var(--pink); box-shadow: 0 0 16px rgba(255, 61, 166, .55); }
.talk {
    position: fixed; z-index: 3; left: 50%; transform: translateX(-50%);
    top: calc(4.6rem + env(safe-area-inset-top)); margin: 0;
    padding: .4rem .9rem; border-radius: 999px; white-space: nowrap;
    border: 1px solid var(--panel-brd); background: var(--panel); backdrop-filter: blur(10px);
    color: var(--text); font-family: var(--mono); font-size: .8rem;
}
.talk[hidden] { display: none; }
.talk.is-speaking { border-color: var(--cyan); box-shadow: 0 0 14px rgba(0, 229, 255, .45); }

/* Subtítulos estilo película mientras Ruddy habla por voz */
.subs {
    position: fixed; z-index: 3; left: 50%; transform: translateX(-50%);
    bottom: calc(4.2rem + env(safe-area-inset-bottom)); width: min(42rem, calc(100% - 2 * (120px + 2rem)));  /* entre los botones y el joystick */
    margin: 0; text-align: center; pointer-events: none;
    font-size: clamp(1rem, 2.4vw, 1.3rem); font-weight: 500; line-height: 1.5; color: #fff;
}
.subs span {
    padding: .15em .5em; border-radius: 4px; background: rgba(0, 0, 0, .7);
    -webkit-box-decoration-break: clone; box-decoration-break: clone;
    text-shadow: 0 1px 2px #000;
}
.subs[hidden] { display: none; }
/* En móvil, por encima del botón «Correr» y el joystick. */
@media (max-width: 600px) { .subs { bottom: calc(14rem + env(safe-area-inset-bottom)); width: calc(100% - 2rem); } }

/* ---------- Ajustes: agrupa portafolio, hablar, mensaje, música y primera persona ---------- */
.settings { position: relative; pointer-events: auto; }
.settings__panel {
    position: absolute; right: 0; top: calc(100% + .5rem); z-index: 5;
    display: flex; flex-direction: column; gap: .35rem; min-width: 15rem; padding: .5rem;
    border: 1px solid var(--panel-brd); border-radius: 16px;
    background: var(--panel); backdrop-filter: blur(14px);
    box-shadow: 0 0 22px rgba(0, 229, 255, .22);
}
.settings__panel[hidden] { display: none; }
.settings__item {
    display: block; width: 100%; padding: .65rem .85rem; border: 1px solid transparent; border-radius: 10px;
    background: transparent; color: var(--text); text-align: left; text-decoration: none; cursor: pointer;
    font-family: var(--mono); font-size: .85rem;
}
.settings__item:hover, .settings__item:focus-visible { border-color: var(--cyan); outline: 0; background: rgba(0, 229, 255, .06); }
.settings__item[aria-pressed="true"] { color: var(--cyan); }

/* ---------- Tótem táctil (Medical Center) ---------- */
.totem-panel {
    position: fixed; inset: 0; z-index: 6; display: grid; place-items: center; padding: 1rem;
    background: rgba(5, 6, 10, .6); backdrop-filter: blur(4px);
}
.totem-panel[hidden] { display: none; }
.totem-panel__card {
    width: min(26rem, 100%); padding: 1.4rem; border-radius: 18px; text-align: center;
    border: 1px solid var(--cyan); background: var(--panel); backdrop-filter: blur(14px);
    box-shadow: 0 0 26px rgba(0, 229, 255, .35); font-family: var(--mono);
}
.totem-panel__card h2 { margin: .2rem 0 .6rem; font-family: var(--font); font-size: 1.5rem; }
.totem-panel__card p { color: var(--muted); margin: 0 0 1rem; }
/* El tótem abre su página real (la demo de Medical Center) en un iframe vertical. */
.totem-panel__card--frame { width: min(32rem, 100%); height: min(92vh, 60rem); padding: .8rem; display: flex; flex-direction: column; gap: .6rem; text-align: left; }
.totem-panel__bar { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.totem-panel__bar h2 { margin: 0 !important; font-size: 1.1rem !important; }
.totem-panel__frame { flex: 1; width: 100%; border: 0; border-radius: 12px; background: #fff; }
.totem-panel__tag { color: var(--cyan) !important; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 0 !important; }


/* Nombre, teléfono y email antes de entrar: la sesión del socket es por teléfono. */
.login { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 1rem; background: rgba(5, 6, 10, .7); backdrop-filter: blur(6px); }
.login[hidden] { display: none; }
.login__card {
    display: grid; gap: .8rem; width: min(100%, 22rem); padding: 1.6rem;
    border-radius: 1.2rem; background: rgba(10, 13, 22, .92); border: 1px solid rgba(0, 229, 255, .45);
    box-shadow: 0 0 32px rgba(0, 229, 255, .2);
}
.login__card h2 { margin: 0; font-family: "Space Grotesk", sans-serif; font-size: 1.8rem; }
.login__note { margin: 0; color: rgba(255,255,255,.7); font-size: .88rem; }
.login__card label { display: grid; gap: .35rem; font-size: .9rem; color: rgba(255,255,255,.8); }
.login__card input {
    padding: .7rem .9rem; border-radius: .7rem; border: 1px solid rgba(255,255,255,.2);
    background: rgba(255,255,255,.06); color: #fff; font: inherit; font-size: 16px;
}
.login__card input:focus { outline: none; border-color: #00e5ff; }
.login__error { margin: 0; color: #ff6b9a; font-size: .9rem; }
.login__back { justify-self: center; color: rgba(255,255,255,.7); font-size: .85rem; text-decoration: none; }
