/*
 * Ancient Empires - Dawn of Civilization Style Sheet
 * High-fidelity glassmorphism, responsive HUD layouts, custom styling for tech trees and modal dialogs.
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Cinzel:wght@500;700;900&display=swap');

:root {
    --bg-main: #020617;
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-active: rgba(245, 158, 11, 0.4);
    --bg-glass: rgba(15, 23, 42, 0.7);
    --bg-glass-heavy: rgba(15, 23, 42, 0.92);
    --glow-amber: 0 0 15px rgba(245, 158, 11, 0.45);
    --glow-blue: 0 0 15px rgba(59, 130, 246, 0.4);
    --glow-red: 0 0 15px rgba(239, 68, 68, 0.4);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    /* Terrain Mini Colors */
    --c-water: #1d4ed8;
    --c-plains: #15803d;
    --c-forest: #14532d;
    --c-mountain: #64748b;
    --c-desert: #b45309;
    --c-swamp: #115e59;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

/* Canvas Styles */
#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* UI Overlay Container */
#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 320px 1fr 340px;
    grid-template-areas:
        "topbar topbar topbar"
        "leftpanel centerarea rightpanel"
        "bottombar bottombar bottombar";
}

.interactive {
    pointer-events: auto;
}

/* Glassmorphism Panel styles */
.glass-panel {
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.glass-panel-heavy {
    background: var(--bg-glass-heavy);
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.7);
}

.glass-panel:hover {
    border-color: rgba(255, 255, 255, 0.15);
}

/* Top bar resource panel */
#top-bar {
    grid-area: topbar;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: rgba(15, 23, 42, 0.85);
    border-bottom: 1px solid var(--border-glass);
    backdrop-filter: blur(8px);
    z-index: 12;
}

.title-container h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 900;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, #fef08a 0%, #eab308 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.resources-list {
    display: flex;
    gap: 16px;
    overflow-x: auto;
}

.res-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    min-width: 90px;
    transition: all 0.2s;
}

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

.res-item.food { color: #facc15; }
.res-item.wood { color: #4ade80; }
.res-item.stone { color: #94a3b8; }
.res-item.iron { color: #f97316; }
.res-item.gold { color: #f59e0b; }
.res-item.science { color: #3b82f6; }

.res-net {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.8;
    margin-left: 4px;
}

.res-net.pos { color: #22c55e; }
.res-net.neg { color: #ef4444; }

/* Left selection panel */
#left-panel {
    grid-area: leftpanel;
    margin: 16px 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 120px);
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-primary);
}

.panel-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
}

.panel-footer {
    padding: 16px;
    border-t: 1px solid var(--border-glass);
    background: rgba(255, 255, 255, 0.01);
}

/* Right HUD control stack */
#right-panel {
    grid-area: rightpanel;
    margin: 16px 16px 16px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 120px);
}

/* Minimap container */
.minimap-wrapper {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: 12px;
}

#minimapCanvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
}

/* Comms and logger panel */
.comms-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-log {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
}

.chat-msg {
    animation: slideIn 0.2s ease-out;
}

.chat-msg.system {
    color: #eab308;
    font-style: italic;
}

.chat-msg.combat {
    color: #f87171;
}

.chat-msg.diplomacy {
    color: #a855f7;
}

.chat-input-wrapper {
    display: flex;
    border-top: 1px solid var(--border-glass);
    background: rgba(0, 0, 0, 0.2);
}

#chat-input-field {
    flex-grow: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    padding: 12px;
    font-size: 0.85rem;
}

#chat-input-field::placeholder {
    color: #64748b;
}

.chat-send-btn {
    background: transparent;
    border: none;
    padding: 0 16px;
    color: #3b82f6;
    cursor: pointer;
    transition: color 0.2s;
}

.chat-send-btn:hover {
    color: #60a5fa;
}

/* Buttons and Controls */
.btn-primary {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.2);
    transition: all 0.2s;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(217, 119, 6, 0.35), var(--glow-amber);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    box-shadow: var(--glow-red);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* Modals System */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 900px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

/* Tech Tree Styling */
.tech-tree-container {
    padding: 24px;
    overflow: auto;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    background: radial-gradient(circle at 50% 50%, #0f172a 0%, #020617 100%);
    min-height: 450px;
}

.tech-epoch-col {
    display: flex;
    flex-direction: column;
    gap: 32px;
    min-width: 200px;
    align-items: center;
}

.tech-node {
    width: 170px;
    padding: 12px;
    background: rgba(30, 41, 59, 0.7);
    border: 2px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    position: relative;
    z-index: 2;
}

.tech-node.locked {
    opacity: 0.5;
    background: rgba(15, 23, 42, 0.5);
    cursor: not-allowed;
}

.tech-node.available {
    border-color: rgba(59, 130, 246, 0.4);
}

.tech-node.available:hover {
    border-color: rgba(59, 130, 246, 0.8);
    box-shadow: var(--glow-blue);
    transform: translateY(-2px);
}

.tech-node.researched {
    border-color: rgba(34, 197, 94, 0.6);
    background: rgba(20, 83, 45, 0.4);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.15);
}

.tech-node.researching {
    border-color: rgba(245, 158, 11, 0.8);
    animation: pulsateBorder 1.5s infinite;
}

