:root {
  --base: #1e1e2e;
  --mantle: #181825;
  --crust: #11111b;
  --surface0: #313244;
  --surface1: #45475a;
  --surface2: #585b70;
  --text: #cdd6f4;
  --subtext: #a6adc8;
  --overlay: #6c7086;
  --blue: #89b4fa;
  --mauve: #cba6f7;
  --green: #a6e3a1;
  --red: #f38ba8;
  --yellow: #f9e2af;
  --peach: #fab387;
  --teal: #94e2d5;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--base);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}

#app { max-width: 480px; margin: 0 auto; padding: 24px 18px 48px; }

.screen { display: none; animation: fade .25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.title {
  font-size: 2.1rem; line-height: 1.1; font-weight: 800; text-align: center;
  margin-top: 12px;
  background: linear-gradient(120deg, var(--mauve), var(--blue), var(--teal));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.subtitle { text-align: center; color: var(--subtext); margin: 8px 0 24px; font-size: .95rem; }

.card {
  background: var(--mantle); border: 1px solid var(--surface0);
  border-radius: 18px; padding: 18px; margin-bottom: 16px;
}
.card-title { font-size: 1.05rem; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

label { display: block; font-size: .8rem; color: var(--subtext); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
label:first-child { margin-top: 0; }

input {
  width: 100%; background: var(--crust); border: 1px solid var(--surface0);
  color: var(--text); font-size: 1.05rem; padding: 14px 16px; border-radius: 12px;
  outline: none; transition: border-color .15s;
}
input:focus { border-color: var(--blue); }
.code-input { text-transform: uppercase; letter-spacing: .35em; text-align: center; font-weight: 700; font-size: 1.4rem; }

.btn {
  width: 100%; padding: 15px; border: none; border-radius: 12px; margin-top: 12px;
  font-size: 1.05rem; font-weight: 700; cursor: pointer; color: var(--text);
  background: var(--surface0); transition: transform .1s, filter .15s; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(120deg, var(--mauve), var(--blue)); color: var(--crust); }
.btn-primary:active { filter: brightness(1.05); }
.btn-ghost { background: transparent; border: 1px solid var(--surface1); color: var(--subtext); }
.btn-mini { background: var(--surface0); color: var(--text); border: none; padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: .85rem; cursor: pointer; }

.divider { text-align: center; color: var(--overlay); margin: 18px 0 6px; position: relative; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--surface0); }
.divider::before { left: 0; } .divider::after { right: 0; }
.divider span { background: var(--mantle); padding: 0 10px; font-size: .8rem; }

.error { color: var(--red); text-align: center; margin-top: 12px; min-height: 1.2em; font-size: .9rem; }
.hint { color: var(--subtext); font-size: .85rem; margin-top: 8px; }

/* Lobby */
.room-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.room-label { font-size: .7rem; color: var(--subtext); letter-spacing: .15em; display: block; }
.room-code { font-size: 1.8rem; font-weight: 800; letter-spacing: .2em; color: var(--teal); }
.badge { background: var(--surface0); color: var(--text); border-radius: 999px; padding: 2px 10px; font-size: .85rem; }

.player-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--crust); padding: 12px 14px; border-radius: 12px;
}
.player-list .pname { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); flex: 0 0 auto; }
.dot.off { background: var(--surface2); }
.tag-host { font-size: .65rem; background: var(--mauve); color: var(--crust); padding: 2px 7px; border-radius: 6px; font-weight: 700; }
.tag-you { font-size: .65rem; background: var(--surface1); color: var(--text); padding: 2px 7px; border-radius: 6px; }
.kick { background: transparent; border: none; color: var(--red); font-size: 1.2rem; cursor: pointer; padding: 0 4px; }

/* Config roles */
.role-config { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.role-row { display: flex; align-items: center; justify-content: space-between; }
.role-name { font-weight: 700; font-size: 1.05rem; }
.role-name.dios { color: var(--yellow); }
.role-name.policia { color: var(--blue); }
.role-name.ladron { color: var(--red); }
.role-name.doctor { color: var(--green); }
.role-name.pueblo { color: var(--subtext); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 38px; height: 38px; border-radius: 10px; border: none; background: var(--surface0);
  color: var(--text); font-size: 1.3rem; font-weight: 700; cursor: pointer; line-height: 1;
}
.stepper button:active { background: var(--surface1); }
.stepper .val, .val { min-width: 32px; text-align: center; font-weight: 700; font-size: 1.1rem; }
.val.auto { color: var(--subtext); }
.pueblo-row { padding-right: 8px; }

/* Abanico de cartas en el home */
.deck-fan { position: relative; height: 132px; display: flex; align-items: center; justify-content: center; margin: 10px 0 2px; }
.deck-fan .fan-card {
  position: absolute; width: 84px; aspect-ratio: 1024 / 1536; object-fit: cover;
  border-radius: 9px; box-shadow: 0 8px 22px rgba(0,0,0,.5); border: 2px solid rgba(255,255,255,.06);
}
.fan-l { transform: rotate(-16deg) translateX(-46px) translateY(8px); }
.fan-c { transform: translateY(-10px) scale(1.07); z-index: 2; }
.fan-r { transform: rotate(16deg) translateX(46px) translateY(8px); }

/* acento de color por rol en el lobby */
.role-row[data-role] { padding-left: 12px; border-left: 3px solid var(--surface1); }
.role-row[data-role="dios"]    { border-left-color: var(--yellow); }
.role-row[data-role="policia"] { border-left-color: var(--blue); }
.role-row[data-role="ladron"]  { border-left-color: var(--red); }
.role-row[data-role="doctor"]  { border-left-color: var(--green); }

/* Carta (flip 3D) */
.reveal-hint { text-align: center; color: var(--subtext); margin: 4px 0 14px; font-size: .92rem; }

.flip-card {
  width: min(74vw, 290px); aspect-ratio: 1024 / 1536;
  margin: 0 auto 12px; perspective: 1500px; cursor: pointer;
}
.flip-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .7s cubic-bezier(.2, .85, .25, 1);
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .04);
}
.flip-face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.flip-front { transform: rotateY(180deg); background: #f4efe2; }

/* glow del borde según rol cuando está dada vuelta */
.flip-card.flipped[data-role="dios"]    .flip-front { box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 2px var(--yellow), 0 0 28px -4px var(--yellow); }
.flip-card.flipped[data-role="policia"] .flip-front { box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 2px var(--blue),   0 0 28px -4px var(--blue); }
.flip-card.flipped[data-role="ladron"]  .flip-front { box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 2px var(--red),    0 0 28px -4px var(--red); }
.flip-card.flipped[data-role="doctor"]  .flip-front { box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 2px var(--green),  0 0 28px -4px var(--green); }

/* "tocá" pulsando en el dorso */
.tap-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(17, 17, 27, .72); color: #f4efe2; font-size: .72rem; letter-spacing: .18em;
  text-transform: uppercase; padding: 5px 13px; border-radius: 999px; backdrop-filter: blur(4px);
  animation: tapPulse 1.6s ease-in-out infinite;
}
.flip-card.flipped .tap-hint { display: none; }
@keyframes tapPulse {
  0%, 100% { opacity: .55; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.06); }
}

