/* ========================================================================
   MAHJONG SOLITAIRE - Klassische chinesische Tiles
   ======================================================================== */

:root {
    --mj-tile-width: 52px;
    --mj-tile-height: 68px;
    --mj-tile-gap-x: 2px;
    --mj-tile-gap-y: 2px;
    --mj-depth: 5px;
    --mj-layer-offset-x: -4px;
    --mj-layer-offset-y: -4px;
    --mj-tile-face: #f5f0e0;
    --mj-tile-face-light: #faf6ea;
    --mj-tile-edge-right: #c8b898;
    --mj-tile-edge-bottom: #a09070;
    --mj-tile-border: #b0a080;
    --mj-bg-dark: #2a1a0e;
    --mj-bg-wood: #3d2b1a;
    --mj-red: #c41e3a;
    --mj-green: #1a7a3a;
    --mj-blue: #1a4a8a;
    --mj-purple: #6a3a8a;
    --mj-pink: #b03060;
    --mj-gold: #c8a84e;
    --mj-gold-light: #e8c86e;
}

/* --- Game Container (Holztisch-Hintergrund) --- */
.mj-game-container {
    background:
        radial-gradient(ellipse at 40% 40%, var(--mj-bg-wood) 0%, var(--mj-bg-dark) 100%);
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    font-family: 'Georgia', 'Palatino Linotype', serif;
}

/* --- Board Container --- */
.mj-board {
    position: relative;
    margin: 0 auto;
    /* Sized dynamically via inline style */
}

/* --- 3D Tile Base --- */
.mj-tile {
    position: absolute;
    width: var(--mj-tile-width);
    height: var(--mj-tile-height);
    cursor: default;
    transition: transform 0.15s ease, opacity 0.3s ease;
}

.mj-tile-body {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, var(--mj-tile-face-light), var(--mj-tile-face));
    border: 1px solid var(--mj-tile-border);
    border-radius: 5px;
    overflow: hidden;
}

