/* Brand Colors */
:root {
    /* Core Neutrals */
    --full-moon: #FFFFFF;
    --new-moon: #000000;
    --moon-gray: #C8CCCC;
    --moon-dust: #F5F5F5;
    --earth-sand: #FBF9F6;

    /* Moss - Forest Green */
    --moss-dark: #0C2725;
    --moss: #1F504A;
    --moss-light: #F2FBF8;

    /* Lichen - Pale Green */
    --lichen: #CDF3A3;
    --lichen-light: #F4FCE9;

    /* Iris - Violet Blue */
    --iris-dark: #4D2CAB;
    --iris: #9F93F2;
    --iris-light: #F5F4FE;

    /* Sky - Bright Blue */
    --sky-dark: #135079;
    --sky: #4AAEE6;
    --sky-light: #F1F8FE;

    /* Sun - Warm Yellow */
    --sun-dark: #725F00;
    --sun: #FFEB88;
    --sun-light: #FFFCEB;

    /* Nectary - Coral Orange */
    --nectary-dark: #933A21;
    --nectary: #EF7E5F;
    --nectary-light: #FDF5F3;
}

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

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--iris) 0%, var(--iris-dark) 100%);
    color: var(--new-moon);
    line-height: 1.6;
    min-height: 100vh;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    color: white;
    padding: 40px 20px;
}

header h1 {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 3em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    letter-spacing: -0.02em;
}

.site-title {
    cursor: pointer;
    transition: all 0.3s ease;
}

.site-title:hover {
    transform: scale(1.05);
    text-shadow: 3px 3px 6px rgba(0,0,0,0.4);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
}

main {
    background: white;
    border-radius: 15px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    margin-top: 20px;
}

.game-section {
    display: none;
}

.game-section.active {
    display: block;
}

h2 {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    color: var(--iris);
    margin-bottom: 20px;
    font-size: 2em;
    letter-spacing: -0.01em;
}

h3 {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    color: #555;
    margin-bottom: 15px;
}

/* Monospace elements */
.sandbox-log,
code,
pre,
.param-description {
    font-family: 'DM Mono', 'Courier New', monospace;
}

.narrative-text {
    background: var(--iris-light);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    border-left: 4px solid var(--iris);
}

.narrative-text p {
    margin-bottom: 10px;
}

.cooperate {
    color: var(--moss);
}

.defect {
    color: var(--nectary);
}

/* Concept Cards */
.concept-intro {
    text-align: center;
    font-size: 1.15em;
    color: #555;
    margin-bottom: 35px;
    line-height: 1.8;
}

.concept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.concept-card {
    background: linear-gradient(135deg, #ffffff 0%, var(--moon-dust) 100%);
    padding: 25px;
    border-radius: 12px;
    border: 2px solid var(--moon-gray);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.concept-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, var(--iris) 0%, var(--iris-dark) 100%);
}

.concept-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.15);
    border-color: var(--iris);
}

.concept-card-icon {
    font-size: 2.5em;
    margin-bottom: 12px;
    display: block;
}

.concept-card h3 {
    color: var(--iris);
    margin-bottom: 12px;
    font-size: 1.3em;
}

.concept-card p {
    color: #555;
    font-size: 0.95em;
    line-height: 1.6;
    margin: 0;
}

.key-insight {
    background: linear-gradient(135deg, var(--iris)15 0%, var(--iris-dark)15 100%);
    padding: 25px;
    border-radius: 12px;
    border-left: 4px solid var(--iris);
    margin: 30px 0;
    text-align: center;
}

.key-insight-label {
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--iris);
    font-weight: bold;
    margin-bottom: 10px;
}

.key-insight-text {
    font-size: 1.2em;
    color: #333;
    font-weight: 500;
    line-height: 1.6;
}

/* Landing Page Options */
.landing-options {
    margin-top: 40px;
}

.landing-options h3 {
    text-align: center;
    color: var(--iris);
    margin-bottom: 30px;
    font-size: 1.8em;
}

.option-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 25px;
    margin-top: 30px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.option-card {
    background: linear-gradient(135deg, var(--moon-dust) 0%, var(--moon-gray) 100%);
    padding: 30px 20px;
    border-radius: 15px;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 2px solid transparent;
}

