:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
}

body.mj-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f8f1e3;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 12% 8%, rgba(244, 196, 48, 0.16), transparent 42%),
        radial-gradient(circle at 88% 12%, rgba(201, 12, 15, 0.2), transparent 46%),
        linear-gradient(180deg, #3a1c12 0%, #5a2e18 48%, #1c0e0a 100%);
}

body.mj-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

body.mj-page.game-menu-active #game-header {
    display: none !important;
}

.mj-page .game-screen {
    display: none;
    min-height: 100vh;
}

.mj-page .game-screen.active {
    display: block;
}

body.mj-page.with-game-header .mj-shell {
    padding-top: 5.5rem;
}

.mj-shell {
    max-width: min(1100px, 98vw);
    margin: 0 auto;
    padding: 1.1rem 0.6rem 2.5rem;
}

.mj-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 720px;
    margin: 0 auto 0.85rem;
    padding: 0.55rem 0.7rem;
    background: linear-gradient(180deg, #7a3e22, #3a1c12);
    border: 3px solid #1c0e0a;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.mj-lcd {
    min-width: 4.6rem;
    padding: 0.2rem 0.45rem;
    background: #140c08;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #7f1d1d, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.mj-lcd span {
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #f4c430;
}

.mj-chip {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fde68a;
    font-weight: 700;
}

.mj-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 auto 0.85rem;
    max-width: 720px;
}

.mj-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(244, 196, 48, 0.28);
    background: rgba(20, 12, 8, 0.75);
    color: #f8f1e3;
    font-weight: 700;
    cursor: pointer;
}

.mj-tool-btn:hover {
    border-color: #f5c518;
    color: #f5c518;
}

.mj-tool-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.mj-status {
    text-align: center;
    min-height: 1.4rem;
    margin: 0 auto 0.75rem;
    color: #fde68a;
    font-weight: 700;
}

.mj-board-wrap {
    display: flex;
    justify-content: center;
    overflow: auto;
    padding: 0.5rem 0.25rem 1rem;
    min-height: 42vh;
}

