* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    background: #1a0a00;
    background-image:
        /* 木目調の外枠 */
        radial-gradient(ellipse at center, transparent 60%, rgba(30,15,5,0.9) 100%);
    min-height: 100vh;
    min-height: 100dvh;
    font-family: 'Arial Black', 'Arial', sans-serif;
    overflow: hidden;
    touch-action: manipulation;
}

#game-container {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    padding: 15px 10px;
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    /* カジノテーブルのフェルト */
    background:
        /* フェルトのテクスチャ */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E"),
        /* 中央が明るいグラデーション */
        radial-gradient(ellipse at 50% 40%, #1b7340 0%, #145c32 40%, #0d4526 70%, #0a3a20 100%);
    border-left: 8px solid #8B4513;
    border-right: 8px solid #8B4513;
    box-shadow:
        inset 0 0 60px rgba(0,0,0,0.4),
        inset 0 0 20px rgba(0,0,0,0.3),
        -5px 0 15px rgba(0,0,0,0.5),
        5px 0 15px rgba(0,0,0,0.5);
}

#game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    right: -8px;
    height: 12px;
    background: linear-gradient(to bottom,
        #654321 0%,
        #8B4513 30%,
        #A0522D 50%,
        #8B4513 70%,
        #654321 100%);
    border-bottom: 2px solid #DAA520;
    box-shadow: 0 3px 10px rgba(0,0,0,0.5);
}

#game-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    right: -8px;
    height: 12px;
    background: linear-gradient(to bottom,
        #654321 0%,
        #8B4513 30%,
        #A0522D 50%,
        #8B4513 70%,
        #654321 100%);
    border-top: 2px solid #DAA520;
    box-shadow: 0 -3px 10px rgba(0,0,0,0.5);
}

/* Score Area */
#score-area {
    text-align: center;
    padding: 15px 20px;
    margin: 10px 20px 15px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.4), rgba(0,0,0,0.2));
    border: 3px solid #DAA520;
    border-radius: 10px;
    box-shadow:
        inset 0 2px 10px rgba(0,0,0,0.5),
        0 2px 5px rgba(0,0,0,0.3);
    position: relative;
}

#score-area::before {
    content: '💰 SCORE 💰';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(to bottom, #0d4526, #0a3a20);
    padding: 2px 15px;
    font-size: 12px;
    color: #DAA520;
    border: 2px solid #DAA520;
    border-radius: 10px;
    letter-spacing: 2px;
}

#score-display {
    font-size: 48px;
    font-weight: bold;
    color: #ffd700;
    text-shadow:
        0 0 10px rgba(255,215,0,0.5),
        2px 2px 0 #8b4513,
        -1px -1px 0 #8b4513,
        1px -1px 0 #8b4513,
        -1px 1px 0 #8b4513;
    letter-spacing: 6px;
    font-family: 'Georgia', serif;
}

#highscore-display {
    font-size: 14px;
    color: #DAA520;
    margin-top: 5px;
    letter-spacing: 2px;
    font-family: 'Arial', sans-serif;
}

#highscore-value {
    color: #fff;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(255,215,0,0.3);
}

#highscore-display.new-record {
    animation: newRecordPulse 0.5s ease-out;
}

@keyframes newRecordPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); color: #ffd700; }
    100% { transform: scale(1); }
}

/* Combo Display */
#combo-display {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    font-weight: bold;
    color: #ff6600;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#combo-display.show {
    opacity: 1;
    animation: comboPulse 0.5s ease-out;
}

@keyframes comboPulse {
    0% { transform: translate(-50%, -50%) scale(0.5); }
    50% { transform: translate(-50%, -50%) scale(1.3); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* Tableau - Card Grid */
#tableau {
    display: flex;
    justify-content: center;
    gap: 4px;
    flex: 1;
    padding: 10px 5px;
    margin: 0 10px;
    background: rgba(0,0,0,0.1);
    border-radius: 10px;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.2);
}

