/* style.css */

/* === START: License Modal Instruction Styles === */

  /* ซ่อนปุ่มกลับหน้าหลักทั้งหมดอย่างถาวร */
  .back-to-home {
    display: none !important;
  }

/* แก้ปัญหา Modal ล้นหน้าจอโดยการเพิ่ม scrollbar */
#license-prompt-content {
    max-height: 90vh; /* กำหนดความสูงสูงสุดไม่ให้เกิน 90% ของหน้าจอ */
    overflow-y: auto;   /* เพิ่ม scrollbar แนวตั้งเมื่อเนื้อหาเกิน */
}

/* สไตล์สำหรับกล่องคำแนะนำ */
.license-instructions {
    margin-top: 1.5rem;
    padding: 1rem 1.5rem;
    background-color: #f7f5ff;
    border-radius: 0.5rem;
    text-align: left;
    font-size: 0.9rem;
    border: 1px solid #EAE6F8;
    line-height: 1.6;
}

.license-instructions p {
    margin-top: 0;
    margin-bottom: 0.75rem;
}

.license-instructions ul {
    margin: 0;
    padding-left: 1.25rem;
}

.license-instructions li:not(:last-child) {
    margin-bottom: 0.5rem;
}

body.night-mode .license-instructions {
    background-color: #3a506b;
    border-color: #4a6572;
}

/* === END: License Modal Instruction Styles === */

.hidden {
    display: none !important;
}

/* === สวิตช์ควบคุมหลัก === */
html {
    font-size: 15px;
}

/* --- General Styles (Day Mode - Default) --- */
body {
    font-family: 'Sarabun', sans-serif;
    background-color: #FFFDF5;
    color: #3d3d3d;
    margin: 0;
    padding: 1.25rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    text-align: center;
    transition: background-color 0.4s, color 0.4s;
    overflow-x: hidden;
}

.screen {
    display: none;
    width: 100%;
    max-width: 75rem;
}

.screen.active {
    display: block;
}

h1, h2, h3, h4 {
    color: #6A5ACD;
    text-shadow: 0.125rem 0.125rem 0.25rem rgba(0,0,0,0.1);
    transition: color 0.4s;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.6rem; margin-top: 2rem; }
h4 { font-size: 1.4rem; }

.app-description {
    font-size: 1.1rem;
    color: #5a5a5a;
    max-width: 40rem;
    margin: 0.5rem auto 2rem auto;
    line-height: 1.6;
}

button {
    background-color: #C3B1E1;
    color: #2c3e50;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1.05rem; 
    font-weight: bold; 
    font-family: inherit;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
    margin: 0.3125rem;
    box-shadow: 0 0.25rem 0.375rem rgba(0,0,0,0.15);
}

button:hover {
    background-color: #B19CD9;
    transform: translateY(-0.125rem);
}

button:active {
    transform: translateY(0.0625rem);
}

.button-link {
    background: none;
    border: none;
    box-shadow: none;
    color: #6A5ACD;
    text-decoration: underline;
    padding: 0.5rem;
}
.button-link:hover {
    background: none;
    transform: none;
    color: #4a148c;
}


#theme-switcher {
    position: fixed;
    bottom: 1rem; 
    left: 1rem;   
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    font-size: 1.5rem;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
    box-sizing: border-box;
}

.modal-content {
    background-color: #f8f6fe;
    color: #3d3d3d; 
    padding: 1.875rem 3.125rem;
    border-radius: 0.625rem;
    box-shadow: 0 0.3125rem 1rem rgba(0,0,0,0.2);
    text-align: center;
    transition: background-color 0.4s, color 0.4s;
    position: relative;
}

.layout-description {
    background-color: #f7f5ff; 
    border-left: 4px solid #C3B1E1;
    padding: 1rem 1.5rem;
    margin: 1.5rem auto;
    max-width: 45rem;
    text-align: left;
    line-height: 1.8;
    border-radius: 0 0.5rem 0.5rem 0;
    color: #4a4a4a;
}
.layout-description:empty { display: none; }

