:root {
    --bg-color: #0f172a;
    /* Slate 900 */
    --grid-color: #334155;
    /* Slate 700 */
    --text-color: #f1f5f9;
    /* Slate 100 */
    --accent-color: #eab308;
    /* Yellow 500 */
    --debit-color: #60a5fa;
    /* Blue 400 */
    --credit-color: #f87171;
    /* Red 400 */
    --danger-color: #ef4444;
    /* Red 500 */
    --success-color: #22c55e;
    /* Green 500 */
    --panel-bg: rgba(30, 41, 59, 0.95);
    /* Slate 800 */
}

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #020617;
    font-family: 'Roboto Mono', monospace;
    color: var(--text-color);
    touch-action: manipulation;
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    /* Use dynamic viewport height for better iOS behavior */
    height: 100dvh;
    min-height: 100vh;

    background-color: var(--bg-color);
    background-image:
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 40px 40px;
    overflow: hidden;
    /* iOS safe areas */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box;
}

/* Desktop sizing */
@media (min-width: 850px) and (min-height: 650px) {
    #game-container {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        width: 800px;
        height: 600px;
        padding: 0;
        border: 1px solid #334155;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
        border-radius: 12px;
    }
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    touch-action: none;
    /* Prevent any stretching - size controlled by JS */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

#hud {
    position: absolute;
    top: 16px;
    left: 0;
    width: 100%;
    padding: 0 16px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 10;
    pointer-events: none;
}

@media (min-width: 600px) {
    #hud {
        padding: 0 32px;
        top: 24px;
    }
}

#score-board {
    display: flex;
    flex-direction: column;
}

.label {
    font-size: 12px;
    font-weight: bold;
    color: #94a3b8;
}

@media (min-width: 600px) {
    .label {
        font-size: 14px;
    }
}

#score {
    font-size: 28px;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

@media (min-width: 600px) {
    #score {
        font-size: 36px;
    }
}

#lives {
    display: flex;
    gap: 8px;
}

.heart {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

@media (min-width: 600px) {
    .heart {
        font-size: 32px;
    }
}

.heart.lost {
    opacity: 0.3;
    filter: grayscale(100%);
}

#feedback {
    position: absolute;
    top: 80px;
    width: 100%;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    z-index: 15;
    pointer-events: none;
    animation: bounce 0.5s;
}

@media (min-width: 600px) {
    #feedback {
        top: 100px;
        font-size: 24px;
    }
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--panel-bg);
    z-index: 20;
    text-align: center;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

#language-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    z-index: 30;
}

.lang-btn {
    padding: 6px 12px;
    font-size: 12px;
    min-width: auto;
    min-height: auto;
    background-color: rgba(15, 23, 42, 0.8);
    color: #e5e7eb;
    border-radius: 9999px;
    border: 1px solid #4b5563;
    box-shadow: none;
}

.lang-btn.active {
    background-color: var(--accent-color);
    color: #0f172a;
    border-color: var(--accent-color);
}