.column {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Grid Cell (card slot in column) */
.grid-cell {
    width: 54px;
    height: 26px;
    position: relative;
    margin-bottom: -4px;
}

.grid-cell:last-child {
    height: auto;
    margin-bottom: 0;
}

/* Stacked Card (in column - gray inactive style) */
.stacked-card {
    width: 54px;
    height: 30px;
    background: linear-gradient(to bottom, #c0c0c0 0%, #a0a0a0 100%);
    border: 1.5px solid #606060;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1px 5px;
    font-size: 13px;
    font-weight: bold;
    color: #c41e3a;
    position: absolute;
    top: 0;
    left: 0;
    cursor: default;
}

.stacked-card .rank {
    font-size: 13px;
    line-height: 1;
}

.stacked-card .suit {
    font-size: 11px;
    line-height: 1;
}

.stacked-card.joker {
    font-size: 9px;
    justify-content: center;
    padding: 0;
}

.stacked-card.joker .joker-text {
    color: #996515;
    display: flex;
    align-items: center;
    gap: 2px;
}

.stacked-card.joker .joker-icon {
    font-size: 11px;
}

/* Active Card (bottom of column - white playable) */
.active-card {
    width: 58px;
    height: 82px;
    background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 50%, #eeeeee 100%);
    border: 2px solid #444;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    box-shadow:
        2px 3px 8px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.8);
    transition: transform 0.15s, box-shadow 0.15s;
}

.active-card::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    height: 30%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.4), transparent);
    border-radius: 4px 4px 50% 50%;
    pointer-events: none;
}

.active-card:active {
    transform: scale(0.95);
}

.active-card.selected {
    transform: translateY(-8px) scale(1.05);
    box-shadow:
        0 12px 25px rgba(0,0,0,0.6),
        0 0 15px rgba(255,215,0,0.5);
    border-color: #ffd700;
    z-index: 10;
}

.active-card .corner-tl {
    position: absolute;
    top: 3px;
    left: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.active-card .corner-tr {
    position: absolute;
    top: 3px;
    right: 5px;
}

.active-card .corner-tl .rank {
    font-size: 14px;
    font-weight: bold;
    color: #c41e3a;
}

.active-card .corner-tl .suit,
.active-card .corner-tr .suit {
    font-size: 12px;
    color: #c41e3a;
}

.active-card .center {
    font-size: 38px;
    font-weight: bold;
    color: #c41e3a;
    margin-top: 5px;
}

.active-card.joker .corner-tl .rank,
.active-card.joker .corner-tl .suit {
    color: #996515;
}

.active-card.joker .corner-tl .rank {
    font-size: 10px;
}

.active-card.joker .corner-tl .suit {
    font-size: 8px;
}

.active-card.joker .corner-tr .suit {
    color: #996515;
    font-size: 14px;
}

.active-card.joker .center {
    font-size: 12px;
    color: #996515;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 0;
}

.active-card.joker .joker-icon-large {
    font-size: 24px;
    line-height: 1;
}

.active-card.joker .joker-text {
    font-size: 10px;
    font-weight: bold;
}

/* Empty slot */
.empty-slot {
    width: 58px;
    height: 82px;
    background: rgba(0,0,0,0.1);
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 6px;
}

/* Hand Area (手札エリア) */
#selected-area {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px 30px;
    min-height: 120px;
    margin: 5px 20px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.3), rgba(0,0,0,0.15));
    border: 2px solid rgba(218,165,32,0.5);
    border-radius: 15px;
    box-shadow: inset 0 2px 15px rgba(0,0,0,0.4);
    position: relative;
}

#selected-area::before {
    content: '🎴 YOUR HAND 🎴';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(to bottom, #0d4526, #0a3a20);
    padding: 2px 12px;
    font-size: 11px;
    color: #DAA520;
    border: 2px solid #DAA520;
    border-radius: 10px;
    letter-spacing: 1px;
    white-space: nowrap;
}

.selected-slot {
    width: 68px;
    height: 92px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.2);
    border: 2px dashed rgba(218,165,32,0.3);
}

.selected-slot:empty {
    border: 2px dashed rgba(218,165,32,0.3);
}

