/* ── Retro QBasic Gorillas — Modernised DOS Aesthetic ──────────────── */

/* Retro palette */
:root {
    --bg-dark:     #0a0a14;
    --bg-panel:    #0f0f1e;
    --border:      #3a3a5c;
    --border-glow: #6c5ce7;
    --cyan:        #00e5ff;
    --amber:       #ffb300;
    --green:       #39ff14;
    --magenta:     #ff2d95;
    --white:       #e0e0e0;
    --muted:       #6b6b8d;
    --input-bg:    #161628;
    --fire-red:    #ff1744;
}

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

body {
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Courier New', Consolas, monospace;
    overflow: hidden;
}

#gameContainer {
    position: relative;
    width: 1280px;
    height: 720px;
}

#gameCanvas {
    display: block;
    width: 1280px;
    height: 720px;
}

/* ── Screen Overlays ─────────────────────────────────────────────── */
.screen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--bg-dark);
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255,255,255,0.015) 2px,
            rgba(255,255,255,0.015) 4px
        );
    z-index: 10;
}

/* ── Title Screen ────────────────────────────────────────────────── */

/* CRT overlay — scanlines + vignette on the whole title screen */
#titleScreen::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        repeating-linear-gradient(
            0deg,
            rgba(0,0,0,0.25) 0px,
            rgba(0,0,0,0.25) 1px,
            transparent 1px,
            transparent 3px
        );
    pointer-events: none;
    z-index: 2;
    animation: scanlineScroll 8s linear infinite;
}

/* Vignette corners */
#titleScreen::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.7) 100%);
    pointer-events: none;
    z-index: 2;
}

@keyframes scanlineScroll {
    0%   { background-position: 0 0; }
    100% { background-position: 0 300px; }
}

.title-box {
    text-align: center;
    position: relative;
    z-index: 3;
    animation: crtFlicker 4s infinite;
}

/* Subtle CRT flicker on the whole title */
@keyframes crtFlicker {
    0%, 100% { opacity: 1; }
    3%       { opacity: 0.85; }
    6%       { opacity: 1; }
    42%      { opacity: 1; }
    43%      { opacity: 0.9; }
    44%      { opacity: 1; }
    87%      { opacity: 1; }
    87.5%    { opacity: 0.7; }
    88%      { opacity: 1; }
}

.title-decoration {
    color: var(--border-glow);
    font-size: 20px;
    letter-spacing: 4px;
    opacity: 0.6;
}

/* Main title with RGB-split glitch */
#titleScreen h1 {
    font-size: 80px;
    color: var(--amber);
    letter-spacing: 12px;
    position: relative;
    margin: 4px 0;
    text-shadow:
        0 0 10px rgba(255, 179, 0, 0.5),
        0 0 30px rgba(255, 179, 0, 0.2),
        3px 3px 0 #553800;
    animation: glitchText 3s infinite;
}

/* Red channel ghost — left offset */
#titleScreen h1::before {
    content: 'GORILLAS';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    color: var(--magenta);
    opacity: 0;
    mix-blend-mode: screen;
    animation: glitchRedChannel 3s infinite;
    pointer-events: none;
    text-shadow: none;
}

/* Cyan channel ghost — right offset */
#titleScreen h1::after {
    content: 'GORILLAS';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    color: var(--cyan);
    opacity: 0;
    mix-blend-mode: screen;
    animation: glitchCyanChannel 3s infinite;
    pointer-events: none;
    text-shadow: none;
}

@keyframes glitchText {
    0%, 100% { transform: translate(0, 0); }
    20.5%    { transform: translate(-2px, 0); }
    21%      { transform: translate(3px, 0); }
    21.5%    { transform: translate(0, 0); }
    60%      { transform: translate(0, 0); }
    60.5%    { transform: translate(0, -1px); }
    61%      { transform: translate(-1px, 2px); }
    61.5%    { transform: translate(0, 0); }
}

@keyframes glitchRedChannel {
    0%, 100% { opacity: 0; transform: translate(0, 0); }
    20%      { opacity: 0; }
    20.5%    { opacity: 0.6; transform: translate(-4px, 1px); }
    21.5%    { opacity: 0.6; transform: translate(-3px, -1px); }
    22%      { opacity: 0; transform: translate(0, 0); }
    60%      { opacity: 0; }
    60.5%    { opacity: 0.5; transform: translate(-5px, 0); }
    61.5%    { opacity: 0; transform: translate(0, 0); }
}

@keyframes glitchCyanChannel {
    0%, 100% { opacity: 0; transform: translate(0, 0); }
    20%      { opacity: 0; }
    20.5%    { opacity: 0.5; transform: translate(4px, -1px); }
    21.5%    { opacity: 0.5; transform: translate(3px, 1px); }
    22%      { opacity: 0; transform: translate(0, 0); }
    60%      { opacity: 0; }
    60.5%    { opacity: 0.4; transform: translate(5px, 0); }
    61.5%    { opacity: 0; transform: translate(0, 0); }
}

