/* Khel ON Rummy */
:root {
  --navy: #141721; --navy2: #1c2030; --navy3: #262b3f; --line: #343a55;
  --orange: #ff9a3c; --pink: #f04fa8; --purple: #8b5cf6; --teal: #2fd4c8;
  --text: #f4f5fb; --muted: #a8adc6; --good: #3ddc84; --bad: #ff6b6b;
  --grad: linear-gradient(90deg, #ff9a3c, #f04fa8 55%, #8b5cf6);
  --cw: 50px; --ch: 72px; --peek: 24px;
  --red: #d7263d; --black: #1b1d29; --club: #1b1d29; --diamond: #d7263d;
}
.four { --club: #1f9d55; --diamond: #2563eb; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* a game, not a document: no blinking text cursor, no text highlight when a card or button is double-clicked */
html, body { caret-color: transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html, body { margin: 0; background: var(--navy); color: var(--text); }
body { font-family: Nunito, system-ui, sans-serif; min-height: 100vh; overflow-x: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.bar .home { display: block; margin-right: 2px; }
.bar .home img { height: 34px; width: auto; display: block; }
.bar .title { flex: 1; min-width: 0; font-family: Outfit, Nunito, sans-serif; font-weight: 800; font-size: 20px; line-height: 1.1; }
.bar .title small { display: block; font-family: Nunito, sans-serif; font-size: 11px; font-weight: 700; color: var(--muted); }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--navy2); font-size: 18px; }

/* start */
.screen { flex: 1; display: flex; flex-direction: column; padding: 0 16px 16px; }
#start { align-items: stretch; gap: 12px; }
.hero { text-align: center; padding: 8px 0 4px; }
.hero h1 { font-family: Outfit, Nunito, sans-serif; font-size: 40px; margin: 6px 0 2px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .tag { color: var(--muted); margin: 0; }
.fan { display: flex; justify-content: center; gap: 0; height: 74px; padding-top: 6px; }
.fan .mini { width: 44px; height: 62px; border-radius: 8px; background: #fff; color: var(--black); font-weight: 800; display: grid; place-items: center; font-size: 17px; margin: 0 -6px; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
.fan .mini:nth-child(1) { transform: rotate(-14deg) translateY(6px); }
.fan .mini:nth-child(2) { transform: rotate(-5deg); }
.fan .mini:nth-child(3) { transform: rotate(5deg); }
.fan .mini:nth-child(4) { transform: rotate(14deg) translateY(6px); }
.fan .red { color: var(--red); }
.fan .joker { background: var(--grad); color: #fff; font-size: 24px; }
.opts { background: var(--navy2); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lab { color: var(--muted); font-weight: 700; }
.seg { display: flex; background: var(--navy3); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; font-weight: 800; min-width: 44px; }
.seg button.on { background: var(--grad); color: #fff; }
.tog { display: flex; gap: 10px; align-items: center; font-weight: 700; }
.tog input { width: 22px; height: 22px; accent-color: var(--teal); }
.tog small { color: var(--muted); font-weight: 600; }
.big { border: 0; border-radius: 16px; padding: 15px; font-family: Outfit, Nunito, sans-serif; font-weight: 800; font-size: 20px; background: var(--grad); color: #fff; box-shadow: 0 8px 24px rgba(240,79,168,.3); }
.big.ghost { background: var(--navy2); box-shadow: none; border: 2px solid var(--teal); color: var(--teal); font-size: 17px; }
.link { border: 0; background: none; color: var(--teal); font-weight: 800; text-decoration: underline; padding: 6px; }
.progress { background: var(--navy2); border-radius: 18px; padding: 12px; }
.progress h3 { margin: 0 0 6px; font-family: Outfit, Nunito, sans-serif; font-size: 16px; }
.stars { font-size: 18px; font-weight: 800; color: #ffd23f; }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.badge { background: var(--navy3); border-radius: 12px; padding: 8px 6px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); opacity: .5; }
.badge.got { opacity: 1; color: var(--text); outline: 2px solid var(--teal); }
.badge .bi { font-size: 22px; display: block; }

/* table */
#table { gap: 8px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: radial-gradient(120% 70% at 50% 35%, #1d3b3a 0%, #16282d 45%, var(--navy) 100%); border-radius: 18px 18px 0 0; }
.opps { display: flex; justify-content: space-around; gap: 6px; padding-top: 10px; min-height: 92px; }
.opp { flex: 1; max-width: 160px; text-align: center; position: relative; }
.opp .av { width: 46px; height: 46px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; font-size: 25px; background: var(--navy3); border: 3px solid var(--line); position: relative; }
.opp.turn .av { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(47,212,200,.25); }
.opp.thinking .av::after { content: ''; position: absolute; inset: -7px; border-radius: 50%; border: 3px solid transparent; border-top-color: var(--orange); animation: spin 0.9s linear infinite; }
.opp.out { opacity: .45; }
@keyframes spin { to { transform: rotate(360deg); } }
.opp .nm { font-weight: 800; font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp .sub { font-size: 12px; color: var(--muted); min-height: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp .backs { height: 18px; display: flex; justify-content: center; margin-top: 2px; }
.opp .backs i { width: 10px; height: 16px; border-radius: 2px; background: var(--grad); margin: 0 -2px; border: 1px solid rgba(255,255,255,.6); }

.mid { display: flex; align-items: flex-start; justify-content: center; gap: 18px; padding: 6px 0; }
.pile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 12px; padding: 4px; }
.pile .plab { font-size: 12px; color: var(--muted); font-weight: 700; }
.pile.can { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 0 rgba(47,212,200,0); } 50% { box-shadow: 0 0 0 4px rgba(47,212,200,.55); } }
.pile .count { position: absolute; top: 0; right: -4px; background: var(--navy); border: 1px solid var(--line); border-radius: 10px; font-size: 12px; padding: 1px 6px; font-weight: 800; }
#openTop { min-width: var(--cw); min-height: var(--ch); border-radius: 8px; }
#openTop:empty { border: 2px dashed var(--line); }
#openTop.blocked .card::after { content: 'Joker stays'; position: absolute; inset: auto 0 -2px 0; font-size: 8px; font-weight: 800; color: #fff; background: var(--bad); border-radius: 0 0 6px 6px; text-align: center; }
.wild { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); font-weight: 700; text-align: center; max-width: 84px; }
.wild .card { box-shadow: 0 0 0 3px var(--teal), 0 2px 6px rgba(0,0,0,.45); }
.wild b { color: var(--teal); }

.status { text-align: center; font-weight: 800; min-height: 24px; font-size: 15px; }
.status.mine { color: var(--teal); }

/* cards */
.card { width: var(--cw); height: var(--ch); border-radius: 8px; background: #fff; color: var(--black); position: relative; box-shadow: 0 2px 6px rgba(0,0,0,.45); flex: none; user-select: none; transition: transform .15s ease; }
.card .rk { position: absolute; top: 3px; left: 4px; font-weight: 900; font-size: 15px; line-height: 1; font-family: Outfit, Nunito, sans-serif; }
.card .st { position: absolute; top: 19px; left: 4px; font-size: 13px; line-height: 1; }
.card .pip { position: absolute; right: 4px; bottom: 3px; font-size: 24px; line-height: 1; }
.card.s1, .card.s3 { color: var(--red); }
.card.s2 { color: var(--club); }
.card.s3 { color: var(--diamond); }
.card.s1 { color: var(--red); }
.card.pj { background: var(--grad); color: #fff; }
.card.pj .rk { font-size: 10px; letter-spacing: .5px; top: 5px; }
.card.pj .pip { font-size: 28px; left: 0; right: 0; text-align: center; bottom: 14px; }
.card.wj::before { content: 'J'; position: absolute; left: 3px; bottom: 4px; width: 15px; height: 15px; border-radius: 50%; background: var(--teal); color: var(--navy); font-size: 10px; font-weight: 900; display: grid; place-items: center; }
.card.back { background: var(--grad); border: 3px solid #fff; }
.card.back::after { content: ''; position: absolute; inset: 5px; border-radius: 4px; border: 2px solid rgba(255,255,255,.55); background: repeating-linear-gradient(45deg, rgba(255,255,255,.14) 0 4px, transparent 4px 8px); }
.card.sel { transform: translateY(-12px); box-shadow: 0 0 0 3px var(--teal), 0 6px 12px rgba(0,0,0,.5); }
.card.fresh { box-shadow: 0 0 0 3px var(--orange), 0 2px 6px rgba(0,0,0,.45); }
.card.flying { position: fixed; z-index: 50; pointer-events: none; transition: transform .38s cubic-bezier(.3,.8,.3,1), opacity .38s; }

/* hand */
.hand { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 14px 10px; padding: 16px 2px 4px; min-height: 120px; }
.grp { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.grp .cards { display: flex; padding-left: calc(var(--cw) - var(--peek)); }
.grp .cards .card { margin-left: calc(var(--peek) - var(--cw)); }
.grp .gl { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 10px; background: var(--navy3); color: var(--muted); }
.grp .gl.pure { background: var(--good); color: #062; }
.grp .gl.seq { background: var(--teal); color: var(--navy); }
.grp .gl.set { background: #ffd23f; color: #4a3800; }
.grp .gl.no { background: transparent; color: var(--muted); font-weight: 700; opacity: .8; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.actions button { border: 0; border-radius: 12px; padding: 10px 4px; min-height: 44px; font-weight: 800; background: var(--navy3); font-size: 14px; }
.actions button:disabled { opacity: .35; }
.actions .main { background: var(--orange); color: #2a1300; }
.actions .go { background: var(--good); color: #052b14; }
.actions .go.ready { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(61,220,132,.45); } }
.actions .warn { color: var(--bad); }
.scoreline { text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; }

/* coach */
.coach { background: #fff; color: var(--navy); border-radius: 16px; padding: 10px 12px; box-shadow: 0 6px 18px rgba(0,0,0,.4); display: flex; gap: 10px; align-items: center; border-left: 6px solid var(--teal); }
.coach .ctext { flex: 1; font-weight: 700; font-size: 15px; line-height: 1.3; }
@media (max-width: 480px) { .coach .ctext { font-size: 14px; } }
.coach button { border: 0; border-radius: 10px; background: var(--navy); color: #fff; padding: 8px 12px; font-weight: 800; }

/* sheet */
.sheet { position: fixed; inset: 0; background: rgba(8,10,18,.72); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet .panel { background: var(--navy2); width: min(640px, 100%); max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px 16px max(18px, env(safe-area-inset-bottom)); }
.panel h2 { font-family: Outfit, Nunito, sans-serif; margin: 0 0 8px; font-size: 22px; }
.panel p { color: var(--muted); margin: 6px 0; }
.panel .row { display: flex; gap: 8px; margin-top: 12px; }
.panel .row button { flex: 1; border: 0; border-radius: 12px; padding: 12px; font-weight: 800; background: var(--navy3); }
.panel .row button.pri { background: var(--grad); color: #fff; }
.res { border-top: 1px solid var(--line); padding: 10px 0; }
.res .who { display: flex; justify-content: space-between; font-weight: 800; }
.res .who .pts { color: var(--orange); }
.res.win .who .pts { color: var(--good); }
.res .mini-hand { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; --cw: 32px; --ch: 46px; --peek: 17px; }
.res .mini-hand .card .rk { font-size: 11px; top: 2px; left: 3px; }
.res .mini-hand .card .st { font-size: 10px; top: 14px; left: 3px; }
.res .mini-hand .card .pip { font-size: 0; }
.res .mini-hand .card.pj .pip { font-size: 16px; bottom: 8px; }
.res .mini-hand .card.wj::before { width: 11px; height: 11px; font-size: 8px; }
.res .why { font-size: 12px; color: var(--muted); }
table.tot { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
table.tot td, table.tot th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: center; }
table.tot td:first-child, table.tot th:first-child { text-align: left; }
.rules h3 { font-family: Outfit, Nunito, sans-serif; margin: 14px 0 4px; font-size: 17px; color: var(--teal); }
.rules p, .rules li { color: var(--text); font-size: 15px; line-height: 1.45; }
.rules ul { padding-left: 20px; margin: 4px 0; }
.celebrate { font-size: 44px; text-align: center; }
.earned { text-align: center; font-weight: 800; color: #ffd23f; font-size: 18px; }

.toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: var(--navy3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; z-index: 70; font-weight: 800; max-width: calc(100% - 32px); text-align: center; pointer-events: none; }

@media (max-width: 380px) {
  :root { --cw: 46px; --ch: 66px; --peek: 21px; }
  .hand { gap: 12px 8px; }
  .mid { gap: 12px; }
  .actions button { font-size: 13px; padding: 10px 2px; }
}
/* tall phones: bigger cards, the screen has room for them */
@media (max-width: 559px) and (min-width: 381px) and (min-height: 740px) {
  :root { --cw: 56px; --ch: 80px; --peek: 25px; }
}
@media (max-width: 559px) and (min-width: 381px) and (min-height: 820px) {
  :root { --cw: 62px; --ch: 88px; --peek: 27px; }
}
@media (min-width: 560px) {
  :root { --cw: 58px; --ch: 82px; --peek: 28px; }
  .actions { grid-template-columns: repeat(7, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .card, .card.flying { transition: none; }
  .pile.can, .actions .go.ready, .opp.thinking .av::after { animation: none; }
}
.card.dealin { animation: dealin .35s ease-out both; }
@keyframes dealin { from { opacity: 0; transform: translateY(-40px) scale(.8); } to { opacity: 1; transform: none; } }
.grp .cards .card:not(:last-child) .pip { visibility: hidden; }
/* online with friends: leave room for the "Online · CODE" pill in the bottom-left corner */
body.online #table { padding-bottom: max(52px, calc(44px + env(safe-area-inset-bottom))); }
body.online .sheet .panel { padding-bottom: max(60px, calc(50px + env(safe-area-inset-bottom))); }

/* ---------- pointer: an arrow on things you can't click, a hand on things you can, never a text I-beam ---------- */
html, body, body * { cursor: default; }
button:not(:disabled), a[href], .pile.can, .hand .card, .hand .card * { cursor: pointer; }
button:disabled { cursor: default; }

/* sheets and toasts open over the front door too (How to play, Badges), but stay under the online pill and panels */
.sheet { z-index: 2147482950; }
.toast { z-index: 2147482960; }
.panel .stars { margin: 2px 0 4px; }
.panel .badges .badge { opacity: .55; padding: 10px 6px; }
.panel .badges .badge.got { opacity: 1; }
.panel .badges .badge b { display: block; font-size: 13px; margin-top: 2px; color: var(--text); }
.panel .badges .badge small { display: block; font-size: 11px; color: var(--muted); font-weight: 700; line-height: 1.25; margin-top: 2px; }

/* card faces scale with the card size (same look on phones, bigger on desktop) */
.card .rk { font-size: calc(var(--cw) * .3); top: calc(var(--ch) * .04); left: calc(var(--cw) * .08); }
.card .st { font-size: calc(var(--cw) * .26); top: calc(var(--ch) * .26); left: calc(var(--cw) * .08); }
.card .pip { font-size: calc(var(--cw) * .48); right: calc(var(--cw) * .08); bottom: calc(var(--ch) * .04); }
.card.pj .rk { font-size: calc(var(--cw) * .2); }
.card.pj .pip { font-size: calc(var(--cw) * .56); bottom: calc(var(--ch) * .19); }

/* ---------- desktop: the table fills the screen, cards are big and readable ---------- */
@media (min-width: 900px) and (min-height: 600px) {
  :root { --ch: clamp(96px, calc((100vh - 486px) / 2), 172px); --cw: calc(var(--ch) * .7); --peek: calc(var(--cw) * .42); }
  #app { max-width: 1320px; padding: 0 24px; }
  .bar { padding: 12px 4px 10px; gap: 12px; }
  .bar .title { font-size: 26px; }
  .bar .title small { font-size: 13px; }
  .icon { width: 46px; height: 46px; font-size: 20px; }
  #table { border-radius: 28px; padding: 12px 32px 16px; gap: 10px; position: relative; justify-content: center; margin-bottom: 14px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }
  .opps { min-height: 118px; padding-top: 6px; justify-content: center; gap: 48px; }
  .opp { max-width: 220px; }
  .opp .av { width: 62px; height: 62px; font-size: 34px; }
  .opp .nm { font-size: 16px; margin-top: 4px; }
  .opp .sub { font-size: 13.5px; min-height: 18px; }
  .opp .backs { height: 24px; }
  .opp .backs i { width: 13px; height: 21px; margin: 0 -3px; }
  .mid { gap: 30px; padding: 4px 0; }
  .pile .plab { font-size: 14px; }
  .pile .count { font-size: 13px; padding: 2px 8px; }
  .wild { font-size: 14px; max-width: 130px; }
  .status { font-size: 19px; min-height: 28px; }
  .hand { gap: 14px 22px; padding: 18px 2px 4px; min-height: calc(var(--ch) + 46px); }
  .grp .gl { font-size: 13px; padding: 3px 10px; }
  .card { border-radius: 11px; }
  .card.sel { transform: translateY(-16px); }
  .actions { grid-template-columns: repeat(7, 1fr); gap: 10px; max-width: 1000px; width: 100%; margin: 0 auto; }
  .actions button { font-size: 17px; padding: 13px 6px; border-radius: 14px; }
  .actions button:not(:disabled):hover { filter: brightness(1.15); }
  .scoreline { font-size: 14px; }
  .coach { max-width: 900px; width: 100%; margin: 0 auto; padding: 12px 16px; }
  .coach .ctext { font-size: 17px; }
  .coach button { font-size: 16px; padding: 10px 16px; }
  .sheet { align-items: center; }
  .sheet .panel { border-radius: 24px; padding: 24px 26px; width: min(680px, 100%); }
  .panel h2 { font-size: 28px; }
  .panel p, .rules p, .rules li { font-size: 16px; }
  .panel .row button { font-size: 17px; padding: 14px; }
  .toast { font-size: 17px; top: 76px; }
}
/* wide desktop: the coach sits beside the piles, so the table doesn't grow taller in the guided game */
@media (min-width: 1180px) and (min-height: 600px) {
  .coach { position: absolute; z-index: 5; right: 28px; top: 138px; width: min(330px, calc(50% - 300px)); max-width: none; margin: 0; flex-direction: column; align-items: stretch; border-left: 0; border-top: 6px solid var(--teal); }
  .coach button { align-self: flex-end; }
}

/* short phones (e.g. 320x640, 375x667): tighten the table so the hand and the action buttons fit on one screen */
@media (max-width: 559px) and (max-height: 700px) {
  .bar { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
  .bar .home img { height: 28px; }
  #table { gap: 6px; }
  .opps { padding-top: 6px; min-height: 0; }
  .opp .av { width: 38px; height: 38px; font-size: 21px; }
  .mid { padding: 2px 0; }
  .status { min-height: 20px; font-size: 14px; }
  .hand { padding-top: 14px; gap: 10px 8px; min-height: 100px; }
}

/* ---------- Option A (18 Oct): side panel (turn card, players, last moves, invite) + the shared game dock ---------- */
#status { display: none; }            /* the turn card says whose turn it is and what to do */
.sidehost.hidden { display: none; }
html.kd-on #app { min-height: calc(100vh - var(--kd-h)); }
@media (max-width: 899px), (max-height: 599px) {
  .sidehost { padding: 0 12px 8px; }  /* phones: a compact turn card above the table */
  .sidehost .ksd-turn { min-height: 64px; }
  body.coaching .sidehost { display: none; }   /* the coach bubble says what to do, and the table must fit above the dock */
}
@media (min-width: 900px) and (min-height: 600px) {
  :root { --ch: clamp(92px, min(calc((100vh - 500px) / 2), calc(11.8vw - 34px)), 168px); }
  #app { max-width: none; display: grid; grid-template-columns: minmax(0, 1fr) clamp(340px, 27vw, 430px); grid-template-rows: auto minmax(0, 1fr); column-gap: 20px; padding: 0 24px 16px; }
  html.kd-on #app { height: calc(100vh - var(--kd-h)); min-height: 0; }
  .bar { grid-column: 1 / -1; padding: 10px 4px 10px; }
  .bar .title small { font-size: 14px; margin-top: 2px; }
  #table { grid-column: 1; grid-row: 2; margin-bottom: 0; min-height: 0; overflow-y: auto; }
  #table > * { flex-shrink: 0; }
  .sidehost { grid-column: 2; grid-row: 2; min-height: 0; display: flex; }
  .sidehost .ksd { flex: 1 1 auto; }
  .opps { min-height: 110px; }
}
@media (min-width: 1180px) and (min-height: 600px) {
  .coach { right: 20px; top: 128px; width: min(300px, calc(50% - 250px)); }
}
