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

body {
    font-family: sans-serif;
    background: #f2f6f7;
    color: #1c1f2f;
}

header {
    background: #f2f6f7;
    padding: 12px 16px;
    text-align: center;
    border-bottom: 1px solid #ddd;
}

header h1 {
    font-size: 2rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
}

header h2 {
    font-size: 1.2rem;
    color: rgb(16, 16, 129);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.col {
    flex: 1;
}

/* Stage year buttons */
.stage-btn {
    width: 120px;
    height: 120px;
    font-size: 1rem;
    font-weight: bold;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: default;
    background-color: rgb(16, 16, 129);
}

.stage-btn.active {
    background-color: rgb(255, 77, 31);
}

/* Token displays */
.token-box {
    width: 50px;
    height: 50px;
    border: 1px solid black;
    border-radius: 4px;
    display: inline-block;
    background-color: white;
}

.token-box.active {
    background-color: rgb(160, 218, 170);
}

/* Resource blocks */
.resource-block {
    border: 2px solid rgb(16, 16, 129);
    border-radius: 4px;
    padding: 12px;
    flex: 1;
    min-width: 200px;
}

.resource-block.existing {
    border-color: rgb(255, 198, 151);
}

.resource-block.locked {
    opacity: 0.5;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-primary {
    background-color: rgb(16, 16, 129);
    color: white;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: rgb(171, 191, 227);
    color: white;
}

.btn-danger {
    background-color: rgb(255, 77, 31);
    color: white;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.85rem;
}

.btn-token {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    font-weight: bold;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid rgb(16, 16, 129);
    margin-bottom: 16px;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    color: rgb(16, 16, 129);
    font-weight: bold;
    border: none;
    background: none;
}

.tab.active {
    border-bottom: 3px solid rgb(255, 77, 31);
    color: rgb(255, 77, 31);
}

/* Score tables */
.score-table {
    border-collapse: collapse;
    font-size: 0.85rem;
    width: 100%;
}

.score-table th, .score-table td {
    border: 1px solid black;
    padding: 4px 8px;
    text-align: center;
}

.score-table thead tr {
    background-color: rgb(236, 167, 149);
    color: white;
}

.score-table.clean thead tr {
    background-color: rgb(171, 191, 227);
}

/* Big number display */
.big-number {
    font-size: 1.8rem;
    font-weight: bold;
    text-align: center;
    padding: 8px;
}

/* Shaping token toggles */
.shaping-btn {
    padding: 10px 20px;
    border: 2px solid rgb(16, 16, 129);
    border-radius: 4px;
    cursor: pointer;
    background: white;
    color: rgb(16, 16, 129);
    font-weight: bold;
    margin: 4px;
}

.shaping-btn.active {
    background-color: rgb(16, 16, 129);
    color: white;
}

.shaping-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Chart controls */
.chart-controls {
    margin: 8px 0;
    font-size: 0.9rem;
}

/* Chart container */
.chart-container {
    width: 100%;
    background: #f2f6f7;
    padding: 8px;
}

/* Social backlash highlight */
.backlash-active {
    background-color: red !important;
    color: white !important;
}

/* Disaster alert */
.disaster-alert {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    padding: 12px;
    border-radius: 4px;
    margin: 8px 0;
}

/* Game over panel */
.game-over {
    text-align: center;
    padding: 40px;
}

.final-score {
    font-size: 3rem;
    font-weight: bold;
    color: white;
    background-color: rgb(160, 218, 170);
    width: 160px;
    height: 160px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

/* Dialog/modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background: white;
    border-radius: 8px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
}

/* Setup screen */
.setup-screen {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px 0;
}

.setup-title {
    font-size: 1.4rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
    margin-bottom: 20px;
}

.setup-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.setup-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
    width: 220px;
}

.setup-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 14px;
    border: 2px solid rgb(16, 16, 129);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background 0.15s;
}

.setup-card:hover {
    background: #eef0fb;
}

.setup-card.selected {
    background: rgb(16, 16, 129);
    color: white;
}

.setup-card-code {
    font-size: 1.1rem;
    font-weight: bold;
}

.setup-card-name {
    font-size: 0.85rem;
}

.setup-card-meta {
    font-size: 0.75rem;
    opacity: 0.75;
}

.setup-card.selected .setup-card-meta {
    opacity: 0.85;
}

.setup-detail {
    flex: 1;
    min-height: 200px;
}

.setup-hint {
    color: #666;
    font-style: italic;
    margin-top: 8px;
}

.setup-preview h3 {
    font-size: 1.2rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
    margin-bottom: 12px;
}

.setup-preview h4 {
    font-size: 0.9rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
    margin-bottom: 6px;
}

.setup-upload {
    margin-top: 16px;
    font-size: 0.9rem;
}

.upload-error {
    color: rgb(200, 40, 0);
    margin-top: 6px;
}

.setup-actions {
    margin-top: 24px;
}

/* Planning screen */
.planning-screen {
    padding: 8px 0;
}

.planning-stage-bar {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.stage-btn.done {
    background-color: rgb(100, 100, 180);
    cursor: default;
}

.planning-summary {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    padding: 8px 4px;
    font-size: 0.95rem;
}

.planning-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.planning-shaping {
    border-top: 1px solid #ddd;
    padding-top: 12px;
}

/* Resource block internals */
.rb-name {
    font-weight: bold;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.rb-cap {
    font-size: 1.1rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
}

.rb-info {
    font-size: 0.78rem;
    color: #555;
    margin-bottom: 6px;
}

.rb-token-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.rb-token-count {
    min-width: 24px;
    text-align: center;
    font-weight: bold;
    font-size: 1rem;
}

.rb-token-boxes {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

/* Small token boxes for resource cards */
.token-box-sm {
    width: 18px;
    height: 18px;
    border: 1px solid #999;
    border-radius: 2px;
    display: inline-block;
    background-color: white;
}

.token-box-sm.active {
    background-color: rgb(160, 218, 170);
    border-color: #4a9;
}

/* Budget token market */
.token-market {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.btn-sm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.rb-status {
    font-size: 0.78rem;
    font-weight: bold;
    color: rgb(200, 40, 0);
    margin-bottom: 6px;
}

/* Shaping token toggles with descriptions */
.shaping-item {
    flex: 1;
    min-width: 180px;
    max-width: 280px;
}

.shaping-desc {
    font-size: 0.78rem;
    color: #555;
    margin: 0 4px 8px;
}

.table-scroll {
    overflow-x: auto;
}

.final-breakdown {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

/* Preview panel */
.preview-panel {
    border-top: 2px solid rgb(16, 16, 129);
    padding-top: 12px;
}

.preview-panel h3 {
    color: rgb(16, 16, 129);
    font-size: 1rem;
}

/* Stage results screen */
.results-screen {
    padding: 8px 0;
}

.results-title {
    font-size: 1.4rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
    margin-bottom: 4px;
}

.results-total-score {
    font-size: 2rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
    background: rgb(171, 191, 227);
    width: 100px;
    height: 70px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 4px;
}

.results-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 24px;
}

/* End-game screen */
.endgame-section-title {
    font-size: 1rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
}

/* Uncertainty narrative */
.narrative-section {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 12px;
    background: #fafafa;
}

.narrative-title {
    font-size: 1rem;
    font-weight: bold;
    color: rgb(16, 16, 129);
    margin-bottom: 8px;
}

.narrative-item {
    padding: 6px 0;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

.narrative-item:last-child {
    border-bottom: none;
}

.narrative-disaster {
    color: rgb(180, 30, 0);
    font-weight: 500;
}

.narrative-backlash {
    color: rgb(160, 60, 0);
    font-weight: 500;
}

.narrative-experience {
    color: rgb(0, 120, 60);
}

/* Utility */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.bold { font-weight: bold; }
.hidden { display: none; }

/* ---------------------------------------------------------------------------
   Responsive layout (tablets and phones)
   --------------------------------------------------------------------------- */

.row > .col {
    min-width: 220px;
}

@media (max-width: 900px) {
    .stage-btn {
        width: 72px;
        height: 72px;
        font-size: 0.9rem;
    }

    .setup-layout {
        flex-direction: column;
    }

    .setup-cards {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .setup-card {
        flex: 1 1 140px;
    }

    .resource-block {
        min-width: 160px;
    }
}

@media (max-width: 600px) {
    header h1 {
        font-size: 1.5rem;
    }

    header h2 {
        font-size: 1rem;
    }

    .container {
        padding: 12px;
    }

    .stage-btn {
        width: 56px;
        height: 56px;
        font-size: 0.8rem;
    }

    .planning-summary {
        gap: 8px;
        flex-direction: column;
    }

    .resource-block {
        min-width: 100%;
    }

    .shaping-item {
        max-width: none;
        min-width: 100%;
    }

    .game-over {
        padding: 16px 0;
    }

    .score-table th, .score-table td {
        padding: 4px;
    }
}

