/* 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; }
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: 11px; 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: 11px; 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: 11px; 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; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.actions button { border: 0; border-radius: 12px; padding: 10px 4px; 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% { transform: scale(1.06); box-shadow: 0 0 0 5px rgba(61,220,132,.35); } }
.actions .warn { color: var(--bad); }
.scoreline { text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; }

/* coach */
.coach { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; width: min(560px, calc(100% - 24px)); background: #fff; color: var(--navy); border-radius: 16px; padding: 12px 14px; z-index: 40; box-shadow: 0 10px 30px rgba(0,0,0,.5); display: flex; gap: 10px; align-items: center; border-left: 6px solid var(--teal); }
.coach.top { bottom: auto; top: 70px; }
.coach .ctext { flex: 1; font-weight: 700; font-size: 15px; }
.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; }

@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; }
}
@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; }