.tech-node-title {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.tech-node-cost {
    font-size: 0.7rem;
    color: #60a5fa;
}

/* SVG Line Connections for Tech Nodes */
.tech-connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.tech-connection-line {
    fill: none;
    stroke: rgba(255,255,255,0.1);
    stroke-width: 2;
    stroke-dasharray: 4 4;
}

.tech-connection-line.researched {
    stroke: rgba(34, 197, 94, 0.5);
    stroke-width: 3;
    stroke-dasharray: none;
}

/* Diplomacy Interface */
.diplomacy-container {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 500px;
    overflow: hidden;
}

.diplomacy-list {
    border-right: 1px solid var(--border-glass);
    overflow-y: auto;
}

.diplomacy-bot-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    cursor: pointer;
    transition: background 0.2s;
}

.diplomacy-bot-item:hover, .diplomacy-bot-item.active {
    background: rgba(255, 255, 255, 0.04);
}

.bot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ccc;
    flex-shrink: 0;
}

.bot-info {
    overflow: hidden;
}

.bot-info h4 {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bot-info span {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.diplomacy-chat {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.1);
}

.diplomacy-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dip-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.dip-bubble.bot {
    background: rgba(255,255,255,0.06);
    border-top-left-radius: 2px;
    align-self: flex-start;
}

.dip-bubble.player {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-top-right-radius: 2px;
    align-self: flex-end;
}

.diplomacy-actions {
    padding: 16px 20px;
    border-top: 1px solid var(--border-glass);
    background: rgba(0,0,0,0.2);
    display: flex;
    gap: 12px;
}

/* Loading/Auth overlay screen */
#loading-screen {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, #0f172a 0%, #020617 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease-out;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.logo-large {
    font-family: 'Cinzel', serif;
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: 0.25em;
    background: linear-gradient(135deg, #fef08a 0%, #eab308 50%, #ca8a04 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 15px rgba(0,0,0,0.8);
    margin-bottom: 8px;
    animation: logoGlow 4s ease-in-out infinite alternate;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(245, 158, 11, 0.1);
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: rotateSpinner 1s linear infinite;
    margin-top: 24px;
}

.login-box {
    margin-top: 32px;
    padding: 24px;
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 2;
}

.login-box input {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px 16px;
    border-radius: 8px;
    color: #fff;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
}

.login-box input:focus {
    border-color: #f59e0b;
}

/* Animations declarations */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes rotateSpinner {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulsateBorder {
    0%, 100% { border-color: rgba(245, 158, 11, 0.6); }
    50% { border-color: rgba(245, 158, 11, 1); box-shadow: 0 0 10px rgba(245, 158, 11, 0.4); }
}

@keyframes logoGlow {
    from { filter: drop-shadow(0 0 5px rgba(234, 179, 8, 0.3)); }
    to { filter: drop-shadow(0 0 20px rgba(234, 179, 8, 0.7)); }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Layout adjustments */
#center-controls {
    grid-area: bottombar;
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 16px;
}

/* Utility layout aids */
.flex-row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.text-muted { color: var(--text-secondary); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.85rem; }
.text-md { font-size: 0.95rem; }
.text-lg { font-size: 1.1rem; }
.font-bold { font-weight: 600; }

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}
.w-full { width: 100%; }

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #3b82f6;
    width: 0%;
    transition: width 0.3s ease;
}

.border-pill {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Civic Tree Node Styling */
.tech-node.civic-node.researched {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.4) 0%, rgba(99, 102, 241, 0.25) 100%);
    border-color: #a78bfa;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.25);
}

.tech-node.civic-node.available {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(167, 139, 250, 0.4);
    cursor: pointer;
}

.tech-node.civic-node.available:hover {
    background: rgba(139, 92, 246, 0.25);
    border-color: rgba(167, 139, 250, 0.7);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.2);
}

.tech-node.civic-node.locked {
    background: rgba(15, 23, 42, 0.4);
    border-color: rgba(255, 255, 255, 0.05);
    opacity: 0.55;
    cursor: not-allowed;
}

.civic-node .tech-node-cost {
    color: #c084fc;
}

/* Worker Actions Layout */
.worker-action-btn {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.25);
    color: #93c5fd;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.worker-action-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: #60a5fa;
    color: #ffffff;
}

.worker-action-btn:active {
    transform: scale(0.96);
}

/* Achievements List Card Layout */
.achievement-card {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.3s;
}

.achievement-card.unlocked {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.3);
}

.achievement-icon {
    font-size: 1.8rem;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.03);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,0.06);
}

.achievement-card.unlocked .achievement-icon {
    background: rgba(34, 197,  green, 0.1);
    border-color: rgba(34, 197, 94, 0.4);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.2);
}

.achievement-details {
    flex: 1;
}

.achievement-details h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 2px;
    color: #f8fafc;
}

.achievement-details p {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Charts overlay styling */
.chart-container {
    margin-top: 16px;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 12px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

#statsChartCanvas {
    width: 100%;
    height: 120px;
    background: rgba(2, 6, 23, 0.4);
    border-radius: 6px;
    display: block;
}

/* Season & Disaster Toast Notifications */
.disaster-toast {
    position: fixed;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(220, 38, 38, 0.9);
    border: 1px solid #ef4444;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(220, 38, 38, 0.4);
    z-index: 9999;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideDownToast 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes slideDownToast {
    0% { top: 40px; opacity: 0; }
    100% { top: 90px; opacity: 1; }
}

.season-badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

