body {
    font-family: Calibri, sans-serif;
    background-color: #111827;
    color: white;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: row;
}

main {
    flex-grow: 1;
    position: relative;
}

#top-ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: flex-start;
    pointer-events: none;
    box-sizing: border-box;
    gap: 1rem;
}

#resource-display {
    background-color: rgba(23, 37, 51, 0.8);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    pointer-events: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    grid-column: 1 / 2;
    justify-self: start;
}

#scenario-panel {
    background-color: rgba(23, 37, 51, 0.8);
    border-radius: 0.5rem;
    padding: 1rem;
    pointer-events: auto;
    width: 300px;
    grid-column: 2 / 3;
    justify-self: center;
}

aside {
    width: 16rem;
    flex-shrink: 0;
    background-color: #1f2937;
    padding: 1rem;
    box-shadow: -5px 0 15px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#scenario-panel h2 {
    font-size: 1.25rem;
    margin-top: 0;
    text-align: center;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

#scenario-toggle-icon {
    transition: transform 0.2s ease-in-out;
}

#objectives-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    transition: all 0.3s ease-in-out;
}
#objectives-list.collapsed {
    display: none;
}

#objectives-list li {
    padding: 0.25rem 0;
    color: #9ca3af;
}
#objectives-list li.completed {
    text-decoration: line-through;
    color: #4ade80;
}
#objectives-list li.active {
    color: #fde047;
    font-weight: bold;
}

h1, h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #67e8f9;
}
#resource-display span {
    font-weight: 700;
}
#resource-display p{
    font-size: 1.125rem;
    margin: 0;
}
#wood-count { color: #4ade80; }
#stone-count { color: #9ca3af; }
#food-count { color: #f59e0b; }
#sand-count { color: #eab308; }
#glass-count { color: #06b6d4; }
#tools-count { color: #f97316; }
#knowledge-count { color: #a78bfa; }
#population-count { color: #60a5fa; }
#population-cap { color: #93c5fd; }
#unemployed-workers-count { color: #fca5a5; }
#happiness-count { color: #fde047; }

hr {
    border: none;
    border-top: 1px solid #4b5563;
    margin: 1.5rem 0;
}

.tabs {
    display: flex;
    margin-bottom: 1rem;
}
.tab-button {
    flex-grow: 1;
    padding: 0.5rem;
    background-color: #374151;
    border: 1px solid #4b5563;
    color: white;
    cursor: pointer;
}
.tab-button.active {
    background-color: #0891b2;
    border-bottom: 1px solid #0891b2;
}
.tab-content {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}
.tab-content.active {
    display: flex;
}

.build-category-header {
    font-size: 1.25rem;
    font-weight: 700;
    color: #67e8f9;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #4b5563;
    padding-bottom: 0.25rem;
}

#build-menu button, #research-panel button {
    width: 100%;
    text-align: left;
    padding: 0.75rem;
    background-color: #374151;
    border-radius: 0.5rem;
    border: none;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}
#build-menu button:hover, #research-panel button:hover {
    background-color: #0891b2;
}
#build-menu button:disabled, #research-panel button:disabled {
    background-color: #1f2937;
    color: #6b7280;
    cursor: not-allowed;
}
#build-menu button small, #research-panel button small {
    color: #9ca3af;
}

#message-box {
    margin-top: auto;
    text-align: center;
    color: #facc15;
    height: 2.5rem;
    padding-top: 0.5rem;
}
canvas {
    background-color: #87CEEB;
    display: block;
}

