/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c5f2d;
    --primary-hover: #1e4620;
    --success-color: #28a745;
    --error-color: #dc3545;
    --bg-color: #f5f5f5;
    --text-color: #333;
    --border-color: #ddd;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

/* Header */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 0;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.8rem;
    margin: 0;
    flex: 0 0 auto;
}

nav {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    align-items: center;
    margin-left: 2rem;
}

nav a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

nav a:hover {
    opacity: 0.8;
}

/* Auth Section */
.auth-section {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 0 0 auto;
}

.username {
    color: white;
    font-weight: 500;
    font-size: 0.95rem;
}

.steam-login-btn,
.steam-login-btn-inline {
    display: inline-block;
    transition: opacity 0.2s;
}

.steam-login-btn:hover,
.steam-login-btn-inline:hover {
    opacity: 0.8;
}

.steam-login-btn-inline {
    margin-left: 0.5rem;
    vertical-align: middle;
}

.btn-logout {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    background-color: rgba(220, 53, 69, 0.8);
    color: white;
    transition: background-color 0.2s, opacity 0.2s;
}

.btn-logout:hover {
    background-color: rgba(220, 53, 69, 1);
}

/* Main content */
main {
    flex: 1;
    padding: 2rem 0;
}

.upload-section {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.upload-section h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.upload-section>p {
    margin-bottom: 1.5rem;
    color: #666;
}

/* Form styles */
.upload-form {
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

textarea,
input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

textarea {
    font-family: 'Courier New', monospace;
    resize: vertical;
}

textarea:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Button styles */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
    transform: translateY(1px);
}

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

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

/* Alert styles */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Result box */
.result-box {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 4px;
    border-left: 4px solid var(--primary-color);
    margin-top: 1rem;
}

.result-box h3 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
}

.result-box p {
    margin-bottom: 0.5rem;
}

/* htmx indicator */
.htmx-indicator {
    display: none;
    color: #666;
    font-style: italic;
}

.htmx-request .htmx-indicator {
    display: inline;
}

.htmx-request.htmx-indicator {
    display: inline;
}

/* Game Details Section */
.game-details-section {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.game-details-section h2 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
}

