/* ============================================================
   CHINCHÓN — Marcador en vivo · Felt & gold (responsive)
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-950: #062116;
  --green-900: #0a3f2a;
  --green-800: #0e5133;
  --green-700: #12713f;
  --green-600: #1a8a52;
  --green-500: #27a466;
  --gold: #f4c542;
  --gold-deep: #d99e2b;
  --gold-soft: #fdf3d3;
  --red: #d63a4a;
  --red-dark: #b12c3c;
  --red-soft: #fdecee;
  --ink: #20251f;
  --ink-soft: #38413a;
  --muted: #7d857d;
  --line: #ece5d6;
  --paper: #fffef9;
  --paper-2: #faf6ec;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(6,33,22,.06), 0 12px 32px -8px rgba(6,33,22,.28);
  --shadow-sm: 0 1px 2px rgba(6,33,22,.08), 0 4px 14px -6px rgba(6,33,22,.18);
  --font-ui: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
  background-color: var(--green-900);
  background-image:
    radial-gradient(1200px 700px at 72% -12%, rgba(255,255,255,.10), rgba(255,255,255,0) 58%),
    radial-gradient(900px 620px at 8% 112%, rgba(212,191,88,.12), rgba(212,191,88,0) 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='110' height='110' viewBox='0 0 110 110'%3E%3Cpath d='M55 8l47 47-47 47L8 55z' fill='none' stroke='rgba(255,255,255,0.045)' stroke-width='3'/%3E%3C/svg%3E");
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 36px) clamp(14px, 3.5vw, 40px)
           calc(48px + env(safe-area-inset-bottom));
}

.screen { animation: fade-in .3s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* ---------- Botones ---------- */

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 18px;
  border-radius: 12px;
  font-family: var(--font-ui);
  font-size: .98rem;
  font-weight: 700;
  letter-spacing: .01em;
  color: #fff;
  background: var(--green-700);
  transition: transform .08s ease, box-shadow .18s ease, background .18s ease, opacity .18s ease;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--green-600); box-shadow: 0 8px 20px -8px rgba(6,33,22,.45); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; transform: none; }

.btn.primary {
  background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
  box-shadow: 0 10px 24px -10px rgba(178,44,60,.55);
}
.btn.primary:hover { background: linear-gradient(180deg, #e04b5a 0%, var(--red-dark) 100%); }

.btn.danger {
  background: var(--paper);
  color: var(--red-dark);
  border: 1.5px solid #f2c9cd;
  box-shadow: none;
}
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); box-shadow: none; }

.btn.big { padding: 15px 20px; font-size: 1.05rem; border-radius: 14px; }

.flat .btn { width: auto; min-width: 104px; padding: 12px 18px; margin: 0; }

.link-btn {
  width: auto;
  margin: auto 0 auto auto;
  padding: 7px 12px;
  font-size: .8rem;
  font-weight: 600;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: none;
}
.link-btn:hover { color: var(--red-dark); border-color: var(--red); background: var(--red-soft); box-shadow: none; }

.btn + .btn { margin-top: 10px; }

/* ---------- Inputs ---------- */

