@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=MedievalSharp&display=swap');

:root {
    --bg-color: #0d0d0f;
    --table-color: #1a120b;
    --gold: #d4af37;
    --gold-bright: #f0d583;
    --crimson: #8b0000;
    --parchment-text: #e0d7c6;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    --magic-glow: 0 0 20px rgba(212, 175, 55, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.8) 100%),
        url('../assets/ui/mystical_bg.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--parchment-text);
    font-family: 'MedievalSharp', cursive;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: bg-pulse 15s ease-in-out infinite alternate;
}

@keyframes bg-pulse {
    0% {
        background-size: 100% 100%;
    }

    100% {
        background-size: 110% 110%;
    }
}

header {
    text-align: center;
    width: 100%;
}

h1 {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    color: var(--gold);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 20px rgba(0, 150, 255, 0.6);
    margin-bottom: 2rem;
    margin-top: 2rem;
    letter-spacing: 0.2rem;
    z-index: 10;
    text-align: center;
    width: 100%;
}

.game-container {
    position: relative;
    width: 100%;
    max-width: 1200px;
    min-height: 70vh;
    max-height: 90vh; /* 최대 높이 제한 */
    height: auto; /* Allow height to grow to accommodate cards */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* 위쪽부터 시작하여 잘림 방지 */
    gap: 1rem; /* Reduced gap for tighter spacing */
    overflow-x: visible; /* Allow cards to extend beyond container horizontally */
    overflow-y: auto; /* Enable vertical scrolling with mouse wheel */
    padding: 2rem 1rem 2rem 1rem; /* 상하 패딩 추가로 스크롤 영역 확보 */
    box-sizing: border-box;
    scroll-behavior: smooth; /* 부드러운 스크롤 */
    /* 스크롤바 숨기기 */
    scrollbar-width: none; /* Firefox - hide scrollbar */
    -ms-overflow-style: none; /* IE and Edge - hide scrollbar */
}

/* Chrome, Safari, Opera - 스크롤바 숨기기 */
.game-container::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Card Table */
.table-area {
    position: relative;
    width: 90%;
    max-width: 100%; /* Prevent overflow */
    /* min-height: 500px; Reduced height for better balance */
    height: auto; /* Allow height to grow if needed */
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Changed from center to flex-start to allow content to extend */
    perspective: 2000px;
    overflow: visible; /* Ensure buttons and cards are not clipped */
    padding: 40px 120px; /* Reduced padding for better balance */
    box-sizing: border-box; /* Padding included in width calculation */
}

.table-scroll-container {
    position: relative;
    width: 100%;
    height: auto; /* Changed from 100% to auto to allow content to extend */
    min-height: 270px; /* Ensure minimum height */
    overflow: visible;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Scroll Buttons */
.scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(212, 175, 55, 0.9);
    color: var(--crimson);
    border: 2px solid var(--gold);
    border-radius: 50%;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    display: none; /* Hidden by default, only shown on mobile when .show class is added */
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 0 0 20px rgba(212, 175, 55, 0.4);
    transition: all 0.3s ease;
    pointer-events: auto;
}

/* 데스크탑에서는 항상 숨김 */
@media (min-width: 769px) {
    .scroll-btn {
        display: none !important;
    }
}

.scroll-btn:hover {
    background: var(--gold);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 30px rgba(212, 175, 55, 0.6);
    transform: translateY(-50%) scale(1.1);
}

.scroll-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.scroll-left {
    left: 10px;
}

.scroll-right {
    right: 10px;
}

/* Mobile styles */
/* @media (max-width: 768px) {
    .table-area {
        width: 100% !important;
        max-width: 100% !important;
        height: auto;
        padding: 5px 60px; 
        overflow: visible;
        position: relative;
        margin: 0 auto;
        box-sizing: border-box;
    }

    .table-scroll-container {
        width: 100%;
        height: auto;
        min-height: 300px;
        overflow-x: auto; 
        overflow-y: hidden; 
        scrollbar-width: none; 
        -ms-overflow-style: none; 
        position: relative; 
        -webkit-overflow-scrolling: touch; 
    }

    .table-scroll-container::-webkit-scrollbar {
        display: none; 
        width: 0;
        height: 0;
    }

    .scroll-btn {
        display: none; 
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1000;
    }

    .scroll-btn.show {
        display: flex !important; 
        visibility: visible !important;
        opacity: 1 !important;
        z-index: 1000 !important;
    }
    
    .scroll-left {
        left: 5px;
    }
    
    .scroll-right {
        right: 5px;
    }

    .card-wrapper.spread {
        position: absolute !important;
    }
} */

/* Card Component */
.card-wrapper {
    width: 140px;
    height: 240px;
    position: absolute;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.25, 1, 0.45, 1);
    transform-style: preserve-3d;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-sizing: content-box;
}