.mj-board {
    --mj-tw: 44px;
    --mj-th: 58px;
    position: relative;
    margin: 0 auto;
    background:
        radial-gradient(circle at 30% 18%, rgba(244, 196, 48, 0.1), transparent 52%),
        linear-gradient(180deg, #8a4e2a, #4a2814);
    border: 5px solid #1c0e0a;
    border-radius: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 18px 36px rgba(0, 0, 0, 0.45);
}

.mj-tile {
    --mj-tw: 44px;
    --mj-th: 58px;
    position: absolute;
    width: var(--mj-tw);
    height: var(--mj-th);
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    transform-origin: center bottom;
}

.mj-tile.is-removed {
    visibility: hidden;
    pointer-events: none;
}

.mj-tile-body {
    position: absolute;
    inset: 0 3px 4px 0;
    border-radius: 6px;
    background: linear-gradient(160deg, #fffaf0, #efe2c4);
    border: 1px solid #cbb58a;
    box-shadow:
        3px 4px 0 #6b3e22,
        4px 5px 0 #2a140c,
        0 8px 12px rgba(0, 0, 0, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1a120c;
    overflow: hidden;
}

.mj-tile.is-free .mj-tile-body {
    filter: brightness(1.04);
}

.mj-tile:not(.is-free) .mj-tile-body {
    filter: brightness(0.88);
    cursor: default;
}

.mj-tile.is-selected .mj-tile-body,
.mj-tile.is-hint .mj-tile-body {
    box-shadow:
        0 0 0 3px #f5c518,
        3px 4px 0 #6b3e22,
        4px 5px 0 #2a140c;
    transform: translateY(-3px);
}

.mj-tile.is-mismatch .mj-tile-body {
    box-shadow:
        0 0 0 3px #c90c0f,
        3px 4px 0 #6b3e22;
}

.mj-tile:focus-visible .mj-tile-body {
    outline: 3px solid #f4c430;
    outline-offset: 2px;
}

.mj-face {
    width: 86%;
    height: 88%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.mj-glyph {
    font-size: calc(var(--mj-th) * 0.42);
    line-height: 1;
    font-family: "Songti SC", "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
}

.mj-glyph.red { color: #c90c0f; }
.mj-glyph.green { color: #1f7a3a; }
.mj-glyph.blue { color: #1d4ed8; }
.mj-glyph.plum { color: #9d174d; }
.mj-glyph.gold { color: #b45309; }

.mj-dragon-white {
    width: 70%;
    height: 78%;
    border: 3px solid #2563eb;
    border-radius: 3px;
    background: #fff;
}

.mj-dots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 78%;
    height: 84%;
    gap: 0;
}

.mj-dots i {
    display: block;
    width: calc(var(--mj-tw) * 0.168);
    height: calc(var(--mj-tw) * 0.168);
    padding: 0;
    border-radius: 50%;
    justify-self: center;
    align-self: center;
    background: radial-gradient(circle at 35% 30%, #f87171, #b91c1c 70%);
    box-shadow: inset 0 -1px 1px rgba(0, 0, 0, 0.25);
}

.mj-dots.n-1 i {
    grid-column: 2;
    grid-row: 2;
    width: calc(var(--mj-tw) * 0.36);
    height: calc(var(--mj-tw) * 0.36);
}

.mj-dots.n-2 i,
.mj-dots.n-3 i {
    width: calc(var(--mj-tw) * 0.22);
    height: calc(var(--mj-tw) * 0.22);
}

.mj-dots.n-2 i:nth-child(1) { grid-column: 1; grid-row: 1; }
.mj-dots.n-2 i:nth-child(2) { grid-column: 3; grid-row: 3; }

.mj-dots.n-3 i:nth-child(1) { grid-column: 1; grid-row: 1; }
.mj-dots.n-3 i:nth-child(2) { grid-column: 2; grid-row: 2; }
.mj-dots.n-3 i:nth-child(3) { grid-column: 3; grid-row: 3; }

.mj-dots.n-4 i:nth-child(1) { grid-column: 1; grid-row: 1; }
.mj-dots.n-4 i:nth-child(2) { grid-column: 3; grid-row: 1; }
.mj-dots.n-4 i:nth-child(3) { grid-column: 1; grid-row: 3; }
.mj-dots.n-4 i:nth-child(4) { grid-column: 3; grid-row: 3; }

.mj-dots.n-5 i:nth-child(1) { grid-column: 1; grid-row: 1; }
.mj-dots.n-5 i:nth-child(2) { grid-column: 3; grid-row: 1; }
.mj-dots.n-5 i:nth-child(3) { grid-column: 2; grid-row: 2; }
.mj-dots.n-5 i:nth-child(4) { grid-column: 1; grid-row: 3; }
.mj-dots.n-5 i:nth-child(5) { grid-column: 3; grid-row: 3; }

.mj-dots.n-6 i:nth-child(1) { grid-column: 1; grid-row: 1; }
.mj-dots.n-6 i:nth-child(2) { grid-column: 3; grid-row: 1; }
.mj-dots.n-6 i:nth-child(3) { grid-column: 1; grid-row: 2; }
.mj-dots.n-6 i:nth-child(4) { grid-column: 3; grid-row: 2; }
.mj-dots.n-6 i:nth-child(5) { grid-column: 1; grid-row: 3; }
.mj-dots.n-6 i:nth-child(6) { grid-column: 3; grid-row: 3; }

.mj-dots.n-7 i:nth-child(1) { grid-column: 1; grid-row: 1; }
.mj-dots.n-7 i:nth-child(2) { grid-column: 2; grid-row: 1; }
.mj-dots.n-7 i:nth-child(3) { grid-column: 3; grid-row: 1; }
.mj-dots.n-7 i:nth-child(4) { grid-column: 2; grid-row: 2; }
.mj-dots.n-7 i:nth-child(5) { grid-column: 1; grid-row: 3; }
.mj-dots.n-7 i:nth-child(6) { grid-column: 2; grid-row: 3; }
.mj-dots.n-7 i:nth-child(7) { grid-column: 3; grid-row: 3; }

.mj-dots.n-8 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(4, 1fr);
}

.mj-bamboo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 7%;
    width: 82%;
    height: 86%;
}

.mj-bamboo i {
    display: block;
    width: 18%;
    height: 78%;
    border-radius: 999px;
    background: linear-gradient(90deg, #86efac, #166534 55%, #14532d);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
    position: relative;
}

.mj-bamboo i::after {
    content: "";
    position: absolute;
    left: 15%;
    right: 15%;
    top: 28%;
    height: 2px;
    background: rgba(255, 255, 255, 0.35);
}

.mj-bamboo.n-1 i { width: 28%; }
.mj-bamboo.n-4,
.mj-bamboo.n-5,
.mj-bamboo.n-6,
.mj-bamboo.n-7,
.mj-bamboo.n-8,
.mj-bamboo.n-9 { align-content: center; }
.mj-bamboo.n-4 i,
.mj-bamboo.n-5 i,
.mj-bamboo.n-6 i { height: 38%; width: 22%; }

.mj-hint {
    text-align: center;
    color: #e7d3b0;
    font-size: 0.92rem;
    margin: 0.85rem auto 0;
    max-width: 40rem;
}

.mj-settings-panel__label {
    margin: 0 0 0.45rem;
    color: #1a120c;
    font-weight: 600;
}

.mj-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
}

#settingsModal .mj-settings-panel__note {
    margin: 0.75rem 0 0;
    color: #7f1d1d;
    font-size: 0.9rem;
}

.difficulty-pill {
    padding: 0.45rem 0.75rem;
    min-height: 44px;
    border-radius: 999px;
    border: 2px solid #c90c0f;
    background: #fff !important;
    color: #c90c0f !important;
    font-weight: 700;
    cursor: pointer;
}

.difficulty-pill.is-selected,
.difficulty-pill:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active { display: flex; }

.modal-content {
    background: #fff;
    color: #1a1a1a;
    border-radius: 1rem;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large { max-width: 760px; }

.modal-header,
.modal-footer {
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.modal-header { border-bottom: 2px solid #eee; }

.modal-header h2 {
    margin: 0;
    color: #c90c0f;
    font-size: 1.35rem;
}

.modal-close {
    background: #fff !important;
    border: 2px solid #c90c0f;
    color: #c90c0f !important;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.modal-close:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

.modal-body { padding: 1.2rem 1.4rem; }

.modal-footer {
    border-top: 2px solid #eee;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.help-section { margin-bottom: 1.1rem; }
.help-section h3 { color: #c90c0f; margin: 0 0 0.4rem; }
.help-section ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.help-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.65rem;
}

.help-tiles .mj-tile {
    --mj-tw: 42px;
    --mj-th: 56px;
    position: relative;
    width: var(--mj-tw);
    height: var(--mj-th);
    left: auto;
    top: auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
}

.stat-value { font-size: 1.6rem; color: #c90c0f; font-weight: 700; }
.stat-label { color: #64748b; font-size: 0.85rem; }

.difficulty-stats { display: grid; gap: 0.45rem; }
.difficulty-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0.55rem;
    background: #f8fafc;
    border-radius: 8px;
}

.result-message { font-size: 1.05rem; margin: 0 0 1rem; }

.win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    text-align: center;
}

.win-stat strong { display: block; font-size: 1.35rem; color: #c90c0f; }
.win-stat span { color: #64748b; font-size: 0.82rem; }

.mj-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    font-weight: 700;
    cursor: pointer;
}

.mj-page .btn-primary {
    background: #c90c0f !important;
    color: #fff !important;
    border-color: #c90c0f;
}

.mj-page .btn-secondary {
    background: #fff !important;
    color: #c90c0f !important;
    border-color: #c90c0f;
}

.mj-page .btn-secondary:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

@media (max-width: 900px) {
    .mj-board {
        --mj-tw: 36px;
        --mj-th: 48px;
    }
}

@media (max-width: 640px) {
    body.mj-page.with-game-header .mj-shell {
        padding-top: 0.75rem;
        padding-left: 0.35rem;
        padding-right: 0.35rem;
    }

    .mj-hud { max-width: 100%; }
    .mj-lcd { min-width: 0; flex: 1 1 0; font-size: 1rem; }
    .mj-board {
        --mj-tw: 30px;
        --mj-th: 40px;
    }
    .mj-glyph { font-size: calc(var(--mj-th) * 0.46); }
}