input[type=text], input[type=number], input[readonly] {
  width: 100%;
  padding: 12px 15px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid #dfe4dd;
  border-radius: 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input::placeholder { color: #b3bcb3; }
input:focus {
  border-color: var(--green-600);
  box-shadow: 0 0 0 4px rgba(26,138,82,.15);
  background: #fff;
}
input[readonly] {
  background: var(--paper-2);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
input[readonly]:focus { box-shadow: none; border-color: #dfe4dd; }

label { display: block; }

.row { display: flex; gap: 10px; }
.row input { flex: 1; min-width: 0; }
.row .btn { flex: none; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 33, 22, .55);
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid rgba(6,33,22,.06);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 24px 60px -18px rgba(0,0,0,.45);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.modal-head h3 { margin: 0; font-size: 1.15rem; }
.modal-x {
  background: none;
  border: none;
  padding: 2px 6px;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
}
.modal-x:hover { color: var(--ink); }
.modal .card-sub { margin: 6px 0 16px; }
.modal .btn { margin-top: 16px; width: 100%; }
.modal .muted.small { margin: 10px 0 0; }

/* ---------- Tarjetas ---------- */

.card {
  background: var(--paper);
  border: 1px solid rgba(6,33,22,.05);
  border-radius: var(--radius);
  padding: clamp(18px, 2.4vw, 26px);
  box-shadow: var(--shadow);
}

.card-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: .01em;
  color: var(--green-900);
  margin: 0;
}

.card-sub { font-size: .9rem; color: var(--muted); margin: 6px 0 18px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.card-head .card-title { margin: 0; }

.chip {
  font-size: .78rem;
  font-weight: 700;
  color: var(--green-800);
  background: var(--gold-soft);
  border: 1px solid #f0dfae;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Marca / cabecera ---------- */

.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  color: #fff;
  text-align: center;
  letter-spacing: -.01em;
  text-shadow: 0 2px 18px rgba(0,0,0,.28);
  line-height: 1.05;
}
.logo .suit { color: var(--gold); font-size: .8em; }
.logo .accent { color: var(--gold); }

.logo.sm {
  font-size: 1.3rem;
  text-align: left;
  text-shadow: 0 1px 8px rgba(0,0,0,.22);
}

.tagline {
  color: rgba(255,255,255,.88);
  font-size: clamp(.95rem, 1.6vw, 1.08rem);
  text-align: center;
  margin: 14px 0 30px;
  line-height: 1.5;
}

.hero { animation: fade-in .5s ease; }

/* ---------- Landing ---------- */

.landing-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
  animation: fade-in .5s ease .08s both;
}

.landing-grid .card .card-title { margin-bottom: 4px; }
.landing-grid input { margin-bottom: 14px; }
.landing-grid .btn { margin-top: 2px; }

.features {
  list-style: none;
  display: grid;
  gap: 8px;
  margin-top: 26px;
  color: rgba(255,255,255,.82);
  font-size: .9rem;
  animation: fade-in .5s ease .16s both;
}
.features li { padding-left: 20px; position: relative; }
.features li::before {
  content: "";
  position: absolute;
  left: 0; top: .55em;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--gold);
}
.features b { color: #fff; }

/* ---------- Cabecera de sala ---------- */

.room-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 18px;
}

.code-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  padding: 7px 16px 7px 18px;
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
  backdrop-filter: blur(6px);
}
.code-label {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
}
.code-pill strong {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 1.06rem;
  letter-spacing: .18em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Rejilla de sala ---------- */

.room-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}

.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.col > * { margin: 0; }

/* ---------- Jugadores ---------- */

#players { display: grid; gap: 8px; }

.player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: background .15s ease, border-color .15s ease;
}
.player:hover { background: #fbf7ec; }

.player .avatar {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 13px;
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.18), 0 3px 8px -3px rgba(6,33,22,.4);
}

