/* Reset and basic setup */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background: #090d16;
    font-family: 'Outfit', 'Noto Sans TC', sans-serif;
    color: #e6edf3;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Mahjong Table - Rich felt texture */
.mahjong-table {
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #1b6320 0%, #0c330f 70%, #061c07 100%);
    position: relative;
    box-shadow: inset 0 0 120px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    border: 14px solid #1a100c; /* Rich wood border */
    border-radius: 6px;
    box-sizing: border-box;
}

/* Scoreboard Overlay - Sleek glassmorphic card in the center */
.scoreboard {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 290px;
    height: 145px; /* Reduced from 190px to prevent overlapping ponds */
    background: rgba(10, 15, 30, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    display: grid;
    grid-template-rows: auto 1fr;
    z-index: 10;
    overflow: hidden;
}

.scoreboard-header {
    background: rgba(255, 255, 255, 0.04);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem;
    font-weight: 600;
}

.round-info {
    color: #a5b4fc;
    letter-spacing: 1px;
}

.tiles-left {
    color: #94a3b8;
}

.scoreboard-body {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 12px 16px;
}

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05rem;
    font-weight: 600;
}

.score-row.ai {
    color: #fca5a5;
}

.score-row.player {
    color: #86efac;
}

.score-points {
    font-family: 'Outfit', monospace;
    font-size: 1.25rem;
    letter-spacing: 0.5px;
}

/* Dora Display in Center */
.dora-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
    padding: 6px;
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
}

.dora-label {
    font-size: 0.75rem;
    color: #fbbf24;
    font-weight: 800;
    letter-spacing: 0.5px;
}

/* Hands layout */
.ai-hand-zone {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-top: 15px;
    gap: 30px;
    position: relative;
}

/* AI Avatar Card Styles */
.ai-avatar-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1.5px solid rgba(165, 180, 252, 0.25);
    border-radius: 12px;
    padding: 8px 16px;
    position: relative;
    z-index: 100;
}

.avatar-wrapper {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #a5b4fc;
    background: #0f172a;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.avatar-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-info {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.ai-title {
    font-size: 0.65rem;
    color: #a5b4fc;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.ai-name {
    font-size: 0.85rem;
    color: #f8fafc;
    font-weight: 700;
}

/* Speech Bubble Styles */
.speech-bubble {
    position: absolute;
    left: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%) scale(0);
    transform-origin: left center;
    background: #fef08a;
    color: #0f172a;
    padding: 8px 14px;
    border-radius: 12px;
    border: 2px solid #eab308;
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 160px;
    max-width: 260px;
    text-align: left;
    z-index: 120;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3));
}

.speech-bubble.active {
    transform: translateY(-50%) scale(1);
    opacity: 1;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid #fef08a;
    z-index: 122;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    left: -11px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #eab308;
    z-index: 121;
}

.player-hand-zone {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 25px;
    gap: 15px;
    position: relative;
    z-index: 20;
}

.furo-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    height: 75px;
}

.furo-meld {
    display: flex;
    gap: 1px;
}

.furo-meld .tile-3d {
    transform: scale(0.85);
    transform-origin: bottom center;
    margin: 0 -3px;
    cursor: default;
}

.hand-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 3px;
    height: 75px;
    perspective: 1000px;
}

/* Premium Mahjong Tile - Clean & Flat SVG style */
.tile-3d {
    width: 44px;
    height: 60px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1.25);
    margin: 0 1px;
    background: transparent;
    box-shadow: none;
}

.player-hand-zone .tile-3d {
    cursor: pointer;
}

/* Draw gap for the 14th tile */
.tile-3d.drawn-tile {
    margin-left: 16px !important;
}

/* Hover effect for Player Hand */
.player-hand-zone .tile-3d:not(.discarded):not(.riichi-tile):hover {
    transform: translateY(-16px);
}

/* Selected for exchange cheat style */
.player-hand-zone .tile-3d.selected-for-exchange {
    transform: translateY(-25px) !important;
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.9)) !important;
}

.tile-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
}

/* Front Face (Transparent container for Mahgen SVG) */
.tile-face.front {
    background: transparent;
    border: none;
    box-shadow: none;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    overflow: hidden;
}

.tile-face.front img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Back Face (Teal rounded rectangle for facedown tiles) */
.tile-face.back {
    background: #0f766e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: rotateY(180deg);
    border-radius: 4px;
}

/* Side Thickness - Removed for flat layout */
.tile-3d::after {
    display: none;
}