/* 3D-Tiefe: rechte Kante */
.mj-tile-body::before {
    content: '';
    position: absolute;
    right: calc(var(--mj-depth) * -1);
    top: var(--mj-depth);
    width: var(--mj-depth);
    height: 100%;
    background: linear-gradient(180deg, var(--mj-tile-edge-right), #8a7a5a);
    border-radius: 0 3px 3px 0;
    z-index: -1;
}

/* 3D-Tiefe: untere Kante */
.mj-tile-body::after {
    content: '';
    position: absolute;
    bottom: calc(var(--mj-depth) * -1);
    left: var(--mj-depth);
    width: 100%;
    height: var(--mj-depth);
    background: linear-gradient(90deg, var(--mj-tile-edge-bottom), #8a7a5a);
    border-radius: 0 0 3px 3px;
    z-index: -1;
}

/* --- Tile States --- */
.mj-tile.mj-free {
    cursor: pointer;
}

.mj-tile.mj-free:hover .mj-tile-body {
    background: linear-gradient(145deg, #fffbf0, #f8f0dd);
    box-shadow: 0 0 8px rgba(200, 168, 78, 0.4);
    transform: translateY(-1px);
}

.mj-tile.mj-selected .mj-tile-body {
    background: linear-gradient(145deg, #fff8e0, #f5ead0);
    box-shadow: 0 0 0 2px var(--mj-gold), 0 0 12px rgba(200, 168, 78, 0.5);
}

.mj-tile.mj-hint .mj-tile-body {
    animation: mjHintPulse 1s ease-in-out infinite;
}

.mj-tile.mj-blocked {
    cursor: default;
}

.mj-tile.mj-blocked .mj-tile-body {
    filter: brightness(0.85);
}

.mj-tile.mj-removing {
    animation: mjTileRemove 0.4s ease forwards;
    pointer-events: none;
}

.mj-tile.mj-nomatch {
    animation: mjShake 0.3s ease;
}

/* --- Tile Face Content --- */
.mj-face {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 3px;
    gap: 0;
}

.mj-main {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
}

.mj-main-lg {
    font-size: 30px;
    font-weight: 900;
    line-height: 1;
}

.mj-sub {
    font-size: 11px;
    line-height: 1;
    opacity: 0.6;
    margin-top: -1px;
}

/* --- Suit Colors --- */
.mj-characters .mj-main,
.mj-characters .mj-sub {
    color: var(--mj-red);
}

.mj-bamboo .mj-main,
.mj-bamboo .mj-sub {
    color: var(--mj-green);
}

.mj-circles .mj-main,
.mj-circles .mj-sub {
    color: var(--mj-blue);
}

.mj-wind .mj-main-lg {
    color: var(--mj-blue);
}

.mj-wind .mj-sub {
    color: var(--mj-blue);
    opacity: 0.5;
}

.mj-dragon-red .mj-main-lg {
    color: #fff;
    background: var(--mj-red);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.mj-dragon-green .mj-main-lg {
    color: var(--mj-green);
}

.mj-dragon-white .mj-main-lg {
    color: #999;
    border: 2px solid #bbb;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.mj-season .mj-main { color: var(--mj-purple); }
.mj-season .mj-sub { color: var(--mj-purple); }

.mj-flower .mj-main { color: var(--mj-pink); }
.mj-flower .mj-sub { color: var(--mj-pink); }

/* --- Circle Suit: Rendered Circles --- */
.mj-circle-grid {
    display: grid;
    gap: 2px;
    align-items: center;
    justify-items: center;
}

.mj-circle-grid.mj-cg-1 { grid-template-columns: 1fr; }
.mj-circle-grid.mj-cg-2 { grid-template-columns: 1fr; }
.mj-circle-grid.mj-cg-3 { grid-template-columns: 1fr; }
.mj-circle-grid.mj-cg-4 { grid-template-columns: 1fr 1fr; }
.mj-circle-grid.mj-cg-5 { grid-template-columns: 1fr 1fr; }
.mj-circle-grid.mj-cg-6 { grid-template-columns: 1fr 1fr; }
.mj-circle-grid.mj-cg-7 { grid-template-columns: 1fr 1fr 1fr; }
.mj-circle-grid.mj-cg-8 { grid-template-columns: 1fr 1fr 1fr; }
.mj-circle-grid.mj-cg-9 { grid-template-columns: 1fr 1fr 1fr; }

.mj-circle-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--mj-blue);
    background: radial-gradient(circle at 40% 35%, #5a8acd, var(--mj-blue));
}

.mj-circle-grid.mj-cg-1 .mj-circle-dot {
    width: 26px;
    height: 26px;
    border-width: 3px;
}

.mj-circle-grid.mj-cg-5 .mj-circle-dot:nth-child(5) {
    grid-column: 1 / -1;
    justify-self: center;
}

.mj-circle-grid.mj-cg-7 .mj-circle-dot:nth-child(7) {
    grid-column: 2;
}

/* --- Bamboo Suit: Vertical Bars --- */
.mj-bamboo-grid {
    display: flex;
    gap: 2px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    max-width: 40px;
}

.mj-bamboo-stick {
    width: 5px;
    height: 22px;
    background: linear-gradient(90deg, #2a8a4a, var(--mj-green), #2a8a4a);
    border-radius: 2px;
    position: relative;
}

.mj-bamboo-stick::before,
.mj-bamboo-stick::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: #1a5a2a;
}

.mj-bamboo-stick::before { top: 6px; }
.mj-bamboo-stick::after { bottom: 6px; }

/* Bamboo 1 special: bird/circle */
.mj-bamboo-bird {
    width: 20px;
    height: 20px;
    border: 3px solid var(--mj-green);
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, #4aba6a, var(--mj-green));
}

/* --- Animations --- */
@keyframes mjTileRemove {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(0); opacity: 0; }
}

@keyframes mjHintPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(200, 168, 78, 0.5); }
    50% { box-shadow: 0 0 0 4px rgba(200, 168, 78, 0); }
}

@keyframes mjShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* --- Message Overlay --- */
.mj-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 16px 32px;
    background: rgba(0, 0, 0, 0.8);
    color: var(--mj-gold-light);
    font-size: 18px;
    border-radius: 10px;
    border: 1px solid var(--mj-gold);
    z-index: 1000;
    text-align: center;
    backdrop-filter: blur(4px);
    animation: solFadeIn 0.3s ease;
}

/* --- Win Overlay --- */
.mj-win-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    z-index: 20000;
    animation: solFadeIn 0.5s ease;
    backdrop-filter: blur(6px);
}

