:root {
    --app-bg: #fdfbf7;
    --sidebar-bg: rgba(255, 248, 240, 0.95);
    --glass-border: rgba(214, 59, 29, 0.2);
    --text-primary: #8b0000;
    --text-secondary: #a05a5a;
    --accent-red: #d63b1d;
    --accent-gold: #ffb400;
    --accent-blue: #4a90e2;
    --accent-green: #27c93f;
    --accent-purple: #9b59b6;
    --accent-hover: #b32b12;
    --shadow-sm: 0 2px 8px rgba(139, 0, 0, 0.08);
    --shadow-md: 0 8px 24px rgba(139, 0, 0, 0.12);
    --shadow-lg: 0 20px 40px rgba(139, 0, 0, 0.15);
    --font-family: "Noto Serif SC", "ZCOOL XiaoWei", serif;
    --font-title: "Ma Shan Zheng", cursive;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.1) 0%, rgba(74, 144, 226, 0.1) 100%),
        linear-gradient(to bottom, #fef5e7, #ebf5fb);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 90vw;
    height: 85vh;
    max-width: 1400px;
    background: rgba(255, 252, 245, 0.92);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    overflow: hidden;
}

.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1rem;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.window-controls {
    display: flex;
    gap: 8px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.red {
    background: #ff5f56;
    border: 1px solid #e0443e;
}

.dot.yellow {
    background: #ffbd2e;
    border: 1px solid #dea123;
}

.dot.green {
    background: #27c93f;
    border: 1px solid #1aab29;
}

h1 {
    font-family: var(--font-title);
    font-size: 1.7rem;
    font-weight: 400;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: -5px;
}

.highlight {
    color: var(--accent-red);
}

.controls-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-grow: 1;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group.hidden,
.hidden {
    display: none;
}

label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.mode-tab {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(214, 59, 29, 0.3);
    background: #fff;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-tab:hover {
    background: rgba(214, 59, 29, 0.05);
    border-color: var(--accent-red);
}

.mode-tab.active {
    background: var(--accent-red);
    color: #fff;
    border-color: var(--accent-red);
}

.apple-select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--accent-red);
    background: #fff;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.apple-select:hover {
    border-color: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

.apple-select:focus {
    outline: none;
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(214, 59, 29, 0.1);
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.slider-label {
    font-size: 0.8rem;
    color: var(--text-primary);
    font-weight: 500;
}

.slider-label span {
    color: var(--accent-red);
    font-weight: 700;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 18px;
    width: 18px;
    border-radius: 50%;
    background: var(--accent-red);
    cursor: pointer;
    margin-top: -7px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border: 2px solid #fff;
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(214, 59, 29, 0.2);
    border-radius: 2px;
}

.info-panel {
    background: rgba(255, 255, 255, 0.7);
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(214, 59, 29, 0.15);
}

.info-panel h3 {
    font-size: 0.95rem;
    color: var(--accent-red);
    margin-bottom: 6px;
    font-weight: 700;
}

.info-panel p {
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
    margin-bottom: 4px;
}

.info-panel p:last-child {
    margin-bottom: 0;
}

.political-text {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.8rem !important;
}

.result-panel {
    background: rgba(255, 255, 255, 0.7);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(214, 59, 29, 0.15);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
}

.result-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.result-value {
    font-size: 1.1rem;
    color: var(--accent-red);
    font-weight: 700;
}

.apple-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: var(--font-family);
    width: 100%;
}

.action-btn {
    background: linear-gradient(135deg, var(--accent-red) 0%, var(--accent-hover) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.action-btn:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.secondary-btn {
    background: #fff;
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
}

.secondary-btn:hover {
    background: rgba(214, 59, 29, 0.05);
}

.actions-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.visualizer-stage {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.glass-pane {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 2rem;
    position: relative;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.stage-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.stage-header h2 {
    font-size: 1.8rem;
    color: var(--accent-red);
    margin-bottom: 0.5rem;
    font-family: var(--font-title);
}

.stage-header p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.visualization-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    padding: 1rem;
}

/* 素数网格 */
.number-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

.number-card {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid;
    position: relative;
}

.number-card.prime {
    background: linear-gradient(135deg, #d63b1d 0%, #b32b12 100%);
    color: #fff;
    border-color: #8b0000;
    box-shadow: 0 4px 12px rgba(214, 59, 29, 0.3);
}

.number-card.composite {
    background: #ecf0f1;
    color: #7f8c8d;
    border-color: #bdc3c7;
}

.number-card:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: var(--shadow-lg);
}

.card-number {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.card-label {
    font-size: 0.7rem;
    text-align: center;
    line-height: 1.2;
    opacity: 0.9;
}

/* GCD可视化 */
.gcd-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: center;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.number-box {
    background: rgba(255, 255, 255, 0.8);
    border-radius: 16px;
    padding: 2rem;
    border: 2px solid var(--accent-blue);
    width: 100%;
}

.number-box h3 {
    font-size: 1.5rem;
    color: var(--accent-blue);
    margin-bottom: 1rem;
    text-align: center;
}

.factors-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.factor-badge {
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--accent-blue);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
}

.factor-badge.common {
    background: var(--accent-red);
    animation: pulse 1.5s ease infinite;
}

.gcd-result {
    background: linear-gradient(135deg, var(--accent-red) 0%, var(--accent-hover) 100%);
    color: #fff;
    padding: 2rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.gcd-result h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.gcd-value {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.gcd-explanation {
    font-size: 0.95rem;
    opacity: 0.95;
}

.legend-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(214, 59, 29, 0.2);
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.legend-color {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(214, 59, 29, 0.7);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(214, 59, 29, 0);
    }
}

.number-card {
    animation: fadeIn 0.3s ease forwards;
    opacity: 0;
}

@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        width: 95vw;
        height: 95vh;
    }

    .sidebar {
        width: 100%;
        max-height: 45vh;
    }

    .number-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }
}