.selected-slot .active-card {
    width: 68px;
    height: 92px;
    cursor: pointer;
}

.selected-slot .active-card:hover {
    transform: translateY(-3px);
}

.selected-slot .active-card.selected {
    transform: translateY(-8px) scale(1.05);
    box-shadow: 0 12px 20px rgba(0,0,0,0.5);
    border-color: #ffd700;
}

.selected-slot .active-card .center {
    font-size: 44px;
}

.selected-slot .active-card .corner-tl .rank {
    font-size: 16px;
}

.selected-slot .active-card .corner-tl .suit,
.selected-slot .active-card .corner-tr .suit {
    font-size: 14px;
}

/* 手札エリアのジョーカー */
.selected-slot .active-card.joker .corner-tl .rank {
    font-size: 12px;
}

.selected-slot .active-card.joker .corner-tl .suit {
    font-size: 10px;
}

.selected-slot .active-card.joker .corner-tr .suit {
    font-size: 16px;
}

.selected-slot .active-card.joker .center {
    margin-top: 0;
}

.selected-slot .active-card.joker .joker-icon-large {
    font-size: 36px;
}

.selected-slot .active-card.joker .joker-text {
    font-size: 12px;
}

/* Deck Area */
#deck-area {
    display: flex;
    justify-content: center;
    padding: 15px 0 20px;
}

#deck {
    position: relative;
    width: 220px;
    height: 95px;
    cursor: pointer;
    background: rgba(0,0,0,0.2);
    border: 2px dashed rgba(218,165,32,0.4);
    border-radius: 10px;
    padding: 5px;
    transition: border-color 0.2s;
}

#deck:hover:not(.empty) {
    border-color: rgba(218,165,32,0.8);
}

#deck.empty {
    opacity: 0.3;
    cursor: default;
}

.deck-card {
    position: absolute;
    width: 58px;
    height: 82px;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 50%, #2c3e50 100%);
    border: 2px solid #ecf0f1;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
    overflow: hidden;
}

.deck-card::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background:
        /* 中心の円 */
        radial-gradient(circle at 50% 50%, transparent 8px, rgba(236,240,241,0.1) 8px, rgba(236,240,241,0.1) 10px, transparent 10px),
        /* 四隅の円弧 */
        radial-gradient(circle at 0% 0%, transparent 15px, rgba(230,126,34,0.6) 15px, rgba(230,126,34,0.6) 18px, transparent 18px),
        radial-gradient(circle at 100% 0%, transparent 15px, rgba(230,126,34,0.6) 15px, rgba(230,126,34,0.6) 18px, transparent 18px),
        radial-gradient(circle at 0% 100%, transparent 15px, rgba(230,126,34,0.6) 15px, rgba(230,126,34,0.6) 18px, transparent 18px),
        radial-gradient(circle at 100% 100%, transparent 15px, rgba(230,126,34,0.6) 15px, rgba(230,126,34,0.6) 18px, transparent 18px),
        /* 対角線 */
        linear-gradient(45deg, transparent 48%, rgba(236,240,241,0.15) 48%, rgba(236,240,241,0.15) 52%, transparent 52%),
        linear-gradient(-45deg, transparent 48%, rgba(236,240,241,0.15) 48%, rgba(236,240,241,0.15) 52%, transparent 52%);
}

.deck-card::after {
    content: '◆';
    position: absolute;
    font-size: 18px;
    color: rgba(230,126,34,0.8);
    text-shadow: 0 0 5px rgba(230,126,34,0.5);
}

.deck-card .joker-back {
    display: none;
}

/* Score popup animation */
.score-popup {
    position: fixed;
    font-size: 32px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 2px 2px 0 #8b4513;
    pointer-events: none;
    z-index: 200;
    animation: scoreFloat 0.8s ease-out forwards;
}

@keyframes scoreFloat {
    0% {
        opacity: 1;
        transform: translateY(0) scale(0.5);
    }
    50% {
        transform: translateY(-30px) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) scale(1);
    }
}