#titleScreen .subtitle {
    font-size: 16px;
    color: var(--muted);
    margin-bottom: 12px;
    letter-spacing: 3px;
    animation: subtitleGlitch 6s infinite;
}

@keyframes subtitleGlitch {
    0%, 100% { transform: translate(0, 0) skewX(0deg); opacity: 1; }
    33%      { transform: translate(0, 0) skewX(0deg); opacity: 1; }
    33.3%    { transform: translate(80px, 0) skewX(-5deg); opacity: 0.7; clip-path: inset(0 0 50% 0); }
    33.6%    { transform: translate(-40px, 0) skewX(3deg); opacity: 0.8; clip-path: inset(40% 0 0 0); }
    34%      { transform: translate(0, 0) skewX(0deg); opacity: 1; clip-path: none; }
    74%      { transform: translate(0, 0) skewX(0deg); opacity: 1; }
    74.2%    { transform: translate(-60px, 0) skewX(4deg); opacity: 0.6; }
    74.5%    { transform: translate(0, 0) skewX(0deg); opacity: 1; }
}

#titleScreen .title-banana {
    font-size: 48px;
    margin: 16px 0;
}

#titleScreen .credits {
    font-size: 11px;
    color: var(--muted);
    margin-top: 28px;
    letter-spacing: 1px;
}

#titleScreen .credits.remake-credit {
    margin-top: 4px;
}

#titleScreen .credits.version {
    margin-top: 8px;
    font-size: 10px;
    color: var(--border);
    letter-spacing: 2px;
}

#titleScreen .credits a {
    color: var(--muted);
    text-decoration: underline;
}

#titleScreen .credits a:hover {
    color: #ffffff;
}

.blink-prompt {
    margin-top: 10px;
    font-size: 13px;
    color: var(--cyan);
    letter-spacing: 2px;
    animation: blink 1.2s step-end infinite;
    text-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Settings Screen ─────────────────────────────────────────────── */
#settingsScreen {
    color: var(--white);
}

.settings-form {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    box-shadow:
        0 0 20px rgba(108, 92, 231, 0.15),
        inset 0 0 60px rgba(0, 0, 0, 0.4);
    padding: 36px 48px;
    width: 520px;
    border-radius: 2px;
}

.settings-form h2 {
    color: var(--cyan);
    text-align: center;
    margin-bottom: 8px;
    font-size: 26px;
    letter-spacing: 4px;
    text-shadow: 0 0 12px rgba(0, 229, 255, 0.3);
}

.form-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
    margin: 16px 0;
}

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.form-row > label {
    font-size: 15px;
    color: var(--muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: bold;
}

.form-row input[type="text"],
.form-row input[type="number"] {
    width: 210px;
    padding: 8px 12px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 15px;
    background: var(--input-bg);
    color: var(--green);
    border: 1px solid var(--border);
    border-radius: 2px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -moz-appearance: textfield;
}

/* Hide native spinners on settings number inputs */
.form-row input[type="number"]::-webkit-outer-spin-button,
.form-row input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-row input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.25);
}

/* Settings custom spin buttons */
.settings-input-wrap {
    display: flex;
    align-items: center;
}

.settings-spin-btns {
    display: flex;
    flex-direction: column;
    margin-left: 6px;
    gap: 2px;
}

.settings-spin-btn {
    width: 26px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--border);
    color: var(--cyan);
    border: none;
    cursor: pointer;
    font-size: 10px;
    line-height: 1;
    border-radius: 2px;
    transition: background 0.1s, color 0.1s;
    padding: 0;
    font-family: 'Courier New', Consolas, monospace;
}

.settings-spin-btn:hover {
    background: var(--border-glow);
    color: #fff;
    box-shadow: 0 0 6px rgba(108, 92, 231, 0.4);
}

.settings-spin-btn:active {
    background: var(--cyan);
    color: var(--bg-dark);
}

/* Custom radio buttons */
.radio-group {
    display: flex;
    gap: 16px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--white);
    font-size: 15px;
    letter-spacing: 1px;
}

.radio-label input[type="radio"] {
    display: none;
}

.radio-custom {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-radius: 50%;
    position: relative;
    transition: border-color 0.2s;
}

.radio-label input[type="radio"]:checked + .radio-custom {
    border-color: var(--cyan);
}

