/* Estilo: papel, tinta y un solo acento. Sin degradados ni brillos. */
:root {
  --paper: #f4f1ea; --paper2: #ebe6db; --ink: #1d1b18; --ink2: #5d5850; --line: #d9d2c3;
  --accent: #b5462f; --ok: #3d6b4f;
  --safe-b: env(safe-area-inset-bottom); --safe-t: env(safe-area-inset-top);
  --serif: 'Fraunces', Georgia, serif; --sans: 'Inter', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans); color: var(--ink); background: var(--paper); font-size: 15px;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
  /* grano de papel sutil */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}
.topbar {
  position: sticky; top: 0; z-index: 5; padding: calc(var(--safe-t) + 14px) 20px 12px; background: var(--paper);
  border-bottom: 1px solid var(--ink); display: flex; align-items: baseline; justify-content: space-between;
}
.topbar h1 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 1.6rem; letter-spacing: -.3px; font-style: italic; }
.version { font-size: .7rem; color: var(--ink2); font-variant-numeric: tabular-nums; padding: 4px 0 4px 10px; cursor: pointer; opacity: .7; }
.version:active { opacity: 1; }
main { padding: 18px 18px calc(92px + var(--safe-b)); max-width: 620px; margin: 0 auto; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  padding: 0 8px var(--safe-b); background: var(--paper); border-top: 1px solid var(--ink);
}
.tabbar button {
  flex: 1; background: none; border: 0; color: var(--ink2); font: inherit; font-size: 0; padding: 14px 4px 12px;
  position: relative;
}
.tabbar button span { font-size: .8rem; font-weight: 500; letter-spacing: .3px; }
.tabbar button.active { color: var(--ink); }
.tabbar button.active span { font-weight: 700; }
.tabbar button.active::before { content: ''; position: absolute; top: -1px; left: 30%; right: 30%; height: 3px; background: var(--accent); }

