/* ================================================
   Pixel Balloon Pop - 8-Bit Arcade UI/UX
   Mobile, Tablet & Desktop Responsive CSS
   ================================================ */

:root {
    --black:     #000000;
    --night:     #0D0D2B;
    --dk-blue:   #1D2B53;
    --dk-purple: #7E2553;
    --dk-green:  #008751;
    --brown:     #AB5236;
    --dk-gray:   #5F574F;
    --lt-gray:   #C2C3C7;
    --white:     #FFF1E8;
    --red:       #FF004D;
    --orange:    #FFA300;
    --yellow:    #FFEC27;
    --green:     #00E436;
    --blue:      #29ADFF;
    --indigo:    #83769C;
    --pink:      #FF77A8;
    --peach:     #FFCCAA;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: #060614;
    font-family: 'Press Start 2P', monospace;
    color: var(--white);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Game Cabinet Container ---------- */
#game-container {
    width: 100%;
    height: 100%;
    max-width: 768px;
    position: relative;
    overflow: hidden;
    background: var(--night);
    image-rendering: pixelated;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9);
}

@media (min-width: 769px) {
    #game-container {
        height: 96dvh;
        max-height: 1024px;
        border: 4px solid var(--lt-gray);
        box-shadow: 0 0 0 4px var(--black), 0 12px 48px rgba(0, 0, 0, 0.85);
    }
}

/* ---------- Persistent Background Canvas ---------- */
#game-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 1;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
}

/* ---------- CRT Scanline Overlay ---------- */
#crt-overlay {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.08) 0px,
        rgba(0, 0, 0, 0.08) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 90;
}

/* ---------- Screen Layers ---------- */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: env(safe-area-inset-top, 8px) env(safe-area-inset-right, 8px) env(safe-area-inset-bottom, 8px) env(safe-area-inset-left, 8px);
    pointer-events: none;
}

.screen.active {
    display: flex;
}

/* Allow clicks on menu cards and HUD controls */
.arcade-panel,
#hud,
#problem-banner,
#arcade-deck,
.overlay-box {
    pointer-events: auto;
}

/* ---------- 8-Bit Arcade Panel Card ---------- */
.arcade-panel {
    background: rgba(13, 13, 43, 0.92);
    border: 4px solid var(--white);
    box-shadow: 0 0 0 4px var(--black), 8px 8px 0 rgba(0, 0, 0, 0.75);
    padding: clamp(16px, 4vw, 28px);
    width: min(92%, 480px);
    max-height: 92dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(12px, 2.5vh, 18px);
    text-align: center;
}

.badge-8bit {
    background: var(--dk-purple);
    color: var(--yellow);
    border: 2px solid var(--pink);
    padding: 4px 10px;
    font-size: clamp(7px, 2vw, 9px);
    letter-spacing: 2px;
}

/* ---------- Typography ---------- */
.game-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    line-height: 1.25;
    margin-top: 2px;
}

.title-line {
    font-size: clamp(22px, 6.5vw, 38px);
    text-shadow: 4px 4px 0 var(--black);
    letter-spacing: 3px;
}

.subtitle {
    font-size: clamp(8px, 2.3vw, 11px);
    color: var(--peach);
    letter-spacing: 2px;
}

.c-red    { color: var(--red); }
.c-yellow { color: var(--yellow); }
.c-green  { color: var(--green); }
.c-blue   { color: var(--blue); }
.c-pink   { color: var(--pink); }

/* ---------- Difficulty Selector ---------- */
.difficulty-select {
    width: 100%;
}

.select-label {
    font-size: clamp(8px, 2.2vw, 10px);
    color: var(--lt-gray);
    margin-bottom: 10px;
    letter-spacing: 2px;
}

.diff-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
}

.diff-btn {
    font-family: 'Press Start 2P', monospace;
    padding: 10px 6px;
    color: var(--white);
    background: var(--dk-blue);
    border: 3px solid var(--lt-gray);
    cursor: pointer;
    box-shadow: 0 4px 0 var(--black);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: transform 0.08s;
}

.diff-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--black);
}

.diff-btn.selected {
    background: var(--dk-purple);
    border-color: var(--yellow);
    color: var(--yellow);
    box-shadow: 0 4px 0 var(--black), 0 0 12px rgba(255, 236, 39, 0.35);
}

.diff-title {
    font-size: clamp(9px, 2.5vw, 12px);
}

.diff-desc {
    font-size: clamp(6px, 1.8vw, 8px);
    color: var(--lt-gray);
}

.diff-range {
    font-size: clamp(7px, 2vw, 9px);
    color: var(--peach);
}