.radio-label input[type="radio"]:checked + .radio-custom::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 6px;
    height: 6px;
    background: var(--cyan);
    border-radius: 50%;
    box-shadow: 0 0 6px var(--cyan);
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.retro-btn {
    font-family: 'Courier New', Consolas, monospace;
    font-size: 18px;
    font-weight: bold;
    padding: 12px 36px;
    background: transparent;
    color: var(--amber);
    border: 2px solid var(--amber);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-top: 16px;
    transition: all 0.15s;
    border-radius: 2px;
}

.retro-btn:hover {
    background: var(--amber);
    color: var(--bg-dark);
    box-shadow: 0 0 16px rgba(255, 179, 0, 0.35);
}

.retro-btn:active {
    transform: scale(0.97);
}

.btn-play {
    color: var(--green);
    border-color: var(--green);
}

.btn-play:hover {
    background: var(--green);
    color: var(--bg-dark);
    box-shadow: 0 0 16px rgba(57, 255, 20, 0.35);
}

/* ── Near Miss Flash ──────────────────────────────────────────────── */
.near-miss-flash {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    font-family: 'Courier New', Consolas, monospace;
    font-size: 64px;
    font-weight: bold;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 8px;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    text-shadow:
        3px 0 var(--magenta),
        -3px 0 var(--cyan);
    display: none;
}

.near-miss-flash.active {
    display: block;
    animation: nearMissAnim 1.4s ease-out forwards;
}

@keyframes nearMissAnim {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
        text-shadow: 3px 0 var(--magenta), -3px 0 var(--cyan);
    }
    10% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
        text-shadow: 5px 0 var(--magenta), -5px 0 var(--cyan);
    }
    30% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.15);
        text-shadow: 8px 2px var(--magenta), -8px -2px var(--cyan);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.25) skewX(-2deg);
        text-shadow: 6px -1px var(--magenta), -6px 1px var(--cyan);
    }
    70% {
        opacity: 0.9;
        transform: translate(-50%, -50%) scale(1.3) skewX(4deg);
        text-shadow: 12px 3px var(--magenta), -12px -3px var(--cyan);
    }
    85% {
        opacity: 0.4;
        transform: translate(-50%, -50%) scale(1.4) skewX(-8deg);
        text-shadow: 20px 5px var(--magenta), -20px -5px var(--cyan);
        clip-path: inset(0 0 0 0);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.5) skewX(12deg);
        text-shadow: 30px 8px var(--magenta), -30px -8px var(--cyan);
        clip-path: inset(0 100% 0 0);
    }
}

/* ── Point Scored Flash ──────────────────────────────────────────── */
.point-flash {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    font-family: 'Courier New', Consolas, monospace;
    font-size: 52px;
    font-weight: bold;
    color: var(--amber);
    text-transform: uppercase;
    letter-spacing: 6px;
    white-space: nowrap;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    text-shadow:
        3px 0 var(--magenta),
        -3px 0 var(--cyan);
    display: none;
}

.point-flash.active {
    display: block;
    animation: pointFlashAnim 2.2s ease-out forwards;
}

@keyframes pointFlashAnim {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3);
        filter: brightness(2);
    }
    8% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
        filter: brightness(1.5);
        text-shadow: 3px 0 var(--magenta), -3px 0 var(--cyan);
    }
    15% {
        transform: translate(-50%, -50%) scale(1.0);
        filter: brightness(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.0) skewX(0deg);
        text-shadow: 3px 0 var(--magenta), -3px 0 var(--cyan);
        clip-path: inset(0 0 0 0);
    }
    75% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1.1) skewX(4deg);
        text-shadow: 10px 3px var(--magenta), -10px -3px var(--cyan);
        clip-path: inset(0 0 0 0);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.3) skewX(10deg);
        text-shadow: 25px 6px var(--magenta), -25px -6px var(--cyan);
        clip-path: inset(0 100% 0 0);
    }
}

/* ── Input Overlay (in-game) ─────────────────────────────────────── */
.input-overlay {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 5;
    background: rgba(10, 10, 20, 0.92);
    border: 1px solid var(--border);
    box-shadow: 0 0 20px rgba(108, 92, 231, 0.2);
    padding: 14px 20px 16px;
    border-radius: 2px;
    opacity: 0.85;
    transition: opacity 0.2s;
    min-width: 180px;
}

.input-overlay:hover {
    opacity: 1;
}

.turn-label {
    color: var(--amber);
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

.input-row label {
    color: var(--cyan);
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
    min-width: 70px;
}

/* Number input wrapper for custom spinners */
.input-row .input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.input-row input {
    width: 64px;
    padding: 6px 8px;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 15px;
    background: var(--input-bg);
    color: var(--green);
    border: 1px solid var(--border);
    border-radius: 2px;
    outline: none;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
    -moz-appearance: textfield;
}

/* Hide native spinner */
.input-row input::-webkit-outer-spin-button,
.input-row input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-row input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.25);
}

