html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Lora', serif; /* [風格] 預設字體改為優雅的 Lora 襯線字體 */
    color: #3D352A; /* [風格] 預設文字顏色改為深棕色 */
    background-color: #D3C4B3; /* [風格] 背景色改為有質感的亞麻色 */
    background-image: linear-gradient(rgba(0,0,0,0.02) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(0,0,0,0.02) 1px, transparent 1px);
    background-size: 20px 20px;
}

.background-image {
    display: none; /* 移除舊的背景圖設定，改用新的背景色與紋理 */
}

/* --- 2. 主容器樣式 (模擬一本攤開的書) --- */
.book {
    max-width: 850px;
    margin: 50px auto;
    padding: 50px 60px;
    background-color: #FDFCF7; /* [風格] 模擬羊皮紙或舊書頁的顏色 */
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.3), 0 0 0 10px rgba(0,0,0,0.1);
}

/* --- 3. 標題與文字排版 --- */
.book-header {
    text-align: center;
    border-bottom: 3px double #D1C7B8;
    padding-bottom: 20px;
    margin-bottom: 40px;
}

.book-header h1 {
    font-size: 3em;
    font-weight: 700;
    color: #3D352A;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.book-header h2 {
    font-size: 1.3em;
    color: #8A795D;
    font-style: italic;
    font-weight: 400;
    letter-spacing: 1px;
    margin-top: 5px;
}

.book h3 {
    font-family: 'Open Sans', sans-serif;
    font-size: 1.6em;
    font-weight: 700;
    color: #5C4033;
    border-bottom: 1px solid #D1C7B8;
    padding-bottom: 10px;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.book h4 {
    font-family: 'Open Sans', sans-serif;
    font-size: 1.2em;
    font-weight: 700;
    color: #8A795D;
    margin-bottom: 20px;
}

.book p {
    font-size: 1.1em;
    line-height: 1.8;
    color: #3D352A;
    margin-bottom: 1.5em;
}

.book strong {
    font-weight: 700;
    color: #5C4033;
}

.book a {
    color: #8B4513;
    text-decoration: underline;
    font-weight: bold;
    transition: color 0.3s;
}
.book a:hover {
    color: #A0522D;
}
.book a.button {
    color: #FDFCF7;
    text-decoration: none;
}

/* --- 4. 各區塊樣式 --- */

/* "Find Your Match" & "Wandering Library" 入口區塊 */
.user-description-section, .wandering-library-section {
    margin: 50px 0;
    padding: 30px;
    background-color: #F9F6F0;
    border: 1px solid #EAE6E0;
    border-radius: 3px;
    text-align: center;
}

.user-description-section h3, .wandering-library-section h3 {
    border-bottom: none;
    text-align: center;
}

.user-description-section textarea {
    width: 100%;
    min-height: 120px;
    background-color: #FFFFFF;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    padding: 15px;
    font-size: 1.1em;
    font-family: 'Lora', serif;
    color: #3D352A;
    line-height: 1.8;
    margin-top: 15px;
}

/* 按鈕樣式 */
.button, 
#submitDescription {
    font-family: 'Open Sans', sans-serif;
    display: inline-block;
    background-color: #5C4033;
    color: #FDFCF7;
    padding: 12px 30px;
    border: none;
    border-radius: 3px;
    font-size: 1em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-decoration: none;
    cursor: pointer;
    margin-top: 20px;
    transition: background-color 0.3s, transform 0.2s;
}

.button:hover, 
#submitDescription:hover {
    background-color: #3D352A;
    transform: translateY(-1px);
}

.results-area {
    display: none;
    margin-top: 25px;
    padding: 20px;
    background-color: #fff;
    border: 1px dashed #D1C7B8;
    border-radius: 3px;
    text-align: left;
}