/* Turned/Face-down state */
.tile-3d.facedown {
    transform: rotateY(180deg);
    box-shadow: none;
}

/* Discard Ponds (Ho) */
.pond-container {
    position: absolute;
    width: 330px;
    height: 140px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 3px;
    padding: 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* AI Pond (middle top) */
.ai-pond {
    top: calc(50% - 225px); /* Moved up from -140px to clear the center scoreboard */
    left: 50%;
    transform: translateX(-50%) rotate(180deg);
}

/* Player Pond (middle bottom) */
.player-pond {
    top: calc(50% + 85px); /* Moved down from +20px to clear the center scoreboard */
    left: 50%;
    transform: translateX(-50%);
}

/* Pond Tiles are smaller and lay flat */
.pond-container .tile-3d {
    width: 32px;
    height: 44px;
    cursor: default;
    box-shadow: none;
    background: transparent;
    margin: 1px;
}

.pond-container .tile-3d::after {
    transform: translateZ(1.5px);
}

.pond-container .tile-face.front {
    transform: translateZ(3px);
}

/* Riichi Discard (rotated 90 degrees) */
.tile-3d.riichi-tile {
    transform: rotate(-90deg) !important;
    margin-right: 10px !important;
    margin-left: 8px !important;
}

.pond-container .tile-3d.riichi-tile {
    transform: rotate(-90deg) !important;
}

.ai-pond .tile-3d.riichi-tile {
    transform: rotate(90deg) !important;
}

/* Exchange Control Panel */
.exchange-panel {
    display: none;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 5px;
    position: relative;
    z-index: 30; /* Ensure it renders above discard ponds */
    background: rgba(15, 23, 42, 0.65);
    padding: 8px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Action Control Panel (Riichi, Ron, Tsumo, Skip) */
.action-panel {
    display: flex;
    gap: 12px;
    height: 48px;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.action-panel.active {
    opacity: 1;
    pointer-events: auto;
}

.action-btn {
    padding: 8px 24px;
    border-radius: 9999px;
    border: 1.5px solid rgba(255,255,255,0.25);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    color: white;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    border-color: #818cf8;
}

.action-btn.btn-riichi {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}
.action-btn.btn-tsumo, .action-btn.btn-ron {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}
.action-btn.btn-skip {
    background: rgba(100, 116, 139, 0.6);
}

/* Callout Overlay (Riichi / Ron / Tsumo animation) */
.callout-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    transition: opacity 0.3s;
}

.callout-overlay.active {
    opacity: 1;
}

.callout-text {
    font-size: 5rem;
    font-weight: 900;
    letter-spacing: 4px;
    text-shadow: 0 0 20px rgba(0,0,0,0.8), 0 10px 20px rgba(0,0,0,0.5);
    transform: scale(0.3);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    color: white;
}

.callout-overlay.active .callout-text {
    transform: scale(1);
}

.callout-text.riichi {
    color: #fbbf24;
}
.callout-text.ron, .callout-text.tsumo {
    color: #ef4444;
}

/* Start/End Screen Modals - Sleek glassmorphism */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 8, 16, 0.5); /* Semi-transparent so user sees the board behind it */
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(15, 23, 42, 0.75); /* Highly transparent premium glass */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 30px 40px;
    width: 90%;
    max-width: 460px;
    text-align: center;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-title {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(to right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 15px;
    letter-spacing: 0.5px;
}

.modal-desc {
    color: #cbd5e1;
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 25px;
}

.modal-btn {
    padding: 11px 32px;
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transition: all 0.2s;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

/* Hand display in result screen */
.result-hand {
    display: flex;
    justify-content: center;
    gap: 2px;
    margin: 20px 0;
}

.result-hand .tile-3d {
    width: 32px;
    height: 44px;
    box-shadow: none;
    background: transparent;
}

.result-hand .tile-3d::after {
    transform: translateZ(1.5px);
}
.result-hand .tile-face.front {
    transform: translateZ(3px);
}

/* Simple CSS animations */
@keyframes drawAnim {
    from {
        opacity: 0;
        transform: translateY(-20px) translateZ(40px) rotateX(15deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateZ(0) rotateX(0);
    }
}

.draw-animation {
    animation: drawAnim 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes discardAnim {
    from {
        transform: scale(1.2) translateY(20px);
        opacity: 0.5;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.discard-animation {
    animation: discardAnim 0.25s ease-out forwards;
}
