:root {
  --bg: #0f1020;
  --bg2: #16172e;
  --card: #1d1f3a;
  --card2: #24264a;
  --txt: #f3f4ff;
  --muted: #9a9cc4;
  --accent: #7c5cff;
  --accent2: #ff5c8a;
  --good: #3ddc97;
  --cig: #ff8a5c;
  --cub: #5cc8ff;
  --cer: #ffd45c;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  /* desactiva el zoom por doble toque (clave en iOS, que ignora user-scalable=no) */
  touch-action: manipulation;
}

/* El atributo hidden SIEMPRE oculta, aunque haya un display: flex/grid encima.
   (Sin esto, el modal con position:fixed tapaba toda la pantalla e impedía clicar.) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  /* evita el desplazamiento lateral por rebote/overflow en móvil */
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* Los elementos interactivos no se seleccionan al tocar rápido */
button, .counter, .code-chip, .seg, .tab, .copy-btn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--txt);
  background:
    radial-gradient(1200px 600px at 80% -10%, #2a1d52 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #3a1d40 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: 22px 18px 40px;
  min-height: 100vh;
  display: none;            /* oculta por defecto: solo se ve la pantalla activa */
  flex-direction: column;
}
.screen.active {
  display: flex;
  animation: screenIn .25s ease;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* Pantallas centradas (las de tarjeta) */
#home, #created, #join { justify-content: center; align-items: center; }

.auth-card {
  width: 100%;
  background: linear-gradient(160deg, var(--card), var(--bg2));
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 24px;
  padding: 30px 24px;
  box-shadow: var(--shadow);
}

.logo {
  font-size: 32px;
  margin: 0 0 6px;
  text-align: center;
  font-weight: 800;
  letter-spacing: -.5px;
}
.logo span { display: inline-block; }

.subtitle {
  text-align: center;
  color: var(--muted);
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.4;
}

.tabs {
  display: flex;
  background: rgba(0, 0, 0, .25);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}
.tab.active { background: var(--accent); color: #fff; }

form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input {
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .09);
  color: var(--txt);
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border .15s;
}
input:focus { border-color: var(--accent); }

.btn-primary {
  margin-top: 6px;
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(124, 92, 255, .35);
  transition: transform .08s;
}
.btn-primary:active { transform: scale(.98); }

.error {
  color: #ff8095;
  background: rgba(255, 92, 138, .12);
  border: 1px solid rgba(255, 92, 138, .3);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  margin: 0;
}

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }
.foot.small { margin-top: 24px; opacity: .7; }

/* ---------------- SALA ---------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.hello { color: var(--muted); font-size: 14px; }
#me-name { font-size: 20px; }
.btn-ghost {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  color: var(--txt);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.counters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.counter {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 6px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .08);
  background: linear-gradient(160deg, var(--card2), var(--card));
  color: var(--txt);
  cursor: pointer;
  user-select: none;
  transition: transform .08s, box-shadow .15s;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.counter:active { transform: scale(.96); }
.counter[data-type="cigarro"] { border-top: 3px solid var(--cig); }
.counter[data-type="cubata"]  { border-top: 3px solid var(--cub); }
.counter[data-type="cerveza"] { border-top: 3px solid var(--cer); }

.counter .emoji { font-size: 34px; line-height: 1; }
.counter .cname { font-size: 13px; color: var(--muted); font-weight: 600; }
.counter .cval { font-size: 30px; font-weight: 800; line-height: 1.1; }
.counter .ctoday { font-size: 12px; color: var(--muted); }
.counter .ctoday b { color: var(--good); }

.counter .undo {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}
.counter .undo:active { background: var(--accent2); color: #fff; }

.bump { animation: bump .35s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); color: var(--good); }
  100% { transform: scale(1); }
}

.room-totals {
  display: flex;
  justify-content: space-around;
  background: rgba(0, 0, 0, .22);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 22px;
}
.room-totals div { display: flex; align-items: center; gap: 6px; font-size: 15px; }
.room-totals b { font-size: 17px; }
.room-totals span { font-size: 18px; }

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.board-head h2 { font-size: 17px; margin: 0; }
.toggle { display: flex; background: rgba(0, 0, 0, .25); border-radius: 10px; padding: 3px; }
.seg {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg.active { background: var(--accent); color: #fff; }

.leaderboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 14px;
  padding: 12px 14px;
}
.row.me { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.rank { font-size: 16px; font-weight: 800; width: 30px; color: var(--muted); text-align: center; }
.rank.gold { color: #ffd45c; } .rank.silver { color: #cfd6e6; } .rank.bronze { color: #e0975c; }
.who { flex: 1; min-width: 0; }
.who .name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .breakdown { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; gap: 10px; }
.sum { font-size: 22px; font-weight: 800; }
.sum small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; text-align: right; }

.empty { text-align: center; color: var(--muted); padding: 24px; }

/* ---------------- TOAST ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #000;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: .25s;
  z-index: 50;
  border: 1px solid rgba(255, 255, 255, .15);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- INICIO / CREAR / UNIRSE ---------------- */
