:root {
  --bg: #0d0e10;
  --steel: #16181c;
  --steel-2: #1e2127;
  --line: #2c3037;
  --text: #e9e6df;
  --muted: #8d9199;
  --rust: #e8761f;
  --amber: #ffb347;
  --red: #d94b3b;
  --green: #5fbf6a;
  --radius: 14px;
  --font: "Bahnschrift", "DIN Alternate", "Barlow Condensed", "Arial Narrow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overscroll-behavior: none; }
body {
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(232, 118, 31, .13), transparent 60%),
    repeating-linear-gradient(135deg, rgba(255,255,255,.012) 0 2px, transparent 2px 6px),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
b { font-weight: 700; }

/* ------------------------------------------------------------------ pantallas */
.screen { min-height: 100%; padding: calc(var(--sat) + 20px) calc(var(--sar) + 16px) calc(var(--sab) + 24px) calc(var(--sal) + 16px); }
#screen-auth { display: grid; place-items: center; }

.card {
  background: linear-gradient(180deg, var(--steel-2), var(--steel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.04);
}
#screen-auth .card { max-width: 400px; text-align: center; }
.logo { display: block; margin: 0 auto 6px; filter: drop-shadow(0 6px 18px rgba(232,118,31,.35)); }
h1 { margin: 0; font-size: 2.2rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 800; }
h1 span { color: var(--rust); }
h2 { margin: 0 0 12px; font-size: 1rem; letter-spacing: .14em; text-transform: uppercase; color: var(--amber); font-weight: 700; }
.sub { color: var(--muted); margin: 6px 0 18px; font-size: .95rem; }
.note { color: var(--muted); font-size: .85rem; line-height: 1.45; margin: 12px 0 0; }
.msg { min-height: 1.3em; font-size: .9rem; margin: 12px 0 0; color: var(--amber); }
.msg.err { color: var(--red); }
.msg.ok { color: var(--green); }

.stack { display: grid; gap: 12px; text-align: left; }
label { display: grid; gap: 6px; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input:not([type]) {
  width: 100%; padding: 13px 14px; font: inherit; font-size: 16px; /* 16px evita el zoom de iOS */
  color: var(--text); background: #0f1114; border: 1px solid var(--line); border-radius: 10px; outline: none; text-transform: none; letter-spacing: 0;
}
input:focus { border-color: var(--rust); box-shadow: 0 0 0 3px rgba(232,118,31,.22); }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--steel-2); color: var(--text);
  padding: 12px 16px; border-radius: 10px; font: inherit; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: .85rem;
  cursor: pointer; transition: transform .06s, background .15s, border-color .15s; touch-action: manipulation; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { border-color: #444a54; background: #262a31; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: linear-gradient(180deg, #f08a36, var(--rust)); border-color: #ffb36e; color: #1a0e04; box-shadow: 0 6px 18px rgba(232,118,31,.28); }
.btn.primary:hover { background: linear-gradient(180deg, #ff9a4a, #ee7f2a); }
.btn.big { width: 100%; padding: 16px; font-size: 1rem; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .75rem; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: 0; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 500; min-height: 32px; text-decoration: underline; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.file { cursor: pointer; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; background: #0f1114; padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab { appearance: none; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 9px; font: inherit; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: .8rem; cursor: pointer; }
.tab.on { background: var(--steel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

/* ------------------------------------------------------------------ lobby */
.topbar { display: flex; align-items: center; justify-content: space-between; max-width: 980px; margin: 0 auto 18px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.15rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; }
.brand b { color: var(--rust); font-size: 1.5rem; }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.who span { color: var(--text); font-weight: 700; }
.grid { display: grid; gap: 16px; max-width: 980px; margin: 0 auto; grid-template-columns: 1fr; }
@media (min-width: 820px) { .grid { grid-template-columns: 1fr 1fr; } .grid > .card:last-child { grid-column: 1 / -1; } }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: .25em; text-align: center; font-weight: 700; font-family: var(--mono); }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.status { font-size: .95rem; margin-bottom: 12px; color: var(--text); }
.status .ok { color: var(--green); } .status .warn { color: var(--amber); } .status .bad { color: var(--red); }

.rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rooms li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: #0f1114; border: 1px solid var(--line); border-radius: 10px; }
.rooms li.empty { color: var(--muted); justify-content: center; font-size: .9rem; }
.rooms .code { font-family: var(--mono); font-weight: 700; letter-spacing: .2em; color: var(--amber); }
.rooms .meta { color: var(--muted); font-size: .8rem; }

.bar { height: 8px; background: #0f1114; border: 1px solid var(--line); border-radius: 99px; overflow: hidden; margin: 0 0 12px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--rust), var(--amber)); transition: width .2s; }

/* ------------------------------------------------------------------ juego */
.game { position: fixed; inset: 0; padding: 0; background: #000; overflow: hidden; z-index: 5; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#dos { position: absolute; inset: 0; }
#dos .jsdos-rso, #dos .flex, #dos .jsdos-rso > div { max-width: 100%; }
#touch { position: absolute; inset: 0; z-index: 10; touch-action: none; cursor: none; }

.loading { position: absolute; inset: 0; z-index: 30; display: grid; place-content: center; justify-items: center; gap: 14px; background: radial-gradient(600px 300px at 50% 40%, rgba(232,118,31,.14), #07080a 70%); text-align: center; padding: 20px; }
.loading .bar { width: min(320px, 70vw); }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #2a2d33; border-top-color: var(--rust); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; background: var(--bg); transition: opacity .25s; }
.boot.gone { opacity: 0; pointer-events: none; }

#hud { position: absolute; z-index: 20; top: calc(var(--sat) + 8px); left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); pointer-events: none; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
#hud > * { pointer-events: auto; }
.hud-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(13,14,16,.62); color: #fff; font-size: 18px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); cursor: pointer; opacity: .55; touch-action: manipulation; }
.hud-btn:hover, .hud-btn.on { opacity: 1; }
.panel { background: rgba(16,17,20,.92); border: 1px solid var(--line); border-radius: 14px; padding: 12px; width: min(360px, calc(100vw - 16px - var(--sal) - var(--sar))); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-height: calc(100dvh - var(--sat) - var(--sab) - 70px); overflow: auto; }
.hud-status { font-size: .9rem; margin-bottom: 10px; }
.hud-status ul { list-style: none; margin: 6px 0 0; padding: 0; color: var(--muted); font-size: .82rem; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.hud-status li::before { content: "● "; color: var(--green); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); margin-right: 8px; vertical-align: 0; }
.dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); } .dot.warn { background: var(--amber); } .dot.bad { background: var(--red); }
.hud-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hud-grid button, .bar-keys button, .dpad button { appearance: none; background: var(--steel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 11px 8px; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; min-height: 44px; touch-action: manipulation; }
.hud-grid button.on, .bar-keys button.on { background: var(--rust); color: #1a0e04; border-color: #ffb36e; }
.hud-grid button.danger { color: #ff9b8f; }
.hud-grid button:active, .bar-keys button:active, .dpad button:active { background: #303541; }
.bar-keys { position: fixed; left: calc(var(--sal) + 8px); bottom: calc(var(--sab) + 8px); display: flex; flex-wrap: wrap; gap: 6px; max-width: min(560px, calc(100vw - 16px - 170px)); background: rgba(16,17,20,.82); padding: 8px; border-radius: 12px; border: 1px solid var(--line); }
.bar-keys button { min-width: 44px; padding: 8px 10px; }
.dpad { position: fixed; right: calc(var(--sar) + 16px); bottom: calc(var(--sab) + 16px); display: grid; grid-template: "u u" "l r" "d d" / 1fr 1fr; gap: 6px; width: 150px; opacity: .85; }
.dpad button { min-height: 54px; font-size: 1.1rem; }
.dpad [data-d=up] { grid-area: u; } .dpad [data-d=left] { grid-area: l; } .dpad [data-d=right] { grid-area: r; } .dpad [data-d=down] { grid-area: d; }
.textbar { position: fixed; left: calc(var(--sal) + 8px); top: calc(var(--sat) + 56px); display: flex; gap: 8px; width: min(480px, calc(100vw - 16px)); background: rgba(16,17,20,.92); padding: 8px; border-radius: 12px; border: 1px solid var(--line); }
.textbar input { flex: 1; }

.modal { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0,0,0,.68); padding: 16px; }
.modal-card { background: var(--steel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; max-width: 460px; width: 100%; max-height: 90dvh; overflow: auto; }
.modal-card ol { padding-left: 20px; line-height: 1.55; color: #cfcbc2; }
.modal-card li { margin-bottom: 6px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(var(--sab) + 24px); transform: translateX(-50%); background: #0b0c0e; border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 99px; font-size: .9rem; max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.toast.err { border-color: var(--red); }

@media (max-height: 460px) {
  .panel { width: min(640px, calc(100vw - 16px)); padding: 10px; }
  .hud-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .hud-grid button { min-height: 40px; padding: 8px 4px; font-size: .74rem; }
  .hud-status { margin-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---- idioma y aviso de sonido ---- */
.lang { position: fixed; z-index: 60; bottom: calc(var(--sab) + 12px); right: calc(var(--sar) + 12px); appearance: none; border: 1px solid var(--line); background: rgba(22,24,28,.85); color: var(--text); font: inherit; font-weight: 700; font-size: .75rem; letter-spacing: .08em; padding: 7px 11px; border-radius: 99px; cursor: pointer; backdrop-filter: blur(6px); }
html[data-screen="game"] .lang { display: none; }
.audio-hint { position: fixed; z-index: 90; left: 50%; top: calc(var(--sat) + 14px); transform: translateX(-50%); appearance: none; border: 1px solid #ffb36e; background: var(--rust); color: #1a0e04; font: inherit; font-weight: 700; padding: 10px 16px; border-radius: 99px; box-shadow: 0 10px 30px rgba(0,0,0,.5); cursor: pointer; max-width: calc(100vw - 24px); }
