/* ========================================
   SUBMARINE BATTLE - Retro Handheld Style
   ======================================== */

/* Reset & Base */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --device-yellow: #e8b820;
    --device-dark-yellow: #c89a10;
    --device-shadow: #a07808;
    --bezel-color: #1a6848;
    --bezel-dark: #0d4830;
    --screen-bg: #8bac0f;
    --screen-dark: #306230;
    --btn-red: #d42020;
    --btn-red-dark: #a01818;
    --btn-red-glow: #ff4040;
    --dpad-red: #c83030;
    --dpad-dark: #901818;
    --text-dark: #1a1a2e;
    --text-light: #f0e8c0;
    --hud-color: #0a2a18;
    --overlay-bg: rgba(10, 42, 24, 0.92);
}

body {
    font-family: 'Press Start 2P', monospace;
    background: linear-gradient(135deg, #0a0a2e 0%, #1a1a4e 30%, #0a2a4e 60%, #0a1a3e 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    -webkit-overflow-scrolling: touch;
}

/* Animated background bubbles */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(2px 2px at 20% 30%, rgba(100, 200, 255, 0.3), transparent),
        radial-gradient(2px 2px at 40% 70%, rgba(100, 200, 255, 0.2), transparent),
        radial-gradient(3px 3px at 60% 20%, rgba(100, 200, 255, 0.3), transparent),
        radial-gradient(2px 2px at 80% 50%, rgba(100, 200, 255, 0.2), transparent),
        radial-gradient(2px 2px at 10% 80%, rgba(100, 200, 255, 0.15), transparent),
        radial-gradient(3px 3px at 90% 90%, rgba(100, 200, 255, 0.2), transparent);
    animation: bubbleFloat 8s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes bubbleFloat {
    0% {
        transform: translateY(0);
    }

    100% {
        transform: translateY(-20px);
    }
}

/* ==================
   DEVICE FRAME
   ================== */
.device {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1200px;
    background: linear-gradient(180deg, #f0c830 0%, var(--device-yellow) 15%, var(--device-dark-yellow) 85%, var(--device-shadow) 100%);
    border-radius: 24px;
    padding: 12px 16px 20px;
    box-shadow:
        0 0 0 3px #b08810,
        0 8px 32px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -2px 0 rgba(0, 0, 0, 0.2);
    user-select: none;
}

/* Top decorative strip */
.device-top-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 6px 0 10px;
}

.strip-lines {
    display: flex;
    gap: 3px;
}

.strip-lines span {
    display: block;
    width: 40px;
    height: 3px;
    border-radius: 2px;
}

.strip-lines.left span {
    background: linear-gradient(90deg, #1a1a4e, #2040a0);
    transform: skewX(-15deg);
}

.strip-lines.right span {
    background: linear-gradient(90deg, #2040a0, #1a1a4e);
    transform: skewX(-15deg);
}

.game-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 18px;
    color: var(--text-dark);
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.3);
    letter-spacing: 2px;
    white-space: nowrap;
}

/* ==================
   SCREEN
   ================== */
.screen-bezel {
    background: linear-gradient(180deg, var(--bezel-dark) 0%, var(--bezel-color) 10%, var(--bezel-color) 90%, var(--bezel-dark) 100%);
    border-radius: 12px;
    padding: 12px;
    box-shadow:
        inset 0 2px 8px rgba(0, 0, 0, 0.5),
        0 2px 0 rgba(255, 255, 255, 0.1);
}

.screen {
    position: relative;
    width: 100%;
    background: #1a3a2a;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Scanline overlay */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px);
    pointer-events: none;
    z-index: 5;
}

/* HUD */
.hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: linear-gradient(180deg, rgba(0, 20, 10, 0.8) 0%, transparent 100%);
    z-index: 10;
    font-family: 'Press Start 2P', monospace;
}

.hud-left,
.hud-center,
.hud-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-size: 7px;
    color: #60a060;
    letter-spacing: 1px;
}

.hud-value {
    font-size: 14px;
    color: #a0ff60;
    text-shadow: 0 0 8px rgba(160, 255, 96, 0.5);
}

