:root {
    /* Red Culture Theme */
    --app-bg: #fdfbf7;
    --sidebar-bg: rgba(255, 248, 240, 0.8);
    --glass-border: rgba(214, 59, 29, 0.2);
    --text-primary: #8b0000;
    --text-secondary: #a05a5a;
    --accent-red: #d63b1d;
    --accent-gold: #ffb400;
    --accent-hover: #b32b12;
    --danger-red: #ff3b30;
    --construct-green: #10b981;

    /* Key Generation Colors */
    --color-generated: #10b981;
    --color-current: #4ecdc4;
    --color-unused: #e0e0e0;
    --color-security-high: #10b981;
    --color-security-med: #ffb400;
    --color-security-low: #ff6b6b;

    --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", "Outfit", serif;
    --font-title: "Ma Shan Zheng", cursive;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--app-bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: url('https://images.unsplash.com/photo-1533038590840-1cde6e668a91?q=80&w=2574&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
}

.app-container {
    width: 90vw;
    height: 85vh;
    max-width: 1400px;
    background: rgba(255, 252, 245, 0.85);
    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: 350px;
    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: 0.5rem;
    margin-bottom: 0.3rem;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

.dot.red {
    background: linear-gradient(135deg, #ff5f57, #ff3b30);
}

.dot.yellow {
    background: linear-gradient(135deg, #ffbd2e, #ffaa00);
}

.dot.green {
    background: linear-gradient(135deg, #28ca42, #27c93f);
}

h1 {
    font-family: var(--font-title);
    font-size: 1.6rem;
    color: var(--text-primary);
    letter-spacing: 1px;
    line-height: 1.3;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
}

.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;
}

label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
}

/* Prime Panel */
.prime-panel {
    background: rgba(255, 255, 255, 0.5);
    padding: 12px;
    border-radius: 12px;
}

.apple-select {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(139, 0, 0, 0.2);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    margin-bottom: 10px;
}

.apple-select:focus {
    outline: none;
    border-color: var(--accent-red);
}

.prime-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prime-info p {
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
}

.prime-info span {
    color: var(--accent-red);
    font-weight: 600;
}

/* Generator Panel */
.generator-panel {
    background: rgba(255, 255, 255, 0.5);
    padding: 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.generator-display {
    background: rgba(255, 180, 0, 0.15);
    padding: 12px;
    border-radius: 8px;
    border: 2px solid var(--accent-gold);
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.gen-symbol {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.gen-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-gold);
    font-family: 'Outfit', sans-serif;
}

.gen-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
}

/* Key Control Panel */
.key-control-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.manual-input {
    display: flex;
    gap: 6px;
}

.manual-input-field {
    flex: 1;
    padding: 8px;
    border: 1px solid rgba(139, 0, 0, 0.2);
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: 0.85rem;
}

.manual-input-field:focus {
    outline: none;
    border-color: var(--accent-red);
}

/* Stats Panel */
.stats-panel {
    background: rgba(255, 255, 255, 0.5);
    padding: 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: 700;
    color: var(--accent-red);
    font-size: 0.95rem;
}

.stat-value.success {
    color: var(--construct-green);
}

/* Info Box */
.info-box {
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.05), rgba(255, 180, 0, 0.05));
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(214, 59, 29, 0.2);
}

.info-box h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--accent-red);
}

.info-box p {
    font-size: 0.8rem;
    line-height: 1.5;
    margin-bottom: 0.4rem;
}

/* Actions Footer */
.actions-footer {
    display: flex;
    gap: 0.75rem;
}

.apple-btn {
    flex: 1;
    padding: 0.7rem;
    border: none;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-family);
}

.action-btn {
    background: var(--accent-red);
    color: #fff;
}

.action-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
    border: 1px solid rgba(139, 0, 0, 0.2);
}

.secondary-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 1);
    border-color: var(--accent-red);
}

.construct-btn {
    background: var(--construct-green);
    color: #fff;
}

.construct-btn:hover:not(:disabled) {
    background: #0d9668;
}

.danger-btn {
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger-red);
    border: 1px solid var(--danger-red);
}

.danger-btn:hover {
    background: var(--danger-red);
    color: #fff;
}

.apple-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Visualizer Stage */
.visualizer-stage {
    flex-grow: 1;
    padding: 2rem;
    display: flex;
    background: rgba(255, 255, 255, 0.1);
    overflow-y: auto;
}

.glass-pane {
    width: 100%;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.2rem;
}

.graph-title {
    text-align: center;
}