.player-info { flex: 1; min-width: 0; }
.player-name {
  font-weight: 700;
  font-size: .98rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-total {
  font-size: .8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}
.player-total .pts-strong { color: var(--green-800); font-weight: 700; }

.pts-entry {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.pts-input {
  flex: none;
  width: 68px !important;
  padding: 8px;
  text-align: center;
  font-size: .95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: 10px;
  -moz-appearance: textfield;
  appearance: textfield;
}
.pts-input::-webkit-outer-spin-button,
.pts-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.chin-btn {
  flex: 1;
  width: auto;
  min-width: 0;
  padding: 10px 8px;
  font-size: .74rem;
  letter-spacing: .02em;
  border-radius: 10px;
  background: linear-gradient(180deg, #d9a92c 0%, #b8860b 100%);
  box-shadow: var(--shadow-sm);
}
.chin-btn:hover { background: linear-gradient(180deg, #e5b83a 0%, #c7950e 100%); }
.chin-btn.flash { animation: chinflash .45s ease; }

@keyframes chinflash {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.pts-view {
  flex: none;
  font-size: .92rem;
  font-weight: 800;
  color: var(--green-800);
  background: #e9f5ee;
  padding: 8px 13px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .08em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: 1px;
}
.badge.elim {
  color: var(--red-dark);
  background: var(--red-soft);
  border: 1px solid #f2c9cd;
}
.badge.waiting {
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
}

.player.eliminated { background: #fbfaf6; border-style: dashed; }
.player.eliminated .player-name,
.player.eliminated .player-total { color: #b3bab1; text-decoration: line-through; }
.player.eliminated .player-name { text-decoration-color: rgba(182,39,58,.85); }
.player.eliminated .avatar { opacity: .55; filter: saturate(.3); }

.no-play { flex: none; font-size: .72rem; font-weight: 600; color: var(--red-dark); }

.muted { color: var(--muted); }
.small { font-size: .8rem; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 12px;
  text-align: center;
  border: 1.5px dashed #dfe4dd;
  border-radius: 14px;
  color: var(--muted);
}
.empty-state .big-ico {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: #c9cfc9;
}

.flat { padding-top: 14px; border-top: 1px solid var(--line); }

#add-player-form .row { margin-top: 2px; }

/* ---------- Controles ---------- */

#controls { display: flex; flex-direction: column; }
#controls .btn { margin-top: 10px; }
#controls .btn:first-child { margin-top: 0; }
#controls .btn.danger:last-child { margin-top: 18px; }

.note-viewer {
  color: rgba(255,255,255,.92);
  font-size: .95rem;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22);
  padding: 14px 18px;
  border-radius: 14px;
  backdrop-filter: blur(6px);
}
.note-viewer b { color: var(--gold); }

/* ---------- Banners ---------- */

.banner {
  margin-bottom: 18px;
  padding: 13px 18px;
  border-radius: 14px;
  font-size: .95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.banner::before {
  content: "";
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: currentColor;
}
.banner.info {
  background: rgba(255,255,255,.97);
  color: var(--green-800);
  border: 1px solid rgba(23,138,88,.2);
  box-shadow: var(--shadow-sm);
}
.banner.winner {
  background: linear-gradient(120deg, var(--gold), #ffd97a 70%);
  color: #4a3a08;
  border: none;
  box-shadow: 0 14px 34px -14px rgba(212,158,43,.8);
}
.banner.winner::before { background: #b8860b; }

/* ---------- Marcador ---------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -6px; padding: 0 6px; }

#results { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
#results th, #results td {
  padding: 10px 13px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#results thead th {
  background: var(--green-900);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
#results thead th:first-child { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
#results thead th:last-child { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
#results thead th.total-col { background: var(--green-700); }

#results tbody tr:nth-child(odd) td { background: var(--paper-2); }
#results tbody td { border-bottom: 1px solid var(--line); }
#results td:first-child { text-align: left; font-weight: 700; color: var(--ink); }
#results td.total-col {
  font-weight: 800;
  color: var(--green-800);
  background: var(--gold-soft);
}
#results tr.lost td { color: #b3bab1; text-decoration: line-through; }
#results tr.lost td:first-child { color: #98a298; }
#results tr.lost td.total-col { color: var(--red-dark); }

/* ---------- Cargando ---------- */

#screen-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  color: rgba(255,255,255,.9);
}
.loading-text { margin-top: 18px; font-weight: 600; letter-spacing: .02em; }

.dots { display: flex; gap: 10px; }
.dots i {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--gold);
  animation: bounce 1.1s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .55; } 30% { transform: translateY(-12px); opacity: 1; } }

.error-box {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.error-box h2 { font-family: var(--font-display); color: var(--green-900); margin-bottom: 8px; }
.error-box p { color: var(--muted); font-size: .95rem; margin-bottom: 18px; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  background: var(--green-950);
  color: #fff;
  padding: 13px 20px;
  border-radius: 12px;
  font-size: .92rem;
  font-weight: 600;
  box-shadow: 0 16px 40px -12px rgba(0,0,0,.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  max-width: min(92vw, 480px);
  text-align: center;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--red-dark); }

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .wrap { padding-top: clamp(28px, 4vw, 44px); }

  .landing-grid {
    grid-template-columns: 1fr 1fr;
    max-width: 860px;
    margin: 0 auto;
  }
  .features {
    max-width: 620px;
    margin: 30px auto 0;
  }

  .room-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }

  .card-title { font-size: 1.5rem; }

  #players { grid-template-columns: 1fr 1fr; gap: 10px; }
  .player { padding: 13px 14px; gap: 14px; }
  .player .avatar { width: 46px; height: 46px; font-size: 1.1rem; }

  .pts-input { width: 76px !important; }
  .chin-btn { padding: 11px 12px; font-size: .76rem; }

  .btn.big { padding: 16px 22px; }
}

@media (min-width: 1240px) {
  #players { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Scrollbar ---------- */

.table-scroll::-webkit-scrollbar { height: 9px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb {
  background: #cfd6cf;
  border-radius: 999px;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: #b6c0b7; }

/* ---------- Movimiento reducido ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}