/* codex: 2026-08-10 Add move history and clear victory-modal actions. */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700&display=swap');

:root {
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.85);
    --card-border: rgba(255, 255, 255, 0.15);
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    
    --blue-color: #38bdf8;  /* Cyan-Blue for Blue/Top-Bottom player */
    --red-color: #f43f5e;   /* Rose Red for Red/Left-Right player */
    --gold-accent: #fbbf24;
    
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html {
    font-size: 18px;
}

body {
    background: radial-gradient(circle at top center, #1e1b4b 0%, #0f172a 100%);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
}

.game-container {
    width: 100%;
    max-width: 1050px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Header & Controls */
header {
    width: 100%;
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 20px 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.title-section h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #38bdf8, #f43f5e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.title-section p {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.control-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

select {
    background: rgba(15, 23, 42, 0.9);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
    padding: 8px 14px;
    border-radius: 8px;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

select:hover {
    border-color: var(--blue-color);
}

/* Action Buttons */
.btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
    padding: 10px 18px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7, #2563eb);
    border: none;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0369a1, #1d4ed8);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.9rem;
}

/* Status Bar */
.status-bar {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 14px 24px;
    gap: 16px;
}

.status-badge {
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 1.05rem;
    font-weight: 700;
}

.status-badge.player-turn.blue {
    background: rgba(56, 189, 248, 0.25);
    color: var(--blue-color);
    border: 2px solid var(--blue-color);
}

.status-badge.player-turn.red {
    background: rgba(244, 63, 94, 0.25);
    color: var(--red-color);
    border: 2px solid var(--red-color);
}

.status-badge.ai-turn {
    background: rgba(244, 63, 94, 0.2);
    color: #fda4af;
    border: 2px solid var(--red-color);
    animation: thinkingPulse 1.2s infinite ease-in-out;
}

@keyframes thinkingPulse {
    0% {
        box-shadow: 0 0 4px rgba(244, 63, 94, 0.3);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 16px rgba(244, 63, 94, 0.7);
        transform: scale(1.03);
        background: rgba(244, 63, 94, 0.35);
    }
    100% {
        box-shadow: 0 0 4px rgba(244, 63, 94, 0.3);
        transform: scale(1);
    }
}

.status-badge.game-over {
    background: rgba(148, 163, 184, 0.25);
    color: var(--text-secondary);
}

.exempt-badge {
    background: rgba(245, 158, 11, 0.25);
    color: #fbbf24;
    border: 1px solid #fbbf24;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 700;
}

.game-metrics {
    display: flex;
    gap: 20px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* SVG Board Container */
.board-wrapper {
    width: 100%;
    min-height: 480px;
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: auto;
}

svg#boardSvg {
    display: block;
    margin: 0 auto;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* SVG Goal Labels */
.svg-goal-label {
    font-size: 14px;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: middle;
}

.svg-goal-label.blue-label {
    fill: var(--blue-color);
}

.svg-goal-label.red-label {
    fill: var(--red-color);
}

/* SVG Dots */
.dot.blue-dot {
    fill: var(--blue-color);
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.8));
}

.dot.red-dot {
    fill: var(--red-color);
    filter: drop-shadow(0 0 8px rgba(244, 63, 94, 0.8));
}

/* SVG Lines */
.edge {
    stroke-width: 8;
    stroke-linecap: round;
    transition: all 0.2s ease;
}

.edge.blue-edge {
    stroke: rgba(56, 189, 248, 0.25);
}

.edge.blue-edge.playable {
    cursor: pointer;
}

.edge.blue-edge.playable:hover {
    stroke: rgba(56, 189, 248, 0.9);
    stroke-width: 12;
}

.edge.blue-edge.owned {
    stroke: var(--blue-color);
    stroke-width: 12;
    filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.9));
}

.edge.red-edge {
    stroke: rgba(244, 63, 94, 0.25);
}

.edge.red-edge.playable {
    cursor: pointer;
}

.edge.red-edge.playable:hover {
    stroke: rgba(244, 63, 94, 0.9);
    stroke-width: 12;
}

.edge.red-edge.owned {
    stroke: var(--red-color);
    stroke-width: 12;
    filter: drop-shadow(0 0 10px rgba(244, 63, 94, 0.9));
}

.edge.unplayable {
    cursor: default;
}

.edge.blocked {
    stroke: rgba(255, 255, 255, 0.05);
    cursor: not-allowed;
}

.edge.last-move {
    animation: pulseGlow 1.2s infinite alternate;
}

@keyframes pulseGlow {
    0% { stroke-width: 12; filter: drop-shadow(0 0 6px var(--gold-accent)); }
    100% { stroke-width: 16; filter: drop-shadow(0 0 16px var(--gold-accent)); }
}

.edge.hint-pulse {
    stroke: var(--gold-accent) !important;
    stroke-width: 14 !important;
    animation: hintGlow 0.5s 4 alternate;
}

@keyframes hintGlow {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 999;
    padding: 20px;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 32px;
    max-width: 680px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 14px;
}

.modal-header h2 {
    font-size: 1.6rem;
    color: var(--text-primary);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.8rem;
    cursor: pointer;
}

.rules-body p {
    margin-bottom: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
    font-size: 1.05rem;
}

.rules-body strong {
    color: var(--text-primary);
}

.rule-diagram {
    background: rgba(15, 23, 42, 0.7);
    border-radius: 14px;
    padding: 20px;
    margin: 20px 0;
    text-align: center;
    border: 1px solid var(--card-border);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.stats-table th, .stats-table td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid var(--card-border);
    font-size: 1rem;
}

.stats-table th {
    color: var(--text-secondary);
}

.overall-summary {
    margin-top: 24px;
    text-align: right;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.victory-body {
    text-align: center;
    padding: 24px 0;
}

.victory-body h2 {
    font-size: 2.2rem;
    margin-bottom: 14px;
}

.victory-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.victory-actions .btn {
    padding: 12px 20px;
    font-size: 1.05rem;
}

.move-history-panel {
    width: 100%;
    border-top: 1px solid var(--card-border);
    padding: 4px 0 0;
}

.move-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.move-history-header h2 {
    font-size: 1.1rem;
}

.move-history-header span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.move-history-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    list-style: none;
    max-height: 180px;
    overflow-y: auto;
    padding: 0 2px 4px;
}

.move-history-item,
.move-history-empty {
    border-left: 3px solid var(--card-border);
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 8px 10px;
}

.move-history-item.blue {
    border-left-color: var(--blue-color);
}

.move-history-item.red {
    border-left-color: var(--red-color);
}

.move-history-item code {
    color: var(--text-primary);
    margin-left: 6px;
}
