/* Reset base del archivo original */
:root{color-scheme:light;box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}html{scroll-padding-top:env(safe-area-inset-top,0px)}body{margin:0;padding:0;font:14px -apple-system,BlinkMacSystemFont,sans-serif;background:#fff;color:#000}img{max-width:100%}[hidden]:not([hidden=until-found i]){display:none!important}

/* Layout: mesa vertical de una columna. Rival arriba, pilas al centro, tu mano abajo. */
:root {
  --felt: #0e3a35;
  --felt-deep: #0a2b27;
  --paper: #f6efdd;
  --ink: #f1e9d6;
  --card-ink: #1c1916;
  --suit-red: #c1302a;
  --gold: #e9b43c;
  --muted: #93b5ac;
  --line: rgba(241, 233, 214, 0.2);
  --font-display: 'Bowlby One', 'Arial Black', sans-serif;
  --font-body: 'Barlow', system-ui, sans-serif;
  --font-card: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--felt-deep);
  color: var(--ink);
  font-family: var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px;
}
#app {
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}
.top { display: flex; align-items: center; gap: 10px; }
.top h1 { font: 400 22px/1 var(--font-display); letter-spacing: 0.02em; margin: 0; flex: 1; min-width: 0; color: var(--paper); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score { display: flex; gap: 12px; font-size: 13px; color: var(--muted); }
.score b { color: var(--ink); font-variant-numeric: tabular-nums; font-size: 15px; }
.weave {
  height: 6px; flex: none;
  background: repeating-linear-gradient(90deg, var(--suit-red) 0 10px, var(--gold) 10px 14px, var(--paper) 14px 18px, var(--gold) 18px 22px);
}
.btn {
  font: 600 14px var(--font-body);
  min-height: 44px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line);
  background: rgba(241, 233, 214, 0.06); color: var(--ink);
  cursor: pointer;
}
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn.icon { min-width: 34px; padding: 0 8px; font-size: 18px; line-height: 1; }
.btn.tiny { min-height: 28px; padding: 0 8px; font-size: 12px; margin-left: auto; text-transform: none; letter-spacing: 0; }
.btn.primary { background: var(--gold); color: #2a1d00; border-color: transparent; }
.btn.active { background: var(--gold); color: #2a1d00; border-color: transparent; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.zlabel { font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.zone { display: flex; flex-direction: column; gap: 6px; }
.mini-backs { display: flex; gap: 3px; }
.mini-backs .card { width: 22px; border-radius: 3px; }
.laid { display: flex; flex-wrap: wrap; gap: 8px; min-height: 48px; align-items: center; }
.laid:empty::before { content: attr(data-empty); color: var(--muted); font-size: 12px; }
.grp { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; align-items: center; }
.grp .card { width: 30px; border-radius: 4px; }
.grp .tag { font-size: 11px; color: var(--gold); padding: 0 4px; }

.piles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; justify-items: center; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; }
.pile label { font-size: 12px; color: var(--muted); text-align: center; }
.slot {
  width: 100%; max-width: 72px; aspect-ratio: 5 / 7; padding: 0;
  border: 2px dashed var(--line); border-radius: 8px; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: inherit;
}
.slot .card { width: 100%; }
.slot:disabled { cursor: default; }
.slot.on { border: 2px solid var(--gold); }
.slot.ready { border: 2px solid var(--gold); box-shadow: 0 0 0 3px rgba(233, 180, 60, 0.2); }
.slot.static { cursor: default; }

.msg { margin: 0; min-height: 38px; font-size: 14px; line-height: 1.35; color: var(--ink); }

.card {
  position: relative; container-type: inline-size;
  aspect-ratio: 5 / 7; background: var(--paper); color: var(--card-ink);
  border-radius: 6px; font-family: var(--font-card); font-weight: 700;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  user-select: none; -webkit-user-select: none; overflow: hidden;
}
.card.red { color: var(--suit-red); }
.card .rk { position: absolute; left: 9cqw; top: 4cqw; font-size: 40cqw; line-height: 1; }
.card .st { position: absolute; left: 10cqw; top: 44cqw; font-size: 30cqw; line-height: 1; }
.card .big { position: absolute; right: 7cqw; bottom: 4cqw; font-size: 52cqw; line-height: 1; opacity: 0.92; }
.card.back {
  background-color: #6f2622;
  background-image: linear-gradient(140deg, rgba(255, 255, 255, 0.07), transparent 55%);
  border: 2px solid #d9c9a8;
  box-shadow: inset 0 0 0 2px rgba(233, 180, 60, 0.18), 0 1px 0 rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
}
.card.back::after { content: ""; position: absolute; inset: 22%; border: 1px solid rgba(233, 180, 60, 0.35); border-radius: 3px; }
.card.back span { display: none; }

/* Mano: las cartas se reparten el ancho disponible y se solapan (--ov). */
.hand { --ov: 18px; --basis: calc((100% + 7 * var(--ov)) / 8); display: flex; align-items: flex-start; justify-content: center; padding-top: 16px; }
.hand .card { flex: 0 0 min(var(--basis), 92px); margin-left: calc(-1 * var(--ov)); touch-action: none; cursor: grab; transition: transform 0.15s; }
.hand .card:first-child { margin-left: 0; }
.hand .card .rk { left: 8cqw; top: 3cqw; font-size: 46cqw; }
.hand .card .st { left: 9cqw; top: 48cqw; font-size: 32cqw; }
.hand .card .big { right: auto; left: 7cqw; bottom: 2cqw; font-size: 58cqw; }
.hand .card.sel { transform: translateY(-14px); outline: 2px solid var(--gold); z-index: 4; }
#myLaid .grp .card { width: 38px; }
.hand .card.drag { z-index: 5; transition: none; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45); cursor: grabbing; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 0; min-width: 0; white-space: nowrap; }

