:root {
    --bg-black: #050505;
    --panel-bg: rgba(20, 20, 20, 0.85);
    --accent-green: #42f485;
    --frame-grey: #666;
    --text-dim: #888;
    --accent-cyan: #00ffff;
    --alert-red: #ff3333;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100vh;
    margin: 0;
    padding: 10px;
    overflow: hidden; /* Prevents window scrollbars entirely */
    background-color: var(--bg-black);
    color: #eee;
    font-family: 'Courier New', monospace;
}

/* Fixed-height flex column filling exact viewport height */
.outer-frame {
    border: 1px solid var(--frame-grey);
    padding: 12px;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    position: relative;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--frame-grey);
    padding-bottom: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.terminal-title {
    font-size: 1.1rem;
    letter-spacing: 3px;
    color: var(--accent-green);
    font-weight: bold;
}

/* Main stage expands to fill all remaining vertical space */
.duel-stage {
    display: flex;
    align-items: stretch;
    gap: 10px;
    flex: 1;
    min-height: 0; /* Critical for inner flex scrolling/scaling */
    margin-bottom: 10px;
}

.player-box {
    flex: 0 0 280px;
    background: var(--panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.pane-title {
    font-size: 0.85rem;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--accent-green);
    padding-bottom: 5px;
    margin-bottom: 10px;
    color: var(--accent-green);
    text-transform: uppercase;
}

.arena-container {
    flex: 1;
    background: var(--panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

#physics-canvas {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #0a0a0a 0%, #030303 100%);
    display: block;
}

.stat-line {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
}

.stat-value {
    color: #fff;
    font-weight: bold;
}

.glyph-preview {
    width: 80px;
    height: 80px;
    margin: 0 auto 8px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Added transition and dynamic glow effects */
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 0 12px rgba(66, 244, 133, 0.35);
}

.glyph-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.controls-bar {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.load-btn, .start-btn, .help-btn {
    background: transparent;
    border: 1px solid var(--frame-grey);
    color: white;
    font-family: 'Courier New', monospace;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
}

.load-btn:hover {
    border-color: var(--accent-green);
    color: var(--accent-green);
    background: rgba(66, 244, 133, 0.05);
}

.start-btn {
    border-color: var(--accent-green);
    color: var(--accent-green);
    letter-spacing: 2px;
    flex: 1;
}

.start-btn:hover {
    background: rgba(66, 244, 133, 0.15);
    box-shadow: 0 0 10px rgba(66, 244, 133, 0.3);
}

.help-btn {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    letter-spacing: 2px;
}

.help-btn:hover {
    border-color: var(--accent-cyan);
    color: #000000;
    background: var(--accent-cyan);
}

.pulse-green {
    animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
    0% { box-shadow: 0 0 0 0 rgba(66, 244, 133, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(66, 244, 133, 0); }
    100% { box-shadow: 0 0 0 0 rgba(66, 244, 133, 0); }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #000; border-left: 1px solid rgba(255, 255, 255, 0.1); }
::-webkit-scrollbar-thumb { background: #222; border: 1px solid rgba(66, 244, 133, 0.2); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-green); }

/* Frosted Glass Floating Game Over Scorecard */
.game-over-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 150%); /* Starts offscreen below */
    width: 82%;
    max-width: 620px;
    background: rgba(10, 15, 25, 0.65);
    backdrop-filter: blur(12px) saturate(160%);
    -webkit-backdrop-filter: blur(12px) saturate(160%);
    border: 1px solid rgba(0, 255, 255, 0.3);
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(0, 255, 255, 0.15);
    z-index: 100;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
}

.game-over-modal.active {
    transform: translate(-50%, -50%); /* Smooth float up into center */
    opacity: 1;
    pointer-events: auto;
}

.scorecard-header {
    font-family: monospace;
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 2px;
    color: #00ffff;
    text-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
}

.scorecard-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
}

.scorecard-card {
    flex: 1;
    background: rgba(5, 10, 20, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    box-sizing: border-box;
}

.scorecard-card.winner {
    border-color: #42f485;
    box-shadow: 0 0 15px rgba(66, 244, 133, 0.3);
}

.card-winner-badge {
    display: none;
    position: absolute;
    top: -10px;
    background: #42f485;
    color: #000;
    font-family: monospace;
    font-size: 9px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 3px;
    letter-spacing: 1px;
}

.scorecard-card.winner .card-winner-badge {
    display: block;
}

.card-title {
    font-family: monospace;
    font-size: 10px;
    color: #888;
    margin-bottom: 8px;
}

.card-preview {
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    background: #000;
    margin-bottom: 8px;
}

.card-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-family: monospace;
    font-size: 10px;
    margin-top: 3px;
}

.info-label { color: #666; }
.info-val { color: #fff; font-weight: bold; }

.card-score-box {
    margin-top: 10px;
    width: 100%;
    text-align: center;
    background: rgba(0, 0, 0, 0.4);
    padding: 6px 0;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.score-label {
    font-family: monospace;
    font-size: 9px;
    color: #aaa;
}

.score-value {
    font-family: monospace;
    font-size: 20px;
    font-weight: bold;
    color: #00ffff;
}

.vs-divider {
    font-family: monospace;
    font-size: 14px;
    font-weight: bold;
    color: #ff3366;
    text-shadow: 0 0 6px rgba(255, 51, 102, 0.6);
}

.scorecard-dismiss-btn {
    background: rgba(0, 255, 255, 0.15);
    border: 1px solid #00ffff;
    color: #00ffff;
    font-family: monospace;
    font-size: 12px;
    font-weight: bold;
    padding: 6px 24px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.scorecard-dismiss-btn:hover {
    background: #00ffff;
    color: #000;
    box-shadow: 0 0 12px rgba(0, 255, 255, 0.6);
}