:root {
  --bg: #0e1a14; --felt: #14402b; --felt2: #0f3322; --panel: #16241c; --line: #2a4235;
  --ink: #f2ecd8; --muted: #a5b5a8; --gold: #e0b44c; --good: #6fcf8a; --bad: #ee7b6e;
  --card: #fbf5e3; --card-ink: #26241e;
  --espada: #2c5fa8; --basto: #2c7a3c; --oro: #c8921a; --copa: #b3302a;
  --cw: 84px; --ch: 124px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { font-family: Georgia, "Iowan Old Style", serif; margin: 0; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; margin: 1.1rem 0 .4rem; }
.muted { color: var(--muted); font-size: .92rem; }

/* header */
.top { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 1.7rem; color: var(--gold); letter-spacing: .02em; }
.brand span { color: var(--muted); font-size: .85rem; }
nav { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.btn { background: #1f3328; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--gold); color: #231a05; border-color: var(--gold); font-weight: 600; }
.btn.big { font-size: 1.05rem; padding: 12px 20px; margin-top: 8px; }
.select { font-size: .9rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
select { background: #1f3328; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .95rem; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 11px; background: #33483c; position: relative; transition: .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: .2s; }
.switch input:checked + .track { background: var(--gold); }
.switch input:checked + .track::after { left: 19px; background: #231a05; }
.switch input:focus-visible + .track { outline: 2px solid var(--gold); outline-offset: 2px; }

/* layout */
.layout { display: grid; gap: 16px; padding: 16px; max-width: 1180px; margin: 0 auto; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  body.with-ladder .layout { grid-template-columns: minmax(0, 1fr) 340px; }
  body.with-ladder .log-panel { grid-column: 1; }
  .side { grid-column: 2; grid-row: 1 / span 2; }
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }

/* table */
.table { background: radial-gradient(ellipse at 50% 40%, var(--felt) 0%, var(--felt2) 100%); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.scorebar { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.score { background: rgba(0,0,0,.28); border-radius: 12px; padding: 6px 14px; text-align: center; min-width: 78px; }
.score .who { display: block; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.score b { font: 700 1.9rem/1.1 Georgia, serif; }
.score i { display: block; font-size: .72rem; color: var(--muted); min-height: 1em; font-style: normal; }
.score.lead b { color: var(--gold); }
.handinfo { display: flex; flex-direction: column; align-items: center; font-size: .82rem; color: var(--muted); text-align: center; }
.handinfo .stake { color: var(--ink); font-size: 1rem; }

.seat { position: relative; display: flex; justify-content: center; min-height: calc(var(--ch) + 6px); }
.hand { display: flex; gap: 10px; justify-content: center; align-items: center; }
.bubble { position: absolute; top: 4px; right: 8%; max-width: 46%; background: var(--ink); color: #1b1b16; padding: 6px 14px; border-radius: 16px; font: 700 1.05rem Georgia, serif; opacity: 0; transform: translateY(6px); transition: .25s; pointer-events: none; z-index: 3; }
.bubble.show { opacity: 1; transform: none; }
.seat.me .bubble { top: auto; bottom: 4px; left: 6%; right: auto; background: var(--gold); }

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; background: rgba(0,0,0,.2); border-radius: 14px; padding: 10px; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.slot-no { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.cell { padding: 3px; border-radius: 10px; min-height: calc(var(--ch) * .78 + 6px); min-width: calc(var(--cw) * .78 + 6px); display: flex; }
.cell.won { box-shadow: 0 0 0 3px var(--gold); }
.cell.tied { box-shadow: 0 0 0 2px var(--muted); }
.ghost { width: calc(var(--cw) * .78); height: calc(var(--ch) * .78); border: 2px dashed rgba(255,255,255,.14); border-radius: 8px; }
.result { font-size: .78rem; color: var(--gold); }

.notice { min-height: 1.4em; text-align: center; font-size: .9rem; color: var(--gold); }
.prompt { text-align: center; font-weight: 600; min-height: 1.5em; }
.prompt.ask { color: var(--gold); font-size: 1.05rem; }
.prompt.good { color: var(--good); font-size: 1.1rem; } .prompt.bad { color: var(--bad); font-size: 1.1rem; } .prompt.wait { color: var(--muted); font-weight: 400; }
.hint { background: rgba(224,180,76,.14); border: 1px solid rgba(224,180,76,.5); border-radius: 10px; padding: 10px 14px; font-size: .95rem; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.act { display: flex; flex-direction: column; align-items: center; min-width: 108px; min-height: 48px; padding: 7px 14px; background: #20382b; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; font: inherit; cursor: pointer; }
.act b { font-size: 1rem; } .act small { font-size: .72rem; color: var(--muted); }
.act:hover { border-color: var(--gold); }
.act.primary { background: var(--good); color: #0a2512; border-color: var(--good); } .act.primary small { color: #1d4b2b; }
.act.danger { background: #4a2724; border-color: #8a4039; }
.act.call { border-color: var(--gold); } .act.env { border-color: #7fb1e8; }
.act.ghost { background: transparent; }

/* cards */
.card { position: relative; width: var(--cw); height: var(--ch); background: var(--card); color: var(--card-ink); border-radius: 9px; border: 1px solid #cfc6a8; box-shadow: 0 2px 6px rgba(0,0,0,.35); flex: none; user-select: none; }
.card .corner { position: absolute; top: 5px; left: 7px; display: flex; flex-direction: column; align-items: center; line-height: 1; font: 700 1.15rem Georgia, serif; gap: 2px; }
.card .corner .suit { width: 15px; height: 15px; }
.card .pip { position: absolute; inset: 0; display: grid; place-items: center; opacity: .95; }
.card .pip .suit { width: 46px; height: 46px; }
.card .fig { position: absolute; bottom: 7px; width: 100%; text-align: center; font: italic .72rem Georgia, serif; }
.card .suit { color: var(--sc); }
.suit-espada { --sc: var(--espada); } .suit-basto { --sc: var(--basto); } .suit-oro { --sc: var(--oro); } .suit-copa { --sc: var(--copa); }
.card .corner b { color: var(--sc); }
.card.back { background: repeating-linear-gradient(45deg, #7d2a2a 0 7px, #6a2020 7px 14px); border: 3px solid var(--card); }
.card.small { --cw: 66px; --ch: 98px; width: 66px; height: 98px; }
.card.small .corner { font-size: .95rem; top: 4px; left: 5px; } .card.small .corner .suit { width: 12px; height: 12px; }
.card.small .pip .suit { width: 34px; height: 34px; } .card.small .fig { font-size: .62rem; bottom: 4px; }
.card.playable { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.card.playable:hover, .card.playable:focus-visible { transform: translateY(-10px); box-shadow: 0 8px 14px rgba(0,0,0,.45), 0 0 0 2px var(--gold); }
.card.mini { width: 40px; height: 54px; border-radius: 6px; }
.card.mini .corner { position: static; height: 100%; justify-content: center; font-size: 1rem; gap: 3px; }
.card.mini .corner .suit { width: 17px; height: 17px; }
.card.mini.mine { box-shadow: 0 0 0 3px var(--gold), 0 0 14px rgba(224,180,76,.6); transform: scale(1.06); z-index: 1; }
.card.mini.opp { box-shadow: 0 0 0 3px #7fb1e8; }
.card.mini.dim { opacity: .45; }
.card .tag { position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #231a05; font: 700 .58rem/1 system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase; padding: 2px 5px; border-radius: 6px; white-space: nowrap; }
.card.opp .tag { background: #7fb1e8; }

/* ladder */
.ladder { display: flex; flex-direction: column; gap: 5px; margin: 10px 0; }
.ladder-end { text-align: center; font-size: .72rem; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }
.rung { display: grid; grid-template-columns: 24px auto 1fr; gap: 10px; align-items: center; padding: 8px 8px 12px; border-radius: 10px; background: rgba(255,255,255,.03); border: 1px solid transparent; }
.rung.has-mine { background: rgba(224,180,76,.12); border-color: rgba(224,180,76,.55); }
.rung-no { font: 700 .95rem Georgia, serif; color: var(--muted); text-align: center; }
.rung.has-mine .rung-no { color: var(--gold); }
.rung-cards { display: flex; gap: 5px; }
.rung-name { display: flex; flex-direction: column; font-size: .85rem; line-height: 1.25; min-width: 0; }
.rung-name i { color: var(--muted); font-size: .78rem; }
.envido-box { margin-top: 8px; padding: 10px; background: rgba(0,0,0,.25); border-radius: 10px; font-size: .9rem; }
.side[hidden] { display: none; }
.side .panel { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }

/* log */
.log { list-style: none; margin: 8px 0 0; padding: 0; max-height: 220px; overflow: auto; font-size: .88rem; color: var(--muted); }
.log li { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.log li.deal { color: var(--gold); } .log li.hand, .log li.game { color: var(--ink); font-weight: 600; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: flex-start; justify-content: center; padding: 16px; overflow: auto; z-index: 10; }
.overlay[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 640px; margin: 4vh 0; }
.modal-body { padding: 20px 20px 22px; position: relative; }
.modal .close { position: absolute; top: 8px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 1.9rem; line-height: 1; cursor: pointer; }
.modal .close:hover { color: var(--ink); }
.modal h2 { font-size: 1.5rem; margin-bottom: 10px; padding-right: 30px; }
.modal ul { padding-left: 1.2rem; } .modal li { margin: 6px 0; }
.progress { display: flex; gap: 4px; margin: 4px 30px 10px 0; }
.progress span { flex: 1; height: 4px; border-radius: 2px; background: #2c4236; } .progress span.on { background: var(--gold); }
.step-no { margin: 0 0 4px; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.nav { display: flex; justify-content: space-between; margin-top: 20px; }
.callout { background: rgba(224,180,76,.12); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 6px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; margin: 10px 0; }
.tbl th, .tbl td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.quiz { background: rgba(0,0,0,.22); border-radius: 12px; padding: 14px; margin-top: 10px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.quiz-cards, .quiz-hand { display: flex; gap: 14px; align-items: center; }
.quiz-input { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.quiz input { width: 84px; padding: 8px; font: inherit; background: #1f3328; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.cardbtn { background: none; border: 0; padding: 4px; cursor: pointer; border-radius: 12px; }
.cardbtn:hover:not(:disabled) .card { box-shadow: 0 0 0 3px var(--gold); }
.vs { color: var(--muted); }
.feedback { margin: 0; text-align: center; min-height: 3em; }
.feedback.good { color: var(--good); } .feedback.bad { color: var(--bad); }
.quiz-done { font-size: 1.1rem; margin: 0; }

@media (max-width: 600px) {
  :root { --cw: 72px; --ch: 108px; }
  .layout { padding: 10px 16px 20px; gap: 12px; }
  .table { padding: 10px; }
  .card.small { --cw: 56px; --ch: 84px; width: 56px; height: 84px; }
  .card.small .pip .suit { width: 28px; height: 28px; }
  .card.small .fig { display: none; }
  .board { gap: 4px; padding: 8px 4px; }
  .cell { min-width: 62px; min-height: 90px; }
  .ghost { width: 56px; height: 84px; }
  .act { min-width: 96px; flex: 1 1 96px; }
  .bubble { font-size: .92rem; }
  .rung { grid-template-columns: 20px auto 1fr; gap: 6px; }
  .modal-body { padding: 18px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* online */
.netbar { background: #1c3a2a; border-bottom: 1px solid var(--line); padding: 8px 16px; font-size: .9rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.netbar[hidden] { display: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--good); } .dot.off { background: var(--bad); } .dot.wait { background: var(--gold); }
.btn.small { padding: 3px 10px; font-size: .85rem; }
.btn.online { border-color: var(--gold); color: var(--gold); }
.bigcode { font: 700 3.4rem/1.1 Georgia, serif; letter-spacing: .25em; text-align: center; color: var(--gold); margin: 10px 0; }
.linkbox, .field input, .codein { width: 100%; padding: 10px; font: inherit; background: #1f3328; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; }
.field { display: block; margin: 10px 0; font-size: .9rem; color: var(--muted); }
.field input { margin-top: 4px; }
.codein { width: 110px; text-align: center; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.lobby { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin: 6px 0 10px; }
@media (max-width: 600px) { .lobby { grid-template-columns: 1fr; } }