.option-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
    border-color: var(--iris);
}

.option-emoji {
    font-size: 3em;
    margin-bottom: 15px;
}

.option-card h4 {
    color: #333;
    margin-bottom: 10px;
    font-size: 1.4em;
}

.option-card p {
    color: #666;
    margin-bottom: 20px;
    font-size: 0.95em;
    min-height: 40px;
}

/* Payoff Matrix */
.payoff-matrix {
    margin: 30px 0;
}

.payoff-matrix table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.payoff-matrix th,
.payoff-matrix td {
    padding: 15px;
    border: 2px solid #ddd;
    text-align: center;
}

.payoff-matrix th {
    background: var(--iris);
    color: white;
}

.both-cooperate {
    background: var(--moss-light);
    font-weight: bold;
}

.sucker {
    background: var(--nectary-light);
}

.temptation {
    background: var(--sun-light);
}

.both-defect {
    background: var(--moon-dust);
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-cooperate,
.btn-defect {
    padding: 15px 30px;
    font-size: 1.1em;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
    margin: 10px 5px;
}

.btn-primary {
    background: var(--iris);
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-cooperate {
    background: var(--moss);
    color: white;
    flex: 1;
}

.btn-cooperate:hover {
    background: #229954;
    transform: scale(1.05);
}

.btn-defect {
    background: var(--nectary);
    color: white;
    flex: 1;
}

.btn-defect:hover {
    background: #c0392b;
    transform: scale(1.05);
}

.btn-cooperate:disabled,
.btn-defect:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 30px;
    margin: 30px 0;
    padding: 30px;
    background: var(--iris-light);
    border-radius: 10px;
}

.player-area,
.opponent-area {
    text-align: center;
}

.vs-area {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-width: 150px;
}

#round-info {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--iris);
    margin-bottom: 15px;
}

#last-result {
    padding: 10px 20px;
    border-radius: 8px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.agent-visual {
    width: 120px;
    height: 120px;
    margin: 20px auto;
    border-radius: 50%;
    background: #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3em;
    transition: all 0.3s ease;
}

.agent-visual.cooperated {
    background: var(--moss);
    animation: pulse 0.5s ease;
}

.agent-visual.defected {
    background: var(--nectary);
    animation: pulse 0.5s ease;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.score {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--iris);
    margin-top: 10px;
}

/* History */
.history-container {
    margin: 30px 0;
}

#history-display {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
    min-height: 100px;
}

.history-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    min-width: 80px;
}

.history-item .round-number {
    font-size: 0.8em;
    color: #999;
    margin-bottom: 5px;
}

.history-item .moves {
    display: flex;
    gap: 5px;
    font-size: 1.5em;
}

.history-item .result {
    font-size: 0.9em;
    margin-top: 5px;
    font-weight: bold;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 30px 0;
}

/* Evolution Section */
#evolution-canvas-container {
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
    min-height: 200px;
    transition: all 0.3s ease;
}

#evolution-canvas-container.hidden {
    display: none;
}

.evolution-log {
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.6;
}

.log-entry {
    padding: 8px 12px;
    margin: 4px 0;
    background: white;
    border-radius: 6px;
    border-left: 3px solid var(--iris);
    animation: slideIn 0.3s ease;
}

.log-entry.milestone {
    background: linear-gradient(135deg, var(--iris)15 0%, var(--iris-dark)15 100%);
    border-left-color: var(--iris-dark);
    font-weight: bold;
}

.log-entry .timestamp {
    color: #999;
    font-size: 0.85em;
    margin-right: 10px;
}

.log-entry .event {
    color: #333;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.evolution-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
}

.evolution-stats {
    display: flex;
    gap: 30px;
    font-weight: bold;
    color: var(--iris);
}

#population-chart {
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
}

