* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    line-height: 1.6;
    color: #1a1a1a;
    background: #fefcf8;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 40px;
}

.header {
    text-align: center;
    background: none;
    padding: 0;
    margin-bottom: 80px;
}

.header h1 {
    color: #000;
    margin-bottom: 20px;
    font-size: 3em;
    font-weight: 300;
    letter-spacing: -0.02em;
}

.header h2 {
    color: #999;
    font-size: 1.1em;
    font-weight: 400;
    margin-bottom: 8px;
}

.header p {
    color: #666;
    font-size: 1.1em;
    margin-bottom: 40px;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 60px;
    flex-wrap: wrap;
}

.stat {
    text-align: center;
    padding: 0;
    background: none;
    border-radius: 0;
    min-width: 120px;
}

.stat-number {
    font-size: 2.5em;
    font-weight: 200;
    color: #000;
    display: block;
    line-height: 1;
}

.stat-label {
    color: #999;
    font-size: 0.9em;
    margin-top: 8px;
    font-weight: 400;
}

.search-section {
    background: none;
    backdrop-filter: none;
    border: 1px solid #e5e5e5;
    border-radius: 0;
    padding: 40px;
    margin-bottom: 60px;
    box-shadow: none;
    transition: all 0.3s ease;
}

.search-section.collapsed {
    padding: 20px 40px;
    cursor: pointer;
}

.search-section.collapsed:hover {
    background: #fafafa;
}

.search-section.collapsed .search-form {
    display: none;
}

.search-section.collapsed .search-header {
    margin-bottom: 0;
}

.search-toggle {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 0.9em;
    padding: 5px 5px 5px 20px;
    border-radius: 0;
    transition: color 0.2s ease;
    position: relative;
}

.search-toggle::before {
    content: '';
    position: absolute;
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid #999;
    transition: all 0.2s ease;
}

.search-toggle:hover {
    color: #000;
}

.search-toggle:hover::before {
    border-bottom-color: #000;
}

.search-section.collapsed .search-toggle::before {
    border-bottom: none;
    border-top: 6px solid #999;
}

.search-section.collapsed .search-toggle:hover::before {
    border-top-color: #000;
}

.search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    padding: 8px;
    margin: -8px -8px 16px -8px;
    border-radius: 4px;
}

.search-header:hover {
    background: #f8f6f2;
}

