.mj-shell {
    --mj-ivory: #fdf8ec;
    --mj-ivory-2: #efe4cb;
    --mj-edge-dark: #a58f66;
    --mj-side: #c2a97e;
    --mj-side-2: #9c8355;
    max-width: 880px;
    margin: 0 auto;
    padding: 0 12px 26px;
    color: var(--cg-ink);
    font-family: Inter, Arial, sans-serif;
}

.mj-shell,
.mj-shell *,
.mj-shell *::before,
.mj-shell *::after {
    box-sizing: border-box;
}

.mj-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.mj-stats,
.mj-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mj-stat,
.mj-hud-card {
    min-width: 68px;
    padding: 8px 10px;
    border: 1px solid var(--cg-line);
    border-radius: 8px;
    background: var(--cg-panel);
    box-shadow: 0 8px 18px rgba(33, 43, 40, 0.08);
}

.mj-stat span,
.mj-hud-card span {
    display: block;
    color: var(--cg-muted);
    font-size: 10px;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.mj-stat strong,
.mj-hud-card strong {
    display: block;
    margin-top: 3px;
    font-size: 18px;
    line-height: 1;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.mj-btn,
.mj-close {
    min-height: 44px;
    min-width: 44px;
    padding: 0 14px;
    border: 1px solid var(--cg-line);
    border-radius: 8px;
    background: var(--cg-panel);
    color: var(--cg-ink);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(33, 43, 40, 0.08);
    transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}

.mj-btn:hover:not(:disabled),
.mj-close:hover {
    border-color: var(--cg-teal);
    transform: translateY(-1px);
}

.mj-btn:disabled {
    opacity: 0.42;
    cursor: default;
    box-shadow: none;
}

.mj-btn:focus-visible,
.mj-close:focus-visible,
.mj-stage:focus-visible {
    outline: 3px solid rgba(18, 122, 137, 0.45);
    outline-offset: 3px;
}

.mj-btn.mj-on {
    border-color: var(--cg-teal);
    background: #e3f2f3;
    color: #0d5b66;
}

.mj-primary {
    border-color: transparent;
    background: var(--cg-green);
    color: #fff;
}

.mj-primary:hover {
    filter: brightness(1.08);
}

.mj-icon-btn {
    display: inline-grid;
    place-items: center;
    padding: 0;
}

.mj-icon-btn svg {
    width: 21px;
    height: 21px;
}

.mj-hud {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.mj-hud-card {
    flex: 1 1 84px;
    overflow: hidden;
    text-align: center;
}

.mj-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 723 / 527;
    overflow: hidden;
    border: 1px solid #123528;
    border-radius: 12px;
    background:
        radial-gradient(120% 90% at 50% 8%, #3d8a68 0%, #266a4e 42%, #164733 78%, #0f3325 100%);
    box-shadow: var(--cg-shadow), inset 0 0 60px rgba(6, 26, 18, 0.55);
    touch-action: manipulation;
}

.mj-stage::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 5px),
        repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.045) 0 2px, transparent 2px 5px);
    z-index: 9000;
}

.mj-scaler {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
}

.mj-board {
    position: absolute;
}

.mj-tile {
    position: absolute;
    width: calc(var(--mj-tw) + var(--mj-d));
    height: calc(var(--mj-th) + var(--mj-d));
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mj-tile::before {
    content: '';
    position: absolute;
    left: 1px;
    top: 1px;
    right: 0;
    bottom: 0;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--mj-side) 0%, var(--mj-side-2) 100%);
    box-shadow: 2px 4px 7px rgba(4, 22, 15, 0.5);
}

.mj-face {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--mj-tw);
    height: var(--mj-th);
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 6px;
    border-top: 1px solid #fffdf6;
    border-left: 1px solid #fffdf6;
    border-right: 1px solid var(--mj-edge-dark);
    border-bottom: 1px solid var(--mj-edge-dark);
    background: linear-gradient(150deg, #fffefa 0%, var(--mj-ivory) 42%, var(--mj-ivory-2) 100%);
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.95),
        inset -2px -2px 3px rgba(150, 126, 84, 0.4);
    transition: box-shadow 0.12s ease, transform 0.1s ease;
}

.mj-glyph {
    grid-area: 1 / 1;
    font-family: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", "Noto Sans Symbols2", FreeSerif, Symbola, "Unifont Upper", serif;
    font-size: calc(var(--mj-th) * 1.15);
    line-height: 1;
    -webkit-user-select: none;
    user-select: none;
}

