/* Mahjong solitar (js/mahjong.js). Theme-aware like the other game pages:
   tokens on :root, redefined under body.dark-theme. */
:root {
    --mj-accent: #0f766e;
    --mj-accent-2: #0d9488;
    --mj-accent-soft: #dff5f0;
    --mj-on-accent: #ffffff;
    --mj-page-bg: #f3f6f2;
    --mj-card-bg: #ffffff;
    --mj-card-border: #d8e2dc;
    --mj-muted: #56655d;
    --mj-shadow: 0 10px 30px rgba(15, 60, 45, .10);
    --mj-felt: #2f7356;
    --mj-felt-2: #245c45;
    --mj-tile: #fffdf6;
    --mj-tile-2: #efe6d0;
    --mj-tile-edge: #d8c9a3;
    --mj-tile-back: #1f7a5c;
    --mj-tile-line: rgba(120, 96, 50, .28);
    --mj-sel: #fff1b8;
    --mj-sel-2: #f6d87a;
    --mj-sel-ring: #f59e0b;
    --mj-hint: #22d3ee;
    --mj-block: rgba(38, 30, 12, .2);
    --mj-good: #15803d;
    --mj-bad: #dc2626;
    --mj-warn: #b45309;
    --mj-gold: #f59e0b;
}

body.dark-theme {
    --mj-accent: #2dd4bf;
    --mj-accent-2: #5eead4;
    --mj-accent-soft: #10302b;
    --mj-on-accent: #04201b;
    --mj-page-bg: #0c1311;
    --mj-card-bg: #141e1b;
    --mj-card-border: #263833;
    --mj-muted: #9fb3ab;
    --mj-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --mj-felt: #143a2c;
    --mj-felt-2: #0e2a20;
    --mj-tile: #f4efe1;
    --mj-tile-2: #ddd2b8;
    --mj-tile-edge: #b9aa86;
    --mj-tile-back: #14563f;
    --mj-sel: #ffe9a3;
    --mj-sel-2: #eac35d;
    --mj-block: rgba(0, 0, 0, .40);
    --mj-good: #4ade80;
    --mj-bad: #f87171;
    --mj-warn: #fbbf24;
}

/* 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. */
.mj-body, body.mj-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--mj-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.mj-main { padding-top: 92px; padding-bottom: 40px; }
.mj-game .container, .mj-hero .container { max-width: 1120px; }

/* ---- hero ---- */
.mj-hero { text-align: center; padding: 4px 0 8px; }
.mj-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); margin-bottom: 4px; }
.mj-hero-icon { color: var(--mj-accent); }
.mj-lead { margin: 0 auto; max-width: 600px; color: var(--mj-muted); font-size: .98rem; line-height: 1.45; }
body.mj-playing .mj-hero { display: none; }
body.mj-playing .mj-main { padding-top: 14px; }

/* ---- buttons ---- */
.mj-btn { min-height: 48px; padding: 8px 16px; border-radius: 14px; border: 1px solid var(--mj-card-border); background: var(--mj-card-bg); color: inherit; font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; transition: background .15s, border-color .15s, transform .1s; }
.mj-btn:hover { border-color: var(--mj-accent); }
.mj-btn:active { transform: scale(.98); }
.mj-btn[hidden] { display: none; }
.mj-btn-primary { background: var(--mj-accent); border-color: var(--mj-accent); color: var(--mj-on-accent); }
.mj-btn-primary:hover { background: var(--mj-accent-2); border-color: var(--mj-accent-2); }
.mj-btn-ghost { background: transparent; }
.mj-wide { width: 100%; max-width: 420px; margin: 10px auto 0; display: flex; }
.mj-btn:focus-visible, .mj-round:focus-visible, .mj-tool:focus-visible, .mj-x:focus-visible, .mj-link:focus-visible, .mj-lay:focus-visible { outline: 3px solid var(--mj-gold); outline-offset: 2px; }

