:root {
    --primary-red: #D32F2F;
    --accent-gold: #FFC107;
    --bg-cream: #FFF8E1;
    --text-dark: #212121;
    --text-light: #FFFFFF;
    --festive-red: #C62828;
    --light-gold: #FFD54F;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: linear-gradient(135deg, var(--primary-red) 0%, #B71C1C 50%, #8E0000 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    min-height: 100vh;
    color: var(--text-dark);
    position: relative;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 背景装饰 - 漂浮的金币 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(255, 193, 7, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(255, 193, 7, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 193, 7, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

header {
    text-align: center;
    padding: 1.5rem 1rem 1rem;
    color: var(--text-light);
    position: relative;
    z-index: 1;
}

/* 标题装饰 */
header::before {
    content: '🏮 🧧 🏮';
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    animation: swing 2s ease-in-out infinite;
    transform-origin: top center;
}

@keyframes swing {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

header h1 {
    font-size: 1.8rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.4), 0 0 20px rgba(255,193,7,0.5);
    background: linear-gradient(to bottom, #FFD54F, #FFC107);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
}

header .subtitle {
    font-size: 0.95rem;
    opacity: 0.95;
    font-weight: 500;
    color: var(--light-gold);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

#app {
    max-width: 500px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

main {
    background: var(--bg-cream);
    border-radius: 24px 24px 0 0;
    padding: 1.25rem;
    min-height: calc(100vh - 100px);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    position: relative;
}

/* 顶部装饰条 */
main::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: repeating-linear-gradient(
        90deg,
        var(--accent-gold) 0px,
        var(--accent-gold) 20px,
        var(--festive-red) 20px,
        var(--festive-red) 40px
    );
    border-radius: 24px 24px 0 0;
}

/* Path display */
.path-display {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 1rem 0.75rem;
    background: linear-gradient(135deg, #fff 0%, #fff5e6 100%);
    border-radius: 16px;
    margin-bottom: 1rem;
    min-height: 56px;
    border: 2px solid rgba(211, 47, 47, 0.2);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.path-item {
    padding: 0.4rem 0.9rem;
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--festive-red) 100%);
    color: white;
    border-radius: 20px;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.3);
    animation: bounceIn 0.3s ease;
}

@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.path-item.self {
    background: linear-gradient(135deg, var(--accent-gold) 0%, #FFA000 100%);
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.4);
}

.path-arrow {
    color: var(--primary-red);
    font-size: 1.3rem;
    font-weight: bold;
}

/* Buttons container - 移动端优化 */
.buttons-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.relation-btn {
    padding: 1.1rem 0.5rem;
    background: linear-gradient(135deg, #ffffff 0%, #fff8e1 100%);
    border: 2px solid var(--primary-red);
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary-red);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

.relation-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(211, 47, 47, 0.1);
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
}

.relation-btn:active::before {
    width: 200px;
    height: 200px;
}

.relation-btn:hover {
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--festive-red) 100%);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.4);
}

.relation-btn:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 1px 4px rgba(211, 47, 47, 0.3);
}

/* Action buttons */
.actions {
    display: flex;
    gap: 0.65rem;
}

.action-btn {
    flex: 1;
    padding: 0.9rem;
    background: linear-gradient(135deg, #ffffff 0%, #f5f5f5 100%);
    border: 2px solid #ccc;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f0f0f0;
}

/* Result section */
.result-section {
    margin-top: 1.5rem;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-card {
    background: linear-gradient(135deg, #ffffff 0%, #fffef0 100%);
    border-radius: 20px;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    border: 2px solid rgba(211, 47, 47, 0.15);
    position: relative;
}

/* 结果卡片装饰 */
.result-card::before {
    content: '🎊';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    background: var(--bg-cream);
    padding: 0 8px;
    border-radius: 10px;
}

.result-card h2 {
    font-size: 0.95rem;
    color: #888;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.title-display {
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-red) 0%, #B71C1C 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0;
    text-shadow: 0 2px 4px rgba(211, 47, 47, 0.2);
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.generation-info {
    font-size: 1rem;
    color: #666;
    margin-bottom: 1rem;
    font-weight: 500;
}

.region-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: linear-gradient(135deg, rgba(255, 245, 224, 0.8) 0%, rgba(255, 238, 208, 0.8) 100%);
    border-radius: 12px;
    border: 1px solid rgba(211, 47, 47, 0.2);
}

#region-select {
    padding: 0.5rem 2rem 0.5rem 1rem;
    border: 2px solid var(--primary-red);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    background: white;
    cursor: pointer;
}

.note {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: rgba(255, 193, 7, 0.1);
    border-radius: 8px;
}

.new-search-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--festive-red) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(211, 47, 47, 0.3);
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.new-search-btn::after {
    content: '🧧';
    margin-left: 0.5rem;
}

.new-search-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(211, 47, 47, 0.4);
}

.new-search-btn:active {
    transform: translateY(0);
}

#tree-canvas {
    width: 100%;
    max-width: 280px;
    margin: 1rem auto 0.5rem;
    display: block;
}

/* 移动端优化 */
@media (max-width: 480px) {
    header {
        padding: 1.25rem 0.75rem 0.75rem;
    }

    header::before {
        font-size: 1.3rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    header .subtitle {
        font-size: 0.85rem;
    }

    main {
        padding: 1rem;
        border-radius: 20px 20px 0 0;
    }

    .path-display {
        padding: 0.85rem 0.5rem;
        min-height: 50px;
    }

    .path-item {
        padding: 0.35rem 0.75rem;
        font-size: 0.85rem;
    }

    .buttons-container {
        gap: 0.55rem;
        grid-template-columns: repeat(3, 1fr);
    }

    .relation-btn {
        padding: 0.9rem 0.25rem;
        font-size: 1rem;
    }

    .actions {
        gap: 0.55rem;
    }

    .action-btn {
        padding: 0.8rem;
        font-size: 0.9rem;
    }

    .title-display {
        font-size: 2rem;
    }

    .generation-info {
        font-size: 0.95rem;
    }

    .result-card {
        padding: 1.25rem;
    }

    .new-search-btn {
        font-size: 1rem;
        padding: 0.9rem;
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    header h1 {
        font-size: 1.3rem;
    }

    .title-display {
        font-size: 1.8rem;
    }

    .buttons-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.4rem;
    }

    .relation-btn {
        font-size: 0.9rem;
        padding: 0.8rem 0.2rem;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .relation-btn, .action-btn, .new-search-btn {
        min-height: 52px;
        min-width: 52px;
    }
}

/* iOS Safari优化 */
input {
    font-size: 16px;
}

/* 加载和错误提示 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(211, 47, 47, 0.3);
    border-radius: 50%;
    border-top-color: #D32F2F;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    background: linear-gradient(135deg, #FFEBEE 0%, #FFCDD2 100%);
    color: #D32F2F;
    padding: 1rem;
    border-radius: 12px;
    margin-top: 1rem;
    text-align: center;
    font-weight: 500;
    border: 2px solid #FFCDD2;
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.2);
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
