/* Noos Mahjong 2.0 - assets/css/mahjong.css */
body {
    font-family: 'Quicksand', sans-serif;
    background: #daf0dc;
    margin: 0;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
*, *::before, *::after { box-sizing: border-box; }
:root { --accent: #88b04b; }
[hidden] { display: none !important; }

/* Legacy: the old page hid this element; kept so the shared win modal behaves exactly as before. */
#winModal { display: none !important; }

/* ---------- tile themes ---------- */
.game-container {
    --accent: #88b04b;
    --area: transparent;
    --mat: #c8e4cd;
    --mat-hi: rgba(255, 255, 255, .55);
    --face: #fdfbf3;
    --face2: #ece5d0;
    --back: #3f9d70;
    --back-edge: #2b7752;
    --ink-k: #1e293b;
    --ink-r: #c62828;
    --ink-g: #17803f;
    --ink-b: #1d4ed8;
    --ink-p: #be185d;
    --ink-o: #c2410c;
    --text: #64748b;
    --blocked: brightness(.58) saturate(.5) contrast(.9);
}
.game-container.theme-jade {
    --mat: #b9d9d0;
    --face: #eef8f3;
    --face2: #d5eadf;
    --back: #1f6f5a;
    --back-edge: #134f40;
    --ink-g: #0f6b3a;
}
.game-container.theme-night {
    --area: #141c2b;
    --mat: #1d2940;
    --mat-hi: rgba(120, 150, 220, .12);
    --face: #2f3b52;
    --face2: #252f44;
    --back: #0e1626;
    --back-edge: #070b14;
    --ink-k: #e6edf7;
    --ink-r: #fb7185;
    --ink-g: #4ade80;
    --ink-b: #7db2ff;
    --ink-p: #f472b6;
    --ink-o: #fb923c;
    --text: #94a3b8;
    --blocked: brightness(.45) saturate(.5);
}
.game-container.no-dim { --blocked: none; }

/* ---------- layout ---------- */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 0 20px;
    min-height: 0;
    background: var(--area);
    transition: background .3s;
}
.game-stats {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    max-width: 1000px;
    padding: 12px 0;
    flex: 0 0 auto;
}
.stats-left, .stats-right { display: flex; gap: 8px; flex: 0 0 auto; }
.stats-right { justify-content: flex-end; }
.stats-center { flex: 1; text-align: center; color: var(--text); line-height: 1.25; min-width: 0; }
.sc-title { font-weight: 700; font-size: .9rem; letter-spacing: .5px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-sub { font-weight: 600; font-size: .78rem; opacity: .85; }
.hide-timer #timerWrap { display: none; }

.btn-small {
    background: white;
    color: var(--accent);
    border: 2px solid var(--accent);
    padding: 6px 14px;
    border-radius: 20px;
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: .75rem;
    cursor: pointer;
    transition: transform .2s, box-shadow .2s, opacity .2s;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .05);
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.btn-small.btn-primary { background: var(--accent); color: white; }
.btn-small:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0, 0, 0, .1); }
.btn-small:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-small:focus-visible, .chip:focus-visible { outline: 3px solid rgba(136, 176, 75, .55); outline-offset: 2px; }

/* ---------- board ---------- */
.board-container {
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
    overflow: hidden;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}
.board-container.zoomed { cursor: grab; }
#mahjong-board {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
    isolation: isolate;
    will-change: transform;
}
#mahjong-board.animating { transition: transform .3s ease-out; }
.mat {
    position: absolute;
    z-index: 0;
    border-radius: 30px;
    background: radial-gradient(ellipse at 28% 18%, var(--mat-hi), rgba(255, 255, 255, 0) 62%), var(--mat);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, .1), 0 12px 32px rgba(0, 0, 0, .1);
    border: 1px solid rgba(255, 255, 255, .35);
}

.tile {
    position: absolute;
    width: 58px;
    height: 78px;
    border-radius: 8px;
    background: var(--back);
    box-shadow: 0 0 0 1px var(--back-edge), 5px 8px 12px rgba(0, 0, 0, .24);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform .15s ease, opacity .2s;
}
.tile .face {
    position: absolute;
    left: 0;
    top: 0;
    width: 54px;
    height: 74px;
    border-radius: 7px;
    background: linear-gradient(145deg, var(--face), var(--face2));
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1), inset 1px 1px 0 rgba(255, 255, 255, .65);
    transition: filter .2s, box-shadow .2s;
}
.tile .face svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
/* Flower / Season family tints (any flower pairs with any flower, any season with any season) */
.tile .face.fam-f { background: linear-gradient(rgba(214, 69, 138, .17), rgba(214, 69, 138, .17)), linear-gradient(145deg, var(--face), var(--face2)); }
.tile .face.fam-s { background: linear-gradient(rgba(224, 138, 30, .20), rgba(224, 138, 30, .20)), linear-gradient(145deg, var(--face), var(--face2)); }
.theme-night .tile .face.fam-f { background: linear-gradient(rgba(214, 69, 138, .28), rgba(214, 69, 138, .28)), linear-gradient(145deg, var(--face), var(--face2)); }
.theme-night .tile .face.fam-s { background: linear-gradient(rgba(224, 138, 30, .30), rgba(224, 138, 30, .30)), linear-gradient(145deg, var(--face), var(--face2)); }
.tile.blocked { cursor: default; }
.tile.blocked .face { filter: var(--blocked); }
.tile.gone { display: none; }