.strategy-bar {
    margin: 10px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.strategy-bar .label {
    min-width: 150px;
    font-weight: bold;
}

.strategy-bar .bar-container {
    flex: 1;
    height: 30px;
    background: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

.strategy-bar .bar-fill {
    height: 100%;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: white;
    font-weight: bold;
}

.strategy-cooperator { background: var(--moss); }
.strategy-defector { background: var(--nectary); }
.strategy-tit-for-tat { background: var(--sky); }
.strategy-grudger { background: var(--iris); }
.strategy-random { background: var(--moon-gray); }
.strategy-detective { background: var(--sun); }

/* Payoff Matrix Configuration */
.payoff-matrix-config {
    margin: 30px 0;
    padding: 25px;
    background: var(--iris-light);
    border-radius: 10px;
    border-left: 4px solid var(--iris);
}

.payoff-matrix-config h3 {
    color: var(--iris);
    margin-bottom: 10px;
}

.payoff-matrix-config h4 {
    color: #555;
    margin-bottom: 10px;
    margin-top: 20px;
}

.payoff-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.payoff-input {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 2px solid var(--moon-gray);
    transition: all 0.3s ease;
}

.payoff-input:hover {
    border-color: var(--iris);
}

.payoff-input label {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.payoff-label {
    font-weight: bold;
    color: #333;
    font-size: 0.95em;
}

.payoff-input input[type="number"] {
    padding: 10px;
    font-size: 1.1em;
    border: 2px solid #ddd;
    border-radius: 6px;
    text-align: center;
    font-weight: bold;
    color: var(--iris);
    transition: all 0.3s ease;
}

.payoff-input input[type="number"]:focus {
    outline: none;
    border-color: var(--iris);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Sandbox Section */
.sandbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 20px;
    flex-wrap: wrap;
}

.sandbox-header h2 {
    margin: 0;
}

.sandbox-header-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.sandbox-header-actions .btn-primary,
.sandbox-header-actions .btn-secondary {
    margin: 0;
    white-space: nowrap;
}

.sandbox-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-group label {
    font-weight: bold;
    color: #555;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label strong {
    color: var(--iris);
    font-size: 1.05em;
}

.param-description {
    font-weight: normal;
    font-size: 0.9em;
    color: #666;
    line-height: 1.5;
    padding: 8px 12px;
    background: rgba(102, 126, 234, 0.05);
    border-radius: 6px;
    border-left: 3px solid var(--iris);
}

.control-group input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.sandbox-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 30px 0;
}

.sandbox-stats {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
    font-weight: bold;
    color: var(--iris);
}

#sandbox-population-chart {
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
    min-height: 200px;
}

#sandbox-results {
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
}

#sandbox-log-container {
    margin: 30px 0;
    padding: 20px;
    background: var(--iris-light);
    border-radius: 10px;
    border-left: 4px solid var(--iris);
    transition: all 0.3s ease;
}

#sandbox-log-container.hidden {
    display: none;
}

#sandbox-log-container h4 {
    color: var(--iris);
    margin-bottom: 15px;
}

.sandbox-log {
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    line-height: 1.6;
    background: white;
    padding: 15px;
    border-radius: 8px;
}

.sandbox-log-entry {
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--moon-dust);
    border-radius: 6px;
    border-left: 3px solid #ddd;
    animation: slideIn 0.3s ease;
}

.sandbox-log-entry.generation-header {
    background: linear-gradient(135deg, var(--iris)15 0%, var(--iris-dark)15 100%);
    border-left-color: var(--iris);
    font-weight: bold;
    color: var(--iris);
    margin-top: 12px;
    padding: 10px 12px;
}

.sandbox-log-entry.match-result {
    display: grid;
    grid-template-columns: 2fr 1fr 2fr 1fr;
    gap: 8px;
    align-items: center;
    font-size: 0.9em;
}

.sandbox-log-entry .agent-name {
    font-weight: bold;
    color: #333;
}

.sandbox-log-entry .vs {
    text-align: center;
    color: #999;
    font-size: 0.85em;
}

.sandbox-log-entry .score {
    text-align: right;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 4px;
    background: white;
}

.sandbox-log-entry .score.winner {
    color: var(--moss);
    background: var(--moss-light);
}

.sandbox-log-entry .score.loser {
    color: var(--nectary);
    background: var(--nectary-light);
}

.sandbox-log-entry .score.tie {
    color: var(--iris);
    background: var(--sky-light);
}