h2 {
  font-family: var(--serif); font-weight: 600; font-size: 1.15rem; margin: 26px 0 10px; color: var(--ink);
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.card { background: #fbf9f4; border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.muted { color: var(--ink2); font-size: .85rem; }
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--ink); border-radius: 4px; padding: 11px 16px;
  color: var(--paper); background: var(--ink); cursor: pointer; transition: transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; padding: 15px; font-size: 1rem; letter-spacing: .2px; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.danger { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.sm { padding: 7px 12px; font-size: .85rem; }
input, textarea, select {
  font: inherit; color: var(--ink); background: #fbf9f4; border: 1px solid var(--line); border-radius: 4px;
  padding: 11px 12px; width: 100%; outline: none; user-select: text; -webkit-user-select: text; -webkit-appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--ink); }
textarea { min-height: 60vh; line-height: 1.6; resize: vertical; font-family: var(--serif); font-size: 1rem; }
label { display: block; font-size: .8rem; color: var(--ink2); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .6px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper b { min-width: 44px; text-align: center; font-family: var(--serif); font-size: 1.3rem; font-variant-numeric: tabular-nums; }

/* Partida */
.players { display: grid; gap: 10px; }
.player { position: relative; border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; background: #fbf9f4; transition: opacity .3s; }
.player.leader { border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.player.out { opacity: .35; }
.player.out .score { text-decoration: line-through; text-decoration-thickness: 2px; }
.player .name { font-weight: 600; font-size: 1rem; }
.player .score { font-family: var(--serif); font-size: 3.6rem; font-weight: 500; line-height: 1; letter-spacing: -2px; font-variant-numeric: tabular-nums; }
.player .score.bump { animation: bump .35s ease; }
@keyframes bump { 50% { color: var(--accent); } }
.bar { height: 2px; background: var(--line); margin: 10px 0; }
.bar i { display: block; height: 100%; background: var(--ink); transition: width .4s; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: .7rem; padding: 2px 7px; border: 1px solid var(--line); border-radius: 3px; color: var(--ink2); }
.badge.red { color: var(--accent); border-color: var(--accent); }
.entry { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 10px; }
.entry input { font-family: var(--serif); font-size: 1.3rem; text-align: center; padding: 9px; }
.pending { font-family: var(--serif); font-size: 1.4rem; min-width: 60px; text-align: right; align-self: center; color: var(--accent); font-variant-numeric: tabular-nums; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.quick button {
  font: inherit; font-weight: 600; font-size: .82rem; padding: 9px 2px; border-radius: 4px; border: 1px solid var(--line);
  background: transparent; color: var(--ink);
}
.quick button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.quick .q-pen { color: var(--accent); }
.quick .q-pen.on { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.sticky-actions { position: sticky; bottom: calc(66px + var(--safe-b)); display: flex; gap: 8px; margin-top: 14px; z-index: 4; padding: 8px 0; background: linear-gradient(transparent, var(--paper) 30%); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 4px; text-align: center; border-bottom: 1px solid var(--line); }
th { font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--ink2); }
td.tag, .tag { font-size: .68rem; color: var(--ink2); }

.hero { text-align: center; padding: 24px 16px 8px; }
.hero img { width: 72px; height: 72px; border-radius: 16px; filter: grayscale(.4) sepia(.25); }
.empty { text-align: center; color: var(--ink2); padding: 30px 10px; font-family: var(--serif); font-style: italic; }
.rules-view { white-space: pre-wrap; line-height: 1.7; font-family: var(--serif); font-size: 1rem; user-select: text; -webkit-user-select: text; }
.rank { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dotted var(--line); }
.rank:last-child { border-bottom: 0; }

#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 66px); transform: translate(-50%, -10px); opacity: 0; z-index: 50;
  background: var(--ink); color: var(--paper); font-weight: 500; font-size: .9rem;
  padding: 10px 16px; border-radius: 4px; transition: .25s; pointer-events: none; text-align: center; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(29,27,24,.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal .card { width: 100%; max-width: 420px; background: var(--paper); border-color: var(--ink); box-shadow: 5px 5px 0 var(--ink); animation: pop .2s ease; }
.modal h2 { margin-top: 4px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.win { text-align: center; }
.win .trophy { font-size: 3.5rem; }
.confetti { position: fixed; top: -10px; width: 6px; height: 10px; z-index: 45; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* Repartidor */
.dealer {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--paper2); border: 1px dashed var(--line); border-radius: 4px;
  padding: 8px 12px; margin-bottom: 12px; font-size: .88rem; cursor: pointer;
}
.dealer:active { background: var(--line); }
.dealer b { color: var(--ink); }

/* Mesa en directo y compartir */
.live-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: #edf6f0; border: 1px solid var(--ok); border-radius: 4px;
  padding: 8px 12px; margin-bottom: 10px; cursor: pointer; font-size: .86rem; color: #1e4d30;
}
.live-bar.off { background: var(--paper2); border: 1px dashed var(--line); color: var(--ink2); }
.live-bar:active { opacity: .8; }
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); margin-right: 6px; vertical-align: middle;
  animation: pulse-dot 1.8s infinite;
}
@keyframes pulse-dot { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.3); opacity: .4; } }
.remote-badge {
  display: inline-block; font-size: .68rem; font-weight: 600; padding: 2px 6px;
  border-radius: 3px; background: #eaf5ee; color: var(--ok); border: 1px solid var(--ok); margin-left: 4px;
}
.guest-panel {
  background: #fffdf9; border: 2px solid var(--ink); border-radius: 6px;
  padding: 16px; margin: 12px 0 16px; box-shadow: 3px 3px 0 var(--line);
}
.guest-tag {
  display: inline-block; font-size: .72rem; text-transform: uppercase; font-weight: 700;
  letter-spacing: 1px; color: var(--accent); margin-bottom: 4px;
}
.share-code-box {
  background: var(--paper2); border: 1px dashed var(--ink); border-radius: 4px;
  padding: 12px; text-align: center; margin: 12px 0;
}
.share-code {
  font-family: var(--serif); font-size: 2.2rem; font-weight: 700; letter-spacing: 3px;
  color: var(--ink); line-height: 1.1; margin: 4px 0;
}
.btn-wa {
  background: #25d366 !important; border-color: #1ebe5d !important; color: #fff !important;
}
.btn-wa:active { background: #1da851 !important; }

/* Botón campana y Administrador */
.btn-bell {
  background: var(--accent) !important; border-color: #8c321f !important; color: #fff !important;
  font-weight: 700 !important; font-size: .95rem !important;
}
.btn-bell:active { opacity: .9; }
.admin-badge {
  background: var(--ink); color: var(--paper); font-size: .7rem; font-weight: 700;
  padding: 3px 8px; border-radius: 3px; display: inline-flex; align-items: center; gap: 4px;
}
.pot-card {
  display: flex; justify-content: space-between; align-items: center;
  background: #faf6ea; border: 1px solid #d9c89e; border-radius: 4px;
  padding: 8px 12px; margin-bottom: 10px; font-size: .88rem;
}

/* Botón icono de cabecera */
.btn-icon {
  background: none; border: 0; font-size: 1.15rem; cursor: pointer; padding: 4px;
  line-height: 1; border-radius: 4px; transition: transform .15s;
}
.btn-icon:active { transform: scale(.88); }

/* Pestañas de configuración y elementos de Administrador */
.cfg-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.cfg-tab {
  background: none; border: 0; border-bottom: 2px solid transparent; font: inherit; font-size: .82rem;
  font-weight: 600; padding: 6px 10px; cursor: pointer; color: var(--ink2); white-space: nowrap;
}
.cfg-tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.cfg-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cfg-row:last-child { border-bottom: 0; }
.cfg-title { font-weight: 600; font-size: .92rem; }
.cfg-desc { font-size: .78rem; color: var(--ink2); margin-top: 2px; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: var(--line); transition: .2s; border-radius: 24px; border: 1px solid var(--ink2); }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; transition: .2s; border-radius: 50%; }
input:checked + .slider { background: var(--ok); border-color: var(--ok); }
input:checked + .slider:before { transform: translateX(20px); }

/* Normas numeradas */
.seg { display: flex; border: 1px solid var(--ink); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.seg button { flex: 1; font: inherit; font-weight: 600; font-size: .88rem; padding: 10px; border: 0; background: transparent; color: var(--ink); }
.seg button.on { background: var(--ink); color: var(--paper); }
.rule { padding: 14px 2px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.rule:active { background: var(--paper2); }
.rule-n { font-size: .7rem; text-transform: uppercase; letter-spacing: 1.4px; color: var(--accent); font-weight: 700; }
.rule-t { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; margin: 2px 0 4px; }
.rule-x { font-size: .95rem; line-height: 1.55; color: var(--ink2); white-space: pre-wrap; }
.btn:disabled { opacity: .3; }