.card-wrapper.hover-popup {
    filter: drop-shadow(0 10px 25px rgba(212, 175, 55, 0.5));
    transition: top 0.2s ease-out,
                left 0.2s ease-out,
                transform 0.2s ease-out,
                filter 0.2s ease-out,
                z-index 0s;
    pointer-events: none; /* hover 중인 카드는 마우스 이벤트 무시 → 떨림 방지 */
    /* z-index 0s = 즉시 변경으로 깜빡임 방지 */
}

/* 선택된 카드 스타일 */
.card-wrapper.selected {
    filter: drop-shadow(0 15px 35px rgba(212, 175, 55, 0.8));
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
                filter 0.4s ease-out,
                z-index 0s;
    /* border는 padding 영역 내부에 적용되도록 box-shadow로 대체 */
    box-shadow:
        0 0 20px rgba(212, 175, 55, 0.6),
        0 0 40px rgba(212, 175, 55, 0.4),
        inset 0 0 20px rgba(212, 175, 55, 0.2);
    /* transform은 JavaScript에서 각도 방향으로 처리됨 */
}

/* 선택된 카드의 앞면에 테두리 적용 */
.card-wrapper.selected .card-face {
    border: 3px solid var(--gold);
    box-shadow: 
        var(--shadow),
        0 0 20px rgba(212, 175, 55, 0.6),
        0 0 40px rgba(212, 175, 55, 0.4);
}

.card-wrapper.in-deck {
    transform: translate(-50%, -50%) translateZ(calc(var(--index) * -1px));
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    border: 2px solid var(--gold);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-back {
    background-color: var(--table-color);
    background-image: url('../assets/ui/card_back.png');
    background-size: cover;
    background-position: center;
}

.card-back::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(0, 0, 0, 0.1) 100%);
    pointer-events: none;
}

/* Controls */
.controls {
    margin-top: 1rem; /* Reduced margin for tighter spacing */
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 100;
    flex-shrink: 0; /* Prevent shrinking */
}

.btn-magic {
    background: #1b1e23;
    color: var(--gold);
    border: 2px solid var(--gold);
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: var(--shadow), var(--magic-glow);
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.btn-magic:hover {
    background:  #1b1e23;
    color: var(--gold-bright);
    box-shadow: 0 0 30px rgba(212, 175, 55, 0.6);
    transform: translateY(-2px);
}

.btn-magic:active {
    transform: translateY(1px);
}

/* Download Button */
.btn-download {
    background: linear-gradient(135deg, #2c5f2d 0%, #1e4620 100%);
    color: var(--gold);
    border: 2px solid var(--gold);
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: var(--shadow), 0 0 20px rgba(44, 95, 45, 0.4);
    transition: all 0.3s ease;
    text-transform: uppercase;
    margin-left: 1rem;
}

.btn-download:hover {
    background: linear-gradient(135deg, #3a7f3d 0%, #2c5f2d 100%);
    color: var(--gold-bright);
    box-shadow: 0 0 30px rgba(44, 95, 45, 0.6);
    transform: translateY(-2px);
}

.btn-download:active {
    transform: translateY(1px);
}

.btn-download:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Result Stage */
.result-stage {
    position: relative;
    width: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 2rem;
    box-sizing: border-box;
}

.result-stage.active {
    display: flex;
    opacity: 1;
}

/* 선택된 카드 표시 영역 */
.selected-card-display {
    position: relative;
    margin: 0 auto;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    background-color: var(--table-color);
    background: transparent;
}

.selected-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    margin: 0;
    padding: 0;
}

.parchment-panel {
    background-image: url('../assets/ui/parchment.png');
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    width: 90%;
    max-width: 600px;
    aspect-ratio: 1 / 1;
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 1);
    border: 1px solid var(--gold);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.parchment-content {
    padding: 3rem;
    overflow-y: auto;
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: rgba(146, 108, 70, 0.5) rgba(0, 0, 0, 0);
    flex: 1;
}

.parchment-content::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.parchment-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0);
}