.graph-title h2 {
    font-family: var(--font-title);
    font-size: 1.8rem;
    color: var(--accent-red);
}

.graph-title p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Quote Banner */
.quote-banner {
    background: linear-gradient(90deg, rgba(214, 59, 29, 0.1), transparent);
    border-left: 3px solid var(--accent-red);
    padding: 12px 15px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.quote-icon {
    font-size: 1.5rem;
}

.quote-text {
    font-family: var(--font-title);
    font-size: 1rem;
    color: var(--text-primary);
    flex: 1;
}

.quote-author {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Visualization Container */
.visualization-container {
    display: flex;
    gap: 1.5rem;
    flex: 1;
}

.cycle-visualization {
    flex: 1;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 1rem;
    position: relative;
    display: flex;
    flex-direction: column;
}

#cycleSvg {
    flex: 1;
    min-height: 300px;
}

.cycle-legend {
    display: flex;
    gap: 1rem;
    justify-content: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    margin-top: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

/* Key List Panel */
.key-list-panel {
    width: 280px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.key-list-panel h4 {
    color: var(--accent-red);
    font-size: 0.95rem;
    margin-bottom: 10px;
    text-align: center;
}

.key-list-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.empty-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 20px;
}

.key-item {
    background: rgba(255, 255, 255, 0.7);
    padding: 8px 10px;
    border-radius: 6px;
    border-left: 3px solid var(--accent-gold);
    font-size: 0.8rem;
    animation: fadeIn 0.3s ease;
}

.key-item.new {
    background: var(--color-current);
    color: #fff;
    border-left-color: #fff;
    animation: pulse 0.6s ease;
}

.key-item strong {
    color: var(--accent-red);
    font-size: 0.9rem;
}

.key-item.new strong {
    color: #fff;
}

/* Computation Box */
.computation-box {
    background: linear-gradient(135deg, rgba(214, 59, 29, 0.08), rgba(255, 180, 0, 0.08));
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    padding: 1rem;
}

.computation-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.comp-icon {
    font-size: 1.2rem;
}

.computation-header h3 {
    color: var(--accent-red);
    font-family: var(--font-title);
    font-size: 1.2rem;
}

.computation-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.formula-display {
    background: rgba(255, 255, 255, 0.6);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.formula-text {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-red);
    font-family: 'Outfit', serif;
}

#computationSteps {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Security Box */
.security-box {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08), rgba(78, 205, 196, 0.08));
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 12px;
    padding: 1rem;
}

.security-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.red-star {
    color: var(--accent-red);
    font-size: 1.2rem;
}

.security-header h3 {
    color: var(--accent-red);
    font-family: var(--font-title);
    font-size: 1.2rem;
}

.security-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.metric-item {
    background: rgba(255, 255, 255, 0.5);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
}

.metric-item label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: none;
}

.metric-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.security-high {
    color: var(--color-security-high);
}

.security-med {
    color: var(--color-security-med);
}

.security-low {
    color: var(--color-security-low);
}

/* Ideology Box */
.ideology-content-box {
    background: linear-gradient(135deg, rgba(139, 0, 0, 0.05), rgba(255, 180, 0, 0.05));
    border: 1px solid rgba(214, 59, 29, 0.2);
    border-radius: 12px;
    padding: 1rem;
}

.ideology-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.ideology-header h3 {
    color: var(--accent-red);
    font-family: var(--font-title);
    font-size: 1.2rem;
}

.ideology-text p {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 10px;
}

.social-analogy {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(139, 0, 0, 0.1);
}

.social-analogy label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.social-analogy p {
    font-size: 0.85rem;
    line-height: 1.6;
}

/* Scrollbar */
.sidebar::-webkit-scrollbar,
.key-list-container::-webkit-scrollbar,
.visualizer-stage::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.key-list-container::-webkit-scrollbar-track,
.visualizer-stage::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar::-webkit-scrollbar-thumb,
.key-list-container::-webkit-scrollbar-thumb,
.visualizer-stage::-webkit-scrollbar-thumb {
    background: var(--accent-red);
    border-radius: 3px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes glow {

    0%,
    100% {
        filter: drop-shadow(0 0 5px currentColor);
    }

    50% {
        filter: drop-shadow(0 0 15px currentColor);
    }
}

.animated {
    animation: fadeIn 0.5s ease;
}

/* SVG Styles */
.key-node {
    cursor: pointer;
    transition: all 0.3s;
}

.key-node:hover circle {
    filter: brightness(1.1);
}

.key-label {
    font-size: 11px;
    fill: #fff;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
    font-weight: 600;
}