/* cara de Pueblo (sin imagen, estilo carta vintage) */
.pueblo-face {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  background: #f4efe2; color: #2a2622; padding: 18px; text-align: center;
  border: 7px solid #c9b27a; border-radius: 14px; box-shadow: inset 0 0 0 2px #c9b27a;
}
.pueblo-face .pf-title { font-size: clamp(1.6rem, 7vw, 2.4rem); font-weight: 900; letter-spacing: .06em; }
.pueblo-face .pf-sub { font-size: .8rem; color: #6b5d44; font-style: italic; }
.pueblo-face .pf-corner { position: absolute; font-size: 1.5rem; font-weight: 900; color: #8a7a55; top: 10px; left: 14px; }
.pueblo-face .pf-corner-b { top: auto; left: auto; bottom: 10px; right: 14px; }

.card-caption {
  text-align: center; margin: 0 0 14px;
  font-size: .95rem; color: var(--teal); line-height: 1.4; font-style: italic;
}
.card-caption:empty { margin: 0; }

.god-panel { margin-top: 4px; }
.god-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.god-list li { display: flex; justify-content: space-between; background: var(--crust); padding: 10px 14px; border-radius: 10px; }
.god-list .gr { font-weight: 700; }
.god-list .gr.dios { color: var(--yellow); }
.god-list .gr.policia { color: var(--blue); }
.god-list .gr.ladron { color: var(--red); }
.god-list .gr.doctor { color: var(--green); }
.god-list .gr.pueblo { color: var(--subtext); }

.host-only { display: none; }
body.is-host .host-only { display: block; }
li.host-only { display: none; }
body.is-host li.host-only { display: flex; }

/* Ajustes del juicio (toggle) */
.toggle-row { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-weight: 600; }
.switch { width: 50px; height: 28px; border-radius: 999px; background: var(--surface1); border: none; position: relative; cursor: pointer; transition: background .15s; flex: 0 0 auto; }
.switch.on { background: var(--green); }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .18s; }
.switch.on .knob { transform: translateX(22px); }

/* Controles de Dios */
.dios-controls { border: 1px solid var(--yellow); }
.dios-controls .card-title { color: var(--yellow); }
.narrate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.btn-narrate { padding: 12px 8px; border: 1px solid var(--surface1); border-radius: 10px; background: var(--crust); color: var(--text); font-weight: 600; font-size: .9rem; cursor: pointer; line-height: 1.2; }
.btn-narrate:active { background: var(--surface0); }

/* Overlay de narración */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(8, 8, 14, .95); display: flex; align-items: center; justify-content: center; padding: 30px; animation: fade .2s ease; }
.overlay p { font-size: clamp(1.9rem, 9vw, 3rem); font-weight: 900; text-align: center; line-height: 1.2; background: linear-gradient(120deg, var(--mauve), var(--blue), var(--teal)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

/* Timer del juicio */
.trial-timer { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 55; display: flex; align-items: center; gap: 10px; background: var(--mantle); border: 1px solid var(--surface1); padding: 8px 16px; border-radius: 999px; box-shadow: 0 6px 18px rgba(0, 0, 0, .45); }
.tt-label { font-size: .7rem; letter-spacing: .15em; color: var(--subtext); }
.tt-time { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--teal); }
.trial-timer.urgent { border-color: var(--red); animation: ttPulse .8s ease-in-out infinite; }
.trial-timer.urgent .tt-time { color: var(--red); }
@keyframes ttPulse { 0%, 100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.06); } }

/* Modal de votación */
.vote-modal { position: fixed; inset: 0; z-index: 65; background: rgba(8, 8, 14, .92); display: flex; align-items: center; justify-content: center; padding: 22px; animation: fade .2s ease; }
.vote-inner { background: var(--base); border: 1px solid var(--surface0); border-radius: 18px; padding: 22px; width: 100%; max-width: 380px; }
.vote-title { text-align: center; font-size: 1.4rem; margin-bottom: 4px; }
.vote-sub { text-align: center; color: var(--subtext); font-size: .9rem; margin-bottom: 16px; }
.vote-count { color: var(--red); font-weight: 800; font-variant-numeric: tabular-nums; }
.vote-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.vote-opt { padding: 14px; border: 1px solid var(--surface1); border-radius: 12px; background: var(--crust); color: var(--text); font-size: 1.05rem; font-weight: 600; cursor: pointer; }
.vote-opt:active { background: var(--surface0); }
.vote-opt.chosen { border-color: var(--red); background: color-mix(in srgb, var(--red) 18%, var(--crust)); }
.vote-done { text-align: center; color: var(--green); font-weight: 700; margin-top: 14px; }