/* ---- setup ---- */
.mj-setup { max-width: 1000px; margin: 6px auto 0; }
.mj-setup[hidden], .mj-play[hidden] { display: none; }
.mj-setup-title { text-align: center; font-weight: 800; font-size: 1.25rem; margin: 4px 0 10px; }
.mj-layouts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.mj-lay { position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 10px 12px; border-radius: 18px; border: 1px solid var(--mj-card-border); background: var(--mj-card-bg); color: inherit; text-align: left; cursor: pointer; box-shadow: var(--mj-shadow); touch-action: manipulation; transition: transform .12s, border-color .15s; }
.mj-lay:hover { border-color: var(--mj-accent); transform: translateY(-2px); }
.mj-lay:active { transform: scale(.98); }
.mj-lay-pic { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 12px; background: linear-gradient(160deg, var(--mj-felt) 0%, var(--mj-felt-2) 100%); }
.mj-lay-pic svg { position: absolute; left: 8px; top: 8px; width: calc(100% - 16px); height: calc(100% - 16px); display: block; }
.mj-lay-name { font-weight: 800; font-size: 1rem; line-height: 1.2; }
.mj-lay-meta { color: var(--mj-muted); font-size: .8rem; line-height: 1.3; }
.mj-lay-rec { color: var(--mj-accent); font-size: .8rem; font-weight: 700; min-height: 1.1em; }
.mj-lay.is-last { border-color: var(--mj-accent); box-shadow: 0 0 0 2px var(--mj-accent), var(--mj-shadow); }