.mj-win-card {
    background: linear-gradient(135deg, var(--mj-bg-wood) 0%, #4a3020 100%);
    border: 3px solid var(--mj-gold);
    border-radius: 16px;
    padding: 40px 60px;
    text-align: center;
    color: #e8e0d0;
    box-shadow: 0 0 60px rgba(200, 168, 78, 0.3);
    animation: solScaleIn 0.5s ease 0.2s both;
}

.mj-win-title {
    font-size: 36px;
    font-weight: 700;
    color: var(--mj-gold-light);
    margin-bottom: 16px;
    letter-spacing: 4px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.mj-win-stats {
    font-size: 16px;
    margin-bottom: 24px;
    line-height: 1.8;
}

.mj-win-stats strong {
    color: var(--mj-gold-light);
}

@keyframes solFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes solScaleIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* --- Remaining Counter --- */
.mj-remaining-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mj-remaining-track {
    width: 120px;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.mj-remaining-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--mj-gold), var(--mj-gold-light));
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* --- Responsive --- */
@media (max-width: 800px) {
    :root {
        --mj-tile-width: 42px;
        --mj-tile-height: 56px;
        --mj-depth: 4px;
        --mj-layer-offset-x: -3px;
        --mj-layer-offset-y: -3px;
    }

    .mj-main { font-size: 18px; }
    .mj-main-lg { font-size: 24px; }
    .mj-sub { font-size: 9px; }
    .mj-circle-dot { width: 9px; height: 9px; border-width: 1.5px; }
    .mj-circle-grid.mj-cg-1 .mj-circle-dot { width: 20px; height: 20px; }
    .mj-bamboo-stick { width: 4px; height: 16px; }
    .mj-bamboo-bird { width: 16px; height: 16px; border-width: 2px; }
    .mj-dragon-red .mj-main-lg { width: 26px; height: 26px; font-size: 16px; }
    .mj-dragon-white .mj-main-lg { width: 22px; height: 22px; font-size: 13px; }
}

@media (max-width: 600px) {
    :root {
        --mj-tile-width: 34px;
        --mj-tile-height: 46px;
        --mj-depth: 3px;
        --mj-layer-offset-x: -2px;
        --mj-layer-offset-y: -2px;
    }

    .mj-main { font-size: 14px; }
    .mj-main-lg { font-size: 18px; }
    .mj-sub { font-size: 8px; }
    .mj-circle-dot { width: 7px; height: 7px; border-width: 1px; }
    .mj-circle-grid.mj-cg-1 .mj-circle-dot { width: 16px; height: 16px; }
    .mj-circle-grid { gap: 1px; }
    .mj-bamboo-stick { width: 3px; height: 12px; }
    .mj-bamboo-bird { width: 12px; height: 12px; }
    .mj-bamboo-grid { gap: 1px; }
    .mj-dragon-red .mj-main-lg { width: 20px; height: 20px; font-size: 13px; }
    .mj-dragon-white .mj-main-lg { width: 18px; height: 18px; font-size: 11px; }
    .mj-win-card { padding: 24px 32px; }
    .mj-win-title { font-size: 24px; }
}