/* Custom spin buttons */
.spin-btns {
    display: flex;
    flex-direction: column;
    margin-left: 4px;
    gap: 2px;
}

.spin-btn {
    width: 20px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--border);
    color: var(--cyan);
    border: none;
    cursor: pointer;
    font-size: 10px;
    line-height: 1;
    border-radius: 2px;
    transition: background 0.1s;
    padding: 0;
    font-family: 'Courier New', Consolas, monospace;
}

.spin-btn:hover {
    background: var(--border-glow);
    color: #fff;
    box-shadow: 0 0 6px rgba(108, 92, 231, 0.4);
}

.spin-btn:active {
    background: var(--cyan);
    color: var(--bg-dark);
}

#fireButton {
    font-family: 'Courier New', Consolas, monospace;
    font-size: 15px;
    font-weight: bold;
    padding: 10px 32px;
    width: 100%;
    background: var(--fire-red);
    color: #fff;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-radius: 2px;
    transition: all 0.15s;
    box-shadow: 0 0 10px rgba(255, 23, 68, 0.3);
    margin-top: 4px;
}

#fireButton:hover {
    background: #ff5252;
    box-shadow: 0 0 20px rgba(255, 23, 68, 0.5);
}

#fireButton:active {
    transform: scale(0.95);
}

/* Fire shake + fade out */
.input-overlay.firing {
    animation: fireShakeFade 0.5s ease-out forwards;
    pointer-events: none;
}

@keyframes fireShakeFade {
    0%   { transform: translateX(-50%) translate(0, 0);     opacity: 0.85; }
    10%  { transform: translateX(-50%) translate(-6px, 0);  opacity: 0.8; }
    20%  { transform: translateX(-50%) translate(5px, -2px); opacity: 0.7; }
    30%  { transform: translateX(-50%) translate(-4px, 1px); opacity: 0.6; }
    40%  { transform: translateX(-50%) translate(3px, -1px); opacity: 0.5; }
    50%  { transform: translateX(-50%) translate(-2px, 0);  opacity: 0.4; }
    60%  { transform: translateX(-50%) translate(1px, 0);   opacity: 0.3; }
    70%  { transform: translateX(-50%) translate(-1px, 0);  opacity: 0.2; }
    80%  { transform: translateX(-50%) translate(0, 0);     opacity: 0.1; }
    100% { transform: translateX(-50%) translate(0, 0);     opacity: 0; }
}

/* ── Match End Screen ────────────────────────────────────────────── */
.match-end-box {
    text-align: center;
}

.match-end-banner {
    font-size: 14px;
    color: var(--magenta);
    letter-spacing: 12px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

#matchEndScreen h2 {
    font-size: 52px;
    color: var(--amber);
    margin-bottom: 16px;
    text-shadow:
        0 0 12px rgba(255, 179, 0, 0.4),
        3px 3px 0 #553800;
    letter-spacing: 4px;
}

#matchEndScreen .final-score {
    font-size: 28px;
    color: var(--cyan);
    margin-bottom: 30px;
    letter-spacing: 2px;
}

/* ── Game Control Buttons (bottom-right) ─────────────────────────── */
.game-buttons {
    position: absolute;
    bottom: 14px;
    right: 14px;
    display: flex;
    gap: 8px;
    z-index: 6;
}

.game-ctrl-btn {
    font-family: 'Courier New', Consolas, monospace;
    font-size: 13px;
    font-weight: bold;
    padding: 6px 12px;
    background: rgba(10, 10, 20, 0.85);
    color: var(--muted);
    border: 1px solid var(--border);
    cursor: pointer;
    letter-spacing: 1px;
    border-radius: 2px;
    transition: all 0.15s;
    line-height: 1;
}

.game-ctrl-btn:hover {
    color: var(--white);
    border-color: var(--border-glow);
    box-shadow: 0 0 8px rgba(108, 92, 231, 0.3);
    background: rgba(15, 15, 30, 0.95);
}

.game-ctrl-btn:active {
    transform: scale(0.95);
}

.game-ctrl-btn.muted {
    color: var(--fire-red);
    border-color: var(--fire-red);
}

.game-ctrl-btn.muted:hover {
    box-shadow: 0 0 8px rgba(255, 23, 68, 0.3);
}

.btn-quit {
    font-size: 15px;
}

.btn-quit:hover {
    color: var(--fire-red);
    border-color: var(--fire-red);
    box-shadow: 0 0 8px rgba(255, 23, 68, 0.3);
}

/* ── Responsive scaling ──────────────────────────────────────────── */
@media (max-width: 1300px) {
    #gameContainer {
        transform: scale(0.8);
        transform-origin: center center;
    }
}

@media (max-width: 1050px) {
    #gameContainer {
        transform: scale(0.6);
        transform-origin: center center;
    }
}