/* 國家列表樣式 */
.country-list {
    text-align: center;
}
.country-menu {
    list-style: none;
    padding: 0;
    margin: 30px 0 0 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
}
.country-menu a {
    display: block;
    text-decoration: none;
    color: #8A795D;
    padding: 12px;
    border: 1px solid #EAE6E0;
    border-radius: 3px;
    transition: all 0.3s ease;
    text-align: center;
    font-family: 'Open Sans', sans-serif;
    font-size: 0.9em;
    font-weight: 700;
}
.country-menu a:hover {
    background-color: #F9F6F0;
    border-color: #D1C7B8;
    color: #5C4033;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

/* 頁尾樣式 */
.footer {
    text-align: center;
    margin-top: 50px;
    padding-top: 20px;
    border-top: 1px solid #EAE6E0;
    font-family: 'Open Sans', sans-serif;
}
.footer a, .footer p {
    font-size: 0.9em;
    color: #8A795D;
    text-decoration: none;
    margin: 5px 0;
}
.footer a:hover {
    text-decoration: underline;
}
.footer ul { list-style: none; padding: 0; margin: 10px 0 0 0; }
.footer ul li { display: inline-block; margin: 0 10px; }

/* 響應式設計 */
@media (max-width: 768px) {
    .book {
        margin: 20px;
        padding: 20px 25px;
    }
    .book-header h1 { font-size: 2.2em; }
    .book-header h2 { font-size: 1.1em; }
    .book p { font-size: 1em; }
    .country-menu { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

.results-area.loading p,
.results-area.error p {
    text-align: center;
    font-style: italic;
    color: #8A795D; /* 使用柔和的棕褐色作為提示文字顏色 */
    margin: 0;
}

.results-area.error p {
    color: #9c3c3c; /* 錯誤訊息使用深紅色，但比純紅更典雅 */
    font-weight: bold;
}

/* [新增] 按鈕在禁用狀態下的樣式 */
#submitDescription:disabled,
.button:disabled {
    background-color: #a99985; /* 使用較淺的灰色，表示不可用 */
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* --- 5. 表單輸入框與下拉選單樣式 (統一風格) --- */
input[type="text"], 
input[type="email"], 
textarea, 
select {
    width: 100%;
    padding: 12px;
    background-color: #FFFFFF;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    font-size: 1em;
    font-family: 'Lora', serif; /* 使用襯線字體保持書本質感 */
    color: #3D352A;
    margin-bottom: 10px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

input[type="text"]:focus, 
input[type="email"]:focus, 
textarea:focus, 
select:focus {
    border-color: #8A795D;
    outline: none;
    box-shadow: 0 0 5px rgba(138, 121, 93, 0.2);
}

/* 下拉選單特別樣式 */
select {
    appearance: none; /* 移除預設箭頭 */
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A795D' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}

/* --- 6. 自定義捲軸樣式 (Webkit only) --- */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #F9F6F0; 
    border-left: 1px solid #EAE6E0;
}

::-webkit-scrollbar-thumb {
    background: #D1C7B8; 
    border-radius: 5px;
    border: 2px solid #F9F6F0; /* 增加邊框讓捲軸看起來更細緻 */
}

::-webkit-scrollbar-thumb:hover {
    background: #8A795D; 
}

/* --- 7. New Profile Page Styles --- */

/* Goals as Tags/Pills */
.goal-tag {
    display: inline-block;
    margin: 5px;
    cursor: pointer;
}

.hidden-checkbox {
    display: none;
}

.goal-tag span {
    display: inline-block;
    padding: 8px 16px;
    background-color: #F9F6F0;
    border: 1px solid #D1C7B8;
    border-radius: 20px;
    font-size: 0.9em;
    color: #5C4033;
    transition: all 0.2s ease;
}

.hidden-checkbox:checked + span {
    background-color: #8A795D;
    color: #FFF;
    border-color: #8A795D;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.goal-tag:hover span {
    border-color: #8A795D;
}

/* Social Links Grid */
.social-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

@media (max-width: 600px) {
    .social-grid {
        grid-template-columns: 1fr;
    }
}

.social-input-group {
    display: flex;
    flex-direction: column;
}

.social-label {
    font-size: 0.85em;
    font-weight: bold;
    color: #5C4033;
    margin-bottom: 4px;
}

.social-input-group input {
    margin-bottom: 2px; /* Error msg space */
    font-size: 0.9em;
}

/* Nationality Checkbox Item */
.nationality-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    width: 48%; /* 2 cols */
    min-width: 140px;
    cursor: pointer;
    font-size: 0.95em;
}

/* ... previous styles ... */

@media (max-width: 480px) {
    .nationality-item {
        width: 100%;
    }
}

/* --- 8. Connect / Browse Profiles Page Styles --- */
.connect-section {
    padding: 20px 0;
}

.filters {
    margin-bottom: 25px;
    text-align: right;
    background: #f9f6f0;
    padding: 15px;
    border-radius: 5px;
    border: 1px solid #eae6e0;
}

.filters select {
    width: auto;
    display: inline-block;
    margin-bottom: 0;
    min-width: 200px;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 25px;
}

.profile-card {
    background: #fff;
    border: 1px solid #D1C7B8;
    border-radius: 6px;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.profile-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
    border-color: #8A795D;
}

.profile-card h3 {
    margin: 0 0 10px 0;
    color: #5C4033;
    font-size: 1.3em;
    font-family: 'Lora', serif;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;
}

.profile-card p {
    font-size: 0.95em;
    color: #555;
    line-height: 1.6;
    margin-bottom: 10px;
}

.profile-card p.intro-snippet {
    flex-grow: 1; /* Pushes stats/button down */
    font-style: italic;
    color: #666;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-card .stats {
    margin-top: 15px;
    font-weight: bold;
    color: #e65100; /* Deep orange */
    font-family: 'Open Sans', sans-serif;
    display: flex;
    align-items: center;
    gap: 5px;
}

.profile-card button {
    margin-top: 15px;
    background-color: #8A795D;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-weight: bold;
    font-family: 'Open Sans', sans-serif;
    text-transform: uppercase;
    font-size: 0.9em;
    transition: background-color 0.3s;
}

.profile-card button:hover {
    background-color: #5C4033;
}

.profile-card button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}