/* Barra inferior fija: la mano y las acciones siempre visibles. */
.playbar {
  position: sticky; bottom: 0; z-index: 6;
  display: flex; flex-direction: column; gap: 8px;
  margin-top: auto;
  padding-top: 4px; padding-bottom: 2px;
  background: linear-gradient(to bottom, rgba(10, 43, 39, 0) 0, var(--felt-deep) 10px);
}

.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(5, 20, 18, 0.84);
  display: grid; place-items: end center;
  padding: 16px max(16px, env(safe-area-inset-left, 0px)) calc(16px + env(safe-area-inset-bottom, 0px));
}
.sheet {
  width: 100%; max-width: 480px; max-height: 100%; overflow-y: auto;
  background: var(--felt); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.sheet h2 { font: 400 22px/1.1 var(--font-display); margin: 0; color: var(--paper); text-wrap: balance; }
.sheet p, .sheet li { font-size: 14px; line-height: 1.45; margin: 0; }
.sheet ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.setting-row .seg { display: flex; gap: 6px; }
.setting-row .btn { min-height: 36px; }
.endcards { display: flex; flex-wrap: wrap; gap: 8px; }

/* Online: lobby, sala y datos compartidos */
.online-badge {
  font: 600 12px var(--font-body); color: var(--gold);
  background: rgba(233, 180, 60, 0.1); border: 1px solid rgba(233, 180, 60, 0.3);
  padding: 3px 7px; border-radius: 999px; white-space: nowrap;
}
body.online .score { display: none; }
body.online #btnEmotes { display: inline-flex; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input[type="text"] {
  width: 100%; min-height: 44px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(241, 233, 214, 0.06); color: var(--ink); padding: 0 12px;
  font: 600 16px var(--font-body); letter-spacing: 0.04em;
}
input[type="text"]:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; text-transform: uppercase; }
.join-row .btn { flex: none; }
.online-msg { min-height: 20px; margin: 0; color: var(--gold); font-size: 13px; line-height: 1.35; }
.hint { color: var(--muted); font-size: 13px; }
.room-code-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-code { font: 700 28px/1 var(--font-card); letter-spacing: 0.18em; color: var(--paper); }
.room-players { display: flex; flex-direction: column; gap: 6px; }
.room-player { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.room-player .dot { color: var(--gold); }
#online { z-index: 35; }
#room { z-index: 36; }

[hidden] { display: none !important; }
.chip { display: inline-block; margin-right: 8px; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; background: rgba(241, 233, 214, 0.12); color: var(--muted); }
.chip.me { background: var(--gold); color: #2a1d00; }
#emote {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  background: rgba(10, 43, 39, 0.95);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 20px;
}
.emote-panel {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 168px;
  display: flex;
  gap: 8px;
  background: rgba(10, 43, 39, 0.95);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px;
}
.emote-panel button {
  min-width: 44px; min-height: 44px;
  background: transparent; border: 0; font-size: 22px;
  cursor: pointer;
}
@media (max-width: 380px) {
  .emote-panel button { min-width: 38px; font-size: 20px; }
}
.slot { position: relative; }
.slot .card.fresh { outline: 3px solid var(--gold); }
.newtag { position: absolute; top: -9px; right: -6px; z-index: 2; background: var(--gold); color: #2a1d00; font: 700 11px var(--font-body); padding: 2px 6px; border-radius: 4px; }
#rules { z-index: 40; }
#menu { z-index: 45; }
#confirm { z-index: 50; }
.start {
  position: fixed; inset: 0; z-index: 30; background: var(--felt-deep);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px)) max(24px, env(safe-area-inset-left, 0px));
}
.start .weave { width: min(280px, 70%); }
.start h1 { font: 400 clamp(40px, 13vw, 60px)/1 var(--font-display); margin: 0; color: var(--paper); letter-spacing: 0.02em; }
.start p { margin: 0; max-width: 30ch; font-size: 15px; line-height: 1.45; color: var(--muted); }
.fan { display: flex; justify-content: center; align-items: flex-end; height: 108px; }
.fan .card { width: 66px; margin: 0 -10px; transform-origin: 50% 120%; }
.fan .card:nth-child(1) { transform: rotate(-12deg); }
.fan .card:nth-child(3) { transform: rotate(12deg); }
.start .menu { display: flex; flex-direction: column; gap: 10px; width: min(280px, 100%); }
.start .menu .btn { min-height: 52px; font-size: 16px; }
.record { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.record b { color: var(--ink); }

@media (max-width: 380px) {
  .top { gap: 6px; }
  .top h1 { font-size: 19px; }
  .score { gap: 8px; font-size: 12px; }
  .score b { font-size: 14px; }
  .btn.small { padding: 0 8px; font-size: 12px; }
  .btn.icon { min-width: 32px; padding: 0 6px; }
  .hand { --ov: 16px; }
  .piles { gap: 6px; }
  .slot { max-width: 68px; }
  .msg { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .hand .card { transition: none; }
}
