/* === BASE === */
* {
    box-sizing: border-box;
}

body {
    background: #1a1a1a;
    color: #f0f0f0;
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* === AD BANNER === */
.ad-banner {
    width: 100%;
    max-width: 740px;
    text-align: center;
    padding: 6px 0;
    margin-bottom: 10px;
    background: #111;
    border: 1px solid #333;
    border-radius: 6px;
    position: relative;
}
.ad-label {
    position: absolute;
    top: 2px;
    left: 8px;
    font-size: 0.55rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.ad-placeholder {
    color: #ff99cc;
    font-size: 0.85rem;
    padding: 4px;
}

/* === GAME CONTAINER === */
.game-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    background: #2d2d2d;
    border: 4px solid #ff99cc;
    border-radius: 15px;
    box-shadow: 0 0 20px rgba(255, 153, 204, 0.3);
    max-width: 100%;
}

/* === SIDEBARS === */
.sidebar {
    width: 160px;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.sidebar h3 {
    color: #ff99cc;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.95rem;
}
.sidebar ul {
    list-style: none;
    padding: 0;
    font-size: 0.8rem;
    line-height: 2;
}

/* === INFO BLOCKS === */
.info-block {
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 8px;
    margin: 6px 0;
    width: 100%;
}
.info-block p {
    margin: 4px 0;
    font-size: 0.9rem;
}
.info-block .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #999;
    letter-spacing: 1px;
}
.big-number {
    font-size: 2rem;
    font-weight: bold;
    color: #ff99cc;
}
.level-display {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.level-name {
    font-size: 0.75rem;
    color: #ffb3d9;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 2px;
}
.lives-display {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.lives-hearts {
    font-size: 1.1rem;
    letter-spacing: 2px;
}

/* === MAIN STAGE === */
.main-stage {
    position: relative;
    border: 2px solid #444;
    background: #000;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}
canvas#tetris {
    display: block;
    max-width: 100%;
    height: auto;
    flex-shrink: 0;
}

/* === POWER-UPS BAR === */
.powerups-bar {
    display: flex;
    justify-content: space-around;
    padding: 4px;
    background: rgba(0, 0, 0, 0.7);
    border-top: 1px solid #333;
    flex-shrink: 0;
}
.pu-btn {
    background: #222;
    border: 1px solid #555;
    color: #f0f0f0;
    font-size: 0.75rem;
    padding: 4px 8px;
    min-height: 44px;
    min-width: 44px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    touch-action: manipulation;
}
.pu-btn:hover:not(:disabled) {
    background: #ff99cc;
    color: #000;
    transform: scale(1.1);
}
.pu-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.pu-btn.active {
    background: #ffcc00;
    color: #000;
    border-color: #ffcc00;
    animation: pulse 0.5s infinite alternate;
}
@keyframes pulse {
    from { box-shadow: 0 0 5px #ffcc00; }
    to   { box-shadow: 0 0 15px #ffcc00; }
}

/* === TAP-TO-MOVE CONTROLS (Mobile) === */

/* Tap feedback flash — brief white flash where the user tapped */
.tap-feedback {
    display: none;
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 6;
    opacity: 0;
    transition: opacity 0.08s ease-out;
    border-radius: 2px;
}
.tap-feedback.flash-left {
    background: radial-gradient(ellipse at 15% 50%, rgba(255,153,204,0.35) 0%, transparent 60%);
    opacity: 1;
    display: block;
}
.tap-feedback.flash-center {
    background: radial-gradient(ellipse at 50% 50%, rgba(255,204,0,0.35) 0%, transparent 60%);
    opacity: 1;
    display: block;
}
.tap-feedback.flash-right {
    background: radial-gradient(ellipse at 85% 50%, rgba(255,153,204,0.35) 0%, transparent 60%);
    opacity: 1;
    display: block;
}
.tap-feedback.flash-down {
    background: radial-gradient(ellipse at 50% 90%, rgba(100,200,255,0.4) 0%, transparent 50%);
    opacity: 1;
    display: block;
}

/* Subtle edge arrows — hint that tapping edges moves the piece */
.edge-indicator {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.4rem;
    color: rgba(255, 153, 204, 0.2);
    pointer-events: none;
    z-index: 4;
    transition: color 0.15s;
    text-shadow: 0 0 6px rgba(255, 153, 204, 0.1);
    user-select: none;
    -webkit-user-select: none;
}
.edge-left {
    left: 4px;
}
.edge-right {
    right: 4px;
}

/* Power-ups bar — compact on mobile */
.powerups-bar.mobile-compact {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 2px;
    z-index: 7;
    background: rgba(0, 0, 0, 0.6);
    border-top: 1px solid rgba(51,51,51,0.5);
}
.powerups-bar.mobile-compact .pu-btn {
    min-height: 32px;
    min-width: 32px;
    padding: 2px 6px;
    font-size: 0.65rem;
    background: rgba(34,34,34,0.7);
    border-color: rgba(85,85,85,0.5);
}

/* === OVERLAYS === */
.overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 2px;
}
.overlay.hidden {
    display: none;
}
.overlay .content {
    text-align: center;
    padding: 20px;
    max-height: 100%;
    overflow-y: auto;
}
.overlay h1 {
    color: #ff99cc;
    font-size: 2.2rem;
    margin: 0 0 10px;
}
.overlay .tagline {
    color: #ffb3d9;
    font-size: 1rem;
    margin-bottom: 20px;
}
.overlay .mechanics-list {
    color: #ccc;
    font-size: 0.85rem;
    margin-bottom: 20px;
    line-height: 1.8;
}
.stats-block {
    background: rgba(255, 153, 204, 0.1);
    border: 1px solid #ff99cc;
    border-radius: 8px;
    padding: 12px;
    margin: 10px 0;
}
.stats-block p {
    margin: 5px 0;
    font-size: 0.95rem;
}
.new-highscore {
    color: #ffcc00;
    font-size: 1.3rem;
    font-weight: bold;
    animation: glow 1s infinite alternate;
}
.new-highscore.hidden { display: none; }
@keyframes glow {
    from { text-shadow: 0 0 5px #ffcc00; }
    to   { text-shadow: 0 0 20px #ffcc00; }
}

/* === BUTTONS === */
.btn-primary, .btn-secondary, .btn-donate, .btn-store {
    display: block;
    width: 200px;
    margin: 8px auto;
    border: none;
    padding: 10px 16px;
    min-height: 44px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
    text-align: center;
    touch-action: manipulation;
}
.btn-primary {
    background: #ff99cc;
    color: #1a1a1a;
    font-weight: bold;
}
.btn-primary:hover {
    transform: scale(1.05);
    background: #ffb3d9;
}
.btn-secondary {
    background: #444;
    color: #f0f0f0;
}
.btn-secondary:hover {
    background: #555;
    transform: scale(1.03);
}
.btn-donate {
    background: #333;
    color: #ffcc00;
    border: 1px solid #ffcc00;
    font-size: 0.85rem;
}
.btn-donate:hover {
    background: #ffcc00;
    color: #1a1a1a;
}

/* === SAVE SLOTS === */
.save-slots {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
    max-height: 200px;
    overflow-y: auto;
}
.save-slot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #222;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.85rem;
}
.save-slot .slot-info {
    text-align: left;
    flex: 1;
}
.save-slot .slot-info .slot-name {
    color: #ff99cc;
    font-weight: bold;
}
.save-slot .slot-info .slot-details {
    color: #999;
    font-size: 0.75rem;
}
.save-slot .slot-actions {
    display: flex;
    gap: 4px;
}
.save-slot button {
    padding: 4px 10px;
    min-height: 44px;
    font-size: 0.75rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    touch-action: manipulation;
}
.slot-save-btn {
    background: #4a4;
    color: #fff;
}
.slot-load-btn {
    background: #44a;
    color: #fff;
}
.slot-delete-btn {
    background: #a44;
    color: #fff;
}
.slot-save-btn:hover { background: #5b5; }
.slot-load-btn:hover { background: #55b; }
.slot-delete-btn:hover { background: #b55; }

/* === HIGH SCORES LIST === */
.highscores-list {
    margin: 12px 0;
    text-align: left;
    max-height: 250px;
    overflow-y: auto;
}
.hs-entry {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid #333;
    font-size: 0.85rem;
}
.hs-rank { color: #ffcc00; font-weight: bold; width: 30px; }
.hs-score { color: #ff99cc; }
.hs-details { color: #888; font-size: 0.75rem; }

/* === SKINS === */
.skins-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 12px 0;
}
.skin-pack {
    background: #222;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    min-height: 44px;
    touch-action: manipulation;
}
.skin-pack:hover {
    border-color: #ff99cc;
}
.skin-pack.selected {
    border-color: #ff99cc;
    background: rgba(255, 153, 204, 0.15);
}
.skin-pack.locked {
    opacity: 0.5;
    cursor: not-allowed;
}
.skin-emojis {
    font-size: 1.5rem;
    margin-bottom: 4px;
}
.skin-name {
    font-size: 0.75rem;
    color: #ccc;
}
.skin-status {
    font-size: 0.65rem;
    color: #888;
    margin-top: 2px;
}
.skin-status.unlocked { color: #4a4; }
.skin-status.premium { color: #ffcc00; }

/* === LEVEL PROGRESS === */
.level-progress-box {
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    margin-top: 10px;
    width: 100%;
}
.level-progress-box h4 {
    margin: 0 0 6px;
    color: #ff99cc;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.progress-bar-outer {
    background: #111;
    border-radius: 4px;
    height: 10px;
    overflow: hidden;
}
.progress-bar-inner {
    background: linear-gradient(90deg, #ff99cc, #ffcc00);
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.progress-text {
    font-size: 0.7rem;
    color: #999;
    margin: 4px 0 0;
}

/* === CREDIT DISPLAY === */
.credits-block {
    background: linear-gradient(135deg, #2a1f00, #1a1500);
    border: 1px solid #ffcc00;
}
.credits-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.credits-icon {
    font-size: 1.4rem;
}
.credits-display .big-number {
    color: #ffcc00;
    font-size: 1.6rem;
}

/* === STORE BUTTON === */
.btn-store {
    background: linear-gradient(135deg, #ffcc00, #ff9900);
    color: #1a1a1a;
    font-weight: bold;
    border: none;
}
.btn-store:hover {
    transform: scale(1.05);
    background: linear-gradient(135deg, #ffdd44, #ffaa22);
}

/* === STORE OVERLAY === */
.store-credits-header {
    background: rgba(255, 204, 0, 0.15);
    border: 1px solid #ffcc00;
    border-radius: 8px;
    padding: 8px 16px;
    margin: 10px auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    color: #ffcc00;
}
.store-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 16px 0;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}
.store-item {
    background: #222;
    border: 2px solid #444;
    border-radius: 10px;
    padding: 12px 10px;
    text-align: center;
    transition: all 0.15s;
}
.store-item:hover {
    border-color: #ffcc00;
    transform: scale(1.02);
}
.store-item.owned {
    border-color: #4a4;
    opacity: 0.7;
}
.store-item-icon {
    font-size: 2rem;
    margin-bottom: 6px;
}
.store-item-name {
    font-size: 0.85rem;
    color: #f0f0f0;
    font-weight: bold;
    margin-bottom: 4px;
}
.store-item-desc {
    font-size: 0.7rem;
    color: #999;
    margin-bottom: 8px;
}
.store-item-cost {
    font-size: 0.8rem;
    color: #ffcc00;
    font-weight: bold;
    margin-bottom: 8px;
}
.store-buy-btn {
    background: #ffcc00;
    color: #1a1a1a;
    border: none;
    padding: 6px 14px;
    min-height: 44px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    touch-action: manipulation;
}
.store-buy-btn:hover {
    background: #ffdd44;
    transform: scale(1.05);
}
.store-buy-btn:disabled {
    background: #555;
    color: #999;
    cursor: not-allowed;
    transform: none;
}
.store-buy-btn.owned-btn {
    background: #4a4;
    color: #fff;
    cursor: default;
}

/* === CREDIT POPUP === */
.credit-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid #ffcc00;
    border-radius: 12px;
    padding: 16px 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 100;
    animation: popupSlide 0.4s ease-out;
    pointer-events: none;
}
.credit-popup.hidden {
    display: none;
}
.popup-icon {
    font-size: 1.8rem;
}
.popup-amount {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ffcc00;
}
.popup-reason {
    font-size: 0.85rem;
    color: #ccc;
}
@keyframes popupSlide {
    0% { opacity: 0; transform: translate(-50%, -30%); }
    20% { opacity: 1; transform: translate(-50%, -50%); }
    80% { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; transform: translate(-50%, -70%); }
}

/* ===========================================================
   RESPONSIVE BREAKPOINTS
   =========================================================== */

/* --- Small Mobile (max-width: 414px) --- */
@media (max-width: 414px) {
    body {
        padding: 4px;
    }

    .ad-banner {
        max-width: 100%;
        margin-bottom: 6px;
    }
    .ad-placeholder {
        font-size: 0.7rem;
    }

    .game-container {
        flex-direction: column;
        align-items: center;
        padding: 8px;
        gap: 8px;
        border-width: 2px;
        border-radius: 10px;
    }

    /* Hide sidebars on mobile — controls shown via touch */
    .sidebar.left {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        justify-content: center;
        gap: 6px;
    }
    .sidebar.left h3 {
        width: 100%;
        font-size: 0.8rem;
        margin-bottom: 4px;
    }
    .sidebar.left .info-block {
        flex: 1 1 45%;
        min-width: 100px;
        margin: 3px 0;
        padding: 6px;
    }
    .sidebar.left .big-number {
        font-size: 1.4rem;
    }
    .sidebar.left ul {
        display: none;
    }

    .sidebar.right {
        display: none;
    }

    .main-stage {
        width: 100%;
        max-width: 300px;
    }
    canvas#tetris {
        width: 100% !important;
        height: auto !important;
    }

    /* Show tap-to-move indicators */
    .edge-indicator {
        display: block;
    }
    .tap-feedback {
        display: none;
    }

    /* Compact power-ups on mobile */
    .powerups-bar {
        display: flex !important;
    }

    .overlay h1 {
        font-size: 1.5rem;
    }
    .overlay .tagline {
        font-size: 0.85rem;
    }
    .overlay .content {
        padding: 12px;
    }

    .btn-primary, .btn-secondary, .btn-donate, .btn-store {
        width: 180px;
        font-size: 0.9rem;
        padding: 10px 12px;
    }

    .skins-list {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .skin-pack {
        padding: 6px;
    }
    .skin-emojis {
        font-size: 1.2rem;
    }

    .store-list {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .save-slot {
        flex-direction: column;
        gap: 6px;
        text-align: center;
    }
    .save-slot .slot-info {
        text-align: center;
    }
    .save-slot .slot-actions {
        justify-content: center;
    }
}

/* --- Mobile (max-width: 768px) --- */
@media (max-width: 768px) {
    body {
        padding: 4px;
    }

    .ad-banner {
        max-width: 100%;
        margin-bottom: 6px;
    }

    .game-container {
        flex-direction: column;
        align-items: center;
        padding: 10px;
        gap: 10px;
        border-width: 3px;
        border-radius: 12px;
    }

    .sidebar.left {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        justify-content: center;
        gap: 6px;
    }
    .sidebar.left h3 {
        width: 100%;
        font-size: 0.85rem;
    }
    .sidebar.left .info-block {
        flex: 1 1 45%;
        min-width: 110px;
    }

    .sidebar.right {
        display: none;
    }

    .main-stage {
        width: 100%;
        max-width: 360px;
    }
    canvas#tetris {
        width: 100% !important;
        height: auto !important;
    }

    /* Show tap-to-move indicators */
    .edge-indicator {
        display: block;
    }
    .tap-feedback {
        display: none;
    }

    /* Compact power-ups on mobile */
    .powerups-bar {
        display: flex !important;
    }

    .overlay h1 {
        font-size: 1.7rem;
    }
    .overlay .content {
        padding: 15px;
    }

    .btn-primary, .btn-secondary, .btn-donate, .btn-store {
        width: 190px;
        font-size: 0.95rem;
    }

    .store-list {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- Tablet (769px - 1024px) --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .game-container {
        gap: 14px;
        padding: 14px;
    }
    .sidebar {
        width: 140px;
    }
    .sidebar h3 {
        font-size: 0.85rem;
    }

    .edge-indicator {
        display: none;
    }
}

/* --- Desktop (1025px+) --- */
@media (min-width: 1025px) {
    .edge-indicator {
        display: none;
    }
}

/* --- Short Viewport (height < 700px) --- */
@media (max-height: 700px) {
    .game-container { padding: 10px; gap: 12px; }
    .sidebar { width: 130px; }
    .overlay h1 { font-size: 1.8rem; }
    .btn-primary, .btn-secondary, .btn-donate, .btn-store { width: 170px; font-size: 0.9rem; }
}