/* ==================
   OVERLAYS
   ================== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: opacity 0.3s;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 20px;
}

.overlay-content h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: 20px;
    color: #a0ff60;
    text-shadow: 0 0 16px rgba(160, 255, 96, 0.6);
    margin-bottom: 16px;
}

.overlay-content .subtitle {
    font-size: 9px;
    color: #60c060;
    margin-bottom: 20px;
    letter-spacing: 2px;
}

.enemy-preview {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 24px;
}

.enemy-preview span {
    font-size: 8px;
    color: #80d080;
    letter-spacing: 1px;
}

.press-start {
    font-size: 12px;
    color: #ffdd40;
    text-shadow: 0 0 10px rgba(255, 221, 64, 0.5);
    margin-bottom: 12px;
}

.controls-hint {
    font-size: 7px;
    color: #508050;
    line-height: 1.6;
}

/* Blink animation */
.blink {
    animation: blink 1s step-end infinite;
}

.blink-slow {
    animation: blink 1.5s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Game Over */
.game-over-text {
    color: #ff4040 !important;
    text-shadow: 0 0 16px rgba(255, 64, 64, 0.6) !important;
    font-size: 24px !important;
}

.final-stats {
    margin: 16px 0;
}

.final-stats p {
    font-size: 10px;
    color: #80d080;
    margin: 6px 0;
}

.final-stats span {
    color: #a0ff60;
}

.name-input {
    margin: 16px 0;
}

.name-input label {
    font-size: 8px;
    color: #60a060;
    display: block;
    margin-bottom: 8px;
}

.name-input input {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    background: #0a2a18;
    border: 2px solid #40a040;
    color: #a0ff60;
    padding: 8px 12px;
    text-align: center;
    text-transform: uppercase;
    width: 180px;
    outline: none;
    border-radius: 4px;
}

.name-input input:focus {
    border-color: #80ff80;
    box-shadow: 0 0 10px rgba(128, 255, 128, 0.3);
}

/* Retro buttons */
.btn-retro {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    background: linear-gradient(180deg, #40a040, #208020);
    color: #e0ffe0;
    border: 2px solid #60c060;
    padding: 10px 20px;
    margin: 6px;
    cursor: pointer;
    border-radius: 4px;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
    transition: all 0.1s;
}

.btn-retro:hover {
    background: linear-gradient(180deg, #50c050, #30a030);
    box-shadow: 0 0 12px rgba(80, 192, 80, 0.5);
}

.btn-retro:active {
    transform: scale(0.95);
}

/* Scores table */
.scores-table {
    margin: 12px auto;
    width: 100%;
    max-width: 380px;
}

.score-header,
.score-row {
    display: grid;
    grid-template-columns: 50px 1fr 80px 40px;
    gap: 4px;
    padding: 4px 0;
    font-size: 8px;
}

.score-header {
    color: #60a060;
    border-bottom: 1px solid #306030;
    padding-bottom: 8px;
    margin-bottom: 4px;
}

.score-row {
    color: #a0ff60;
}

.score-row:nth-child(even) {
    color: #80d080;
}

.score-row .rank-1 {
    color: #ffd700;
}

.score-row .rank-2 {
    color: #c0c0c0;
}

.score-row .rank-3 {
    color: #cd7f32;
}

/* ==================
   CONTROLS AREA
   ================== */
.controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 8px 8px;
    gap: 12px;
}

/* Left: Action buttons */
.controls-left {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

.action-btn-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.action-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.action-label span {
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    color: var(--text-dark);
    letter-spacing: 1px;
}

/* Big red action buttons */
.btn-action {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid var(--btn-red-dark);
    background: radial-gradient(circle at 35% 35%, #ff5050, var(--btn-red) 50%, var(--btn-red-dark) 100%);
    cursor: pointer;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.2),
        0 0 0 2px var(--device-dark-yellow);
    transition: all 0.1s;
    position: relative;
}

.btn-action .btn-inner-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    pointer-events: none;
}

.btn-inner-label svg {
    opacity: 0.9;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.btn-inner-label span {
    font-family: 'Press Start 2P', monospace;
    font-size: 5px;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 0.5px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
}

.btn-action:active {
    transform: scale(0.92);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 2px 8px rgba(0, 0, 0, 0.3),
        0 0 0 2px var(--device-dark-yellow);
}

.btn-action:hover {
    box-shadow:
        0 4px 12px rgba(212, 32, 32, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.2),
        0 0 0 2px var(--device-dark-yellow),
        0 0 20px rgba(255, 64, 64, 0.3);
}

/* Center buttons */
.controls-center {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.center-buttons {
    display: flex;
    gap: 8px;
}

.btn-small {
    width: 40px;
    height: 32px;
    border: none;
    border-radius: 4px;
    background: linear-gradient(180deg, #555, #333);
    color: white;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: all 0.1s;
}

.btn-small:active {
    transform: scale(0.9);
}

.btn-start {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    padding: 8px 20px;
    background: linear-gradient(180deg, #50a0e0, #2070b0);
    color: white;
    border: 2px solid #3088c8;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.1s;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
}

.btn-start:hover {
    background: linear-gradient(180deg, #60b0f0, #3080c0);
    box-shadow: 0 3px 12px rgba(80, 160, 224, 0.5);
}

.btn-start:active {
    transform: scale(0.92);
}

/* Right: D-Pad */
.controls-right {
    display: flex;
    align-items: center;
    justify-content: center;
}

.dpad {
    display: grid;
    grid-template-areas:
        ".  up  ."
        "left center right"
        ".  down .";
    grid-template-columns: 44px 44px 44px;
    grid-template-rows: 44px 44px 44px;
    gap: 0px;
}

.dpad-btn {
    font-size: 14px;
    border: none;
    color: #1a0808;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.05s;
    font-weight: bold;
}

.dpad-up {
    grid-area: up;
    background: linear-gradient(180deg, #e84040, var(--dpad-red));
    border-radius: 6px 6px 0 0;
    box-shadow: 0 -2px 0 var(--dpad-dark);
}

.dpad-down {
    grid-area: down;
    background: linear-gradient(0deg, #e84040, var(--dpad-red));
    border-radius: 0 0 6px 6px;
    box-shadow: 0 2px 0 var(--dpad-dark);
}

.dpad-left {
    grid-area: left;
    background: linear-gradient(90deg, #e84040, var(--dpad-red));
    border-radius: 6px 0 0 6px;
    box-shadow: -2px 0 0 var(--dpad-dark);
}

.dpad-right {
    grid-area: right;
    background: linear-gradient(-90deg, #e84040, var(--dpad-red));
    border-radius: 0 6px 6px 0;
    box-shadow: 2px 0 0 var(--dpad-dark);
}

.dpad-center {
    grid-area: center;
    background: var(--dpad-red);
    border-radius: 50%;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.dpad-btn:active {
    filter: brightness(0.8);
    transform: scale(0.92);
}

/* Bottom strip */
.device-bottom-strip {
    height: 8px;
    background: linear-gradient(90deg, var(--device-shadow), var(--device-dark-yellow), var(--device-shadow));
    border-radius: 0 0 16px 16px;
    margin-top: 4px;
}

/* Footer credit */
.device-footer {
    text-align: center;
    padding: 6px 0 2px;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    color: var(--device-shadow);
    letter-spacing: 0.5px;
    line-height: 1.8;
}

.device-footer a {
    color: var(--text-dark);
    text-decoration: none;
    border-bottom: 1px dotted var(--device-shadow);
    transition: color 0.2s;
}

.device-footer a:hover {
    color: #2060a0;
}

/* ==================
   TOUCH OPTIMIZATIONS
   ================== */
.btn-action,
.btn-start,
.btn-small,
.dpad-btn,
.btn-retro {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.dpad {
    touch-action: none;
}

/* ==================
   RESPONSIVE - TABLET (≤ 820px)
   ================== */
@media (max-width: 820px) {
    body {
        align-items: flex-start;
        padding: 0;
    }

    .device {
        width: 100%;
        max-width: 100vw;
        border-radius: 0;
        padding: 8px 12px 14px;
        min-height: 100vh;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    .screen-bezel {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .screen {
        flex: 1;
        display: flex;
        flex-direction: column;
        position: relative;
    }

    #gameCanvas {
        flex: 1;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .game-title {
        font-size: 14px;
    }

    .strip-lines span {
        width: 25px;
    }

    .controls-area {
        padding: 14px 12px 10px;
        gap: 10px;
    }

    .btn-action {
        width: 56px;
        height: 56px;
    }

    .dpad {
        grid-template-columns: 42px 42px 42px;
        grid-template-rows: 42px 42px 42px;
    }

    .dpad-btn {
        font-size: 16px;
    }

    .hud-value {
        font-size: 12px;
    }

    .hud-label {
        font-size: 6px;
    }

    .btn-start {
        font-size: 9px;
        padding: 10px 24px;
    }
}

/* ==================
   RESPONSIVE - MOBILE (≤ 580px)
   ================== */
@media (max-width: 580px) {
    .device {
        padding: 4px 6px 8px;
    }

    .device-top-strip {
        padding: 4px 0 6px;
        gap: 8px;
    }

    .game-title {
        font-size: 11px;
        letter-spacing: 1px;
    }

    .strip-lines span {
        width: 16px;
        height: 2px;
    }

    .screen-bezel {
        padding: 8px;
        border-radius: 8px;
    }

    .hud {
        padding: 6px 8px;
    }

    .hud-label {
        font-size: 5px;
    }

    .hud-value {
        font-size: 10px;
    }

    .controls-area {
        padding: 10px 6px 6px;
        gap: 6px;
    }

    .controls-left {
        gap: 10px;
    }

    .action-btn-group {
        gap: 6px;
    }

    .action-label svg {
        width: 14px;
        height: 20px;
    }

    .action-label span {
        font-size: 5px;
    }

    .btn-action {
        width: 50px;
        height: 50px;
        border-width: 2px;
    }

    .controls-center {
        gap: 6px;
    }

    .btn-small {
        width: 34px;
        height: 28px;
        font-size: 12px;
    }

    .btn-start {
        font-size: 7px;
        padding: 7px 16px;
    }

    .dpad {
        grid-template-columns: 38px 38px 38px;
        grid-template-rows: 38px 38px 38px;
    }

    .dpad-btn {
        font-size: 13px;
    }

    .overlay-content h1 {
        font-size: 16px;
    }

    .overlay-content .subtitle {
        font-size: 8px;
        margin-bottom: 14px;
    }

    .enemy-preview {
        gap: 5px;
        margin-bottom: 16px;
    }

    .enemy-preview span {
        font-size: 7px;
    }

    .press-start {
        font-size: 10px;
    }

    .controls-hint {
        font-size: 6px;
    }

    .game-over-text {
        font-size: 18px !important;
    }

    .final-stats p {
        font-size: 9px;
    }

    .name-input label {
        font-size: 7px;
    }

    .name-input input {
        font-size: 12px;
        padding: 6px 10px;
        width: 150px;
    }

    .btn-retro {
        font-size: 8px;
        padding: 8px 14px;
    }

    .scores-table {
        max-width: 300px;
    }

    .score-header,
    .score-row {
        font-size: 7px;
        grid-template-columns: 35px 1fr 60px 30px;
    }

    .device-bottom-strip {
        height: 4px;
    }
}

/* ==================
   RESPONSIVE - SMALL MOBILE (≤ 400px)
   ================== */
@media (max-width: 400px) {
    .device-top-strip {
        padding: 2px 0 4px;
        gap: 4px;
    }

    .game-title {
        font-size: 9px;
    }

    .strip-lines {
        gap: 2px;
    }

    .strip-lines span {
        width: 12px;
    }

    .screen-bezel {
        padding: 6px;
    }

    .controls-area {
        padding: 8px 4px 4px;
        gap: 4px;
    }

    .action-label {
        display: none;
    }

    .btn-action {
        width: 46px;
        height: 46px;
    }

    .dpad {
        grid-template-columns: 34px 34px 34px;
        grid-template-rows: 34px 34px 34px;
    }

    .dpad-btn {
        font-size: 12px;
    }

    .btn-start {
        font-size: 6px;
        padding: 6px 12px;
    }

    .btn-small {
        width: 30px;
        height: 26px;
        font-size: 11px;
    }

    .overlay-content h1 {
        font-size: 13px;
    }

    .press-start {
        font-size: 8px;
    }

    .hud-value {
        font-size: 9px;
    }
}

/* ==================
   LANDSCAPE MOBILE
   ================== */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        align-items: flex-start;
    }

    .device {
        min-height: 100vh;
        min-height: 100dvh;
        border-radius: 0;
        padding: 4px 8px;
    }

    .device-top-strip {
        padding: 2px 0 4px;
    }

    .game-title {
        font-size: 10px;
    }

    .strip-lines span {
        width: 15px;
        height: 2px;
    }

    .screen-bezel {
        padding: 6px;
        flex: 1;
    }

    .controls-area {
        padding: 6px 12px 4px;
    }

    .btn-action {
        width: 44px;
        height: 44px;
    }

    .controls-left {
        flex-direction: row;
        gap: 8px;
    }

    .action-label {
        display: none;
    }

    .dpad {
        grid-template-columns: 32px 32px 32px;
        grid-template-rows: 32px 32px 32px;
    }

    .device-bottom-strip {
        height: 3px;
        margin-top: 2px;
    }
}

/* ==================
   DESKTOP LARGE (≥ 1200px)
   ================== */
@media (min-width: 1200px) {
    .device {
        max-width: 1200px;
    }

    .btn-action {
        width: 65px;
        height: 65px;
    }

    .dpad {
        grid-template-columns: 48px 48px 48px;
        grid-template-rows: 48px 48px 48px;
    }

    .dpad-btn {
        font-size: 16px;
    }
}