/* ---------- Pixel Buttons ---------- */
.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 320px;
}

.pixel-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2.6vw, 13px);
    padding: 13px 18px;
    color: var(--white);
    background: var(--dk-blue);
    border: 3px solid var(--white);
    cursor: pointer;
    letter-spacing: 1px;
    box-shadow: 0 5px 0 var(--black);
    transition: transform 0.06s, box-shadow 0.06s, background 0.1s;
    text-align: center;
}

.pixel-btn:hover {
    border-color: var(--yellow);
}

.pixel-btn:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--black);
}

.big-btn {
    font-size: clamp(12px, 3.2vw, 16px);
    padding: 16px 24px;
    background: var(--dk-green);
    border-color: var(--green);
    color: var(--white);
    text-shadow: 2px 2px 0 var(--black);
}

.big-btn:hover {
    background: #00a864;
    border-color: var(--yellow);
}

.install-btn {
    background: var(--brown);
    border-color: var(--orange);
}

.pulse-btn {
    animation: gentlePulse 1.4s ease-in-out infinite alternate;
}

.start-controls {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 320px;
    justify-content: center;
}

.icon-btn {
    flex: 1;
    font-size: clamp(8px, 2.2vw, 10px);
    padding: 10px 8px;
}

.hint-text {
    font-size: clamp(7px, 2vw, 9px);
    color: var(--blue);
    letter-spacing: 1px;
    line-height: 1.5;
}

/* ---------- Game Screen Layout ---------- */
#game-screen {
    justify-content: space-between;
    padding: 0;
}

/* Top HUD */
#hud {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: calc(env(safe-area-inset-top, 4px) + 8px) 14px 8px;
    background: rgba(0, 0, 0, 0.88);
    border-bottom: 4px solid var(--dk-gray);
    z-index: 20;
}

#hud-left {
    display: flex;
    align-items: center;
}

#hud-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

#hud-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.streak-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
}

#hud-lives {
    display: flex;
    gap: 6px;
}

.heart {
    font-size: clamp(18px, 4.5vw, 24px);
    color: #3b3530;
    transition: transform 0.2s, color 0.2s;
}

.heart.full {
    color: var(--red);
    text-shadow: 2px 2px 0 var(--black), 0 0 8px rgba(255, 0, 77, 0.6);
}

.hud-label {
    font-size: clamp(6px, 1.8vw, 8px);
    color: var(--lt-gray);
    letter-spacing: 1px;
}

#score-value {
    font-size: clamp(14px, 4vw, 20px);
    color: var(--yellow);
    text-shadow: 2px 2px 0 var(--black);
}

#streak-value {
    font-size: clamp(12px, 3.5vw, 17px);
    color: var(--orange);
    text-shadow: 2px 2px 0 var(--black);
}

#multiplier-badge {
    font-size: clamp(9px, 2.5vw, 12px);
    color: var(--black);
    background: var(--yellow);
    border: 2px solid var(--white);
    padding: 3px 6px;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

/* Problem Banner */
#problem-banner {
    width: 100%;
    background: rgba(13, 13, 43, 0.9);
    border-bottom: 4px solid var(--blue);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 12px 0;
    z-index: 20;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.5);
}

#problem-box {
    padding-bottom: 8px;
}

#problem-text {
    font-size: clamp(22px, 6.5vw, 36px);
    color: var(--white);
    text-shadow: 3px 3px 0 var(--black);
    letter-spacing: 3px;
}

#danger-bar-wrap {
    width: 100%;
    height: 6px;
    background: #1a1a2e;
    overflow: hidden;
}

#danger-bar {
    width: 100%;
    height: 100%;
    background: var(--green);
    transition: width 0.1s linear, background-color 0.2s;
}

/* Playfield Spacer (Lets user see & tap canvas balloons) */
#playfield-spacer {
    flex: 1;
    width: 100%;
    pointer-events: none;
}

/* Bottom Arcade Control Deck */
#arcade-deck {
    width: 100%;
    background: rgba(0, 0, 0, 0.92);
    border-top: 4px solid var(--lt-gray);
    padding: 10px 12px calc(env(safe-area-inset-bottom, 6px) + 8px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 20;
}

#answer-area {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(8px, 2.5vw, 14px);
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.answer-btn {
    min-height: clamp(64px, 11vh, 88px);
    font-family: 'Press Start 2P', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    border: 4px solid;
    box-shadow: 0 6px 0 var(--black);
    transition: transform 0.05s, box-shadow 0.05s;
    position: relative;
    padding: 6px;
    touch-action: manipulation;
}