.parchment-content::-webkit-scrollbar-thumb {
    background: rgba(146, 108, 70, 0.5);
    border-radius: 10px;
    border: 2px solid rgba(0, 0, 0, 0);
    background-clip: content-box;
}

/* AI Insight Box - TTS Button Container */
.ai-insight-box {
    position: relative; /* Required for absolute positioning of TTS button */
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.ai-insight-box h3 {
    color: var(--gold);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.ai-text {
    color: #fffefe;
    font-size: 1rem;
    line-height: 1.6;
    text-align: left;
    white-space: pre-wrap;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--crimson);
}

#card-name {
    font-family: 'Cinzel', serif;
    color: var(--crimson);
    margin-bottom: 1.5rem;
    text-align: center;
}

.parchment-panel h2 {
    font-family: 'Cinzel', serif;
    color: var(--crimson);
    text-align: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px dashed var(--gold);
    padding-bottom: 0.5rem;
}

.meaning-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #fffefe;
    /* Darker ink color on parchment */
    text-align: justify;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--crimson);
}

/* Input Stage */
#input-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2.5rem;
    padding: 2rem;
}

#input-stage h2 {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    color: var(--gold);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin-bottom: 0;
    text-align: center;
}

.category-grid {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

/* Scatter layout used by dynamic CategoryGrid */
.category-grid.category-grid-scatter {
    position: relative;
    width: 100%;
    min-height: 320px;
    display: block; /* cards will be absolutely positioned inside */
}

.category-card {
    background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(250,245,230,0.05));
    color: var(--table-color);
    border: 2px solid  rgba(250, 245, 230, 0.215);
    border-radius: 10px;
    box-shadow: var(--shadow), var(--magic-glow);
    padding: 12px;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.25s ease;
    text-align: left;
    overflow: hidden;
    z-index: 2;
}

.category-card .card-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--gold);
}

.category-card .card-desc {
    font-size: 0.85rem;
    color: rgb(247, 233, 221);
    line-height: 1.1;
    max-height: 3.1em;
    overflow: hidden;
}


.category-card.list-item {
    position: relative;
    overflow: visible;
}

.category-card:hover {
    /* 이동 효과 제거, 박스 밖으로 퍼지는 금빛 글로우만 */
    box-shadow:
        0 0 0 0 rgba(0,0,0,0),
        0 0 32px 12px rgba(212,175,55,0.35),
        0 0 60px 18px rgba(212,175,55,0.18);
    border-color: var(--gold-bright);
    border: 2px solid rgba(252, 224, 39, 0.393);
    z-index: 3;
}

/* .category-card:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6), 0 0 28px rgba(212,175,55,0.12);
} */

/* .category-card.list-item:hover {
    transform: translateY(-4px) scale(1.01) skewX(-2deg);
    box-shadow: 0 14px 40px rgba(0,0,0,0.55), 0 0 30px rgba(212,175,55,0.18);
    border-color: var(--gold-bright);
    background: linear-gradient(180deg, rgba(255,255,255,1), rgba(253,250,236,0.98));
} */


/* .category-card.list-item:hover {
    transform: translateY(-4px) scale(1.02) skewX(-2deg);
    box-shadow:
        0 12px 34px rgba(0,0,0,0.56),
        0 0 22px rgba(212,175,55,0.18),
        0 0 48px rgba(212,175,55,0.12),
        0 0 120px rgba(212,175,55,0.07);
    border-color: var(--gold-bright);
} */

.category-card.selected {
    box-shadow: 0 12px 40px rgba(212,175,55,0.25), 0 0 36px rgba(212,175,55,0.18);
    transform: scale(1.04);
}

.category-card.hidden {
    opacity: 0.12;
    transform: scale(0.96);
}

/* List layout styles: top -> bottom ordered list */
.category-grid.category-grid-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    padding: 12px 8px;
}