/* Upgrade / Selected Building Panel */
#selected-building-info {
        position: absolute;
        right: 18rem; /* next to sidebar */
        top: 1rem;
        width: 320px;
        background: rgba(31,41,55,0.92);
        backdrop-filter: blur(4px);
        border: 1px solid #374151;
        border-radius: 0.75rem;
        padding: 0.75rem 0.9rem 1rem;
        z-index: 60;
        color: #fff;
        font-size: 0.9rem;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
}
#selected-building-info.hidden { display: none; }
#selected-building-info h3 { margin: 0 0 0.25rem 0; font-size: 1.05rem; color: #67e8f9; }
#selected-building-info img { width: 48px; height: 48px; image-rendering: pixelated; border-radius: 0.25rem; }
.upgrade-header { display: flex; justify-content: space-between; align-items: flex-start; }
.upgrade-header button { background: transparent; border: none; color: #9ca3af; cursor: pointer; font-size: 1rem; }
.upgrade-header button:hover { color: #f87171; }
.current-info { display: flex; gap: 0.75rem; align-items: center; }
.upgrade-arrow { text-align: center; font-size: 1.4rem; color: #9ca3af; }
.next-info-inner { display: flex; gap: 0.75rem; }
.stat-list { list-style: none; padding: 0; margin: 0; }
.stat-list li { line-height: 1.2; color: #cbd5e1; }
#upgrade-costs { margin-top: 0.35rem; font-size: 0.8rem; color: #9ca3af; }
#upgrade-costs span { display: inline-block; margin-right: 0.6rem; }
#upgrade-button { margin-top: 0.5rem; width: 100%; background: #0891b2; border: none; padding: 0.5rem 0.75rem; border-radius: 0.5rem; color: #fff; cursor: pointer; font-weight: 600; }
#upgrade-button:disabled { background: #1f2937; color: #6b7280; cursor: not-allowed; }
#upgrade-button:not(:disabled):hover { background: #0ea5e9; }
.requirements { font-size: 0.7rem; color: #fbbf24; margin: 0.3rem 0 0; }
.no-upgrade { text-align: center; font-size: 0.85rem; color: #94a3b8; padding: 0.25rem 0 0.5rem; }
.hidden { display:none !important; }

@media (max-width: 1100px) {
    #selected-building-info { right: 1rem; top: auto; bottom: 1rem; width: calc(100% - 2rem); }
}

.build-cursor {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' style='font-size: 24px;'><text y='24'>🏗️</text></svg>") 16 16, auto;
}
.selected-building {
    box-shadow: 0 0 0 3px #67e8f9;
}

#open-worker-panel-button, #open-settings-button {
    position: absolute;
    left: 1rem;
    padding: 0.75rem 1.5rem;
    border: none;
    color: white;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
#open-worker-panel-button {
    bottom: 1rem;
    background-color: #0891b2;
}
#open-settings-button {
    bottom: 4.5rem;
    background-color: #4b5563;
}

#worker-panel-modal, #stats-panel-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
#worker-panel-modal.hidden, #stats-panel-modal.hidden {
    display: none;
}
.modal-content {
    background-color: #1f2937;
    padding: 2rem;
    border-radius: 0.5rem;
    width: 90%;
    max-width: 500px;
}
.modal-content:focus {
    outline: 3px solid rgba(103,232,249,0.25);
    outline-offset: 4px;
}
.modal-content h2 {
    text-align: center;
    margin-top: 0;
}
#worker-assignments-list, #stats-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
    max-height: 60vh;
    overflow-y: auto;
}
#worker-assignments-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid #374151;
}
#stats-image {
    width: 60px;
    height: 60px;
    margin: 0 auto 1rem;
    display: block;
    image-rendering: pixelated;
}
#stats-list li {
    padding: 0.5rem;
    border-bottom: 1px solid #374151;
}
#stats-list li:last-child {
    border-bottom: none;
}

#settings-panel button {
    width: 100%;
    padding: 0.75rem;
    font-size: 1.1rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    color: white;
}
#settings-new-game-button {
    background-color: #dc2626;
}

#event-notification-bar {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(167, 139, 250, 0.9);
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 0.5rem;
    text-align: center;
    z-index: 50;
    width: 90%;
    max-width: 400px;
}
#event-notification-bar.hidden {
    display: none;
}
#event-notification-bar h3 {
    margin: 0 0 0.25rem 0;
}
#event-notification-bar p {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
}
.progress-bar-container {
    width: 100%;
    height: 5px;
    background-color: rgba(0,0,0,0.2);
    border-radius: 5px;
}
#event-progress-bar {
    width: 100%;
    height: 100%;
    background-color: white;
    border-radius: 5px;
    transition: width 0.1s linear;
}