/* ---- top bar ---- */
.mj-play { max-width: 1120px; margin: 0 auto; }
.mj-top { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.mj-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.mj-info strong { font-weight: 800; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mj-info small { color: var(--mj-muted); font-size: .82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mj-clock { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 6px 12px; border-radius: 14px; background: var(--mj-card-bg); border: 1px solid var(--mj-card-border); font-variant-numeric: tabular-nums; flex: none; }
.mj-clock b { font-size: 1.12rem; font-weight: 900; min-width: 3.1em; text-align: right; }
.mj-clock-icon { color: var(--mj-accent); }
.mj-round { width: 44px; height: 44px; flex: none; border-radius: 14px; border: 1px solid var(--mj-card-border); background: var(--mj-card-bg); color: inherit; font-size: 1.05rem; display: grid; place-items: center; cursor: pointer; touch-action: manipulation; }
.mj-round:hover { border-color: var(--mj-accent); }
.mj-round span[hidden], .mj-tool span[hidden] { display: none; }

/* ---- the table ---- */
.mj-stage { position: relative; height: clamp(300px, calc(100vh - 252px), 820px); height: clamp(300px, calc(100dvh - 252px), 820px); overflow: auto; border-radius: 18px; background: radial-gradient(120% 90% at 50% 35%, var(--mj-felt) 0%, var(--mj-felt-2) 100%); box-shadow: inset 0 2px 14px rgba(0, 0, 0, .28), var(--mj-shadow); touch-action: none; overscroll-behavior: contain; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; scrollbar-width: thin; }
.mj-board { position: relative; z-index: 0; isolation: isolate; margin: 0 auto; }   /* tiles stack inside the board only */
.mj-paused { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: radial-gradient(120% 90% at 50% 35%, var(--mj-felt) 0%, var(--mj-felt-2) 100%); color: #f4f1e6; }
.mj-paused[hidden] { display: none; }
.mj-paused p { font-size: 1.6rem; font-weight: 800; margin: 0; display: flex; gap: 10px; align-items: center; }

/* a tile: ivory face over a green back, the thickness drawn as two offset shadows */
.mj-t { position: absolute; left: 0; top: 0; width: var(--tw); height: var(--th); padding: 0; border: 0; border-radius: calc(var(--tw) * .13); background: linear-gradient(150deg, var(--mj-tile) 0%, var(--mj-tile) 45%, var(--mj-tile-2) 100%); box-shadow: inset 0 0 0 1px var(--mj-tile-line), inset 1px 1px 0 2px rgba(255, 255, 255, .55), var(--dd) var(--dd) 0 0 var(--mj-tile-edge), calc(var(--dd) * 2) calc(var(--dd) * 2) 0 0 var(--mj-tile-back), calc(var(--dd) * 2 + 1px) calc(var(--dd) * 2 + 3px) calc(var(--dd) * 3) 0 rgba(0, 0, 0, .38); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .12s ease-out, background .12s; }
.mj-t[hidden] { display: none; }
.mj-t svg { position: absolute; left: 7%; top: 5.5%; width: 86%; height: 89%; display: block; pointer-events: none; overflow: visible; }
.mj-t::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: transparent; pointer-events: none; transition: background .15s; }
.mj-board.is-dim .mj-t.is-blocked::after { background: var(--mj-block); }
.mj-t.is-blocked { cursor: default; }
.mj-t.is-sel { background: linear-gradient(150deg, var(--mj-sel) 0%, var(--mj-sel) 40%, var(--mj-sel-2) 100%); transform: translate(-1px, -3px); box-shadow: inset 0 0 0 2px var(--mj-sel-ring), var(--dd) calc(var(--dd) + 3px) 0 0 var(--mj-tile-edge), calc(var(--dd) * 2) calc(var(--dd) * 2 + 3px) 0 0 var(--mj-tile-back), 0 0 0 3px var(--mj-sel-ring), calc(var(--dd) * 2 + 2px) calc(var(--dd) * 2 + 8px) calc(var(--dd) * 4) 0 rgba(0, 0, 0, .4); }
.mj-t.is-hint { animation: mj-hint 0.9s ease-in-out 3; }
@keyframes mj-hint { 50% { box-shadow: inset 0 0 0 3px var(--mj-hint), 0 0 0 4px var(--mj-hint), 0 0 18px 6px var(--mj-hint); transform: translateY(-3px); } }
.mj-t.is-nope { animation: mj-nope .38s ease-out; }
@keyframes mj-nope { 20% { transform: translateX(-4px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }
.mj-t.is-out { animation: mj-out .3s ease-in forwards; pointer-events: none; }
@keyframes mj-out { to { transform: translateY(-14px) scale(.78); opacity: 0; } }
.mj-t.is-in { animation: mj-in .28s ease-out; }
@keyframes mj-in { from { transform: translateY(-14px) scale(.8); opacity: 0; } }
.mj-board.is-shuffle .mj-t:not([hidden]) { animation: mj-flip .42s ease-in-out; }
@keyframes mj-flip { 45% { transform: scaleX(.08); } }
.mj-t:focus { outline: none; }
.mj-t:focus-visible { outline: 3px solid var(--mj-gold); outline-offset: 1px; }
@media (hover: hover) {
    .mj-t:not(.is-blocked):not(.is-sel):hover { background: linear-gradient(150deg, #ffffff 0%, #fffaf0 45%, var(--mj-tile-2) 100%); }
    body.dark-theme .mj-t:not(.is-blocked):not(.is-sel):hover { background: linear-gradient(150deg, #fffdf6 0%, #f7f1e3 45%, var(--mj-tile-2) 100%); }
}

.mj-status { margin: 4px 2px 0; height: 2.7em; overflow: hidden; display: flex; align-items: center; justify-content: center; font-weight: 700; text-align: center; color: var(--mj-muted); line-height: 1.3; font-size: .92rem; }   /* two lines reserved: no layout shift */
.mj-status.is-good { color: var(--mj-good); }
.mj-status.is-bad { color: var(--mj-bad); }
.mj-status.is-warn { color: var(--mj-warn); }

/* ---- tools ---- */
.mj-tools { display: flex; gap: 6px; justify-content: center; margin: 4px auto 0; max-width: 720px; }
.mj-tool { flex: 1 1 0; min-width: 0; min-height: 54px; padding: 4px 2px; border-radius: 14px; border: 1px solid var(--mj-card-border); background: var(--mj-card-bg); color: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 1.08rem; cursor: pointer; touch-action: manipulation; }
.mj-tool > span:last-child { font-size: .7rem; font-weight: 700; color: var(--mj-muted); white-space: nowrap; }
.mj-tool .mj-on, .mj-tool .mj-off { display: flex; line-height: 1; }
.mj-tool:hover:not(:disabled) { border-color: var(--mj-accent); }
.mj-tool:disabled { opacity: .42; cursor: not-allowed; }
.mj-tool[hidden] { display: none; }
.mj-tool-hint { color: var(--mj-gold); }
.mj-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; max-width: 420px; margin: 12px auto 0; }
.mj-opts { display: flex; justify-content: center; margin-top: 8px; }
.mj-switch { display: inline-flex; align-items: center; gap: 8px; margin: 0; min-height: 40px; font-weight: 700; cursor: pointer; user-select: none; }
.mj-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.mj-switch-ui { position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--mj-card-border); transition: background .2s; flex: none; }
.mj-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.mj-switch input:checked + .mj-switch-ui { background: var(--mj-accent); }
.mj-switch input:checked + .mj-switch-ui::after { transform: translateX(18px); }
.mj-switch input:focus-visible + .mj-switch-ui { outline: 3px solid var(--mj-gold); outline-offset: 2px; }

.mj-record { text-align: center; color: var(--mj-muted); font-size: .88rem; margin: 10px 0 0; min-height: 1.3em; }
.mj-record b { color: var(--text-color); }

.mj-help { max-width: 780px; margin: 14px auto 0; padding: 12px 16px; border-radius: 14px; background: var(--mj-card-bg); border: 1px solid var(--mj-card-border); }
.mj-help summary { cursor: pointer; font-weight: 700; }
.mj-help ul { margin: 10px 0 0; padding-left: 20px; color: var(--mj-muted); line-height: 1.55; }
.mj-help li { margin-bottom: 4px; }
.mj-help strong { color: var(--text-color); }
.mj-help p.mj-credit { color: var(--mj-muted); margin: 10px 0 0; line-height: 1.5; font-size: .8rem; }
.mj-help a { color: var(--mj-accent); }
.mj-powered { text-align: center; color: var(--mj-muted); font-size: .85rem; margin: 26px 0 0; }
.mj-powered a { color: var(--mj-accent); }

/* ---- full screen (native, or the fallback that just covers the window) ---- */
.mj-play:fullscreen, .mj-play.is-max { max-width: none; width: 100%; height: 100%; margin: 0; padding: 10px 12px; background: var(--mj-page-bg); overflow: auto; }
.mj-play.is-max { position: fixed; inset: 0; z-index: 1900; }
.mj-play:fullscreen .mj-stage, .mj-play.is-max .mj-stage { height: calc(100vh - 176px); height: calc(100dvh - 176px); }
.mj-play:fullscreen .mj-actions, .mj-play:fullscreen .mj-opts, .mj-play.is-max .mj-actions, .mj-play.is-max .mj-opts { display: none; }
body.mj-max { overflow: hidden; }

/* ---- dialogs ---- */
.mj-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .5); animation: mj-fade .2s ease-out; }
.mj-overlay[hidden] { display: none; }
@keyframes mj-fade { from { opacity: 0; } }
.mj-dialog { width: 100%; max-width: 420px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; padding: 20px 16px 16px; border-radius: 22px; background: var(--mj-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: mj-rise .25s ease-out; }
@keyframes mj-rise { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.mj-dialog h2 { font-weight: 800; font-size: 1.35rem; margin: 2px 0 6px; }
.mj-dialog-icon { font-size: 34px; color: var(--mj-gold); }
.mj-dialog-icon.is-warn { color: var(--mj-accent); }
.mj-dialog-sub { color: var(--mj-muted); margin: 0 0 6px; line-height: 1.45; }
.mj-dialog-sub b { color: var(--text-color); }
.mj-dialog-actions { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; margin-top: 14px; }
.mj-dialog-actions.mj-three { grid-template-columns: 1fr 1fr; }
.mj-dialog-actions.mj-three .mj-btn:first-child { grid-column: 1 / -1; }
.mj-recs-card { max-width: 560px; text-align: left; }
.mj-recs-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mj-x { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--mj-card-border); background: var(--mj-card-bg); color: inherit; font-size: 1.1rem; cursor: pointer; }
.mj-rec-wrap { overflow-x: auto; margin-top: 8px; }
.mj-rec-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.mj-rec-table th, .mj-rec-table td { padding: 8px 6px; border-top: 1px solid var(--mj-card-border); white-space: nowrap; }
.mj-rec-table thead th { border-top: 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--mj-muted); }
.mj-rec-table td { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.mj-rec-table thead th:not(:first-child) { text-align: right; }
.mj-rec-note { color: var(--mj-muted); font-size: .84rem; margin: 10px 0 4px; line-height: 1.4; }
.mj-link { border: 0; background: none; padding: 6px 0; color: var(--mj-bad); font-weight: 700; text-decoration: underline; cursor: pointer; }

@media (max-width: 900px) {
    .mj-layouts { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
    .mj-layouts { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .mj-lay { padding: 8px 8px 10px; border-radius: 16px; }
    .mj-lay:last-child:nth-child(odd) { grid-column: 1 / -1; display: grid; grid-template-columns: calc(50% - 8px) 1fr; column-gap: 12px; align-items: center; }
    .mj-lay:last-child:nth-child(odd) .mj-lay-pic { grid-row: 1 / span 3; }
    .mj-stage { border-radius: 14px; }
    .mj-tools { gap: 4px; }
    .mj-tool { min-height: 52px; border-radius: 12px; }
    .mj-tool > span:last-child { font-size: .64rem; }
    .mj-clock { padding: 6px 9px; }
}
@media (max-width: 380px) {
    .mj-info strong { font-size: .95rem; }
    .mj-info small { font-size: .76rem; }
    .mj-tool > span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .mj-t, .mj-dialog, .mj-overlay, .mj-lay { animation: none !important; transition: none !important; }
}