.category-card.list-item {
    width: min(880px, 92%);
    display: flex;
    align-items: center;
    padding: 14px 18px;
}

.category-card.list-item .card-title {
    font-size: 1.25rem;
}

.category-card.list-item .card-desc {
    font-size: 0.95rem;
    opacity: 0.95;
}

/* When subpanel is active, hide the background main category cards completely */
.category-grid.has-subpanel .category-card {
    display: none;
}

/* Subcategory panel */
.subcategory-panel {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(820px, 92%);
    background: rgba(13,13,15,0.95);
    border: 2px solid rgba(212,175,55,0.12);
    border-radius: 12px;
    padding: 18px;
    z-index: 50;
    box-shadow: 0 30px 80px rgba(0,0,0,0.8);
}

/* Subcategory card adjustments within the centered panel */
.subcategory-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.subcategory-list .category-card.sub-item {
    width: 100%;
    padding: 12px 14px;
    box-shadow: none;
    border-radius: 8px;
}

.subcategory-list .category-card.sub-item .card-title {
    font-size: 1rem;
    color: var(--gold);
}

.subcategory-list .category-card.sub-item .card-desc {
    font-size: 0.9rem;
    color: var(--parchment-text);
    opacity: 0.95;
}

.subcategory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 12px;
}

.subcategory-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
}

.subcategory-item {
    background: rgba(255,255,255,0.95);
    border: 1px solid var(--gold);
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.subcategory-item:hover { transform: translateY(-4px); box-shadow: 0 8px 20px rgba(0,0,0,0.4); }

.selected-main-header { text-align: center; margin-bottom: 1rem; }
.selected-main-header h3 { font-size: 1.4rem; color: var(--gold); margin-bottom: 6px; }
.selected-main-header .muted { color: var(--parchment-text); opacity: 0.9; font-size: 0.95rem; }

/* Required info form shown after subcategory selection */
.required-info {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 6px 0 0 0;
    align-items: stretch;
}
.required-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
.required-field label {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.95rem;
}
.required-input {
    padding: 10px 12px;
    font-size: 1rem;
    border-radius: 6px;
    border: 2px solid rgba(212,175,55,0.12);
    background: rgba(255,255,255,0.1);
    color: #1a120b;
    width: 100%;
}
.required-input:focus {
    outline: none;
    border-color: var(--gold-bright);
    box-shadow: 0 6px 20px rgba(212,175,55,0.12);
}

.category-btn {
    background: rgba(255, 255, 255, 0.95);
    color: #1a120b;
    border: 2px solid var(--gold);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-family: 'MedievalSharp', cursive;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.category-btn:hover {
    background: var(--gold-bright);
    color: var(--crimson);
    box-shadow: 0 6px 15px rgba(212, 175, 55, 0.5);
    transform: translateY(-2px);
}

.category-btn.active {
    background: var(--gold);
    color: var(--crimson);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.7);
}

/* Query Area */
.query-area {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1.5rem;
    width: min(880px, 92%);
    margin-top: 0;
    animation: fadeInUp 0.5s ease-out;
}

/* Combined panel that holds required-info and the query area to appear as one unit */
.required-query-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 60%;
    max-width: 720px;
    min-width: 320px;
    margin: 0 auto;
    background: transparent; /* no opaque background as requested */
    border: none; /* remove the border line */
    padding: 8px 6px;
    border-radius: 6px;
    box-shadow: none; /* remove panel shadow so it blends */
    box-sizing: border-box;
    color: inherit;
    align-items: center; /* center inner fields horizontally */
}

.required-query-panel .required-info {
    margin: 0; /* no extra gap inside the panel */
    width: 100%;
}

.required-query-panel .query-area {
    margin: 0; /* no extra gap inside the panel */
}

.required-textarea {
    width: 100%;
    padding: 12px;
    border-radius: 6px;
    border: 2px solid rgba(212,175,55,0.12);
    background: rgba(255,255,255,0.98);
    color: #1a120b;
    font-family: 'MedievalSharp', cursive;
    resize: vertical;
}

.submit-area {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-top: 6px;
}