@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    aside {
        width: 100%;
        height: 40vh;
        box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        order: 1;
    }
    main {
        order: 2;
    }
    #top-ui-container {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        background-color: #1f2937;
        padding-bottom: 1rem;
    }
    #scenario-panel {
        position: static;
        transform: none;
        width: 90%;
    }
}
#tip-banner {
    position: relative;
    grid-column: 2 / 3;
    justify-self: center;
    top: auto;
    right: auto;
    width: min(90%, 680px);
    max-width: 680px;
    background: rgba(34,197,94,0.28);
    border-left: 4px solid #22c55e;
    border: 1px solid rgba(148,163,184,0.35);
    border-radius: 0.75rem;
    padding: 0.9rem 1.1rem;
    font-size: 1rem;
    line-height: 1.35;
    color:#e2e8f0;
    backdrop-filter: blur(6px);
    animation: tipFadeIn 0.25s ease;
    pointer-events: none;
    z-index: 150;
}
#tip-banner.warning {border-left-color:#fbbf24; background:rgba(251,191,36,0.12);}
#tip-banner.danger { border-left-color:#ef4444; background:rgba(239,68,68,0.12); }
#tip-banner.hidden { display:none; }
@keyframes tipFadeIn {
    from { opacity:0; transform:translateY(-8px); }
    to { opacity:1; transform:translateY(0); }
}
.attention-pulse {
    animation: attPulse 1.4s ease-in-out infinite;
}
@keyframes attPulse {
    0% {box-shadow:0 0 0 0 rgba(103,232,249,0.55);}
    70% {box-shadow:0 0 0 10px rgba(103,232,249,0);}
    100% { box-shadow:0 0 0 0 rgba(103,232,249,0); }
}
#resource-display .rate {
    font-size: 0.7rem;
    margin-left: 4px;
    min-width: 60px;
    display: inline-block;
    text-align: right;
    font-weight: 600;
    opacity: 0.85;
}
.rate.pos { color:#4ade80; }
.rate.neg { color:#f87171; }
.rate.neu { color:#9ca3af;}
#event-choice-modal .modal-content {
    max-width: 550px;
}

#event-choice-description {
    margin-bottom: 1.5rem;
    color: #cbd5e1;
    line-height: 1.5;
}
#event-choices-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.event-choice-button {
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    background-color: #374151;
    border-radius: 0.5rem;
    border: 1px solid #4b5563;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}
.event-choice-button:hover {
    background-color: #4b5563;
    border-color: #67e8f9;
}
.event-choice-button:disabled {
    background-color: #1f2937;
    color: #6b7280;
    cursor: not-allowed;
    border-color: #374151;
}
.event-choice-button small {
    color: #9ca3af;
    display: block;
    margin-top: 0.25rem;
}
#event-choice-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal button.danger {
    background-color: #dc2626;
    color: white;
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
}
.modal button.danger:hover {
    background-color: #ef4444;
}
#prestige-indicator {
    cursor: pointer;
    user-select: none;
}
#welcome-modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0,0,0,0.66);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
}
#welcome-modal.hidden { display: none; }
#welcome-modal .modal-content.welcome {
    width: min(720px, 94%);
    background: linear-gradient(180deg, rgba(31,41,55,0.98), rgba(17,24,39,0.98));
    border-radius: 12px;
    padding: 1.4rem 1.6rem;
    color: #e6eef6;
    text-align: center;
    box-shadow: 0 10px 35px rgba(2,6,23,0.75);
    border: 1px solid rgba(103,232,249,0.08);
}
#welcome-modal .modal-content.welcome h2 {
    margin: 0 0 .5rem 0;
    color: #67e8f9;
}
.welcome-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}
#welcome-start-tutorial {
    background-color: #0891b2;
    border: none;
    color: white;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}
#welcome-start-tutorial:hover { background-color: #0ea5e9; }
#welcome-skip-tutorial {
    background-color: transparent;
    border: 1px solid #374151;
    color: #fff;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    cursor: pointer;
}
#welcome-skip-tutorial.danger {
    background-color: #dc2626;
    border: none;
}
#welcome-skip-tutorial.danger:hover { 
    background-color: #ef4444; 
}
#cancel-tutorial-button {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1300;
    background: #f97316;
    color: white;
    border: none;
    padding: 0.5rem 0.8rem;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.95rem;
}
#cancel-tutorial-button:hover { 
    background: #fb923c; 
}
#cancel-tutorial-button.hidden { 
    display: none !important; 
}
#cancel-tutorial-button:focus {
    outline: 3px solid rgba(255,255,255,0.14);
    outline-offset: 3px;
}
#tutorial-hud {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 1400;
    background: linear-gradient(180deg, rgba(2,6,23,0.9), rgba(20,27,38,0.9));
    color: #e6eef6;
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    min-width: 220px;
    max-width: 320px;
    font-size: 14px;
    border: 1px solid rgba(103,232,249,0.06);
}
#tutorial-hud.hidden {
    display: none;
}
#tutorial-hud .hud-step {
    font-weight: 700; 
    color: #67e8f9; 
    margin-bottom: 6px;
}
#tutorial-hud .hud-action {
    margin-bottom: 8px; 
    color: #cbd5e1; 
    line-height: 1.2;
}
#tutorial-hud .hud-buttons {
    display:flex; 
    gap:8px; 
    justify-content:flex-end;
}
#tutorial-hud .hud-buttons .small {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    color: #e6eef6;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
}
#tutorial-hud .hud-buttons .small:hover {
    background: rgba(255,255,255,0.03);
}