.help-text {
    color: #666;
    margin-bottom: 2rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.game-details-form {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.form-section {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1.5rem;
    background-color: #fafafa;
}

.form-section h3 {
    color: var(--primary-color);
    margin-bottom: 1.25rem;
    font-size: 1.2rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1rem;
}

/* Select inputs */
select {
    width: 100%;
    padding: 0.6rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.95rem;
    background-color: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

select:hover {
    border-color: #999;
}

/* Spirit rows */
.spirit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: white;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    gap: 1.5rem;
}

.spirit-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.spirit-name {
    color: var(--primary-color);
    font-size: 1.05rem;
}

.aspect-select {
    flex: 0 0 250px;
    margin-bottom: 0;
}

.aspect-select label {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

/* Button styles */
.btn-secondary {
    background-color: #6c757d;
    color: white;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

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

.btn-secondary:active {
    transform: translateY(1px);
}

.btn-download {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    background-color: rgba(85, 137, 72, 0.8);
    color: white;
    transition: background-color 0.2s, opacity 0.2s;
}

.btn-download:hover {
    background-color: rgba(85, 137, 72, 1);
}

/* Stats Section */
.stats-section {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stats-section h2 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stats-info {
    color: #666;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.table-container {
    overflow-x: auto;
    margin-top: 1rem;
}

.games-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.games-table thead {
    background-color: var(--primary-color);
    color: white;
}

.games-table th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.games-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.games-table tbody tr:hover {
    background-color: #f8f9fa;
}

.games-table tbody tr.win {
    background-color: #f0f8f0;
}

.games-table tbody tr.loss {
    background-color: #fff5f5;
}

.games-table tbody tr.win:hover {
    background-color: #e6f4e6;
}

.games-table tbody tr.loss:hover {
    background-color: #ffe6e6;
}

.games-table .date {
    white-space: nowrap;
    color: #666;
    font-size: 0.85rem;
}

.games-table .adversary {
    font-weight: 500;
}

.games-table .spirits {
    max-width: 300px;
}

.spirit-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.spirit-list li {
    margin-bottom: 0.25rem;
}

.spirit-list .aspect {
    color: #666;
    font-size: 0.85rem;
}

.games-table .result {
    text-align: center;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85rem;
}

.badge-win {
    background-color: var(--success-color);
    color: white;
}

.badge-loss {
    background-color: var(--error-color);
    color: white;
}

.games-table .difficulty,
.games-table .score {
    text-align: center;
    font-weight: 600;
}

.empty-state {
    text-align: center;
    padding: 3rem 2rem;
}

.empty-state p {
    color: #666;
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}

/* Game Replay Styles */
.replay-page {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.replay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.replay-header h2 {
    color: var(--primary-color);
    margin: 0;
}

.replay-header-buttons {
    display: flex;
    gap: 2px;
}

/* Timeline Styles */
.timeline-container {
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    max-height: 10vh;
    overflow-x: auto;
    overflow-y: hidden;
}

.timeline-scroll {
    display: flex;
    gap: 1rem;
    min-width: min-content;
}

.timeline-turn {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: fit-content;
}

.timeline-turn-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary-color);
    text-align: center;
    padding: 0.25rem 0.5rem;
    background: white;
    border-radius: 4px;
}

.timeline-phases {
    display: flex;
    gap: 0.25rem;
}

.timeline-phase {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    padding-left: 0.4rem;
    padding-right: 0.4rem;
    height: 32px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    cursor: pointer;
}

.timeline-phase:hover {
    background: #e8f4e8;
    border-color: var(--primary-color);
}

.timeline-phase.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.timeline-icon {
    height: 1.2em;
    width: auto;
    vertical-align: middle;
    margin: 0 2px;
}

/* Two Column Layout */
.replay-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

/* Left Column: Game State */
.replay-game-state {
    background: #fafafa;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    overflow: hidden;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.game-state-header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 1.5rem;
}

.game-state-header h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.state-info {
    display: flex;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.game-state-tabs {
    display: flex;
    background: #e8f4e8;
    border-bottom: 2px solid var(--primary-color);
}

.state-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
}

.state-tab:hover {
    background: rgba(44, 95, 45, 0.1);
}

.state-tab.active {
    background: white;
    border-bottom-color: var(--primary-color);
}

.game-state-panels {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.state-panel {
    display: none;
    height: 100%;
}

.state-panel.active {
    display: block;
}

.board-state-content {
    padding: 1.5rem;
    line-height: 1.8;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.blight-healthy,
.blight-still-healthy {
    background-color: #c6d791;

}

.blight-blighted {
    background-color: #bdb4b2;
}

.land {
    border-bottom: 1px solid #aaa;
}

.land-label {
    margin-left: 5px;
    margin-right: 15px;
}

.land-label,
.land-pieces {
    vertical-align: middle;
    display: inline-block;
}

.land[data-terrain="jungle"] {
    background-color: #94c980;
}

.land[data-terrain="wetland"] {
    background-color: #b4d8d7;
}

.land[data-terrain="sands"] {
    background-color: #d1b56f;
}

.land[data-terrain="mountain"] {
    background-color: #8e8e8e;
}

/* Spirit View Styles */
.spirit-tabs-container {
    padding: 1rem;
}

.spirit-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.spirit-tab {
    padding: 0.5rem 1rem;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
}

.spirit-tab:hover {
    background: #e8f4e8;
    border-color: var(--primary-color);
}

.spirit-tab.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.spirit-panels {
    position: relative;
}

.spirit-panel {
    display: none;
}

.spirit-panel.active {
    display: block;
}

.spirit-header h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.spirit-stats {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.spirit-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-label {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 80px;
}

.stat-value {
    font-family: 'Courier New', monospace;
}

.spirit-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cards-section {
    background: white;
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.cards-section h5 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.card-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card-item {
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border-left: 3px solid #6c757d;
    border-radius: 3px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.card-item:hover {
    background: #e9ecef;
    transform: translateX(2px);
}

.card-item.played {
    background: #e8f4e8;
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.card-item.played:hover {
    background: #d4edda;
}

.card-item.discard {
    background: #fff5f5;
    border-left-color: #dc3545;
    opacity: 0.7;
}

.card-item.discard:hover {
    background: #ffe6e6;
    opacity: 0.85;
}

.innate-section {
    margin-top: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.innate-section h5 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.text-muted {
    color: #666;
    font-style: italic;
    font-size: 0.9rem;
}

/* Right Column: Log View */
.replay-log-view {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    max-height: 80vh;
    overflow-y: auto;
}

.log-view-container h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.current-phase-actions {
    margin-bottom: 2rem;
}

.action-list {
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.action-row {
    padding: 0.75rem 1rem;
    line-height: 1.6;
    color: var(--text-color);
    font-size: 0.9rem;
    border-bottom: 1px solid #eee;
}

.action-row:last-child {
    border-bottom: none;
}

.action-row:nth-child(odd) {
    background-color: white;
}

.no-actions {
    padding: 2rem;
    text-align: center;
}

.all-phases-nav {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
}

.all-phases-nav h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1rem;
}

.phases-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.turn-group {
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
}

.turn-label {
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.phase-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    margin: 0.25rem 0;
    background: white;
    border-radius: 4px;
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s;
    cursor: pointer;
}

.phase-row:hover {
    background: #e8f4e8;
}

.phase-row.current {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.phase-row.current:hover {
    background: var(--primary-hover);
}

.phase-name {
    flex: 1;
}

.action-count {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    min-width: 24px;
    text-align: center;
}

/* Inline icons for game elements */
.inline-icon {
    height: 1.2em;
    width: auto;
    vertical-align: middle;
    margin: 0 2px;
}

.presence-icon {
    height: 1.2em;
    width: 1.2em;
    vertical-align: middle;
    margin: 0 2px;
}

/* Card Tooltip Styles */
.card-reference {
    cursor: pointer;
    position: relative;
    display: inline-block;
    border-radius: 3px;
    padding: 1px 2px;
    transition: background-color 0.2s;
}

.card-reference:hover {
    z-index: 100;
    background-color: rgba(44, 95, 45, 0.1);
}

.tippy-box[data-theme~='card-preview'] {
    background: transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    max-width: 300px;
}

.tippy-box[data-theme~='card-preview'] .tippy-content {
    padding: 0;
    width: 100%;
}

.tippy-box[data-theme~='card-preview'] img {
    padding: 0;
    width: 100%;
}

/* Footer */
footer {
    background-color: #333;
    color: white;
    padding: 1.5rem 0;
    text-align: center;
    margin-top: auto;
}

footer p {
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 1200px) {
    .replay-layout {
        grid-template-columns: 400px 1fr;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    header h1 {
        font-size: 1.5rem;
    }

    nav {
        margin-left: 0;
        flex-wrap: wrap;
    }

    .auth-section {
        width: 100%;
        justify-content: flex-start;
    }

    .upload-section,
    .game-details-section,
    .stats-section {
        padding: 1.5rem;
    }

    textarea {
        font-size: 0.85rem;
    }

    .spirit-row {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .aspect-select {
        flex: 1;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .btn,
    .btn-secondary {
        width: 100%;
        text-align: center;
    }

    /* Make table scrollable on mobile */
    .games-table {
        font-size: 0.8rem;
    }

    .games-table th,
    .games-table td {
        padding: 0.5rem;
    }

    .games-table .spirits {
        max-width: 200px;
    }

    /* Replay responsive */
    .replay-page {
        padding: 1rem;
    }

    .replay-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .timeline-container {
        max-height: 15vh;
    }

    .timeline-phase {
        min-width: 40px;
        padding: 0.3rem 0.4rem;
        font-size: 0.75rem;
    }

    .replay-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .replay-game-state {
        order: 2;
        max-height: 60vh;
    }

    .replay-log-view {
        order: 1;
        max-height: none;
    }

    .board-state-content {
        font-size: 0.8rem;
        padding: 1rem;
    }

    .spirit-tabs {
        gap: 0.25rem;
    }

    .spirit-tab {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }

    .card-item {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    .action-row {
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }
}