/* Card removal animation */
@keyframes cardMatch {
    0% {
        transform: scale(1);
        opacity: 1;
        filter: brightness(1);
    }
    30% {
        transform: scale(1.15);
        filter: brightness(1.5);
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
    }
    60% {
        transform: scale(1.1);
        filter: brightness(1.3);
    }
    100% {
        transform: scale(0) rotate(20deg);
        opacity: 0;
        filter: brightness(2);
    }
}

.active-card.matched {
    animation: cardMatch 0.5s ease-out forwards;
    z-index: 100;
}

/* Sparkle effect for matched cards */
@keyframes sparkle {
    0%, 100% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1); }
}

.sparkle {
    position: fixed;
    width: 20px;
    height: 20px;
    pointer-events: none;
    z-index: 200;
}

.sparkle::before {
    content: '✨';
    font-size: 20px;
    animation: sparkle 0.6s ease-out forwards;
}

/* Hint blink animation (チュートリアル用) */
@keyframes hintBlink {
    0%, 100% {
        border-color: #ffd700;
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }
    50% {
        border-color: #fff;
        box-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
    }
}

.active-card.hint-bounce {
    animation: hintBlink 1.5s ease-in-out infinite;
    border-color: #ffd700;
}

/* Message Overlay */
#message-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#message-overlay.show {
    display: flex;
}

#message-box {
    background: linear-gradient(to bottom, #4a3000, #2a1a00);
    border: 4px solid #ffd700;
    border-radius: 20px;
    padding: 30px 50px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#message-title {
    font-size: 36px;
    color: #ffd700;
    margin-bottom: 15px;
    text-shadow: 2px 2px 0 #000;
}

#message-score {
    font-size: 28px;
    color: #fff;
    margin-bottom: 25px;
    line-height: 1.6;
}

.new-record-text {
    color: #ffd700;
    font-size: 20px;
    animation: recordPulse 1s ease-in-out infinite;
}

@keyframes recordPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

.highscore-text {
    color: #DAA520;
    font-size: 18px;
}

#restart-btn {
    padding: 15px 40px;
    font-size: 20px;
    font-weight: bold;
    background: linear-gradient(to bottom, #ffd700, #c9a227);
    border: 3px solid #8b4513;
    border-radius: 30px;
    color: #4a3000;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}

#restart-btn:active {
    transform: scale(0.95);
}

#message-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

#tweet-btn {
    padding: 15px 30px;
    font-size: 18px;
    font-weight: bold;
    background: linear-gradient(to bottom, #333, #000);
    border: 3px solid #555;
    border-radius: 30px;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}

#tweet-btn:active {
    transform: scale(0.95);
}

/* Responsive */
@media (max-width: 380px) {
    .stacked-card {
        width: 48px;
        height: 26px;
        font-size: 11px;
    }

    .stacked-card .rank { font-size: 11px; }
    .stacked-card .suit { font-size: 9px; }

    .active-card {
        width: 50px;
        height: 72px;
    }

    .active-card .center { font-size: 32px; }
    .active-card .corner-tl .rank { font-size: 12px; }

    .grid-cell {
        width: 48px;
        height: 22px;
    }

    .selected-slot {
        width: 58px;
        height: 82px;
    }

    .selected-slot .active-card {
        width: 58px;
        height: 82px;
    }

    .selected-slot .active-card .center { font-size: 36px; }

    #tableau {
        gap: 3px;
    }
}

@media (max-height: 700px) {
    #score-area {
        padding: 5px 0 10px;
    }

    #score-display {
        font-size: 40px;
    }

    .grid-cell {
        height: 22px;
        margin-bottom: -6px;
    }

    .stacked-card {
        height: 26px;
    }

    .active-card {
        height: 72px;
    }

    #selected-area {
        padding: 10px 0;
        min-height: 95px;
    }

    .selected-slot {
        height: 82px;
    }

    #deck-area {
        padding: 5px 0 15px;
    }

    #deck {
        height: 80px;
    }

    .deck-card {
        height: 75px;
    }
}