.recommendation-panel {
    background-color: #EAE6F8;
    border-radius: 0.75rem;
    max-width: 45rem;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
    max-height: 0;
    overflow: hidden;
    padding: 0 1.5rem;
    margin-top: 0;
    transition: max-height 0.5s ease-in-out, padding 0.5s ease-in-out, margin-top 0.5s ease-in-out;
}
.recommendation-panel.visible {
    max-height: 50rem; 
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    margin-top: 1.5rem;
}
.recommendation-panel h4 { margin-top: 0; color: #6A5ACD; }
.recommendation-panel p { line-height: 1.7; margin-bottom: 0.75rem; }
.recommendation-panel p:last-child { margin-bottom: 0; }

.selection-controls-wrapper { padding: 1.5rem 0; }

/* NIGHT MODE */
body.night-mode { background-color: #2c3e50; color: #ecf0f1; }
body.night-mode .app-description { color: #bdc3c7; }
body.night-mode h1, body.night-mode h2, body.night-mode h3, body.night-mode h4 { color: #f1c40f; text-shadow: 0.125rem 0.125rem 0.25rem #000; }
body.night-mode button { background-color: #f1c40f; color: #2c3e50; box-shadow: 0 0.25rem 0.375rem rgba(0,0,0,0.2); }
body.night-mode button:hover { background-color: #f39c12; }
body.night-mode .modal-content { background-color: #34495e; color: #ecf0f1; }
body.night-mode .layout-description { background-color: #3a506b; border-left-color: #f1c40f; color: #ecf0f1; }
body.night-mode .recommendation-panel { background-color: #3d5369; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }
body.night-mode .recommendation-panel h4 { color: #f1c40f; }
body.night-mode .button-link { color: oklab(0% 0 0); }
body.night-mode .button-link:hover { color: hsl(0, 100%, 21%); }

.main-menu { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.main-menu .menu-item { width: 80%; max-width: 25rem; }
.selection-controls-top-center { text-align: center; margin-bottom: 1.25rem; }
.option-group { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.5rem; margin-top: 0.75rem; }

/* --- START: CORRECTED STYLES FOR CHECKBOXES --- */
.option-group.checkbox-options {
    display: inline-flex; /* ทำให้ block นี้ถูกจัดกลางหน้าจอได้ */
    flex-direction: column; /* จัดเรียง checkbox ในแนวตั้ง */
    align-items: flex-start; /* จัดให้ checkbox ชิดซ้าย */
    gap: 0.75rem; /* เพิ่มระยะห่างระหว่างแถว */
}
/* --- END: CORRECTED STYLES FOR CHECKBOXES --- */

.option-group label { font-size: 1rem; cursor: pointer; }
input[type="checkbox"] { width: 1.125rem; height: 1.125rem; cursor: pointer; margin-right: 0.5rem;}
#selection-counter, #custom-selection-counter { font-size: 1.2rem; margin-top: 0.3125rem; }
#card-deck { display: flex; flex-direction: column; align-items: center; padding: 1.25rem; perspective: 1000px; }
.card-row { display: flex; justify-content: center; transition: transform 0.3s ease; margin-top: -0rem; }
.card-row:first-child { margin-top: 0; }
.card-row:hover { transform: translateY(-0.625rem); z-index: 5; }
.deck-card { position: relative; width: 4.375rem; height: 7.5rem; cursor: pointer; transition: transform 0.3s ease; margin-left: 0.1rem; }
.card-row > .deck-card:first-child { margin-left: 0; }
.deck-card:hover { transform: translateY(-1rem) scale(1.05); z-index: 10; }
.deck-card img { width: 100%; height: 100%; border-radius: 0.3125rem; box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.2); }
@keyframes floatUp { from { transform: translateY(0) scale(1); opacity: 1; } to { transform: translateY(-6.25rem) scale(1.1); opacity: 0; } }
.deck-card.selected { animation: floatUp 0.5s forwards ease-out; }
.result-cards-container { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 1.25rem; margin-bottom: 1.875rem; padding: 1.25rem; min-height: 12.5rem; }
.result-card-wrapper { display: flex; flex-direction: column; align-items: center; }
.card-position-label { margin-bottom: 0.625rem; font-size: 1.2rem; font-weight: bold; }
.card-container { width: 7.5rem; height: 12.5rem; perspective: 1000px; cursor: pointer; transition: transform 0.4s ease; }
.card-container.reversed { transform: rotate(180deg); }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform 0.6s; transform-style: preserve-3d; transform: rotateY(180deg); }
.card-container.flipped .card-inner { transform: rotateY(0deg); }
.card-face { position: absolute; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; border-radius: 0.5rem; overflow: hidden; box-shadow: 0 0.375rem 0.75rem rgba(0,0,0,0.2); }
.card-face img { width: 100%; height: 100%; object-fit: cover; }
.card-back { transform: rotateY(180deg); }
.controls { margin-top: 1.25rem; text-align: center; }
.result-cards-container.layout-6 { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 1.25rem; max-width: 31.25rem; margin: auto; }
.result-cards-container.layout-10 { display: grid; grid-template-columns: repeat(4, auto); grid-template-rows: repeat(3, auto); gap: 1.25rem; align-items: center; justify-content: center; max-width: 50rem; margin: auto; }
.layout-10 .result-card-wrapper:nth-child(1)  { grid-area: 2 / 2; }
.layout-10 .result-card-wrapper:nth-child(2)  { grid-area: 2 / 1; }
.layout-10 .result-card-wrapper:nth-child(3)  { grid-area: 1 / 2; }
.layout-10 .result-card-wrapper:nth-child(4)  { grid-area: 3 / 2; }
.layout-10 .result-card-wrapper:nth-child(5)  { grid-area: 3 / 3; }
.layout-10 .result-card-wrapper:nth-child(6)  { grid-area: 1 / 1; }
.layout-10 .result-card-wrapper:nth-child(7)  { grid-area: 3 / 4; }
.layout-10 .result-card-wrapper:nth-child(8)  { grid-area: 2 / 3; }
.layout-10 .result-card-wrapper:nth-child(9)  { grid-area: 2 / 4; }
.layout-10 .result-card-wrapper:nth-child(10) { grid-area: 1 / 4; }
/* *** THIS IS THE CORRECTED RULE *** */
.layout-10 .result-card-wrapper .card-container:not(.reversed) { transform: none; }
.layout-10 .result-card-wrapper:nth-child(7), .layout-10 .result-card-wrapper:nth-child(9), .layout-10 .result-card-wrapper:nth-child(10) { transform: translateX(2.5rem); }

.result-cards-container.capturing { display: inline-flex; padding: 1.875rem; border-radius: 1rem; }
.result-cards-container.capturing .card-inner { transform: none !important; }
.result-cards-container.capturing .card-back { display: none !important; }
.result-cards-container.layout-10.capturing { display: inline-grid; max-width: none; width: 55rem; }
.result-cards-container.layout-6.capturing { display: inline-grid; }

/* Modal Styles */
.details-modal { max-width: 50rem; width: 95%; max-height: 90vh; overflow-y: auto; text-align: left; padding: 1.5rem 2rem; }
.details-modal-header { display: flex; align-items: flex-start; gap: 1.5rem; margin-bottom: 1.5rem; }
.details-modal-img { width: 8rem; flex-shrink: 0; cursor: pointer; }
.details-modal-img img { width: 100%; border-radius: 0.5rem; box-shadow: 0 4px 8px rgba(0,0,0,0.15); transition: transform 0.6s ease; }
.details-modal-img.reversed img { transform: rotate(180deg); }
.details-modal-title h3 { margin: 0 0 0.5rem 0; font-size: 1.8rem; color: #6A5ACD; }
.details-modal-title .reversed-indicator { background-color: #e44d26; color: white; padding: 0.2rem 0.6rem; border-radius: 1rem; font-size: 0.9rem; font-weight: bold; display: inline-block; margin-bottom: 0.75rem; }
.details-modal-keywords { font-style: italic; color: #555; margin-bottom: 1rem; font-size: 1.05rem; }
.details-modal-body h4 { margin-top: 1.5rem; margin-bottom: 0.75rem; border-bottom: 2px solid #C3B1E1; padding-bottom: 0.5rem; font-size: 1.3rem; color: #6A5ACD; }
.details-modal-body p { line-height: 1.7; margin-bottom: 1rem; text-indent: 1.5em; }
.details-modal-body p:first-of-type { text-indent: 0; }
.details-modal-close-btn { position: absolute; top: 0.5rem; right: 0.5rem; background: none; border: none; font-size: 2.2rem; cursor: pointer; color: #888; padding: 0.5rem; line-height: 1; box-shadow: none; font-weight: 300; }
.details-modal-close-btn:hover { color: #333; background: none; transform: none; }
body.night-mode .details-modal-title h3, body.night-mode .details-modal-body h4, body.night-mode .details-modal-meta dt { color: #f1c40f; }
body.night-mode .details-modal-body h4 { border-bottom-color: #f1c40f; }
body.night-mode .details-modal-keywords, body.night-mode .details-modal-close-btn { color: #bdc3c7; }
body.night-mode .details-modal-close-btn:hover { color: #fff; }

.position-meaning-group { background-color: rgba(195, 177, 225, 0.15); border: 1px solid #C3B1E1; border-radius: 0.5rem; padding: 1rem 1.5rem; margin-bottom: 1.5rem; }
.position-meaning-group h4 { margin-top: 0; margin-bottom: 1rem; color: #4a148c; border-bottom: none; font-size: 1.4rem; }
.position-meaning-group p { text-indent: 0; margin-bottom: 0.75rem; }
.position-meaning-group strong { color: #6A5ACD; }
.position-meaning-group h5.position-sub-header { font-size: 1.15rem; color: #512da8; margin-top: 1.25rem; margin-bottom: 0.5rem; padding-bottom: 0.25rem; border-bottom: 1px dotted #b39ddb; }
.position-meaning-group h5.position-sub-header:first-of-type { margin-top: 0; }
body.night-mode .position-meaning-group { background-color: rgba(241, 196, 15, 0.1); border-color: #f1c40f; }
body.night-mode .position-meaning-group h4 { color: #fce28d; }
body.night-mode .position-meaning-group strong { color: #f1c40f; }
body.night-mode .position-meaning-group h5.position-sub-header { color: #fff59d; border-bottom-color: #785e0b; }

.details-modal-meta { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed #d1c4e9; }
.details-modal-meta dl { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1rem; }
.details-modal-meta dt { font-weight: bold; color: #6A5ACD; grid-column: 1; }
.details-modal-meta dd { margin-left: 0; grid-column: 2; }
body.night-mode .details-modal-meta { border-top-color: #4a6572; }

/* Library Styles */
.library-title { margin-bottom: 2rem; }
.suit-heading { font-size: 1.4rem; margin-top: 2.5rem; margin-bottom: 1rem; color: #8878C4; border-bottom: 1px solid #ddd; padding-bottom: 0.5rem; }
body.night-mode .suit-heading { color: #E0C568; border-bottom-color: #4a6572; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr)); gap: 1rem; justify-content: center; }
.library-card { position: relative; cursor: pointer; transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; background-color: #e0e0e0; border-radius: 0.3125rem; overflow: hidden; aspect-ratio: 600 / 1029; }
body.night-mode .library-card { background-color: #455a64; }
.library-card img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 0; box-shadow: none; transition: opacity 0.5s ease-in-out; }
.library-card img.lazy { opacity: 0; }
.library-card:hover { transform: scale(1.08); box-shadow: 0 4px 15px rgba(0,0,0,0.25); }

/* Image Viewer Styles */
.image-viewer { background-color: rgba(0,0,0,0.9); z-index: 1100; }
#fullscreen-card-image { max-width: 90%; max-height: 90vh; box-shadow: 0 0 25px rgba(255, 255, 255, 0.2); border-radius: 1rem; transition: transform 0.4s ease; }
#fullscreen-card-image.reversed { transform: rotate(180deg); }
#image-viewer-close-btn { color: #fff; font-size: 3rem; text-shadow: 0 0 5px black; }

/* Collapsible Section Styles */
.collapsible-section { margin: 1.5rem 0; }
.collapsible-toggle { width: 100%; text-align: left; background-color: #eae6f8; color: #4a148c; border: 1px solid #C3B1E1; font-size: 1.1rem; display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; }
body.night-mode .collapsible-toggle { background-color: #3d5369; color: #fce28d; border-color: #f1c40f; }
.collapsible-toggle:hover { background-color: #e0d8f5; }
body.night-mode .collapsible-toggle:hover { background-color: #4a6572; }
.toggle-indicator { font-size: 1.5rem; font-weight: bold; }
.collapsible-content { max-height: 0; overflow: hidden; transition: max-height 0.4s ease-out; background-color: rgba(234, 230, 248, 0.3); border: 1px solid #C3B1E1; border-top: none; border-radius: 0 0 0.5rem 0.5rem; }
body.night-mode .collapsible-content { background-color: rgba(61, 83, 105, 0.3); border-color: #f1c40f; }
.collapsible-content.expanded { max-height: 100rem; transition: max-height 0.5s ease-in; }
.collapsible-content .position-meaning-group { border: none; background-color: transparent; padding-top: 0; margin-top: 0; }

/* Custom Spread Builder Styles */
.placeholder-wrapper .card-container.placeholder { border: 3px dashed #C3B1E1; background-color: rgba(195, 177, 225, 0.1); box-shadow: none; }
body.night-mode .placeholder-wrapper .card-container.placeholder { border-color: #f1c40f; background-color: rgba(241, 196, 15, 0.1); }
.placeholder-wrapper .card-container.placeholder:hover { background-color: rgba(195, 177, 225, 0.3); }
body.night-mode .placeholder-wrapper .card-container.placeholder:hover { background-color: rgba(241, 196, 15, 0.2); }
.card-inner-placeholder { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; font-weight: bold; color: #6A5ACD; }
.card-inner-placeholder img { width: 100%; height: 100%; object-fit: cover; border-radius: 0.5rem; }
body.night-mode .card-inner-placeholder { color: #f1c40f; }
#custom-card-selector-modal .library-card.disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
#custom-card-selector-modal .library-card.disabled:hover { transform: none; box-shadow: none; }
.custom-reading-item { display: flex; gap: 1.5rem; padding: 1.5rem 0; border-bottom: 1px solid #ddd; }
body.night-mode .custom-reading-item { border-bottom-color: #4a6572; }
.custom-reading-item:last-child { border-bottom: none; }
.custom-reading-img-container { flex-shrink: 0; width: 8rem; }
.custom-reading-img-container .details-modal-img { width: 100%; }
.custom-reading-text-container { flex-grow: 1; }
.clickable-fullscreen-img { cursor: pointer; }

/* Orientation Choice Styles */
#custom-card-selector-content.compact-view { max-width: 25rem; transition: max-width 0.2s ease-in-out; }
#custom-orientation-choice-view { display: flex; flex-direction: column; align-items: center; text-align: center; }
#custom-orientation-choice-view h4 { margin-top: 0; }
.orientation-preview { margin: 1rem 0; }
.orientation-preview img { max-width: 8rem; border-radius: 0.5rem; box-shadow: 0 4px 8px rgba(0,0,0,0.15); }

/* Responsive Styles */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    /* === START: โค้ดที่แก้ไขสำหรับหน้าเลือกไพ่บนมือถือ === */

    /* 1. เปลี่ยน container หลักให้เป็น Grid Layout */
    #card-deck {
        display: grid;
        /* กำหนดให้มี 7 คอลัมน์เท่าๆ กัน */
        grid-template-columns: repeat(7, 1fr);
        gap: 5px; /* ระยะห่างระหว่างการ์ด */
        padding: 10px;
        perspective: none; /* ไม่จำเป็นสำหรับ Grid */
    }

    /* 2. ทำให้ .card-row โปร่งใสต่อ Layout เพื่อให้ Grid มองเห็น .deck-card โดยตรง */
    .card-row {
        display: contents; /* << นี่คือหัวใจสำคัญของการแก้ไข */
        margin-top: 0; /* ลบ margin ที่เคยซ้อนทับกันออก */
    }
    
    .card-row:hover {
        transform: none; /* ไม่ต้องมีการขยับเมื่อ hover */
    }

    /* 3. ปรับขนาดของไพ่แต่ละใบให้พอดีกับช่อง Grid */
    .deck-card {
        width: 100%; /* ให้ความกว้างเต็มช่องของ Grid */
        height: auto; /* ให้ความสูงปรับตามอัตโนมัติ */
        aspect-ratio: 600 / 1029; /* รักษาสัดส่วนของไพ่ */
        margin-left: 0; /* ลบ margin เดิมออก */
    }
    .deck-card:hover {
        transform: scale(1.1); /* ขยายเล็กน้อยเมื่อ hover */
        z-index: 10;
    }

    /* === END: โค้ดที่แก้ไขสำหรับหน้าเลือกไพ่บนมือถือ === */

    .result-cards-container.layout-linear {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        padding: 1rem 1rem 1.5rem 1rem;
        gap: 0.8rem;
    }
    .result-cards-container.layout-linear .card-container {
        width: 6.5rem;
        height: 11rem;
    }
    .result-cards-container.layout-linear .card-position-label {
        font-size: 1rem;
    }
    .result-cards-container.layout-6 {
        max-width: 100%;
        padding: 1rem;
        gap: 0.8rem;
    }
    .result-cards-container.layout-6 .card-container {
        width: 6rem;
        height: 10rem;
    }
    .result-cards-container.layout-6 .card-position-label {
        font-size: 1.1rem;
    }
    .result-cards-container.layout-10 {
        transform: scale(0.75);
        transform-origin: top center;
        margin-bottom: -8rem;
    }
    .controls {
        margin-top: 0;
    }
    .details-modal-header {
        flex-direction: column;
    }
    .details-modal-img {
        width: 6rem;
        margin: 0 auto;
    }
    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(5rem, 1fr));
    }
    .custom-reading-item {
        flex-direction: column;
    }
    .custom-reading-img-container {
        width: 6rem;
        margin: 0 auto;
    }

}
/* AI Summary Styles */
.ai-summary-container {
    margin-top: 2rem;
    padding: 1.5rem;
    border: 1px solid #C3B1E1;
    border-radius: 0.75rem;
    background-color: #f7f5ff;
    max-width: 50rem;
    margin-left: auto;
    margin-right: auto;
}

.ai-summary-container h3 {
    margin-top: 0;
    color: #6A5ACD;
}

.ai-summary-container textarea {
    width: 100%;
    min-height: 4rem;
    padding: 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    border-radius: 0.5rem;
    border: 1px solid #ddd;
    margin: 1rem 0;
    box-sizing: border-box;
     /* --- START: เพิ่ม/แก้ไข property เหล่านี้ --- */
    resize: none; /* ป้องกันไม่ให้ผู้ใช้ลากปรับขนาดเอง */
    overflow-y: hidden; /* ซ่อน scrollbar แนวตั้ง */
    transition: height 0.2s ease; /* เพิ่ม animation ให้การขยายดูนุ่มนวล (ไม่จำเป็น แต่สวยงาม) */
    /* --- END: เพิ่ม/แก้ไข property เหล่านี้ --- */
}

.ai-result-display {
    margin-top: 1rem;
    padding: 1rem;
    background-color: #fff;
    border-radius: 0.5rem;
    text-align: left;
    line-height: 1.7;
    white-space: pre-wrap; /* ทำให้เคารพการขึ้นบรรทัดใหม่ */
}
.ai-result-display:empty {
    display: none;
}

/* Night Mode AI Styles */
body.night-mode .ai-summary-container {
    background-color: #3a506b;
    border-color: #f1c40f;
}
body.night-mode .ai-summary-container h3 {
    color: #f1c40f;
}
body.night-mode .ai-summary-container textarea {
    background-color: #2c3e50;
    color: #ecf0f1;
    border-color: #4a6572;
}
body.night-mode .ai-result-display {
    background-color: #2c3e50;
}

/* === START: Custom Button Colors === */

/* --- Day Mode --- */
/* 10-card spread: Pastel Green */
.main-menu .menu-item[data-cards="10"] {
    background-color: #A7D7C5;
}
.main-menu .menu-item[data-cards="10"]:hover {
    background-color: #8FB9AC;
}

/* Custom spread: Pastel Red */
.main-menu #custom-spread-btn {
    background-color: #F4C2C2;
}
.main-menu #custom-spread-btn:hover {
    background-color: #E1A6A6;
}

/* Library: Pastel Blue */
.main-menu #show-library-btn {
    background-color: #AEC6CF;
}
.main-menu #show-library-btn:hover {
    background-color: #9AB3B8;
}


/* --- Night Mode --- */
/* 10-card spread: Pastel Brown */
body.night-mode .main-menu .menu-item[data-cards="10"] {
    background-color: #BCAAA4;
}
body.night-mode .main-menu .menu-item[data-cards="10"]:hover {
    background-color: #A1887F;
}

/* Custom spread: Pastel Orange */
body.night-mode .main-menu #custom-spread-btn {
    background-color: #FFDAB9;
}
body.night-mode .main-menu #custom-spread-btn:hover {
    background-color: #FFC8A2;
}

/* Library: Pastel Blue (same as day) */
body.night-mode .main-menu #show-library-btn {
    background-color: #AEC6CF;
}
body.night-mode .main-menu #show-library-btn:hover {
    background-color: #9AB3B8;
}
/* === START: Saved Readings Styles === */

/* Container for saved readings section on home page */
.saved-readings-container {
    margin-top: 3rem;
    padding: 1.5rem;
    border-top: 2px solid #C3B1E1;
}

body.night-mode .saved-readings-container {
    border-top-color: #f1c40f;
}

#saved-readings-list {
    display: grid;
    gap: 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 2rem;
}

.saved-reading-item {
    background-color: #f7f5ff;
    border: 1px solid #EAE6F8;
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    text-align: left;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    position: relative;
    transition: box-shadow 0.3s;
}
.saved-reading-item:hover {
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
}

body.night-mode .saved-reading-item {
    background-color: #3a506b;
    border-color: #4a6572;
}

.saved-reading-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-right: 2.5rem;
    box-sizing: border-box;
}

.saved-reading-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #6A5ACD;
}
body.night-mode .saved-reading-header h3 {
    color: #fce28d;
}

.saved-reading-date {
    font-size: 0.9rem;
    color: #5a5a5a;
}
body.night-mode .saved-reading-date {
    color: #bdc3c7;
}

.saved-reading-cards {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.saved-card-thumb {
    width: 3rem;
    height: 5rem;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.saved-card-thumb.reversed {
    transform: rotate(180deg);
}
.clickable-saved-card {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.clickable-saved-card:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}


.saved-reading-question,
.saved-reading-summary {
    background-color: #fff;
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}
.saved-reading-question p,
.saved-reading-summary p {
    margin: 0;
    line-height: 1.6;
    white-space: pre-wrap;
}

.saved-reading-question strong,
.saved-reading-summary strong {
    color: #4a148c;
}

body.night-mode .saved-reading-question,
body.night-mode .saved-reading-summary {
    background-color: #2c3e50;
}
body.night-mode .saved-reading-question strong,
body.night-mode .saved-reading-summary strong {
    color: #f1c40f;
}

/* === START: Improved Delete Button Styles === */
.delete-reading-btn {
    position: absolute;
    /* ย้ายไปมุมขวาบน */
    top: 0.75rem;
    right: 0.75rem;
    
    /* ทำให้เป็นวงกลม */
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    
    /* จัดวางไอคอนให้อยู่กลางปุ่ม */
    display: flex;
    justify-content: center;
    align-items: center;
    
    background-color: #f0f0f0;
    color: #888;
    border: 1px solid #ddd;
    font-size: 1rem; /* ปรับขนาดไอคอนถังขยะ */
    cursor: pointer;
    line-height: 1;
    box-shadow: none;
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}

.delete-reading-btn:hover {
    background-color: #e44d26; /* สีแดงเมื่อ hover */
    color: white;
    transform: scale(1.1);
    border-color: #d43d16;
}

body.night-mode .delete-reading-btn {
    background-color: #4a6572;
    color: #bdc3c7;
    border-color: #5a7582;
}

body.night-mode .delete-reading-btn:hover {
    background-color: #BF616A;
    color: white;
    border-color: #a54f57;
}
/* === END: Improved Delete Button Styles === */
.delete-reading-btn:hover {
    color: #e44d26;
    background: none;
    transform: none;
}
#clear-saved-readings-btn {
    background-color: #F4C2C2;
}
#clear-saved-readings-btn:hover {
    background-color: #E1A6A6;
}
body.night-mode #clear-saved-readings-btn {
    background-color: #BF616A;
    color: white;
}
body.night-mode #clear-saved-readings-btn:hover {
    background-color: #a54f57;
}

#ai-summary-container #save-reading-btn {
    margin-top: 1rem;
}
/* === START: License Bar Styles === */


/* สไตล์สำหรับ Night Mode */
body.night-mode #license-status-container {
    background-color: #34495e; /* สีพื้นหลังสำหรับ Night Mode */
    color: #ecf0f1;
    box-shadow: 0 2px 5px rgba(0,0,0,0.25);
}
/* === END: License Bar Styles === */
/* === START: License Status Button Styles === */

#license-status-button {
    position: fixed;
    bottom: 1rem;
    /* วางไว้ข้างๆ ปุ่ม theme-switcher */
    left: 5rem; /* 1rem (padding) + 3rem (width) + 1rem (gap) */
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    font-size: 1.5rem;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    /* เพิ่ม animation ให้ดูน่าสนใจ */
    animation: pulse 2s infinite ease-in-out;
}

/* ทำให้ปุ่มหยุดกระพริบเมื่อเอาเมาส์ไปชี้ */
#license-status-button:hover {
    animation-play-state: paused;
}

/* Animation สำหรับการกระพริบ */
@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(240, 173, 78, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(240, 173, 78, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(240, 173, 78, 0);
    }
}

/* สำหรับ Night Mode (ถ้าต้องการให้สีเงาเปลี่ยน) */
body.night-mode #license-status-button {
    animation-name: pulse-night;
}

@keyframes pulse-night {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(241, 196, 15, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(241, 196, 15, 0);
    }
}
/* style.css */

/* ... โค้ด CSS ที่มีอยู่เดิมทั้งหมด ... */

/* === START: Reading Details Container Styles === */

#reading-details-container {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid #ddd;
}
#reading-details-container:empty {
    display: none;
}

body.night-mode #reading-details-container {
    border-top-color: #4a6572;
}
/* === START: โค้ดสำหรับ Freemium/Unlock Feature === */

/* สไตล์สำหรับปุ่มปลดล็อกในเมนูหลัก */
#unlock-premium-btn {
    background-color: #f1c40f; /* สีเหลืองทองโดดเด่น */
    color: #2c3e50;
    border: 2px solid #f39c12;
    margin-top: 1rem;
}
#unlock-premium-btn:hover {
    background-color: #f39c12;
}

body.night-mode #unlock-premium-btn {
    background-color: #f39c12;
    border-color: #f1c40f;
}
body.night-mode #unlock-premium-btn:hover {
    background-color: #e67e22;
}

/* สไตล์สำหรับกล่องข้อความเชิญชวน */
.premium-cta-placeholder {
    margin: 2rem auto;
    padding: 2rem;
    max-width: 45rem;
    border: 2px dashed #6A5ACD;
    border-radius: 0.75rem;
    background-color: rgba(195, 177, 225, 0.1);
}

.premium-cta-placeholder h3 {
    margin-top: 0;
    font-size: 1.8rem;
}

.premium-cta-placeholder p {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 1.5rem;
}

.premium-cta-placeholder .unlock-button {
    font-size: 1.2rem;
    padding: 0.8rem 2rem;
    background-color: #2ecc71;
    color: white;
}
.premium-cta-placeholder .unlock-button:hover {
    background-color: #27ae60;
}

body.night-mode .premium-cta-placeholder {
    border-color: #f1c40f;
    background-color: rgba(241, 196, 15, 0.1);
}

body.night-mode .premium-cta-placeholder .unlock-button {
    background-color: #27ae60;
}
body.night-mode .premium-cta-placeholder .unlock-button:hover {
    background-color: #229954;
}


/* === END: โค้ดสำหรับ Freemium/Unlock Feature === */
/* ... โค้ดเดิมทั้งหมด ... */

/* สไตล์สำหรับ Night Mode ของหน้าต่าง License */
body.night-mode #license-prompt-content {
    background-color: #34495e; /* สีพื้นหลังสำหรับ Night Mode */
    color: #ecf0f1;
}

body.night-mode #license-client-id-display {
    background-color: #2c3e50;
    color: #3d3d3d;
}

body.night-mode #license-key-input {
    background-color: #2c3e50;
    color: #ecf0f1;
    border-color: #4a6572;
}
/* === START: Read More/Collapse Styles for Saved Readings === */

.saved-reading-summary .summary-content.collapsed .more-text {
    display: none;
}

.saved-reading-summary .summary-content.collapsed .ellipsis {
    display: inline;
}

.saved-reading-summary .summary-content .more-text {
    display: inline;
}

.saved-reading-summary .summary-content .ellipsis {
    display: none;
}

.toggle-summary-btn {
    background: none;
    border: none;
    box-shadow: none;
    color: #6A5ACD;
    text-decoration: underline;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-top: 0.5rem;
}
.toggle-summary-btn:hover {
    background: none;
    transform: none;
    color: #4a148c;
}

body.night-mode .toggle-summary-btn {
    color: #000000;
}

body.night-mode .toggle-summary-btn:hover {
    color: #f1c40f;
}

/* เพิ่มท้ายไฟล์ style.css */
.saved-summary-controls {
    display: flex;
    align-items: center;
    gap: 1rem; /* ระยะห่างระหว่างปุ่ม */
    margin-top: 0.5rem;
}

.copy-saved-summary-btn {
    background-color: #e0e0e0;
    color: #333;
    border: 1px solid #ccc;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    box-shadow: none;
}
.copy-saved-summary-btn:hover {
    background-color: #d0d0d0;
    transform: none;
}

body.night-mode .copy-saved-summary-btn {
    background-color: #455a64;
    color: #ecf0f1;
    border-color: #5a7582;
}

body.night-mode .copy-saved-summary-btn:hover {
    background-color: #546e7a;
}