/* Democracy 4 inspired color palette */
:root {
    /* Background colors */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #404040;
    
    /* Text colors */
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #888888;
    
    /* Status colors */
    --positive: #4ade80;
    --negative: #f87171;
    --neutral: #60a5fa;
    --warning: #fbbf24;
    
    /* Node colors */
    --economy: #3b82f6;
    --welfare: #10b981;
    --law-order: #ef4444;
    --education: #8b5cf6;
    --health: #06b6d4;
    --transport: #f59e0b;
    
    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#app {
    width: 100%;
    height: 100vh;
    position: relative;
}

/* Start Screen */
#start-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
}

#start-screen h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#start-screen p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

#start-game-btn {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    background: var(--economy);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#start-game-btn:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Main Game */
#main-game {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Bar */
#top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 1000;
}

.budget-info {
    display: flex;
    gap: 2rem;
}

.budget-info span {
    font-weight: 600;
    font-size: 0.9rem;
}

.turn-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.top-buttons {
    display: flex;
    gap: 1rem;
}

.top-buttons button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

.top-buttons button:hover {
    background: var(--economy);
    transform: scale(1.1);
}

/* Radial Canvas */
#radial-canvas {
    flex: 1;
    margin-top: 80px;
    position: relative;
    background: radial-gradient(circle at center, rgba(59, 130, 246, 0.1) 0%, transparent 50%);
}

.force-graph {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}

.force-graph.is-panning {
    cursor: grabbing;
}

.force-link {
    pointer-events: none;
}

.force-node text {
    pointer-events: none;
    user-select: none;
}

.force-node-circle {
    transition: filter 0.2s ease, stroke-width 0.2s ease;
}

.force-node-ring {
    transition: stroke-opacity 0.2s ease, stroke-width 0.2s ease;
}

.force-node-type-badge-bg {
    transition: transform 0.2s ease, filter 0.2s ease;
}

.force-node-type-badge-label {
    pointer-events: none;
    user-select: none;
}

.force-node:hover .force-node-circle {
    filter: brightness(1.2);
}

.policy-force-node:hover .force-node-ring {
    stroke-opacity: 1;
}

.metric-force-node:hover .force-node-ring {
    stroke-opacity: 0.75;
}

.policy-force-node:hover .force-node-type-badge-bg,
.metric-force-node:hover .force-node-type-badge-bg {
    filter: brightness(1.12);
}

/* Metric Nodes - Smaller, distinct styling in center */
.metric-node {
    position: absolute;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 2px solid var(--economy);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.7rem;
    text-align: center;
    z-index: 10;
}

.metric-node:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}

.metric-icon {
    font-size: 1rem;
    margin-bottom: 0.1rem;
}

.metric-value {
    font-weight: bold;
    font-size: 0.6rem;
    color: var(--text-primary);
}

.metric-label {
    font-size: 0.5rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

/* Policy Nodes */
.policy-node {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 3px solid var(--economy);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    text-align: center;
}

.policy-node:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.policy-node .icon {
    font-size: 1.5rem;
    margin-bottom: 0.2rem;
}

.policy-node .label {
    font-weight: 600;
}

/* Modal */
#policy-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#charts-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2200;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 2rem;
    width: 400px;
    backdrop-filter: blur(10px);
}

.charts-modal-content {
    width: min(980px, 92vw);
    max-height: 90vh;
    height: min(760px, 90vh);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at top right, rgba(96, 165, 250, 0.12), transparent 46%),
        radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.1), transparent 42%),
        var(--bg-secondary);
}

.charts-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

#charts-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.1rem;
    min-height: 0;
    flex: 1;
}

.chart-panel {
    background:
        linear-gradient(170deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
        var(--bg-primary);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 8px 22px rgba(0, 0, 0, 0.22);
    display: grid;
    grid-template-rows: auto minmax(240px, 280px) minmax(0, 1fr);
    min-height: 0;
}

.chart-panel h4 {
    color: var(--neutral);
    margin-bottom: 0.3rem;
    letter-spacing: 0.03em;
}

.pie-chart {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    height: 100%;
    background: radial-gradient(circle at center, rgba(96, 165, 250, 0.08), transparent 62%);
    border-radius: 10px;
    border: 1px dashed rgba(255, 255, 255, 0.08);
    margin-bottom: 0.55rem;
    overflow: hidden;
}

.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 0.38rem;
    overflow-y: auto;
    min-height: 0;
    height: 100%;
    padding-right: 0.25rem;
}

.legend-item {
    display: grid;
    grid-template-columns: 12px 1fr auto auto;
    gap: 0.55rem;
    align-items: center;
    font-size: 0.79rem;
    padding: 0.32rem 0.42rem;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.legend-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.16);
}

.legend-item.is-active {
    background: rgba(96, 165, 250, 0.18);
    border-color: rgba(96, 165, 250, 0.45);
    transform: translateX(2px);
}

.chart-legend::-webkit-scrollbar {
    width: 10px;
}

.chart-legend::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 999px;
}

.chart-legend::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(96, 165, 250, 0.75), rgba(59, 130, 246, 0.75));
    border-radius: 999px;
    border: 2px solid rgba(26, 26, 26, 0.45);
}

.chart-legend::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(125, 189, 255, 0.9), rgba(77, 146, 255, 0.9));
}

.chart-legend {
    scrollbar-width: thin;
    scrollbar-color: rgba(96, 165, 250, 0.8) rgba(255, 255, 255, 0.05);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.legend-label {
    color: var(--text-secondary);
}

.legend-value {
    color: var(--text-primary);
    font-weight: 600;
}

.legend-percent {
    color: var(--neutral);
}

.chart-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    margin: 0.8rem 0;
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--economy);
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.preview-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
}

.preview-section h4 {
    margin-bottom: 0.5rem;
    color: var(--neutral);
    font-size: 0.9rem;
}

.preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.preview-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}

.preview-item span:first-child {
    color: var(--text-secondary);
}

.preview-item span:last-child {
    color: var(--text-primary);
    font-weight: 600;
}

.slider-container {
    margin-bottom: 2rem;
}

.slider-container label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

#policy-slider {
    width: 100%;
    margin-bottom: 0.5rem;
}

#slider-value {
    color: var(--economy);
    font-weight: bold;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.modal-buttons button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

#apply-btn {
    background: var(--positive);
    color: white;
}

#apply-btn:hover {
    background: #22c55e;
}

#cancel-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

#cancel-btn:hover {
    background: var(--negative);
}

/* Tooltip styling */
.tooltip {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.8rem;
    z-index: 3000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 200px;
}

.metric-tooltip {
    border-color: var(--economy);
}

.policy-tooltip {
    border-color: var(--welfare);
}

.physics-panel {
    position: fixed;
    top: 90px;
    right: 16px;
    width: 260px;
    background: rgba(26, 26, 26, 0.94);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.85rem;
    z-index: 2500;
    display: none;
    flex-direction: column;
    gap: 0.35rem;
    backdrop-filter: blur(8px);
}

.physics-panel-header {
    margin-bottom: 0.3rem;
    color: var(--text-primary);
}

.physics-panel label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.physics-panel input[type="range"] {
    width: 100%;
    margin-bottom: 0.2rem;
}

.physics-panel input[type="checkbox"] {
    margin: 0 0 0.3rem 0;
    accent-color: var(--economy);
}

#phys-reset-btn {
    margin-top: 0.4rem;
    border: 1px solid var(--glass-border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
    cursor: pointer;
}

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