.gradient-text {
    font-size: 32px;
    font-weight: bold;
    background: linear-gradient(to right, #facc15, #f97316);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

@media (min-width: 600px) {
    .gradient-text {
        font-size: 48px;
    }
}

.debit-text {
    color: var(--debit-color);
    font-weight: bold;
}

.credit-text {
    color: var(--credit-color);
    font-weight: bold;
}

.danger-text {
    color: var(--danger-color);
}

.success-text {
    color: var(--success-color);
    font-weight: bold;
    margin-bottom: 10px;
}

.screen p {
    font-size: 14px;
    color: #94a3b8;
    margin-bottom: 8px;
    padding: 0 20px;
}

.screen p.small {
    font-size: 12px;
    margin-top: 15px;
}

@media (min-width: 600px) {
    .screen p {
        font-size: 18px;
        margin-bottom: 10px;
    }
    .screen p.small {
        font-size: 14px;
        margin-top: 20px;
    }
}

button {
    margin-top: 10px;
    padding: 14px 28px;
    font-size: 16px;
    font-family: 'Roboto Mono', monospace;
    font-weight: 900;
    color: #0f172a;
    background-color: var(--accent-color);
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    box-shadow: 0 4px 6px -1px rgba(234, 179, 8, 0.2);
    min-height: 48px;
    min-width: 120px;
    pointer-events: auto;
    position: relative;
    z-index: 25;
}

@media (min-width: 600px) {
    button {
        padding: 12px 24px;
        font-size: 18px;
    }
}

/* No hover on touch devices */
@media (hover: hover) {
    button:hover {
        background-color: #facc15;
        transform: scale(1.05);
    }
}

button:active {
    transform: scale(0.95);
    background-color: #facc15;
}

.hidden {
    display: none !important;
}

/* Flash Red Animation */
@keyframes flashRed {
    0% {
        background-color: rgba(239, 68, 68, 0.3);
    }

    100% {
        background-color: transparent;
    }
}

.damage-flash {
    animation: flashRed 0.2s ease-out;
}

/* Leaderboard Styles */
#leaderboard-container {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    width: calc(100% - 40px);
    max-width: 300px;
}

@media (min-width: 600px) {
    #leaderboard-container {
        padding: 20px;
        margin: 20px 0;
        width: 300px;
    }
}

#leaderboard-container h3 {
    margin-top: 0;
    color: var(--accent-color);
    border-bottom: 1px solid #334155;
    padding-bottom: 10px;
}

#leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}

#leaderboard-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    font-size: 13px;
}

@media (min-width: 600px) {
    #leaderboard-list li {
        padding: 5px 0;
        font-size: 14px;
    }
}

#leaderboard-list li span:first-child {
    color: #cbd5e1;
}

#leaderboard-list li span:last-child {
    color: var(--accent-color);
    font-weight: bold;
}

/* Submit Score & Certificate */
#submit-score-container {
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: calc(100% - 40px);
    max-width: 250px;
}

@media (min-width: 600px) {
    #submit-score-container {
        margin: 20px 0;
        width: 250px;
    }
}

#username-input {
    padding: 14px;
    border-radius: 8px;
    border: 1px solid #334155;
    background: #0f172a;
    color: #fff;
    font-family: 'Roboto Mono', monospace;
    font-size: 16px;
    text-align: center;
    text-transform: uppercase;
    min-height: 48px;
    box-sizing: border-box;
}

#username-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

#submit-score-btn {
    background-color: var(--success-color);
    color: #fff;
    box-shadow: 0 4px 6px -1px rgba(34, 197, 94, 0.2);
}

#submit-score-btn:hover {
    background-color: #16a34a;
}

#submit-score-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#certificate-container {
    margin: 20px 0;
    padding: 20px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--success-color);
    border-radius: 8px;
}

#download-cert-btn {
    background-color: #3b82f6;
    /* Blue */
    color: #fff;
    font-size: 16px;
    padding: 10px 20px;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.2);
}

@media (hover: hover) {
    #download-cert-btn:hover {
        background-color: #2563eb;
    }
}

/* Mobile touch area indicator */
#touch-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    color: rgba(148, 163, 184, 0.6);
    pointer-events: none;
    z-index: 5;
    text-align: center;
}

@media (min-width: 850px) {
    #touch-hint {
        display: none;
    }
}

/* Landscape orientation warning for very small heights */
@media (max-height: 400px) and (orientation: landscape) {
    .screen {
        padding: 10px;
    }
    .gradient-text {
        font-size: 24px;
        margin-bottom: 5px;
    }
    .screen p {
        font-size: 12px;
        margin-bottom: 5px;
    }
    #leaderboard-container {
        display: none;
    }
    button {
        padding: 10px 20px;
        min-height: 40px;
    }
}