.logo.small { font-size: 24px; }

.home-actions { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.btn-primary.big, .btn-secondary.big { font-size: 18px; padding: 18px; }

.btn-secondary {
  border: 0;
  background: rgba(255, 255, 255, .08);
  color: var(--txt);
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .12);
  transition: transform .08s, background .15s;
}
.btn-secondary:active { transform: scale(.98); background: rgba(255, 255, 255, .14); }
.btn-ghost.full, .btn-secondary.full { width: 100%; margin-top: 12px; }

.back {
  background: none; border: 0; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 0; margin-bottom: 10px;
}

.field-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 14px 0 6px;
}

.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, .3);
  border: 1px dashed rgba(124, 92, 255, .6);
  border-radius: 14px;
  padding: 14px 16px;
}

/* Recuadro del enlace de invitación */
.link-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 14px;
  padding: 10px 10px 10px 14px;
}
.link {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--cub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* Botón icono (📤 compartir) en la barra de la sala */
.icon-btn {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  color: var(--txt);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(.94); background: rgba(255, 255, 255, .14); }
.code {
  flex: 1;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--good);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.copy-btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.copy-btn:active { transform: scale(.96); }

#join-code {
  text-transform: uppercase;
  letter-spacing: 4px;
  font-weight: 700;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.sep { border: 0; border-top: 1px solid rgba(255, 255, 255, .1); margin: 22px 0 16px; }

/* ---------------- TOPBAR de la sala ---------------- */
.topinfo { display: flex; flex-direction: column; gap: 2px; }
.topright { display: flex; align-items: center; gap: 10px; }
.me-name { font-weight: 700; font-size: 15px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(124, 92, 255, .18);
  border: 1px solid rgba(124, 92, 255, .5);
  color: var(--txt);
  border-radius: 9px;
  padding: 4px 10px;
  cursor: pointer;
}
.code-chip strong { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px; font-size: 16px; }
.code-chip .copyicon { color: var(--muted); font-size: 14px; }

/* ---------------- Barra de períodos ---------------- */
.period-bar {
  display: flex;
  background: rgba(0, 0, 0, .25);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 18px;
  gap: 2px;
}
.period-bar .seg { flex: 1; padding: 9px 0; }

/* room-totals (rediseñado) */
.room-totals {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.rt-label { font-size: 13px; color: var(--muted); }
.rt-label b { color: var(--txt); text-transform: capitalize; }
.rt-nums { display: flex; justify-content: center; gap: 28px; width: 100%; }

.board-period { font-size: 13px; color: var(--muted); text-transform: capitalize; background: rgba(255,255,255,.06); padding: 3px 10px; border-radius: 8px; }

/* ---------------- RESPONSIVE (móviles) ---------------- */

/* La barra de períodos: que el texto no se corte en pantallas estrechas */
.period-bar .seg { font-size: 14px; white-space: nowrap; }

@media (max-width: 480px) {
  .screen { padding: 16px 14px 36px; }
  .auth-card { padding: 24px 18px; }

  /* topbar: que pueda envolver sin desbordar */
  .topbar { flex-wrap: wrap; gap: 10px; }
  .me-name { max-width: 90px; }

  /* contadores algo más compactos */
  .counter { padding: 16px 4px 12px; }
  .counter .emoji { font-size: 30px; }
  .counter .cval { font-size: 26px; }

  /* el código grande de "sala creada" no debe desbordar */
  .code { font-size: 26px; letter-spacing: 4px; }
  .rt-nums { gap: 20px; }
}

@media (max-width: 360px) {
  .counter .cname { font-size: 12px; }
  .counter .cval { font-size: 23px; }
  .period-bar .seg { font-size: 13px; padding: 8px 0; }
  .code { font-size: 22px; letter-spacing: 3px; }
  .copy-btn { padding: 10px 12px; }
}

/* Si el móvil está en horizontal y es bajito, centramos menos para que quepa */
@media (max-height: 520px) {
  #home, #created, #join { justify-content: flex-start; }
}

/* ---------------- AVATARES ---------------- */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: 1px solid rgba(255, 255, 255, .15);
  overflow: hidden;
}
.avatar.placeholder { background: linear-gradient(135deg, #3a3c6e, #4a2d52); color: #cfd2f5; }

/* Avatar pequeño en la barra superior */
.me-avatar { display: inline-block; line-height: 0; }
.me-avatar .avatar { width: 30px; height: 30px; font-size: 13px; }

/* Selector de foto en los formularios */
.avatar-pick { display: flex; align-items: center; gap: 14px; }
.avatar-drop {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px dashed rgba(124, 92, 255, .6);
  background: rgba(0, 0, 0, .25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-drop:active { transform: scale(.97); }
.avatar-plus {
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
}
.avatar-plus small { font-size: 11px; font-weight: 600; }
.avatar-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.avatar-hint { font-size: 12px; color: var(--muted); line-height: 1.35; }
.avatar-hint b { color: var(--txt); }

/* Botón para cambiar mi foto (avatar + insignia de cámara) en la barra superior */
.me-avatar-btn {
  position: relative;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  flex-shrink: 0;
}
.me-avatar-btn:active { transform: scale(.94); }
.me-avatar:empty::before {
  /* círculo gris mientras carga, para que la cámara no quede flotando */
  content: "";
  display: inline-block;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .08);
}
.cam-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 1.5px solid var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
}

/* Botón de abandonar sala (acción destructiva) */
.btn-danger {
  margin: 14px auto 0;
  display: block;
  background: rgba(255, 92, 138, .1);
  border: 1px solid rgba(255, 92, 138, .35);
  color: #ff8095;
  padding: 11px 18px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.btn-danger:active { transform: scale(.97); background: rgba(255, 92, 138, .2); }

/* ---------------- MODAL de confirmación ---------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  opacity: 0;
  transition: opacity .2s;
}
.modal.show { opacity: 1; }
.modal-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  transform: translateY(12px) scale(.98);
  transition: transform .2s;
}
.modal.show .modal-card { transform: none; }
.modal-title { margin: 0 0 8px; font-size: 19px; }
.modal-msg { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; padding: 13px; }
.btn-danger-solid {
  border: 0;
  background: linear-gradient(135deg, #ff5c8a, #ff7a5c);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-radius: 11px;
  cursor: pointer;
}
.btn-danger-solid:active { transform: scale(.97); }

/* ---------------- INSTALAR APP ---------------- */
.install-btn {
  width: 100%;
  margin-top: 14px;
  background: rgba(124, 92, 255, .12);
  border: 1px solid rgba(124, 92, 255, .45);
  color: var(--txt);
  padding: 13px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.install-btn:active { transform: scale(.98); background: rgba(124, 92, 255, .22); }

/* Pasos del modal de instalación en iPhone */
.steps {
  margin: 0 0 20px;
  padding-left: 22px;
  color: var(--txt);
  font-size: 14px;
  line-height: 1.6;
}
.steps li { margin-bottom: 8px; }
.steps b { color: var(--accent); }
.ios-share {
  display: inline-block;
  vertical-align: -4px;
  color: #5c9dff;
  margin: 0 2px;
}

/* ---------------- PASOS ILUSTRADOS (instalar en iPhone) ---------------- */
.modal-card { max-height: 88vh; overflow-y: auto; }

.install-steps { display: flex; flex-direction: column; gap: 18px; margin-bottom: 20px; }
.istep-txt {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.4;
  color: var(--txt);
  margin-bottom: 9px;
}
.istep-txt b { color: var(--accent); }
.istep-n {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ill {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}