/* Final Scoreboard */
.final-scoreboard {
    max-width: 900px;
    margin: 0 auto;
    text-align: center;
}

.final-scoreboard h2 {
    color: var(--iris);
    font-size: 2.5em;
    margin-bottom: 30px;
}

.final-scoreboard h3 {
    color: #555;
    margin: 30px 0 20px 0;
    font-size: 1.5em;
}

.scoreboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.summary-card {
    background: linear-gradient(135deg, var(--iris) 0%, var(--iris-dark) 100%);
    color: white;
    padding: 25px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.summary-label {
    font-size: 0.9em;
    opacity: 0.9;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.summary-value {
    font-size: 2em;
    font-weight: bold;
}

/* Results Table */
.results-table-container {
    margin-bottom: 30px;
    overflow-x: auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.results-table thead {
    background: linear-gradient(135deg, var(--iris) 0%, var(--iris-dark) 100%);
    color: white;
}

.results-table thead th {
    padding: 18px 15px;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85em;
    letter-spacing: 0.5px;
}

.results-table tbody tr {
    border-bottom: 1px solid #f0f0f0;
    transition: all 0.3s ease;
}

.results-table tbody tr:hover {
    background: var(--iris-light);
    transform: scale(1.01);
}

.results-table tbody tr.win {
    background: linear-gradient(90deg, rgba(212, 237, 218, 0.3) 0%, white 100%);
}

.results-table tbody tr.loss {
    background: linear-gradient(90deg, rgba(248, 215, 218, 0.3) 0%, white 100%);
}

.results-table tbody tr.tie {
    background: linear-gradient(90deg, rgba(231, 243, 255, 0.3) 0%, white 100%);
}

.results-table tbody td,
.results-table tfoot td {
    padding: 15px;
}

.match-number {
    font-weight: bold;
    color: #999;
    width: 50px;
}

.opponent-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.opponent-emoji {
    font-size: 1.5em;
}

.opponent-name {
    font-weight: 600;
    color: #333;
}

.score-cell {
    font-size: 1.2em;
    font-weight: bold;
    text-align: center;
    width: 120px;
}

.player-score {
    color: var(--iris);
}

.opponent-score {
    color: var(--iris-dark);
}

.outcome-cell {
    font-weight: bold;
    text-align: center;
    padding: 8px 12px !important;
}

.outcome-win {
    color: var(--moss);
}

.outcome-loss {
    color: var(--nectary);
}

.outcome-tie {
    color: var(--iris);
}

.results-table tfoot {
    background: var(--iris-light);
    border-top: 3px solid var(--iris);
}

.results-table tfoot td {
    padding: 20px 15px;
    font-size: 1.1em;
}

.totals-row .score-cell {
    font-size: 1.4em;
}

.total-player {
    color: var(--iris);
}

.total-opponent {
    color: var(--iris-dark);
}

.scoreboard-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Footer */
footer {
    text-align: center;
    color: white;
    padding: 20px;
    margin-top: 30px;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }

    .game-board {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .sandbox-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sandbox-header-actions {
        width: 100%;
        flex-direction: column;
    }

    .sandbox-header-actions .btn-primary,
    .sandbox-header-actions .btn-secondary {
        width: 100%;
    }

    .sandbox-controls {
        grid-template-columns: 1fr;
    }

    .payoff-grid {
        grid-template-columns: 1fr;
    }

    .concept-grid {
        grid-template-columns: 1fr;
    }

    .option-cards {
        grid-template-columns: 1fr;
    }

    .scoreboard-summary {
        grid-template-columns: 1fr;
    }

    .scoreboard-actions {
        flex-direction: column;
    }

    .results-table {
        font-size: 0.85em;
    }

    .results-table thead th,
    .results-table tbody td,
    .results-table tfoot td {
        padding: 10px 8px;
    }

    .match-number {
        width: 30px;
    }

    .score-cell {
        width: 80px;
        font-size: 1em;
    }

    .opponent-emoji {
        font-size: 1.2em;
    }

    .totals-row .score-cell {
        font-size: 1.2em;
    }

    main {
        padding: 20px;
    }
}