/* Label for the main query textarea */
.query-area .query-label {
    color: var(--gold);
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* #user-input {
    padding: 10px 12px;
    font-size: 1rem;
    border-radius: 6px;
    border: 2px solid rgba(212,175,55,0.12);
    background: rgba(255,255,255,0.1);
    color: #1a120b;
    width: 100%;
} */

/* #user-input:focus {
    outline: none;
    border-color: var(--gold-bright);
    box-shadow: 0 0 25px rgba(212, 175, 55, 0.5), 0 4px 15px rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 1);
} */
/* 기본 상태 + 포커스 상태 */
.required-input,
.required-input:focus {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    /* 크롬이 그리는 흰색 박스를 덮어쓰기 */
    box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.1) inset;
    -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.1) inset;
}

/* 자동완성 된 경우까지 포함해서 강제로 동일 스타일 적용 */
.required-input:-webkit-autofill,
.required-input:-webkit-autofill:focus,
.required-input:-webkit-autofill:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    -webkit-text-fill-color: #fff;
    box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.1) inset !important;
    -webkit-box-shadow: 0 0 0 1000px rgba(255, 255, 255, 0.1) inset !important;
}


#user-input::placeholder {
    color: #666;
    font-style: italic;
}

#submit-query {
    min-width: 200px;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
}

/* Summary Message */
.summary-message {
    position: relative; /* Required for absolute positioning of TTS button */
    width: 100%;
    max-width: 600px; /* Match query-area max-width for consistency */
    padding: 1.5rem;
    background: rgba(212, 175, 55, 0.1);
    border: 2px solid var(--gold);
    border-radius: 8px;
    color: var(--gold-bright);
    font-family: 'MedievalSharp', cursive;
    font-size: 1.1rem;
    line-height: 1.8;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), 0 0 20px rgba(212, 175, 55, 0.2);
    animation: fadeInUp 0.5s ease-out;
    height: auto; /* 높이를 자동으로 조정 */
    display: block; /* flex 대신 block으로 변경하여 높이 자동 계산 */
    margin: 0 auto; /* Center the message */
    box-sizing: border-box; /* 패딩과 보더를 포함한 크기 계산 */
    word-wrap: break-word; /* 긴 단어 줄바꿈 */
    overflow-wrap: break-word; /* 긴 단어 줄바꿈 (최신 표준) */
    word-break: keep-all; /* 한글 단어 단위로 줄바꿈 */
    white-space: normal; /* 텍스트 줄바꿈 허용 */
}

.summary-message.loading {
    color: var(--gold);
    font-style: italic;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* ============================================
   TTS Speaker Button Styles
   ============================================ */

/* TTS Button - Position & Layout */
.tts-speaker-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(212, 175, 55, 0.15);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
    padding: 0;
}

/* Interactive States */
.tts-speaker-btn:hover {
    background: rgba(212, 175, 55, 0.3);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
}

.tts-speaker-btn:active {
    transform: scale(0.95);
}

.tts-speaker-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Speaker Icons */
.speaker-icon,
.speaker-icon-playing {
    width: 24px;
    height: 24px;
    color: var(--gold);
}

/* Idle State Animation - Sound Waves */
.speaker-icon .speaker-wave {
    animation: soundwave 1.5s ease-in-out infinite;
}

.speaker-icon .wave-1 {
    animation-delay: 0s;
}

.speaker-icon .wave-2 {
    animation-delay: 0.3s;
}

@keyframes soundwave {
    0%, 100% {
        opacity: 0.4;
    }
    50% {
        opacity: 1;
    }
}

/* Playing State Animation - Spinner */
.speaker-icon-playing .spinner {
    animation: spin 1s linear infinite;
    transform-origin: center;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* State Classes */
.tts-speaker-btn.loading .speaker-icon {
    display: none;
}

.tts-speaker-btn.loading .speaker-icon-playing {
    display: block !important;
}

.tts-speaker-btn.playing {
    background: rgba(212, 175, 55, 0.3);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}

/* ============================================
   Multiple Cards Grid Display
   ============================================ */
.selected-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    justify-items: center;
    justify-content: center;
    max-width: 100%;
    padding: 10px;
    background: transparent; /* 배경 투명 */
}