/* lift via margin, not transform: a transform promotes this tile to its own GPU layer and makes overlapping tiles re-rasterise (a faint shimmer) */
.tile.sel { margin: -3px 0 0 -2px; }
.tile.sel .face { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1), 0 0 0 3px var(--accent), 0 0 18px rgba(136, 176, 75, .8); }
.tile.match .face { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1), 0 0 0 2px rgba(245, 158, 11, .85), 0 0 10px rgba(245, 158, 11, .5); }
.tile.hinted .face { animation: mjPulse .9s ease-in-out infinite; }
.tile.shake { animation: mjShake .35s; }
.tile.removing { animation: mjPop .28s ease-in forwards; pointer-events: none; }
.tile.appear { animation: mjAppear .35s ease-out; }

@keyframes mjPulse {
    0%, 100% { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1), 0 0 0 3px #f59e0b, 0 0 8px rgba(245, 158, 11, .6); }
    50% { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1), 0 0 0 4px #f59e0b, 0 0 22px rgba(245, 158, 11, .95); }
}
@keyframes mjShake { 0%, 100% { translate: 0 0; } 25% { translate: -3px 0; } 75% { translate: 3px 0; } }
@keyframes mjPop { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(.72) translateY(-10px); } }
@keyframes mjAppear { 0% { opacity: 0; transform: scale(.8); } 100% { opacity: 1; transform: scale(1); } }

/* ---------- face art (SVG classes) ---------- */
.fl-r { fill: var(--ink-r); } .fl-g { fill: var(--ink-g); } .fl-b { fill: var(--ink-b); }
.fl-p { fill: var(--ink-p); } .fl-o { fill: var(--ink-o); } .fl-face { fill: var(--face); }
.st-r { stroke: var(--ink-r); } .st-g { stroke: var(--ink-g); } .st-b { stroke: var(--ink-b); } .st-face { stroke: var(--face); }
.tx-k { fill: var(--ink-k); } .tx-r { fill: var(--ink-r); } .tx-g { fill: var(--ink-g); }
.tx-b { fill: var(--ink-b); } .tx-p { fill: var(--ink-p); } .tx-o { fill: var(--ink-o); }
.cjk { font-family: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", "Hiragino Mincho ProN", "Yu Mincho", "PingFang SC", "Microsoft YaHei", serif; }

/* ---------- overlays ---------- */
.mj-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}
.mj-card {
    background: #fff;
    border-radius: 22px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    margin: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, .25);
    color: #334155;
    font-family: 'Quicksand', sans-serif;
}
.mj-card h2 { margin: 0 0 4px; font-size: 1.3rem; color: #1e293b; }
.mj-card p { margin: 0 0 16px; color: #64748b; font-size: .92rem; }
.mj-sec { margin-top: 16px; }
.mj-lab { font-size: .7rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #94a3b8; margin-bottom: 6px; }
.mj-row { display: flex; flex-wrap: wrap; gap: 8px; }
.mj-row.end { justify-content: flex-end; margin-top: 20px; }
.chip {
    background: #f1f5f9;
    color: #475569;
    border: 2px solid transparent;
    padding: 7px 13px;
    border-radius: 18px;
    font: 700 .78rem 'Quicksand', sans-serif;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.chip:hover { background: #e2e8f0; }
.chip.on { border-color: var(--accent, #88b04b); background: #f0fdf4; color: #4d7c0f; }
.mj-check { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-weight: 600; font-size: .9rem; cursor: pointer; }
.mj-check input { width: 18px; height: 18px; accent-color: #88b04b; }
.mj-best { margin-top: 14px; font-size: .8rem; color: #64748b; min-height: 1em; }
.mj-sub { font-size: .78rem; color: #94a3b8; font-weight: 600; margin-top: 2px; }

.mj-toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translate(-50%, 20px);
    background: #1e293b;
    color: #fff;
    padding: 10px 18px;
    border-radius: 20px;
    font: 600 .85rem 'Quicksand', sans-serif;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 9500;
    max-width: 90vw;
    text-align: center;
}
.mj-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 700px) {
    body { position: fixed; width: 100%; }
    .game-container { padding: 0 6px; }
    .game-stats { flex-wrap: wrap; padding: 6px 0; gap: 6px; }
    .stats-left, .stats-right { flex: 1 1 auto; justify-content: center; gap: 6px; }
    .stats-center { order: -1; flex: 0 0 100%; }
    .sc-title { font-size: .76rem; }
    .btn-small { padding: 5px 10px; font-size: .68rem; border-radius: 14px; }
}
@media (max-width: 480px) {
    .btn-small .lbl.hide-sm { display: none; }
}
@media (max-height: 480px) and (orientation: landscape) {
    .game-stats { padding: 4px 0; flex-wrap: nowrap; }
    .stats-center { order: 0; flex: 1; }
    .sc-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .tile, .tile .face, #mahjong-board.animating { transition: none; }
    .tile.hinted .face { animation: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1), 0 0 0 4px #f59e0b; }
    .tile.shake, .tile.appear, .tile.removing { animation: none; }
    .mj-toast { transition: none; }
}


/* Fog level: tiles that have never been free stay face-down */
.tile .face svg { transition: opacity .3s; }
.tile.fogged .face, .theme-night .tile.fogged .face {
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .07) 0 3px, transparent 3px 8px),
        linear-gradient(145deg, var(--back), var(--back-edge));
    filter: none;
}
.tile.fogged .face svg { opacity: 0; }