:root {
  --bg: #14110d; --panel: #201b15; --panel2: #2a231b; --line: #3b3226;
  --text: #f3ead9; --muted: #b3a58d; --accent: #e8a33d; --accent-ink: #1b1306;
  --ok: #7cc36a; --bad: #e46a5a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
[hidden] { display: none !important; }
h1 { font-size: clamp(28px, 6vw, 44px); margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 10px; }
.muted { color: var(--muted); }
small { color: var(--muted); font-weight: 400; }

.wrap { max-width: 720px; margin: 0 auto; padding: 32px 16px 48px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-top: 18px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 22px; }
.choice { display: block; text-decoration: none; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.choice:hover { border-color: var(--accent); }
.choice b { display: block; font-size: 20px; margin-bottom: 4px; color: var(--accent); }

label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], select {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
}
input.code { text-transform: uppercase; letter-spacing: 0.3em; font-size: 24px; font-weight: 700; text-align: center; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }

.files { list-style: none; padding: 0; margin: 12px 0 0; }
.files li { padding: 6px 0 6px 26px; position: relative; }
.files li::before { position: absolute; left: 0; }
.files .ok::before { content: "✔"; color: var(--ok); }
.files .missing::before { content: "✖"; color: var(--bad); }
.files .opt::before { content: "–"; color: var(--muted); }
.filepick { display: inline-flex; cursor: pointer; }
.filepick input { display: none; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; }

/* ---- Pantalla de juego ---- */
.game-layout { display: grid; grid-template-columns: 1fr 300px; height: 100vh; height: 100dvh; }
#stage { position: relative; background: #000; min-height: 0; display: flex; align-items: center; justify-content: center; }
#game { width: 100%; height: 100%; }
#video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.side { background: var(--panel); border-left: 1px solid var(--line); padding: 16px; overflow: auto; }
.bigcode { font-size: 40px; font-weight: 800; letter-spacing: 0.25em; color: var(--accent); margin: 2px 0 8px; }
.players { list-style: none; padding: 0; margin: 8px 0 0; }
.players li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.players select { width: auto; padding: 6px 8px; }
.pname { overflow-wrap: anywhere; }
.pad { color: var(--muted); font-size: 14px; white-space: nowrap; }
#status { margin: 10px 0; color: var(--muted); }
#status.bad { color: var(--bad); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; margin-top: 8px; }
.keys kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; font: 13px ui-monospace, monospace; justify-self: start; }
.overlay-msg { position: absolute; inset: auto 0 16px; text-align: center; }

@media (max-width: 860px) {
  .game-layout { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  #stage { aspect-ratio: 4 / 3; max-height: 70vh; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
}

/* ---- Mando táctil ---- */
#touch { position: absolute; inset: 0; pointer-events: none; user-select: none; -webkit-user-select: none; touch-action: none; }
#touch button {
  pointer-events: auto; position: absolute; width: 54px; height: 54px; padding: 0; border-radius: 50%;
  background: rgba(255,255,255,0.14); border: 1px solid rgba(255,255,255,0.3); color: #fff; font-size: 20px;
}
#touch button.on { background: rgba(232,163,61,0.7); }
#touch .dpad { position: absolute; left: 14px; bottom: 14px; width: 162px; height: 162px; }
#touch .dpad [data-b=up] { left: 54px; top: 0; border-radius: 12px; }
#touch .dpad [data-b=down] { left: 54px; bottom: 0; border-radius: 12px; }
#touch .dpad [data-b=left] { left: 0; top: 54px; border-radius: 12px; }
#touch .dpad [data-b=right] { right: 0; top: 54px; border-radius: 12px; }
#touch .face { position: absolute; right: 14px; bottom: 14px; width: 162px; height: 162px; }
#touch .face [data-b=triangle] { left: 54px; top: 0; }
#touch .face [data-b=cross] { left: 54px; bottom: 0; }
#touch .face [data-b=square] { left: 0; top: 54px; }
#touch .face [data-b=circle] { right: 0; top: 54px; }
#touch [data-b=l1], #touch [data-b=l2], #touch [data-b=r1], #touch [data-b=r2] { width: 58px; height: 36px; border-radius: 10px; font-size: 14px; top: 10px; }
#touch [data-b=l2] { left: 10px; } #touch [data-b=l1] { left: 74px; }
#touch [data-b=r1] { right: 74px; } #touch [data-b=r2] { right: 10px; }
#touch [data-b=select], #touch [data-b=start] { width: 64px; height: 30px; border-radius: 15px; font-size: 12px; bottom: 14px; }
#touch [data-b=select] { left: calc(50% - 70px); } #touch [data-b=start] { left: calc(50% + 6px); }

/* ---- Sin interfaz de EmulatorJS: solo el juego ---- */
#game .ejs_menu_bar, #game .ejs_context_menu, #game .ejs_virtualGamepad_parent { display: none !important; }
input[type=password] {
  padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
}

/* ---- Panel de controles ---- */
details.controls { margin-top: 18px; }
details.controls summary { cursor: pointer; font-weight: 700; font-size: 16px; padding: 4px 0; }
.binds { width: 100%; border-collapse: collapse; font-size: 14px; }
.binds th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px; }
.binds td { padding: 3px 4px; border-top: 1px solid var(--line); }
.binds td:first-child { width: 4.5em; }
button.bind {
  width: 100%; padding: 4px 8px; font-size: 13px; font-weight: 600; justify-content: flex-start;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
}
button.bind:hover { border-color: var(--accent); }
button.bind.wait { border-color: var(--accent); color: var(--accent); }