.selected-card-image-small {
    width: 100%;
    max-width: 140px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.selected-card-image-small:hover {
    transform: scale(1.05);
}

/* Responsive: Stack in 2 columns on mobile */
@media (max-width: 768px) {
    .selected-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .parchment-panel {
        width: 100%;
    }
    .parchment-content {
        padding: 1rem;
    }
    .ai-insight-box {
        padding: 0rem;
    }
}

/* ============================================
   Toast Notification System
   ============================================ */

/* Toast container - fixed at top center */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;  /* Allow clicks through container */
    max-width: 90vw;       /* Responsive width */
}

/* Individual toast */
.toast {
    background: rgba(26, 18, 11, 0.95);  /* Parchment-like dark background */
    border: 2px solid var(--gold);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    min-width: 300px;
    max-width: 500px;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(212, 175, 55, 0.3);  /* Golden glow */
    display: flex;
    align-items: center;
    gap: 1rem;
    pointer-events: auto;  /* Allow clicks on toast */
    opacity: 0;
    transform: translateY(-100px);
    transition: all 0.3s ease-out;
}

/* Show animation */
.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Dismiss animation */
.toast.dismissing {
    opacity: 0;
    transform: translateY(-100px);
    transition: all 0.3s ease-in;
}

/* Toast message text */
.toast-message {
    color: var(--parchment-text);
    font-family: 'MedievalSharp', cursive;
    font-size: 1rem;
    flex: 1;
    line-height: 1.4;
}

/* Close button */
.toast-close {
    background: none;
    border: none;
    color: var(--crimson);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    line-height: 1;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0.8;
}

.toast-close:hover {
    opacity: 1;
    transform: scale(1.2);
}

/* Toast type variants */
.toast-info {
    border-color: var(--gold);
}

.toast-success {
    border-color: #4caf50;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(76, 175, 80, 0.3);
}

.toast-warning {
    border-color: #ff9800;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(255, 152, 0, 0.3);
}

.toast-error {
    border-color: var(--crimson);
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(139, 0, 0, 0.3);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .toast {
        min-width: 280px;
        max-width: 90vw;
        padding: 0.875rem 1.25rem;
        font-size: 0.9rem;
    }

    .toast-message {
        font-size: 0.9rem;
    }

    .toast-close {
        font-size: 1.25rem;
        width: 20px;
        height: 20px;
    }

    .toast-container {
        top: 10px;
    }
}

/* ============================================
   Language Select - Arcane Dropdown
   ============================================ */

/* Make header relative for absolute positioning */
header {
    position: relative;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.language-select {
    position: absolute;
    top: 20px;
    right: 30px;
    display: inline-flex;
    align-items: center;
    z-index: 1000;
    gap: 8px;
}

.language-select__control {
    appearance: none;
    background: rgba(13, 13, 15, 0.85);
    border: 2px solid var(--gold);
    color: var(--gold-bright);
    padding: 8px 34px 8px 14px;
    border-radius: 999px;
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    min-width: 140px;
}

.language-select__control:hover {
    border-color: var(--gold-bright);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.4);
    transform: translateY(-1px);
}

.language-select__control:focus {
    outline: none;
    border-color: var(--gold-bright);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.6);
}

.language-select__control:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.language-select__control.switching {
    opacity: 0.75;
}

.language-select__icon {
    position: absolute;
    right: 14px;
    color: var(--gold-bright);
    pointer-events: none;
    font-size: 0.75rem;
    text-shadow: 0 0 6px rgba(212, 175, 55, 0.7);
}

/* Responsive adjustments for language select */
@media (max-width: 768px) {
    .language-select {
        top: 10px;
        right: 15px;
    }

    .language-select__control {
        min-width: 120px;
        font-size: 0.78rem;
        padding: 6px 30px 6px 12px;
    }
}

@media (max-width: 480px) {
    .language-select {
        top: 8px;
        right: 10px;
    }

    .language-select__control {
        min-width: 110px;
        font-size: 0.72rem;
    }
}

/* ============================================
   Video Loading Overlay
   ============================================ */

.video-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999; /* Above all content */
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    pointer-events: none;
}

.video-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.loading-video {
    max-width: 80%;
    max-height: 80%;
    width: auto;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 0 40px rgba(212, 175, 55, 0.6);
}

/* Fade animations */
@keyframes fadeInVideo {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeOutVideo {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}
