:root {
  --felt: #0f5132;
  --felt-dark: #0a3d26;
  --felt-light: #16683f;
  --ink: #f3f1e8;
  --muted: #b9cbbf;
  --gold: #f2c14e;
  --red: #c8102e;
  --card-w: 52px;
  --card-h: 74px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--felt-light), var(--felt) 55%, var(--felt-dark));
  background-attachment: fixed;
  color: var(--ink);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { max-width: 760px; margin: 0 auto; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center-text { text-align: center; }

/* ---------- buttons & forms ---------- */
.btn {
  border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.25);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; min-height: 44px;
}
.btn.primary { background: var(--gold); color: #2a2100; border-color: var(--gold); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.wide { width: 100%; }
.btn small { display: block; font-weight: 400; opacity: .7; font-size: 12px; }
.link { background: none; border: none; color: var(--gold); padding: 6px; }
.link.danger { color: #ffb3b3; }
.icon { background: rgba(0,0,0,.2); border: none; border-radius: 10px; width: 40px; height: 40px; font-size: 20px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
label input, label select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.25); color: var(--ink); font-size: 16px;
}
label.toggle { display: flex; align-items: center; gap: 6px; margin: 0; }
label.toggle input { width: auto; display: inline; margin: 0; }
.seg { display: inline-flex; background: rgba(0,0,0,.25); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: none; background: none; padding: 8px 18px; border-radius: 8px; font-weight: 600; }
.seg button.on { background: var(--gold); color: #2a2100; }
.seg.small button { padding: 6px 10px; font-size: 13px; }

/* ---------- pages ---------- */
.page { padding: 12px 14px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; }
.topbar h1 { font-size: 20px; }
.card-panel { background: rgba(0,0,0,.22); border-radius: 16px; padding: 16px; }
.card-panel h2 { font-size: 17px; margin: 16px 0 6px; color: var(--gold); }
.card-panel h2:first-child { margin-top: 0; }
.seatrow { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.seatrow input { flex: 1; min-width: 0; padding: 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.25); color: var(--ink); font-size: 16px; }
.seatno { width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.15); display: grid; place-items: center; font-size: 13px; }
.sk-err { color: #ffb3b3; min-height: 1.2em; margin: 6px 0; font-size: 14px; }

.home { display: flex; flex-direction: column; min-height: 90vh; justify-content: center; gap: 40px; }
.logo { text-align: center; }
.logo h1 { font-size: 52px; font-family: Georgia, serif; letter-spacing: 1px; }
.suitrow { font-size: 28px; letter-spacing: 6px; }
.suitrow b { color: #ff6b6b; font-weight: 400; }
.menu { display: flex; flex-direction: column; gap: 12px; max-width: 360px; width: 100%; margin: 0 auto; }

.rules ol { padding-left: 20px; }
.rules p, .rules li { line-height: 1.45; }

/* ---------- cards ---------- */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 7px; background: #fffdf7;
  color: #1b1b1b; position: relative; flex: none; border: 1px solid #cfc8b5;
  box-shadow: 0 1px 3px rgba(0,0,0,.35); user-select: none;
}
.card.red { color: var(--red); }
.card .r { position: absolute; top: 3px; left: 4px; font-weight: 700; font-size: 15px; line-height: 1; display: flex; flex-direction: column; align-items: center; }
.card .r i { font-style: normal; font-size: 12px; }
.card .pip { position: absolute; bottom: 6px; right: 6px; font-size: 26px; line-height: 1; }
.card.joker { color: #6b2fa0; }
.card.joker .pip { font-size: 9px; font-weight: 800; letter-spacing: .5px; bottom: 8px; right: 5px; }
.card.back { background: repeating-linear-gradient(45deg, #8b1e2d 0 6px, #a3293a 6px 12px); border: 3px solid #fffdf7; }
.card.slot { background: transparent; border: 2px dashed rgba(255,255,255,.3); box-shadow: none; }
.card.sm { --card-w: 34px; --card-h: 48px; border-radius: 5px; }
.card.sm .r { font-size: 12px; top: 2px; left: 3px; }
.card.sm .r i { font-size: 10px; }
.card.sm .pip { font-size: 15px; bottom: 3px; right: 3px; }
.card.sm.joker .pip { font-size: 6px; bottom: 4px; right: 2px; }
.card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--gold), 0 6px 10px rgba(0,0,0,.4); }

/* ---------- game table ---------- */
.game { padding: 6px 10px 30px; display: flex; flex-direction: column; gap: 8px; }
.game .topbar { padding: 4px 0; }
.scores { display: flex; gap: 6px; flex: 1; justify-content: center; flex-wrap: wrap; }
.score { background: rgba(0,0,0,.25); border-radius: 10px; padding: 4px 10px; display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.score b { font-size: 16px; }
.score span { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score.mine { box-shadow: inset 0 0 0 1px var(--gold); }
.handno { text-align: right; font-size: 13px; line-height: 1.1; }
.handno small { display: block; color: var(--muted); }
.seats { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.seat { background: rgba(0,0,0,.2); border-radius: 10px; padding: 6px 12px; text-align: center; font-size: 13px; border: 2px solid transparent; }
.seat.turn { border-color: var(--gold); }
.seat .nm { font-weight: 600; }
.seat .ct { color: var(--muted); }
.bot, .partner { font-size: 10px; background: rgba(255,255,255,.15); padding: 1px 5px; border-radius: 6px; vertical-align: middle; }
.partner { background: rgba(242,193,78,.3); }

.team { background: rgba(0,0,0,.15); border-radius: 12px; padding: 8px; }
.team.mine { background: rgba(0,0,0,.25); }
.team-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; margin-bottom: 6px; }
.pill { font-size: 11px; padding: 2px 7px; border-radius: 8px; background: rgba(255,255,255,.12); }
.pill.red3 { background: rgba(200,16,46,.45); }
.pill.need { background: rgba(242,193,78,.25); }
.pill.can { background: rgba(242,193,78,.6); color: #2a2100; }
.melds { display: flex; gap: 8px; flex-wrap: wrap; min-height: 50px; }
.empty { color: var(--muted); font-size: 13px; align-self: center; }
.meld { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.15); border-radius: 10px; padding: 5px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.meld:disabled { cursor: default; opacity: 1; }
.meld:not(:disabled):active { background: rgba(242,193,78,.25); }
.mcards { display: flex; }
.mcards .card + .card { margin-left: -20px; }
.minfo { font-size: 11px; color: var(--muted); }
.meld.canasta { border-width: 2px; }
.meld.natural { border-color: #ff6b6b; background: rgba(200,16,46,.2); }
.meld.mixed { border-color: #111; background: rgba(0,0,0,.35); }

.center { display: flex; justify-content: center; gap: 28px; padding: 4px 0; }
.pile { background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border-radius: 12px; }
.pile:disabled { cursor: default; }
.pile.hot { background: rgba(242,193,78,.15); box-shadow: inset 0 0 0 2px rgba(242,193,78,.6); }
.pile .lbl { font-size: 12px; color: var(--muted); }
.discard-stack { position: relative; }
.discard-stack .sideways { position: absolute; top: 14px; left: -12px; transform: rotate(90deg); background: #e9e3d0; }
.discard-stack .card:not(.sideways) { position: relative; }

.status { text-align: center; font-size: 14px; min-height: 2.6em; padding: 2px 8px; line-height: 1.35; }
.status.error { color: #ffd0d0; font-weight: 600; }

.staged { background: rgba(242,193,78,.12); border: 1px dashed rgba(242,193,78,.6); border-radius: 12px; padding: 8px; }
.staged-head { font-size: 13px; margin-bottom: 6px; }
.staged-head small { color: var(--muted); }
.staged-groups { display: flex; gap: 8px; flex-wrap: wrap; }
.sgroup { display: flex; background: none; border: none; padding: 0; }
.sgroup .card + .card { margin-left: -20px; }

.hand { display: flex; flex-wrap: wrap; justify-content: center; padding: 18px 18px 4px 34px; row-gap: 8px; }
.hand .card { margin-left: -16px; cursor: pointer; transition: transform .12s; }
.hand.tight .card { margin-left: -24px; }
.hand.tighter .card { margin-left: -30px; }
.hand.tight, .hand.tighter { padding-left: 40px; }
.actions {
  position: sticky; bottom: 0; z-index: 5; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  margin: 0 -10px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--felt-dark) 75%, transparent);
}
.selhint { flex-basis: 100%; text-align: center; font-size: 12px; color: var(--muted); }
.recent { text-align: center; font-size: 12px; color: var(--muted); margin-top: -6px; padding: 0 8px; }
.card.new { box-shadow: 0 0 0 2px #7fd1ff, 0 1px 3px rgba(0,0,0,.35); }
.card.new.sel { box-shadow: 0 0 0 3px var(--gold), 0 6px 10px rgba(0,0,0,.4); }
.card.ten .r { letter-spacing: -1.5px; }
.floating { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 11; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
.actions .btn { flex: 1 1 0; max-width: 170px; padding: 10px 8px; }

.log { font-size: 13px; color: var(--muted); }
.log summary { cursor: pointer; padding: 6px 0; }
.log div { padding: 2px 0; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--felt-dark); border: 1px solid rgba(255,255,255,.2); border-radius: 18px; padding: 20px; width: 100%; max-width: 460px; text-align: center; }
.modal h2 { margin-bottom: 6px; }
.modal .btn { margin-top: 14px; }
.modal .row { justify-content: center; }
.breakdown { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.breakdown th, .breakdown td { padding: 6px 4px; border-bottom: 1px solid rgba(255,255,255,.1); }
.breakdown th { text-align: left; font-weight: 500; color: var(--muted); }
.breakdown td, .breakdown tr:first-child th:not(:first-child) { text-align: right; }
.breakdown tr.sum th, .breakdown tr.sum td { font-weight: 700; color: var(--ink); }
.breakdown small { color: var(--muted); }

/* ---------- scorekeeper ---------- */
.sk-totals { display: flex; gap: 8px; }
.sk-total { flex: 1; background: rgba(0,0,0,.25); border-radius: 14px; padding: 12px; text-align: center; }
.sk-total .nm { font-weight: 600; }
.sk-total .pts { font-size: 34px; font-weight: 700; }
.sk-total .sub { font-size: 12px; color: var(--muted); }
.sk-total.win { box-shadow: inset 0 0 0 2px var(--gold); }
.sk-history { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.sk-history th, .sk-history td { padding: 6px; text-align: right; border-bottom: 1px solid rgba(255,255,255,.1); }
.sk-history th:first-child, .sk-history td:first-child { text-align: left; color: var(--muted); }
.sk-form { background: rgba(0,0,0,.2); border-radius: 16px; padding: 14px; }
.sk-entry { border-top: 1px solid rgba(255,255,255,.12); padding-top: 10px; margin-top: 10px; }
.sk-entry h3 { color: var(--gold); font-size: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 label { font-size: 12px; }
.live { text-align: right; font-size: 15px; }

@media (min-width: 600px) {
  :root { --card-w: 62px; --card-h: 88px; }
  .card .pip { font-size: 32px; }
}

/* ---------- records & scoresheets ---------- */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: #111; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; transition: .25s; pointer-events: none; font-size: 14px; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.wide-seg { display: flex; margin: 4px 0 14px; }
.wide-seg button { flex: 1; }
.list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.match-row, .player-row { text-align: left; background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.12); border-radius: 14px; padding: 10px 12px; }
.mr-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.mr-side { display: flex; justify-content: space-between; padding: 2px 0; }
.mr-side.win b, .mr-side.win span { color: var(--gold); }
.player-row { display: flex; justify-content: space-between; align-items: center; }
.pr-stat { text-align: right; }
.pr-stat b { font-size: 20px; display: block; }
.pr-stat small { color: var(--muted); }
.card-panel.slim { margin-top: 18px; }
.card-panel.slim h2 { margin-top: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-grid div { background: rgba(0,0,0,.22); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat-grid b { display: block; font-size: 20px; }
.stat-grid small { color: var(--muted); font-size: 11px; }
.section-h { font-size: 16px; color: var(--gold); margin: 18px 0 6px; }
.next-hand { margin: 14px 0; }
.next-hand h2 { font-size: 16px; margin-bottom: 8px; text-align: center; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice { background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.18); border-radius: 14px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.choice span { font-size: 26px; }
.choice small { color: var(--muted); font-size: 11px; text-align: center; }
.choice:disabled { opacity: .45; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label { font-size: 12px; }
.center-row { justify-content: center; margin-top: 18px; }
.sk-form .row .btn { flex: 1; }

/* ---------- setup ---------- */
.seatbox { margin: 8px 0; }
.seatbox .seatrow { margin: 0; }
.levelrow { display: flex; gap: 4px; margin: 6px 0 0 32px; }
.levelrow button { flex: 1; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.2); border-radius: 8px; padding: 5px 4px; font-size: 12px; }
.levelrow button.on { background: rgba(242,193,78,.85); color: #2a2100; border-color: transparent; font-weight: 600; }
.bot.hard { background: rgba(242,193,78,.85); color: #2a2100; }
.bot.easy { background: rgba(127,209,255,.3); }
.card-panel a { color: var(--gold); }

/* ---------- game extras ---------- */
.cutnote { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; background: rgba(242,193,78,.15); border-radius: 10px; padding: 4px 8px; }
.cutnote .card { --card-w: 24px; --card-h: 34px; }
.cutnote .card .pip { display: none; }

/* ---------- rulebook ---------- */
.rulebook h2 { font-size: 18px; }
.rulebook h3 { font-size: 15px; margin: 14px 0 4px; color: var(--gold); }
.rulebook p, .rulebook li { line-height: 1.5; }
.rulebook ul, .rulebook ol { padding-left: 20px; }
.rulebook hr { border: none; border-top: 1px solid rgba(255,255,255,.15); margin: 18px 0; }
.rules-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.rules-table th, .rules-table td { border-bottom: 1px solid rgba(255,255,255,.12); padding: 5px 4px; text-align: left; vertical-align: top; }
.rules-table th { color: var(--muted); font-weight: 500; }
.sk-history td:first-child { white-space: nowrap; }
.gameover-box { text-align: center; background: rgba(242,193,78,.12); border: 1px solid rgba(242,193,78,.4); border-radius: 14px; padding: 12px; margin: 12px 0; }
.gameover-box .row { justify-content: center; margin-top: 10px; }

/* ---------- Magyar deck ---------- */
.card.mg:not(.back) { background: #fbf5e6; border-color: #d9c9a3; }
.card.mg .r { font-family: Georgia, "Times New Roman", serif; }
.card.mg.black { color: #1d2440; }
.card.mg.red { color: #b3122b; }
.card.mg.joker { color: #2e6b3f; }
.card.mg.back {
  background: var(--back-img) center / 22px 22px, #1c2340;
  border: 3px solid #fbf5e6; box-shadow: inset 0 0 0 1.5px #c8102e, 0 1px 3px rgba(0,0,0,.35);
}
.card .art { position: absolute; left: 9%; right: 6%; bottom: 5%; aspect-ratio: 1; display: block; pointer-events: none; }
.card .art svg { width: 100%; height: 100%; display: block; }
.card.has-art .pip { font-size: 11px; bottom: auto; top: 3px; right: 4px; }
.card.has-art.joker .pip { display: none; }
.card.sm.has-art .pip { display: none; }
.card.sm .art { left: 12%; right: 4%; bottom: 4%; }
.cutnote .card .art { display: none; }

/* ---------- tables ---------- */
html[data-table="balaton"] { --felt: #0f4a66; --felt-dark: #0a344a; --felt-light: #1b6a8c; }
html[data-table="paprika"] { --felt: #7a1d1d; --felt-dark: #531212; --felt-light: #982b25; }
html[data-table="dio"] { --felt: #4a3221; --felt-dark: #322115; --felt-light: #644530; }

/* ---------- home logo ---------- */
.logo-card { display: flex; justify-content: center; height: 108px; margin-top: 18px; }
.logo-card .card { --card-w: 68px; --card-h: 96px; margin: 0 -12px; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.logo-card .card:nth-child(1) { transform: rotate(-14deg) translateY(8px); }
.logo-card .card:nth-child(3) { transform: rotate(14deg) translateY(8px); }
.logo-card .card .r { font-size: 18px; }

/* ---------- look page ---------- */
.look-choices { display: grid; gap: 10px; }
.look-choice { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 14px; border: 2px solid rgba(255,255,255,.15); background: rgba(0,0,0,.18); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.look-choice.on { border-color: var(--gold); }
.look-choice b { display: block; }
.look-choice .fan { display: flex; flex: none; }
.look-choice .fan .card + .card { margin-left: -22px; }
.swatch { width: 46px; height: 46px; border-radius: 10px; flex: none; border: 1px solid rgba(255,255,255,.25); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.gallery figure { margin: 0; display: flex; gap: 10px; align-items: center; }
.gallery .card { --card-w: 72px; --card-h: 102px; }
.gallery .card .r { font-size: 19px; }
.gallery figcaption { font-size: 14px; min-width: 0; }
.gallery figcaption b { display: block; overflow-wrap: anywhere; }
