:root {
  --bg: #0c1410;
  --felt: #17402c;
  --felt2: #0f2e1f;
  --panel: #14221b;
  --panel2: #1b2d24;
  --line: #2a4236;
  --text: #eef3ef;
  --muted: #9bb0a4;
  --gold: #e8b64c;
  --face: #f7f2e4;
  --face-edge: #cfc6ad;
  --pip: #1a1a1a;
  --best: #3fb950;
  --good: #7ee787;
  --inacc: #e3b341;
  --mistake: #f0883e;
  --blunder: #f85149;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%; }
a { color: var(--gold); text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.good { color: var(--best); }
.bad { color: var(--blunder); }
.warn { color: var(--inacc); }

/* ---------- pages ---------- */
.page { min-height: 100dvh; padding: calc(var(--safe-t) + 4px) 16px calc(var(--safe-b) + 24px); max-width: 560px; margin: 0 auto; }
.pbar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; height: 48px; position: sticky; top: 0; background: var(--bg); z-index: 5; margin: 0 -16px 8px; padding: 0 8px; }
.pbar h1 { text-align: center; font-size: 17px; font-weight: 600; }
.back { font-size: 34px; line-height: 1; color: var(--gold); background: none; border: 0; padding: 0 8px; width: 44px; height: 44px; display: flex; align-items: center; }
main { display: flex; flex-direction: column; gap: 12px; }
.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; color: var(--text); }
.card h2 { font-size: 17px; margin-bottom: 6px; }
.chead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chead span { color: var(--muted); }
.bar { height: 6px; background: var(--felt2); border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.bar i { display: block; height: 100%; background: var(--gold); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile-link b { display: block; font-size: 16px; margin-bottom: 2px; }
.tile-link small { font-size: 12px; }
.resume { background: linear-gradient(135deg, #2a4a1e, #1c3326); border-color: #4a7a3a; }
.resume b { display: block; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--gold); color: #1d1605; border-color: var(--gold); }
.btn.danger { border-color: var(--blunder); color: var(--blunder); background: none; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .4; }
.btn:active { transform: scale(.97); }
.btnrow { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.btnrow .btn { flex: 1; }
details summary { color: var(--muted); padding: 10px 0 0; cursor: pointer; }
.steps { padding-left: 22px; margin: 8px 0 0; }
.steps li { padding: 6px 0; }
.steps li a { color: var(--text); }
.steps li.done a { color: var(--muted); text-decoration: line-through; }
.rchips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.rchip { background: var(--felt2); border-radius: 10px; padding: 6px 10px; display: flex; flex-direction: column; min-width: 70px; }
.rchip small { font-size: 11px; }

/* hub */
.hub .hero { text-align: center; padding: 36px 0 20px; }
.hub .logo { font-size: 28px; color: var(--gold); letter-spacing: 6px; }
.hub h1 { font-size: 40px; font-weight: 800; letter-spacing: -1px; }
.hub .hero p { color: var(--muted); margin: 4px 0 0; }
.gamecard { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; color: var(--text); }
.gamecard.live { background: linear-gradient(135deg, var(--felt), var(--felt2)); border-color: #2f6a4a; }
.gamecard.soon { opacity: .55; }
.gamecard h2 { font-size: 19px; }
.gamecard p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.gicon { width: 56px; height: 56px; display: grid; place-items: center; font-size: 30px; background: rgba(0,0,0,.25); border-radius: 14px; }
.go { margin-left: auto; font-size: 28px; color: var(--gold); }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 12px; }

/* setup */
.vlist { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vcard { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.vcard b { display: block; font-size: 15px; }
.vcard small { font-size: 12px; }
.vcard.on { border-color: var(--gold); background: #2a2612; }
.blurb { color: var(--muted); font-size: 14px; margin: 4px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 4px 0 6px; }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { flex: 1; min-height: 38px; border: 0; background: none; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); padding: 4px 6px; }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: 0 0 0 1px var(--gold) inset; }

/* lessons */
.stage { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 10px 0 0; }
.lrow { display: flex; align-items: center; gap: 12px; }
.lrow > span { width: 22px; text-align: center; color: var(--gold); }
.lrow b { flex: 1; }
.lrow div { display: flex; flex-direction: column; }
.lrow.done b { color: var(--muted); }
a.lrow { color: var(--text); padding: 12px 14px; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--gold); width: 18px; border-radius: 4px; }
.dots i.past { background: #6b7f73; }
.lcard { min-height: 50dvh; }
.lcard h2 { font-size: 20px; margin-bottom: 10px; }
.lcard h2.q { font-size: 17px; margin: 12px 0; }
.lbody { font-size: 16px; line-height: 1.5; }
.lbody p { margin: 0 0 10px; }
.lbody ul, .lbody ol { padding-left: 20px; margin: 0 0 10px; }
.lbody li { margin-bottom: 6px; }
.itile { display: inline-block; vertical-align: -3px; margin: 0 1px; }
.qtag { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--gold); border: 1px solid var(--gold); border-radius: 6px; padding: 1px 6px; margin-bottom: 8px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { text-align: left; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 16px; }
.opt.right { border-color: var(--best); background: #173a22; }
.opt.wrong { border-color: var(--blunder); background: #3a1717; }
.fb { margin-top: 12px; font-size: 15px; line-height: 1.45; }
.fb > div { padding: 10px 12px; border-radius: 12px; background: var(--panel2); }
.fb .good { color: var(--text); border-left: 4px solid var(--best); }
.fb .bad { color: var(--text); border-left: 4px solid var(--blunder); }
.pboard { background: radial-gradient(ellipse at center, var(--felt), var(--felt2)); border-radius: 14px; height: 190px; display: flex; align-items: center; justify-content: center; margin: 8px 0; overflow: hidden; position: relative; }
.pboard .board-svg { width: 100%; height: 100%; }
.pboard .empty { color: var(--muted); }
.phand { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.info { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
.vchips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.vchip { font-size: 12px; background: #3a1f1f; color: #ffb4a8; border-radius: 8px; padding: 2px 8px; }
.dhead { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.armrow { display: flex; gap: 8px; justify-content: center; }
.cheat ol, .cheat ul { padding-left: 20px; margin: 0; }
.cheat li { margin-bottom: 5px; }
table.stat, table.track { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stat th, table.stat td, table.track th, table.track td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
table.stat td:first-child, table.track td:first-child { text-align: left; }
table.track tr.end td { background: #2a2612; }
table.track td.zero b { color: var(--blunder); }
.lvls { display: flex; gap: 6px; }
.lvl { flex: 1; background: var(--felt2); border-radius: 10px; padding: 6px; text-align: center; display: flex; flex-direction: column; font-size: 13px; }

/* ---------- tiles ---------- */
.tile-face { fill: var(--face); stroke: var(--face-edge); stroke-width: .05; }
.tile-div { stroke: #8a8270; stroke-width: .06; stroke-linecap: round; }
.tile-back { fill: #274f3a; stroke: #3b7456; stroke-width: 1; }
svg.tile { display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.board-svg .last .tile-face { fill: #fff6cf; stroke: var(--gold); stroke-width: .1; }
.board-svg .spinner .tile-face { stroke: #7cc4ff; stroke-width: .09; }
.board-svg .target circle { fill: rgba(232,182,76,.25); stroke: var(--gold); stroke-width: .08; animation: pulse 1s ease-in-out infinite alternate; }
.board-svg .target text { fill: var(--gold); font-size: .7px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.board-svg .target { cursor: pointer; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }

/* ---------- game ---------- */
.game { height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-t); padding-bottom: var(--safe-b); max-width: 600px; margin: 0 auto; overflow: hidden; }
.gbar { display: grid; grid-template-columns: 40px auto 1fr; align-items: center; gap: 6px; padding: 2px 10px 4px 2px; }
.gtitle div { font-weight: 700; font-size: 15px; }
.gtitle small { font-size: 11px; }
.scores { text-align: right; font-size: 13px; }
.scores .me { color: var(--gold); font-weight: 700; }
.seats { display: grid; gap: 6px; padding: 0 10px; }
.seats.n1 { grid-template-columns: 1fr; }
.seats.n3 { grid-template-columns: 1fr 1fr 1fr; }
.seat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 5px 8px; min-height: 52px; transition: border-color .2s; }
.seat.turn { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.seat.partner { background: #152a3a; border-color: #2c5170; }
.seat.partner.turn { border-color: var(--gold); }
.sname { font-size: 13px; font-weight: 600; }
.sback { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.act { margin-left: auto; display: flex; align-items: center; gap: 2px; color: var(--text); }
.act.pass { color: var(--blunder); font-weight: 700; text-transform: uppercase; font-size: 11px; }
.voids { font-size: 11px; color: #ffb4a8; }
.board { flex: 1; min-height: 0; margin: 6px 10px; border-radius: 18px; background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt2) 100%); box-shadow: inset 0 0 40px rgba(0,0,0,.45); position: relative; display: flex; }
.board .board-svg { width: 100%; height: 100%; }
.bmeta { position: absolute; top: 6px; left: 10px; right: 10px; display: flex; justify-content: space-between; pointer-events: none; font-size: 13px; }
.count { background: rgba(0,0,0,.45); padding: 2px 10px; border-radius: 10px; }
.count b { color: var(--gold); }
.bone { background: rgba(0,0,0,.35); padding: 2px 10px; border-radius: 10px; color: var(--muted); margin-left: auto; font-size: 13px; }
.board .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.coach { margin: 0 10px; min-height: 58px; max-height: 30dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 7px 10px; font-size: 14px; line-height: 1.35; -webkit-user-select: text; user-select: text; }
.coach.mistake { border-color: var(--mistake); }
.coach.blunder { border-color: var(--blunder); }
.cmsg { margin-bottom: 3px; }
.cmsg.warn { color: var(--inacc); }
.cbtns { display: flex; gap: 8px; margin-top: 6px; }
.cbtns .btn { flex: 1; }
.recent .logl { color: var(--muted); font-size: 13px; }
.recent .logl:last-child { color: var(--text); }
.gchip { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 0 6px; margin-right: 2px; color: #111; }
.gchip.best { background: var(--best); } .gchip.good { background: var(--good); } .gchip.inacc { background: var(--inacc); }
.gchip.mistake { background: var(--mistake); } .gchip.blunder { background: var(--blunder); } .gchip.forced { background: #888; }
.hand { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; padding: 8px 8px 2px; min-height: 96px; align-content: center; }
.htile { background: none; border: 0; padding: 2px; border-radius: 8px; transition: transform .12s; }
.htile.ok svg { filter: drop-shadow(0 0 3px rgba(232,182,76,.9)); }
.htile.dim { opacity: .45; }
.htile.sel { transform: translateY(-10px); }
.htile.sel svg { filter: drop-shadow(0 0 5px var(--gold)); }
.htile.right svg { filter: drop-shadow(0 0 5px var(--best)); }
.htile.wrong svg { filter: drop-shadow(0 0 5px var(--blunder)); }
.hand.active { }
.actions { display: flex; align-items: center; gap: 8px; padding: 4px 10px 6px; min-height: 52px; }
.actions .btn.arm { flex: 1; }
.actions .btn.arm small { color: #3b2f0b; font-weight: 500; }
.actions .btn.arm { background: var(--gold); color: #1d1605; }
.turnmsg { color: var(--muted); font-size: 14px; flex: 1; }
.game.myturn .turnmsg { color: var(--gold); font-weight: 600; }
.tools { display: flex; gap: 6px; margin-left: auto; }
.tool { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 20px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--muted); border-top-color: var(--gold); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -1px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* train */
.trains { flex: 1; min-height: 0; overflow-y: auto; margin: 6px 10px; display: flex; flex-direction: column; gap: 6px; background: radial-gradient(ellipse at center, var(--felt), var(--felt2)); border-radius: 18px; padding: 8px; }
.trow { background: rgba(0,0,0,.25); border: 1px solid transparent; border-radius: 10px; padding: 4px 8px; }
.trow.turn { border-color: rgba(232,182,76,.4); }
.trow.target { border-color: var(--gold); background: rgba(232,182,76,.18); }
.trow.pending { border-color: var(--mistake); }
.tlabel { font-size: 12px; font-weight: 600; }
.marker { background: var(--mistake); color: #111; border-radius: 4px; padding: 0 4px; font-size: 10px; }
.ttiles { display: flex; align-items: center; gap: 2px; min-height: 18px; flex-wrap: nowrap; overflow: hidden; }
.tend { margin-left: 6px; font-weight: 800; color: var(--gold); font-size: 13px; }
.more { font-size: 11px; color: var(--muted); margin-right: 2px; }
.train .bone { align-self: flex-end; }

/* ---------- modal / toast ---------- */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 50; opacity: 0; transition: opacity .15s; }
#modal.show { opacity: 1; }
#modal .sheet { width: 100%; max-width: 600px; margin: 0 auto; max-height: 88dvh; overflow-y: auto; background: var(--panel); border-radius: 20px 20px 0 0; padding: 18px 16px calc(var(--safe-b) + 16px); border-top: 1px solid var(--line); }
#modal h2 { font-size: 20px; margin-bottom: 8px; }
.big { font-size: 30px; font-weight: 800; margin: 4px 0; }
.scoreline { font-size: 15px; margin-bottom: 8px; }
.scoreline .me { color: var(--gold); font-weight: 700; }
.rhands { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.rhand { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.rname { font-size: 14px; white-space: nowrap; }
.rtiles { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }
.review { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.rvhead { margin-bottom: 8px; font-size: 14px; }
.rv { background: var(--panel2); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; font-size: 14px; }
.rvtext { margin-top: 4px; color: #d7e0da; line-height: 1.4; }
.rvgood { color: var(--best); }
.lvlup { color: var(--gold); }
.loglist { max-height: 60dvh; overflow-y: auto; font-size: 14px; }
.loglist div { padding: 4px 0; border-bottom: 1px solid var(--line); }
.know { font-size: 14px; margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
#toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 110px); transform: translate(-50%, 20px); background: #000d; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 700px) {
  .hand { min-height: 80px; }
  .coach { min-height: 48px; }
}