.answer-btn:active {
    transform: translateY(5px);
    box-shadow: 0 1px 0 var(--black);
}

.answer-btn[data-index="0"] {
    background: #7E2553;
    border-color: #FF77A8;
}
.answer-btn[data-index="1"] {
    background: #1D4F7E;
    border-color: #29ADFF;
}
.answer-btn[data-index="2"] {
    background: #006837;
    border-color: #00E436;
}

.answer-btn.correct-flash {
    background: var(--green) !important;
    border-color: var(--yellow) !important;
    transform: scale(1.04);
}

.answer-btn.wrong-flash {
    background: var(--red) !important;
    border-color: var(--yellow) !important;
}

.key-hint {
    font-size: clamp(7px, 1.8vw, 9px);
    color: rgba(255, 255, 255, 0.6);
}

.answer-num {
    font-size: clamp(18px, 5.5vw, 28px);
    color: var(--white);
    text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.75);
}

/* Game Controls Bar */
#game-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

.ctrl-btn {
    flex: 1;
    font-size: clamp(8px, 2.2vw, 10px);
    padding: 8px 6px;
    min-height: 36px;
    box-shadow: 0 3px 0 var(--black);
}

/* ---------- Overlays ---------- */
.overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.78);
    z-index: 60;
}

.overlay.active {
    display: flex;
}

.overlay-title {
    font-size: clamp(20px, 6vw, 30px);
    color: var(--yellow);
    text-shadow: 3px 3px 0 var(--brown);
    margin-bottom: 6px;
}

/* ---------- Game Over & High Scores ---------- */
.gameover-title {
    display: flex;
    gap: 12px;
    font-size: clamp(24px, 7vw, 40px);
    text-shadow: 4px 4px 0 var(--black);
}

.stats-box {
    width: 100%;
    background: rgba(0, 0, 0, 0.65);
    border: 3px solid var(--lt-gray);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-size: clamp(8px, 2.2vw, 10px);
    color: var(--lt-gray);
}

.stat-value {
    font-size: clamp(13px, 3.8vw, 18px);
    color: var(--yellow);
}

#new-highscore {
    font-size: clamp(10px, 2.8vw, 13px);
    color: var(--yellow);
    background: var(--dk-purple);
    border: 2px solid var(--yellow);
    padding: 6px 12px;
}

.section-title {
    font-size: clamp(14px, 4vw, 20px);
    color: var(--yellow);
    text-shadow: 3px 3px 0 var(--black);
}

#scores-list {
    width: 100%;
    background: rgba(0, 0, 0, 0.65);
    border: 3px solid var(--lt-gray);
    padding: 12px;
    min-height: 150px;
    max-height: 45dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-entry {
    display: grid;
    grid-template-columns: 32px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-bottom: 2px dashed rgba(255, 255, 255, 0.12);
    font-size: clamp(8px, 2.2vw, 10px);
    text-align: left;
}

.score-entry:last-child {
    border-bottom: none;
}

.score-rank { color: var(--pink); }
.score-pts  { color: var(--yellow); }
.score-diff {
    color: var(--green);
    font-size: clamp(6px, 1.8vw, 8px);
    background: rgba(0, 228, 54, 0.15);
    padding: 2px 5px;
}
.score-date {
    color: var(--lt-gray);
    font-size: clamp(6px, 1.8vw, 8px);
}

.no-scores {
    color: var(--lt-gray);
    font-size: 10px;
    margin: auto;
}

/* ---------- Flash Overlay ---------- */
#flash-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    z-index: 55;
    transition: opacity 0.15s ease-out;
}

/* ---------- Animations ---------- */
@keyframes pulse {
    from { transform: scale(1); }
    to   { transform: scale(1.14); }
}

@keyframes gentlePulse {
    from { transform: scale(1); }
    to   { transform: scale(1.03); }
}

@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    20%      { transform: translate(-6px, 2px); }
    40%      { transform: translate(6px, -2px); }
    60%      { transform: translate(-4px, -2px); }
    80%      { transform: translate(4px, 2px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

.blink {
    animation: blinkAnim 0.6s step-end infinite;
}

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

.hidden {
    display: none !important;
}

/* Landscape Short Viewport Adjustments (Phones in Landscape) */
@media (max-height: 540px) {
    .arcade-panel {
        padding: 10px 16px;
        gap: 8px;
    }
    .title-line {
        font-size: 18px;
    }
    .answer-btn {
        min-height: 48px;
    }
    #problem-text {
        font-size: 18px;
    }
}