.mj-alt {
    display: none;
    grid-area: 1 / 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.mj-alt b {
    font-size: calc(var(--mj-th) * 0.46);
    font-weight: 900;
}

.mj-alt i {
    margin-top: 2px;
    font-size: calc(var(--mj-th) * 0.16);
    font-style: normal;
    font-weight: 800;
    letter-spacing: 0.06em;
    opacity: 0.7;
}

.mj-nofont .mj-glyph {
    display: none;
}

.mj-nofont .mj-alt {
    display: flex;
}

.mj-tile[data-kind="char"] .mj-face { color: #1f2a44; }
.mj-tile[data-kind="bam"] .mj-face { color: #146c4f; }
.mj-tile[data-kind="dot"] .mj-face { color: #2b5590; }
.mj-tile[data-kind="wind"] .mj-face { color: #3a4146; }
.mj-tile[data-kind="dragon-r"] .mj-face { color: #b02f2a; }
.mj-tile[data-kind="dragon-g"] .mj-face { color: #16704a; }
.mj-tile[data-kind="dragon-w"] .mj-face { color: #4a5c86; }
.mj-tile[data-kind="flower"] .mj-face { color: #b03a72; }
.mj-tile[data-kind="season"] .mj-face { color: #b06d12; }

.mj-tile:not(.mj-free) .mj-face {
    filter: brightness(0.92) saturate(0.85);
}

.mj-tile.mj-free:hover .mj-face {
    background: linear-gradient(150deg, #ffffff 0%, #fffcf1 45%, #f5ecd8 100%);
}

.mj-board.mj-showfree .mj-tile.mj-free .mj-face {
    box-shadow:
        inset 0 0 0 2px rgba(16, 122, 137, 0.9),
        inset 0 0 12px rgba(16, 122, 137, 0.22),
        inset 1px 1px 0 rgba(255, 255, 255, 0.9);
}

.mj-tile.mj-sel .mj-face {
    transform: translate(-2px, -3px);
    background: linear-gradient(150deg, #ffffff 0%, #eafaf6 55%, #cfeee6 100%);
    box-shadow:
        inset 0 0 0 3px var(--cg-green),
        0 8px 14px rgba(4, 22, 15, 0.5);
}

.mj-tile.mj-hintpair .mj-face {
    animation: mj-hint 0.72s ease-in-out infinite alternate;
}

@keyframes mj-hint {
    from {
        box-shadow: inset 0 0 0 3px rgba(196, 122, 23, 0.35), inset 1px 1px 0 rgba(255, 255, 255, 0.9);
    }
    to {
        box-shadow: inset 0 0 0 3px rgba(240, 168, 42, 1), inset 0 0 16px rgba(240, 168, 42, 0.5);
    }
}

.mj-tile.mj-cursor .mj-face::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 2px dashed rgba(196, 122, 23, 0.95);
    border-radius: 4px;
    pointer-events: none;
}

.mj-tile.mj-gone {
    pointer-events: none;
    animation: mj-vanish 0.24s ease forwards;
}

@keyframes mj-vanish {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.55) rotate(-8deg); }
}

.mj-banner {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 9100;
    display: grid;
    gap: 4px;
    width: min(86%, 340px);
    padding: 14px 16px;
    border: 1px solid var(--cg-line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.94);
    text-align: center;
    box-shadow: 0 18px 40px rgba(6, 26, 18, 0.45);
    transform: translate(-50%, -50%);
}

.mj-banner strong {
    font-size: 1.1rem;
    color: var(--cg-red);
}

.mj-shell[data-state="won"] .mj-banner strong {
    color: var(--cg-green);
}

.mj-banner span {
    color: var(--cg-muted);
    font-size: 0.86rem;
    line-height: 1.35;
}

.mj-status {
    min-height: 40px;
    margin: 10px 2px;
    color: var(--cg-muted);
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
}

.mj-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mj-controls .mj-btn {
    flex: 1 1 106px;
}

.mj-result {
    margin-top: 14px;
    padding: 16px;
    border: 1px solid var(--cg-line);
    border-radius: 12px;
    background: var(--cg-panel);
    box-shadow: var(--cg-shadow);
    text-align: center;
    animation: mj-rise 0.25s ease;
}

@keyframes mj-rise {
    from { opacity: 0; transform: translateY(8px); }
}

.mj-result-kicker {
    display: block;
    color: var(--cg-teal);
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.mj-result strong {
    display: block;
    margin: 4px 0 2px;
    font-size: 1.35rem;
}

.mj-result p {
    margin: 0 0 12px;
    color: var(--cg-muted);
    font-size: 0.9rem;
}

.mj-result-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.mj-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(20, 26, 30, 0.55);
}

.mj-modal-card {
    position: relative;
    width: min(100%, 460px);
    max-height: 86vh;
    overflow-y: auto;
    padding: 22px;
    border: 1px solid var(--cg-line);
    border-radius: 12px;
    background: var(--cg-panel);
    text-align: left;
    box-shadow: 0 24px 70px rgba(30, 37, 40, 0.24);
}

.mj-modal-card h2 {
    margin: 0 48px 10px 0;
    font-size: 1.2rem;
}

.mj-modal-card p {
    margin: 0 0 10px;
    color: var(--cg-muted);
    font-size: 0.92rem;
    line-height: 1.45;
}

.mj-close {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 0;
    font-size: 24px;
    line-height: 1;
}

.mj-hidden {
    display: none !important;
}

@media (max-width: 640px) {
    .mj-shell {
        padding: 0 0 20px;
    }

    .mj-topbar {
        margin-bottom: 8px;
    }

    .mj-stat,
    .mj-hud-card {
        min-width: 0;
        padding: 6px 6px;
        text-align: center;
    }

    .mj-stat {
        flex: 1 1 0;
    }

    .mj-stats {
        flex: 1 1 auto;
        min-width: 0;
    }

    .mj-stat strong,
    .mj-hud-card strong {
        font-size: 15px;
    }

    .mj-hud {
        gap: 5px;
    }

    .mj-hud-card {
        flex: 1 1 56px;
    }

    .mj-status {
        min-height: 52px;
        font-size: 0.84rem;
    }

    .mj-controls {
        gap: 6px;
    }

    .mj-controls .mj-btn {
        flex: 1 1 30%;
        padding: 0 8px;
        font-size: 0.82rem;
    }
}
