/* Macao — the card game against the phone (js/macao.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme. */
:root {
    --mo-accent: #166534;
    --mo-accent-ink: #ffffff;
    --mo-page-bg: #f3f6f1;
    --mo-card-bg: #ffffff;
    --mo-card-border: #dfe5dc;
    --mo-muted: #5f6b5d;
    --mo-shadow: 0 10px 30px rgba(20, 60, 30, .12);
    --mo-felt: #1d7a46;
    --mo-felt-2: #135c33;
    --mo-felt-edge: #7c4a1e;
    --mo-felt-ink: #ecfdf3;
    --mo-felt-muted: rgba(236, 253, 243, .75);
    --mo-gold: #fbbf24;
    --mo-red: #c81e1e;
    --mo-black: #16181d;
    --mo-face: #fffdf7;
    --mo-face-edge: #d6d0c2;
    --mo-back-1: #9f1d1d;
    --mo-back-2: #7f1414;
    --mo-cw: 62px;
    --mo-ch: 90px;
}

body.dark-theme {
    --mo-accent: #4ade80;
    --mo-accent-ink: #052e16;
    --mo-page-bg: #0f1512;
    --mo-card-bg: #1b231e;
    --mo-card-border: #2f3d33;
    --mo-muted: #9fb0a3;
    --mo-shadow: 0 10px 30px rgba(0, 0, 0, .4);
    --mo-felt: #145232;
    --mo-felt-2: #0c3a22;
    --mo-felt-edge: #4a2c12;
    --mo-felt-ink: #e7f6ec;
    --mo-felt-muted: rgba(231, 246, 236, .7);
    --mo-face: #f4f0e6;
    --mo-face-edge: #b9b2a2;
    --mo-back-1: #7f1d1d;
    --mo-back-2: #5c1010;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll
   container that never scrolls, which silently kills any position: sticky inside. */
.mo-body, body.mo-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--mo-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.mo-main { padding-top: 100px; padding-bottom: 40px; }
.mo-game .container, .mo-hero .container { max-width: 760px; }

/* ---- hero ---- */
.mo-hero { text-align: center; padding: 4px 0 10px; }
.mo-hero h1 { font-weight: 800; font-size: clamp(1.7rem, 5vw, 2.3rem); margin-bottom: 4px; }
.mo-lead { margin: 0 auto; max-width: 520px; color: var(--mo-muted); font-size: 1rem; line-height: 1.5; }

/* ---- settings ---- */
.mo-settings { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; padding: 8px 10px; margin: 6px 0 12px; border-radius: 16px; background: var(--mo-card-bg); border: 1px solid var(--mo-card-border); }
.mo-setting { display: flex; align-items: center; gap: 5px; }
.mo-setting-label { font-weight: 700; font-size: .85rem; color: var(--mo-muted); margin-right: 2px; }
.mo-chip { min-height: 40px; min-width: 42px; padding: 4px 11px; border: 1px solid var(--mo-card-border); border-radius: 12px; background: transparent; color: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; touch-action: manipulation; }
.mo-chip[aria-checked="true"] { background: var(--mo-accent); border-color: var(--mo-accent); color: var(--mo-accent-ink); }
.mo-chip:focus-visible { outline: 2px solid var(--mo-accent); outline-offset: 2px; }

/* ---- the felt ---- */
.mo-table {
    position: relative;
    padding: 10px 10px 12px;
    border-radius: 24px;
    background: radial-gradient(ellipse at 50% 40%, var(--mo-felt) 0%, var(--mo-felt-2) 100%);
    border: 6px solid var(--mo-felt-edge);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, .3), var(--mo-shadow);
    color: var(--mo-felt-ink);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ---- opponents ---- */
.mo-opps { display: grid; grid-template-columns: repeat(var(--mo-opps, 3), minmax(0, 1fr)); gap: 6px; min-height: 104px; }
.mo-seat { position: relative; min-width: 0; padding: 6px 6px 7px; border-radius: 14px; background: rgba(0, 0, 0, .18); border: 2px solid transparent; text-align: center; transition: border-color .2s, background .2s; }
.mo-seat.is-turn { border-color: var(--mo-gold); background: rgba(0, 0, 0, .28); }
.mo-seat-name { font-weight: 800; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.mo-seat-name .svg-inline--fa, .mo-seat-name i { margin-right: 3px; opacity: .85; }
.mo-seat-level { font-size: .72rem; color: var(--mo-felt-muted); display: block; line-height: 1.1; }
.mo-mini { position: relative; height: 38px; margin: 5px auto 3px; }
.mo-mini .mo-card { position: absolute; top: 0; left: 50%; width: 25px; height: 36px; border-radius: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.mo-seat-count { display: inline-block; min-width: 26px; padding: 1px 7px; border-radius: 999px; background: rgba(0, 0, 0, .35); font-weight: 800; font-size: .85rem; }
.mo-seat.is-low .mo-seat-count { background: var(--mo-red); color: #fff; }
.mo-badges { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; min-height: 20px; margin-top: 3px; }
.mo-badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .72rem; font-weight: 800; line-height: 1.5; }
.mo-badge[hidden] { display: none; }
.mo-badge-macao { background: var(--mo-gold); color: #3a2400; }
.mo-badge-skip { background: rgba(255, 255, 255, .85); color: #222; }
.mo-badge-win { background: var(--mo-gold); color: #3a2400; }

/* speech bubbles */
.mo-bubble { position: absolute; left: 50%; top: -6px; z-index: 5; transform: translate(-50%, -100%); padding: 4px 10px; border-radius: 12px; background: #fff; color: #1a1a1a; font-weight: 800; font-size: .85rem; white-space: nowrap; box-shadow: 0 4px 12px rgba(0, 0, 0, .3); pointer-events: none; animation: mo-pop .25s ease-out; }
.mo-bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fff; }
.mo-bubble[hidden] { display: none; }
.mo-bubble.is-bad { background: #fee2e2; color: #7f1d1d; }
.mo-bubble.is-bad::after { border-top-color: #fee2e2; }
.mo-seat .mo-bubble { top: auto; bottom: -8px; transform: translate(-50%, 100%); }
.mo-seat .mo-bubble::after { bottom: auto; top: -6px; border-top: 0; border-bottom: 6px solid #fff; }
.mo-seat .mo-bubble.is-bad::after { border-bottom-color: #fee2e2; }
@keyframes mo-pop { from { opacity: 0; transform: translate(-50%, -80%) scale(.8); } }
.mo-seat .mo-bubble { animation-name: mo-pop-down; }
/* your own bubble sits beside "Tu", clear of the status line */
.mo-me .mo-bubble { top: -6px; left: auto; right: 6px; transform: none; animation-name: mo-pop-side; }
.mo-me .mo-bubble::after { display: none; }
@keyframes mo-pop-side { from { opacity: 0; transform: scale(.8); } }
@keyframes mo-pop-down { from { opacity: 0; transform: translate(-50%, 80%) scale(.8); } }

/* ---- center: piles ---- */
.mo-center { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 14px; padding: 16px 4px 6px; min-height: calc(var(--mo-ch) * 1.15 + 22px); }
.mo-pile { position: relative; width: calc(var(--mo-cw) * 1.15); height: calc(var(--mo-ch) * 1.15); }
.mo-draw-pile { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 9px; touch-action: manipulation; }
.mo-draw-pile .mo-pile-card { position: absolute; inset: 0; width: 100%; height: 100%; box-shadow: 2px 2px 0 rgba(0, 0, 0, .25), 4px 4px 0 rgba(0, 0, 0, .18), 0 6px 14px rgba(0, 0, 0, .35); }
.mo-draw-pile:focus-visible { outline: 3px solid var(--mo-gold); outline-offset: 3px; }
.mo-draw-pile.is-hint .mo-pile-card { box-shadow: 0 0 0 3px var(--mo-gold), 0 6px 14px rgba(0, 0, 0, .35); animation: mo-breathe 1.3s ease-in-out infinite; }
.mo-draw-pile:disabled { cursor: default; }
.mo-pile-count { position: absolute; right: -8px; bottom: -8px; min-width: 28px; padding: 2px 6px; border-radius: 999px; background: #111; color: #fff; font-size: .78rem; font-weight: 800; text-align: center; }
@keyframes mo-breathe { 50% { transform: translateY(-3px); } }
.mo-discard .mo-card { position: absolute; inset: 0; width: 100%; height: 100%; }
.mo-discard .mo-card.is-under { box-shadow: 0 2px 6px rgba(0, 0, 0, .3); }
.mo-discard .mo-card.is-top { box-shadow: 0 6px 16px rgba(0, 0, 0, .4); }
.mo-info { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.mo-suit-chip, .mo-pending { padding: 4px 10px; border-radius: 12px; font-weight: 800; font-size: .9rem; line-height: 1.3; max-width: 100%; }
.mo-suit-chip { background: var(--mo-face); color: var(--mo-black); box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.mo-suit-chip .is-red { color: var(--mo-red); }
.mo-suit-chip b { font-size: 1.25rem; vertical-align: -2px; }
.mo-pending { background: var(--mo-red); color: #fff; animation: mo-throb 1.1s ease-in-out infinite; }
.mo-pending.is-skip { background: #f8fafc; color: #1e293b; }
.mo-suit-chip[hidden], .mo-pending[hidden] { display: none; }
@keyframes mo-throb { 50% { transform: scale(1.06); } }

.mo-status { min-height: 2.6em; margin: 4px 0 2px; padding: 0 4px; text-align: center; font-weight: 700; font-size: .98rem; line-height: 1.3; color: var(--mo-felt-ink); display: flex; align-items: center; justify-content: center; }

/* ---- my hand ---- */
.mo-me { position: relative; margin-top: 18px; }
.mo-me-head { display: flex; align-items: center; gap: 8px; padding: 0 4px 2px; font-weight: 800; }
.mo-me-count { color: var(--mo-felt-muted); font-weight: 700; font-size: .88rem; }
.mo-me.is-turn .mo-me-name { color: var(--mo-gold); }
.mo-hand { position: relative; height: calc(var(--mo-ch) + 24px); margin: 4px 0 0; }
.mo-hand.rows-2 { height: calc(var(--mo-ch) * 1.58 + 22px); }
.mo-hand.rows-3 { height: calc(var(--mo-ch) * 2.16 + 22px); }
.mo-hand .mo-card { position: absolute; top: 14px; left: 0; padding: 0; transform-origin: 50% 120%; transition: transform .18s ease, filter .18s; cursor: pointer; touch-action: manipulation; }
.mo-hand .mo-card.is-playable { box-shadow: 0 0 0 3px var(--mo-gold), 0 6px 14px rgba(0, 0, 0, .35); }
.mo-hand.is-mine .mo-card:not(.is-playable) { filter: brightness(.72) saturate(.7); }
.mo-hand .mo-card:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.mo-hand .mo-card.is-nope { animation: mo-nope .35s ease; }
@keyframes mo-nope { 25% { margin-left: -5px; } 75% { margin-left: 5px; } }

/* ---- card faces (pure CSS) ---- */
.mo-card { display: block; width: var(--mo-cw); height: var(--mo-ch); border-radius: 8px; background: var(--mo-face); border: 1px solid var(--mo-face-edge); color: var(--mo-black); position: relative; font-family: Georgia, "Times New Roman", serif; box-shadow: 0 3px 8px rgba(0, 0, 0, .3); overflow: hidden; }
button.mo-card { font: inherit; font-family: Georgia, "Times New Roman", serif; text-align: left; }
.mo-card.is-red { color: var(--mo-red); }
.mo-corner { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: .95; font-weight: 700; font-size: calc(var(--mo-cw) * .27); }
.mo-corner small { font-size: .8em; }
.mo-corner.tl { top: 4px; left: 4px; }
.mo-corner.br { bottom: 4px; right: 4px; transform: rotate(180deg); }
.mo-pip { position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%); font-size: calc(var(--mo-cw) * .58); line-height: 1; }
.mo-face-letter { position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%); width: 60%; height: 56%; border: 1.5px solid currentColor; border-radius: 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: calc(var(--mo-cw) * .36); line-height: 1; background: rgba(251, 191, 36, .14); }
.mo-face-letter small { font-size: .6em; }
.mo-card.is-special::after { content: ""; position: absolute; inset: 2px; border-radius: 6px; border: 1.5px dashed currentColor; opacity: .25; pointer-events: none; }
.mo-joker { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 2px; text-align: center; }
.mo-joker-star { font-size: calc(var(--mo-cw) * .5); line-height: 1; }
.mo-joker-word { font-family: system-ui, sans-serif; font-weight: 900; font-size: calc(var(--mo-cw) * .16); letter-spacing: .08em; }
.mo-joker-plus { font-family: system-ui, sans-serif; font-weight: 900; font-size: calc(var(--mo-cw) * .22); }
.mo-back { background: repeating-linear-gradient(45deg, var(--mo-back-1) 0 5px, var(--mo-back-2) 5px 10px); border: 2px solid #f8f1e3; }
.mo-back::before { content: ""; position: absolute; inset: 4px; border: 1.5px solid rgba(255, 255, 255, .45); border-radius: 5px; }

/* the flying card used by the animations */
.mo-fly { position: fixed; z-index: 1500; margin: 0; pointer-events: none; will-change: transform; }

/* ---- action buttons ---- */
.mo-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin-top: 10px; }
.mo-btn { min-height: 48px; padding: 8px 12px; border: 1px solid var(--mo-card-border); border-radius: 14px; background: var(--mo-card-bg); color: var(--text-color); font-weight: 700; font-size: .95rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.mo-btn:hover:not(:disabled) { border-color: var(--mo-accent); }
.mo-btn:disabled { opacity: .45; cursor: not-allowed; }
.mo-btn:focus-visible { outline: 2px solid var(--mo-gold); outline-offset: 2px; }
.mo-btn-primary { background: var(--mo-accent); border-color: var(--mo-accent); color: var(--mo-accent-ink); }
.mo-table .mo-btn { border-color: rgba(0, 0, 0, .25); }
.mo-btn-draw.is-urgent { background: var(--mo-red); border-color: var(--mo-red); color: #fff; }
.mo-btn-macao { background: var(--mo-gold); border-color: #d99a06; color: #3a2400; }
.mo-btn-macao:disabled { background: rgba(255, 255, 255, .2); border-color: transparent; color: var(--mo-felt-ink); }
.mo-btn-macao.is-urgent { animation: mo-throb .8s ease-in-out infinite; box-shadow: 0 0 0 4px rgba(251, 191, 36, .45); }

.mo-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* ---- score ---- */
.mo-score { margin-top: 12px; padding: 12px 14px; border-radius: 16px; background: var(--mo-card-bg); border: 1px solid var(--mo-card-border); }
.mo-score-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mo-score h2 { font-size: 1.05rem; font-weight: 800; margin: 0; }
.mo-score h2 .svg-inline--fa, .mo-score h2 i { color: #d99a06; }
.mo-score-table { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: .92rem; }
.mo-score-table th { color: var(--mo-muted); font-weight: 700; font-size: .78rem; text-align: right; padding: 4px 6px; }
.mo-score-table th:first-child, .mo-score-table td:first-child { text-align: left; }
.mo-score-table td { text-align: right; padding: 6px; border-top: 1px solid var(--mo-card-border); font-variant-numeric: tabular-nums; }
.mo-score-table tr.is-me td { font-weight: 800; }
.mo-score-table tr.is-lead td:first-child::after { content: " ★"; color: #d99a06; }
.mo-record { margin: 8px 0 0; color: var(--mo-muted); font-size: .88rem; }
.mo-link { border: 0; background: none; padding: 8px; color: var(--mo-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

.mo-help { margin-top: 14px; padding: 12px 16px; border-radius: 14px; background: var(--mo-card-bg); border: 1px solid var(--mo-card-border); }
.mo-help summary { cursor: pointer; font-weight: 700; min-height: 32px; display: list-item; }
.mo-help ul { margin: 10px 0 0; padding-left: 20px; color: var(--mo-muted); line-height: 1.55; }
.mo-help li { margin-bottom: 5px; }
.mo-help strong { color: var(--text-color); }
.mo-help p { color: var(--mo-muted); margin: 10px 0 0; line-height: 1.55; font-size: .92rem; }
.mo-powered { text-align: center; color: var(--mo-muted); font-size: .85rem; margin: 26px 0 0; }

/* ---- dialogs ---- */
.mo-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .45); animation: mo-fade .2s ease-out; }
.mo-overlay[hidden] { display: none; }
@keyframes mo-fade { from { opacity: 0; } }
.mo-dialog { width: 100%; max-width: 360px; padding: 20px 16px 14px; border-radius: 22px; background: var(--mo-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: mo-rise .25s ease-out; }
@keyframes mo-rise { from { transform: translateY(20px) scale(.96); opacity: 0; } }
.mo-dialog h2 { font-weight: 800; font-size: 1.4rem; margin: 2px 0 12px; }
.mo-suits { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mo-suit-btn { min-height: 84px; border-radius: 16px; border: 2px solid var(--mo-card-border); background: var(--mo-face); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; touch-action: manipulation; }
.mo-suit-btn span { font-size: 2.4rem; line-height: 1; }
.mo-suit-btn small { font-weight: 700; font-size: .85rem; color: #333; }
.mo-suit-btn.is-red span { color: var(--mo-red); }
.mo-suit-btn.is-black span { color: var(--mo-black); }
.mo-suit-btn:hover, .mo-suit-btn:focus-visible { border-color: var(--mo-accent); outline: none; }
.mo-end-icon { font-size: 34px; color: #d99a06; }
.mo-end-icon.is-lost { color: var(--mo-muted); }
.mo-end-text { color: var(--mo-muted); margin: -4px 0 14px; line-height: 1.45; }
.mo-end-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.mo-toast { position: fixed; left: 50%; bottom: 22px; z-index: 1900; transform: translate(-50%, 20px); max-width: calc(100vw - 32px); padding: 9px 16px; border-radius: 14px; background: rgba(17, 24, 39, .92); color: #fff; font-weight: 700; font-size: .92rem; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.mo-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---- bigger screens ---- */
@media (min-width: 640px) {
    :root { --mo-cw: 76px; --mo-ch: 110px; }
    .mo-table { padding: 16px 18px 18px; }
    .mo-mini .mo-card { width: 32px; height: 46px; }
    .mo-mini { height: 48px; }
    .mo-center { justify-content: center; grid-template-columns: auto auto minmax(140px, auto); gap: 22px; }
}

@media (max-width: 400px) {
    :root { --mo-cw: 58px; --mo-ch: 84px; }
    .mo-chip { min-width: 40px; padding: 4px 9px; font-size: .85rem; }
    .mo-settings { gap: 8px 10px; padding: 8px 6px; }
    .mo-table { padding: 8px 6px 10px; border-width: 5px; }
    .mo-btn { font-size: .88rem; padding: 8px; }
    .mo-center { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    .mo-pending, .mo-btn-macao.is-urgent, .mo-draw-pile.is-hint .mo-pile-card, .mo-bubble { animation: none !important; }
}