.search-section h2 {
    color: #000;
    margin: 0;
    text-align: left;
    font-size: 1.5em;
    font-weight: 400;
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.search-form p {
    margin: 0 0 8px 0;
    font-weight: 500;
    color: #555;
    position: relative;
}

.search-help {
    display: inline-block;
    margin-left: 8px;
    padding: 6px 10px;
    background: #f5f5f5;
    color: #666;
    border: 1px solid #e0e0e0;
    border-radius: 0;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-help:hover {
    background: #e0e0e0;
    color: #333;
}


.search-form > div:has(small) {
    margin-top: -8px;
}

.search-row {
    display: flex;
    gap: 15px;
    align-items: start; /* 改为顶部对齐，避免底部提示文字影响对齐 */
    flex-wrap: wrap;
}

/* 朝代和年份筛选行的特殊对齐 */
.search-row:has(#dynastySelect) {
    align-items: end; /* 底部对齐，让输入框在同一水平线上 */
}

.search-row:has(#dynastySelect) .form-group {
    flex: 1;
    min-width: 160px;
}

.search-row:has(#dynastySelect) .form-group label {
    margin-bottom: 8px;
    white-space: nowrap;
}

.name-input {
    flex: 1;
    min-width: 300px;
}

.alias-checkbox {
    min-width: 200px;
    display: flex;
    align-items: center;
}

.name-input .form-group {
    flex-direction: row; /* 让标签和输入框水平排列 */
    align-items: center; /* 垂直居中对齐 */
    gap: 10px; /* 标签和输入框之间的间距 */
}

.name-input label {
    margin-bottom: 0; /* 移除下边距 */
    white-space: nowrap; /* 防止标签换行 */
    min-width: auto; /* 让标签占据自然宽度 */
}

.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0; /* 防止flex item收缩问题 */
}

.dynasty-row {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.dynasty-title {
    font-weight: 500;
    color: #555;
    margin: 0;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #555;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 16px 0;
    border: none;
    border-bottom: 1px solid #e5e5e5;
    border-radius: 0;
    font-size: 16px;
    background: transparent;
    transition: border-color 0.3s ease;
    position: relative;
    overflow: hidden;
}


.form-group input.spotlight-animation {
    animation: spotlightSweep 2s ease-out;
}

@keyframes spotlightSweep {
    0% {
        border-bottom-color: #e5e5e5;
    }
    10% {
        border-bottom-color: #000;
    }
    20% {
        border-bottom-color: #999;
    }
    30% {
        border-bottom-color: #000;
    }
    40% {
        border-bottom-color: #e5e5e5;
    }
    50% {
        border-bottom-color: #000;
    }
    60% {
        border-bottom-color: #999;
    }
    70% {
        border-bottom-color: #000;
    }
    80% {
        border-bottom-color: #e5e5e5;
    }
    90% {
        border-bottom-color: #000;
    }
    100% {
        border-bottom-color: #e5e5e5;
    }
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-bottom-color: #000;
}

.search-button {
    padding: 16px 40px;
    background: #000;
    color: white;
    border: none;
    border-radius: 0;
    font-size: 16px;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 160px;
    align-self: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0;
    margin-bottom: 4px;
}

.search-button:hover {
    background: #333;
    transform: none;
    box-shadow: none;
}

.search-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.results-section {
    background: none;
    backdrop-filter: none;
    border-radius: 0;
    padding: 40px 0 0 0;
    border-top: 1px solid #f0f0f0;
    box-shadow: none;
    display: none;
    margin-top: 40px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.results-count {
    color: #666;
}

.pagination {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pagination button {
    padding: 8px 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination button:hover:not(:disabled) {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.person-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.person-card {
    border: 1px solid #e1e5e9;
    border-radius: 10px;
    padding: 20px;
    background: white;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    position: relative;
    display: block;
    text-decoration: none;
    color: inherit;
}

.person-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.person-name {
    font-size: 1.3em;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 10px;
}

.person-name-chn {
    color: #e74c3c;
    margin-left: 10px;
}

.person-info {
    color: #666;
    margin-bottom: 8px;
}

.person-dynasty {
    display: inline-block;
    background: linear-gradient(135deg, #f39c12, #e67e22);
    color: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    margin-top: 10px;
}

.person-id {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: 500;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.loading-dots {
    display: inline-block;
    width: 20px;
    text-align: left;
}

@keyframes loadingDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

.loading-dots::after {
    content: '';
    animation: loadingDots 1.5s infinite;
}

.error {
    text-align: center;
    padding: 40px;
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    border-radius: 10px;
    margin: 20px 0;
}

.person-detail {
    display: none;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 30px;
    margin-top: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.person-detail h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #3498db;
}

.detail-sections-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 25px;
    margin-bottom: 25px;
}

.detail-section {
    margin-bottom: 0;
}

/* 宽屏时三列布局 */
@media (min-width: 1200px) {
    .detail-sections-container {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 30px;
    }
}

/* 中等屏幕时两列布局 */
@media (min-width: 768px) and (max-width: 1199px) {
    .detail-sections-container {
        grid-template-columns: 1fr 1fr;
        gap: 25px;
    }
}

.detail-section h4 {
    color: #34495e;
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 1.1em;
    scroll-margin-top: 20px;
    position: relative;
}

.detail-sections-container .detail-section h4:first-child {
    margin-top: 0;
}

.detail-section h4 .anchor-link {
    color: #bdc3c7;
    text-decoration: none;
    margin-left: 8px;
    font-weight: normal;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.detail-section h4:hover .anchor-link {
    opacity: 1;
}

.detail-section h4 .anchor-link:hover {
    color: #3498db;
}

.alternate-names {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.alt-name {
    background: rgba(52, 152, 219, 0.1);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    border: 1px solid rgba(52, 152, 219, 0.2);
}

.alt-name-type {
    color: #3498db;
    font-weight: 500;
}

.back-button {
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 20px;
    transition: transform 0.2s ease;
    font-size: 16px;
    font-weight: 500;
}

.back-button:hover {
    transform: translateY(-2px);
}

.footer {
    background: none;
    backdrop-filter: none;
    border: 1px solid #e5e5e5;
    border-radius: 0;
    padding: 40px;
    margin-top: 60px;
    text-align: center;
    box-shadow: none;
    color: #666;
    font-size: 0.9em;
    line-height: 1.8;
}

.footer a {
    color: #3498db;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

.footer a[style*="color: #888"] {
    text-decoration: underline;
}

.footer a[style*="color: #888"]:hover {
    text-decoration: underline;
}

.dynasty-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    font-weight: normal;
    margin: 0;
    padding: 12px 14px; /* 增加上下内边距以匹配其他输入框 */
    border: 2px solid #e1e5e9; /* 匹配其他输入框的边框宽度 */
    border-radius: 8px; /* 匹配其他输入框的圆角 */
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fefcf8;
    font-size: 16px; /* 匹配其他输入框的字体大小 */
    white-space: nowrap;
    height: 48px; /* 设置固定高度以匹配其他输入框 */
    box-sizing: border-box;
}

.checkbox-label:hover {
    background: rgba(100, 100, 100, 0.05);
    border-color: #666;
}

.checkbox-label:focus-within {
    border-color: #666;
}

.checkbox-label input[type="checkbox"] {
    margin: 0 8px 0 0;
    width: 16px;
    height: 16px;
    accent-color: #666;
    vertical-align: middle;
    flex-shrink: 0;
    filter: sepia(0.1) saturate(0.8) brightness(0.98);
}

.checkbox-label:has(input[type="checkbox"]:checked) {
    background: #666;
    color: white;
    border-color: #666;
    font-weight: 500;
}

.checkbox-label:has(input[type="checkbox"]:checked):hover {
    background: #555;
    border-color: #555;
}

/* 大屏幕时的布局调整 */
@media (min-width: 769px) {
    .search-row {
        align-items: end;
    }

    .alias-checkbox {
        flex-shrink: 0;
    }

    .search-button {
        flex-shrink: 0;
    }
}

/* 中等屏幕时的布局调整 */
@media (min-width: 769px) and (max-width: 1024px) {
    .alias-checkbox {
        min-width: 180px;
    }

    .search-button {
        min-width: 100px;
    }
}

.kinship-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: #3498db !important;
}

@media (max-width: 768px) {
    .container {
        padding: 40px 20px;
    }

    .header {
        margin-bottom: 60px;
    }

    .header h1 {
        font-size: 2.2em;
    }

    .search-row {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    /* 移动端保持朝代和年份的对齐 */
    .search-row:has(#dynastySelect) {
        align-items: stretch;
    }

    /* 在小屏幕上确保表单元素有一致的间距 */
    .form-group {
        margin-bottom: 0;
    }

    .name-input,
    .alias-checkbox {
        min-width: unset;
        width: 100%;
    }

    .alias-checkbox .checkbox-label {
        width: 100%;
        justify-content: flex-start;
    }

    .search-button {
        align-self: stretch;
        margin-top: 0;
    }

    .back-button {
        font-size: 18px;
        padding: 14px 24px;
        margin-bottom: 24px;
    }

    .stats {
        display: none;
    }

    .stat {
        background: none;
        padding: 5px;
        min-width: auto;
    }

    .stat-number {
        font-size: 1em;
        font-weight: normal;
        color: #666;
        display: inline;
    }

    .stat-label {
        font-size: 1em;
        color: #666;
        margin-top: 0;
        margin-left: 0;
    }

    .stat-number::after {
        content: " ";
    }

    .header h1 a {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }

    .title-separator {
        display: none;
    }

    .title-part:first-of-type::after {
        content: "\A";
        white-space: pre;
    }

    .header h2 {
        display: none;
    }

    .results-header {
        flex-direction: column;
        align-items: stretch;
    }

    .pagination {
        justify-content: center;
        flex-wrap: wrap;
    }

    .pagination button {
        padding: 6px 12px;
        font-size: 0.9em;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }

    .results-count {
        text-align: center;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .dynasty-checkboxes {
        justify-content: center;
    }
}

/* 通用响应式表格样式 */
@media (max-width: 768px) {
    /* 所有表格的通用响应式处理 */
    .detail-section table,
    .detail-section thead,
    .detail-section tbody,
    .detail-section th,
    .detail-section td,
    .detail-section tr {
        display: block;
    }

    .detail-section thead {
        display: none;
    }

    .detail-section tr {
        border: 1px solid #e1e5e9 !important;
        margin-bottom: 15px !important;
        padding: 0 !important;
        border-radius: 8px !important;
        overflow: hidden;
        background: #fff;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .detail-section td {
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        padding: 12px !important;
        text-align: left !important;
        position: relative;
        padding-left: 35% !important;
        min-height: 40px;
        display: flex;
        align-items: center;
        max-width: none !important;
        width: 100% !important;
    }

    .detail-section td:last-child {
        border-bottom: none !important;
    }

    /* 使用伪元素显示列标题 */
    .detail-section td::before {
        content: attr(data-label) ": ";
        position: absolute;
        left: 6px;
        top: 12px;
        width: 30%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: 600;
        color: #2c3e50;
        font-size: 0.9em;
    }

    .detail-section td > div,
    .detail-section td > span:not([style*="display: inline-block"]) {
        width: 100%;
    }

    /* 保持inline-block span的自然宽度 */
    .detail-section td > span[style*="display: inline-block"] {
        width: auto;
        flex-shrink: 0;
    }

    /* 特殊处理行政层级的缩进 */
    .detail-section td div[style*="margin-left"] {
        margin-left: 0 !important;
    }

    .detail-section td div[style*="margin-left: 8px"] {
        padding-left: 8px;
    }

    .detail-section td div[style*="margin-left: 16px"] {
        padding-left: 16px;
    }

    .detail-section td div[style*="margin-left: 24px"] {
        padding-left: 24px;
    }

    .detail-section td div[style*="margin-left: 32px"] {
        padding-left: 32px;
    }

    /* 社会关系表格内的子表格也需要处理 */
    .associations-list table,
    .associations-list thead,
    .associations-list tbody,
    .associations-list th,
    .associations-list td,
    .associations-list tr {
        display: block;
    }

    .associations-list thead {
        display: none;
    }

    .associations-list tr {
        border: 1px solid #e1e5e9 !important;
        margin-bottom: 10px !important;
        padding: 0 !important;
        border-radius: 6px !important;
        overflow: hidden;
        background: #fff;
    }

    .associations-list td {
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        padding: 10px !important;
        text-align: left !important;
        position: relative;
        padding-left: 35% !important;
        min-height: 35px;
        display: flex;
        align-items: center;
    }

    .associations-list td:last-child {
        border-bottom: none !important;
    }

    .associations-list td::before {
        content: attr(data-label) ": ";
        position: absolute;
        left: 6px;
        top: 10px;
        width: 30%;
        padding-right: 8px;
        white-space: nowrap;
        font-weight: 600;
        color: #2c3e50;
        font-size: 0.85em;
    }
}

/* About page specific styles */
.about-content {
    background: none;
    backdrop-filter: none;
    border: 1px solid #e5e5e5;
    border-radius: 0;
    padding: 40px;
    margin-bottom: 60px;
    box-shadow: none;
    transition: all 0.3s ease;
}

.about-content h2 {
    color: #000;
    font-size: 1.6em;
    margin: 30px 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e5e5;
    font-weight: 400;
}

.about-content h2:first-child {
    margin-top: 0;
}

.about-content h3 {
    color: #333;
    font-size: 1.3em;
    margin: 30px 0 15px 0;
    font-weight: 500;
}

.about-content p {
    margin-bottom: 20px;
    font-size: 1.05em;
    text-align: justify;
    line-height: 1.7;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 25px 0;
}

.stat-item {
    text-align: center;
    padding: 0;
    background: none;
    border-radius: 0;
    border: none;
}

.stat-item .stat-number {
    font-size: 2.5em;
    font-weight: 200;
    color: #000;
    display: block;
    line-height: 1;
}

.stat-item .stat-label {
    color: #999;
    font-size: 0.9em;
    margin-top: 8px;
    font-weight: 400;
}

.features-list {
    list-style: none;
    padding: 0;
}

.features-list li {
    padding: 12px 0;
    border-bottom: 1px solid #ecf0f1;
    position: relative;
    padding-left: 25px;
}

.features-list li:before {
    content: "✓";
    position: absolute;
    left: 0;
    color: #27ae60;
    font-weight: bold;
}

.features-list li:last-child {
    border-bottom: none;
}

/* About page mobile styles */
@media (max-width: 768px) {
    .about-content {
        padding: 30px 20px;
        margin: 0 0 40px 0;
    }

    .about-content h2 {
        font-size: 1.4em;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .stat-item .stat-number {
        font-size: 1.5em;
    }

    /* Footer links mobile layout: 3 links on first row, 2 on second row */
    .footer-links .break-after::after {
        content: '\A';
        white-space: pre;
    }
}
