/* Angry Birds Web Edition - Style System & Mobile Adaptation */

:root {
    --bg-sky-top: #38bdf8;
    --bg-sky-bottom: #f0fdf4;
    --panel-bg: rgba(15, 23, 42, 0.84);
    --panel-border: rgba(255, 255, 255, 0.18);
    --accent-yellow: #facc15;
    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --accent-blue: #38bdf8;
    --font-game: 'Arial Black', Impact, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0b1120;
    font-family: var(--font-game);
    color: #ffffff;
    touch-action: none;
    position: fixed;
}

#app-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: none;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

#gameCanvas:active {
    cursor: grabbing;
}

/* Floating Top HUD */
#top-hud {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 10;
    gap: 8px;
}

.hud-group {
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.hud-card {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    padding: 6px 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
}

.hud-label {
    font-size: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    font-weight: 700;
}

.hud-value {
    font-size: 18px;
    font-weight: 900;
    color: var(--accent-yellow);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.level-title-card {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.88), rgba(185, 28, 28, 0.88));
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.level-title-card .hud-label {
    color: #fef08a;
}

.level-title-card .hud-value {
    color: #ffffff;
    font-size: 15px;
    white-space: nowrap;
}

/* Bird Queue Preview HUD */
.birds-queue-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
}

.queue-label {
    font-size: 10px;
    color: #94a3b8;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: bold;
}

.birds-list {
    display: flex;
    align-items: center;
    gap: 5px;
}

.bird-badge {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    display: inline-block;
    transition: transform 0.2s;
}

.active-bird-badge {
    transform: scale(1.2);
    border-color: var(--accent-yellow);
    box-shadow: 0 0 10px var(--accent-yellow);
}

.bird-red { background: #e52521; }
.bird-chuck { background: #facc15; }
.bird-bomb { background: #262626; border-color: #ef4444; }
.bird-blues { background: #38bdf8; }
.bird-matilda { background: #f8fafc; border-color: #ca8a04; }

/* Control Buttons */
.btn-icon {
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    color: #ffffff;
    border-radius: 8px;
    padding: 7px 10px;
    font-family: var(--font-game);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.15s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-height: 38px;
}

.btn-icon:hover {
    background: rgba(30, 41, 59, 0.95);
    border-color: var(--accent-yellow);
    transform: translateY(-2px);
}

.btn-icon:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(180deg, #22c55e, #15803d);
    border-color: #86efac;
    color: #ffffff;
    font-size: 15px;
    padding: 10px 20px;
}

.btn-danger {
    background: linear-gradient(180deg, #ef4444, #b91c1c);
    border-color: #fca5a5;
    color: #ffffff;
    font-size: 15px;
    padding: 10px 20px;
}

/* Bottom Ability & Hint Bar */
#bottom-hint-bar {
    position: absolute;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    padding: 6px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 10;
    pointer-events: none;
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hint-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.hint-text {
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #f1f5f9;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Modals Overlay */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.25s ease;
    padding: 16px;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.modal-content {
    background: linear-gradient(180deg, #1e293b, #0f172a);
    border: 3px solid #38bdf8;
    border-radius: 8px;
    padding: 24px 30px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(56, 189, 248, 0.3);
    max-width: 460px;
    width: 92%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
    0% { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-title {
    font-size: 28px;
    font-weight: 900;
    color: var(--accent-yellow);
    margin-bottom: 12px;
}

.modal-stars {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin: 14px 0;
}

.star-icon {
    font-size: 42px;
    color: #475569;
    filter: grayscale(1);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.star-icon.unlocked {
    color: #facc15;
    filter: drop-shadow(0 0 12px #facc15);
    transform: scale(1.2) rotate(4deg);
}

.modal-stats {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    padding: 12px 18px;
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: #cbd5e1;
}

.stat-val {
    font-family: var(--font-game);
    font-size: 17px;
    font-weight: 900;
    color: #ffffff;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Level Select Modal Grid */
.level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 16px 0;
    max-height: 52vh;
    overflow-y: auto;
    padding: 2px;
}

.level-card {
    background: rgba(30, 41, 59, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 10px 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.level-card:hover {
    border-color: var(--accent-yellow);
    background: rgba(51, 65, 85, 0.95);
    transform: translateY(-2px);
}

.level-number {
    font-size: 20px;
    font-weight: 900;
    color: #ffffff;
}

.level-card-name {
    font-size: 11px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.level-card-stars {
    font-size: 12px;
    color: #facc15;
}

/* Sandbox Panel */
#sandbox-panel {
    position: absolute;
    top: max(65px, env(safe-area-inset-top) + 55px);
    left: max(10px, env(safe-area-inset-left));
    background: var(--panel-bg);
    border: 2px solid var(--panel-border);
    backdrop-filter: blur(12px);
    border-radius: 8px;
    padding: 10px;
    z-index: 25;
    max-width: 250px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.7);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

#sandbox-panel.hidden {
    display: none;
}

.btn-sandbox-hero {
    width: 100%;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%) !important;
    color: #ffffff !important;
    border: 2px solid #86efac !important;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.45) !important;
    font-size: 13px !important;
    font-weight: 900 !important;
    padding: 8px 12px !important;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.btn-sandbox-hero:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 18px rgba(34, 197, 94, 0.65) !important;
}

.btn-sandbox-hero:active {
    transform: scale(0.98);
}

.sandbox-stat-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 4px 8px;
    margin-bottom: 8px;
    font-size: 11px;
    color: #cbd5e1;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 600;
}

.panel-heading {
    font-size: 13px;
    font-weight: 900;
    color: var(--accent-yellow);
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 3px;
}

.sandbox-tools-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-bottom: 8px;
}

.tool-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 5px 2px;
    color: #ffffff;
    font-size: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.tool-btn.active {
    border-color: var(--accent-yellow);
    background: rgba(250, 204, 21, 0.25);
    color: var(--accent-yellow);
}

/* Floating Workshop Test Bar (Combat Testing HUD) */
#sandbox-test-bar {
    position: absolute;
    top: max(65px, env(safe-area-inset-top) + 55px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.9);
    border: 2px solid rgba(56, 189, 248, 0.4);
    border-radius: 30px;
    padding: 5px 12px;
    z-index: 30;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
}

#sandbox-test-bar.hidden {
    display: none;
}

.sandbox-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Portrait Orientation Prompt Overlay (Auto-appears on mobile portrait) */
#rotate-device-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0f172a, #1e1b4b);
    z-index: 9999;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 30px;
}

@media screen and (orientation: portrait) and (max-width: 900px) {
    #rotate-device-overlay {
        display: flex;
    }
}

.phone-rotate-anim {
    width: 70px;
    height: 110px;
    border: 4px solid var(--accent-yellow);
    border-radius: 14px;
    margin-bottom: 24px;
    position: relative;
    animation: rotatePhone 2.2s infinite ease-in-out;
}

.phone-rotate-anim::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 4px;
    background: var(--accent-yellow);
    border-radius: 2px;
}

.phone-rotate-anim::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border: 2px solid var(--accent-yellow);
    border-radius: 50%;
}

@keyframes rotatePhone {
    0%, 20% { transform: rotate(0deg); }
    50%, 70% { transform: rotate(-90deg); }
    100% { transform: rotate(0deg); }
}

.rotate-title {
    font-size: 22px;
    font-weight: 900;
    color: var(--accent-yellow);
    margin-bottom: 10px;
}

.rotate-desc {
    font-size: 14px;
    color: #cbd5e1;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
    max-width: 320px;
    margin-bottom: 20px;
}

/* ==========================================================================
   Comprehensive Mobile & Landscape Responsive Optimization
   ========================================================================== */

/* 1. Universal Landscape Phones & Small Viewports (Height <= 520px) */
@media (max-height: 520px) {
    #top-hud {
        top: max(4px, env(safe-area-inset-top));
        left: max(6px, env(safe-area-inset-left));
        right: max(6px, env(safe-area-inset-right));
        gap: 4px;
    }

    .hud-group {
        gap: 4px;
        flex-wrap: nowrap;
    }

    .hud-card {
        padding: 3px 7px;
        border-width: 1.5px;
        border-radius: 6px;
    }

    .hud-label {
        font-size: 8px;
        letter-spacing: 0.2px;
    }

    .hud-value {
        font-size: 13px;
    }

    .level-title-card {
        padding: 3px 8px;
    }

    .level-title-card .hud-value {
        font-size: 12px;
    }

    .birds-queue-card {
        padding: 3px 6px;
        gap: 4px;
    }

    .queue-label {
        font-size: 9px;
    }

    .bird-badge {
        width: 16px;
        height: 16px;
        border-width: 1.5px;
    }

    .btn-icon {
        padding: 3px 7px;
        font-size: 11px;
        min-height: 28px;
        gap: 3px;
        border-radius: 6px;
        border-width: 1.5px;
    }

    #bottom-hint-bar {
        bottom: max(4px, env(safe-area-inset-bottom));
        padding: 3px 10px;
        font-size: 10px;
        border-radius: 6px;
        max-width: 82%;
    }

    .hint-icon {
        font-size: 12px;
    }

    .hint-text {
        font-size: 10px;
    }

    /* Modal Compact Fit in Landscape */
    .modal-content {
        padding: 10px 18px;
        max-height: calc(100vh - 16px);
        max-width: 520px;
        border-width: 2px;
    }

    .modal-title {
        font-size: 18px;
        margin-bottom: 4px;
    }

    .modal-stars {
        margin: 4px 0;
        gap: 8px;
    }

    .star-icon {
        font-size: 26px;
    }

    .modal-stats {
        padding: 6px 12px;
        margin-bottom: 8px;
        gap: 2px;
    }

    .stat-row {
        font-size: 12px;
    }

    .stat-val {
        font-size: 14px;
    }

    .modal-actions {
        gap: 6px;
    }

    .modal-actions .btn-icon {
        padding: 5px 12px;
        font-size: 12px;
        min-height: 30px;
    }

    .level-select-stats {
        margin-bottom: 6px;
        gap: 4px;
    }

    .stat-pill {
        padding: 2px 6px;
        font-size: 10px;
    }

    .level-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
        margin: 6px 0;
        max-height: 48vh;
    }

    .level-card {
        padding: 4px;
        gap: 2px;
    }

    .level-number {
        font-size: 14px;
    }

    .level-card-name {
        font-size: 9px;
    }

    .level-card-stars {
        font-size: 10px;
    }

    .level-card-highscore {
        font-size: 9px;
    }

    .level-card-lock-tag {
        font-size: 9px;
    }

    /* Workshop Panel Landscape Compact Layout */
    #sandbox-panel {
        top: max(38px, env(safe-area-inset-top) + 34px);
        left: max(6px, env(safe-area-inset-left));
        max-width: min(340px, 42vw);
        padding: 6px 8px;
        max-height: calc(100vh - 44px);
    }

    .btn-sandbox-hero {
        padding: 4px 8px !important;
        font-size: 11px !important;
        margin-bottom: 4px !important;
    }

    .sandbox-stat-bar {
        padding: 2px 6px;
        font-size: 9px;
        margin-bottom: 4px;
    }

    .panel-heading {
        font-size: 11px;
        margin-bottom: 4px;
        padding-bottom: 2px;
    }

    .sandbox-tools-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 3px;
        margin-bottom: 4px;
    }

    .tool-btn {
        padding: 3px 2px;
        font-size: 8px;
    }

    .sandbox-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 3px;
    }

    .sandbox-actions .btn-icon {
        padding: 3px 4px;
        font-size: 9px;
        min-height: 24px;
    }

    #sandbox-test-bar {
        top: max(38px, env(safe-area-inset-top) + 34px);
        padding: 3px 10px;
        gap: 6px;
    }

    #sandbox-test-bar .btn-icon {
        padding: 4px 8px;
        font-size: 11px;
        min-height: 26px;
    }
}

/* 2. Narrow Width Landscape (< 780px) */
@media (max-width: 780px) and (orientation: landscape) {
    .btn-icon span:last-child {
        display: inline;
    }

    .hud-card:nth-child(3) {
        display: none; /* Hide 'Best Score' on narrow screens to prevent HUD overflow */
    }
}

@media (max-width: 660px) and (orientation: landscape) {
    .btn-icon span:last-child {
        display: none; /* Icon-only buttons on ultra-narrow landscape screens */
    }

    .btn-icon {
        padding: 4px 6px;
    }
}

/* Victory & Modal Tags */
.new-record-tag {
    display: inline-block;
    background: linear-gradient(90deg, #f59e0b, #ef4444);
    color: #ffffff;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 900;
    margin-bottom: 10px;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.6);
    animation: pulseRecord 1.5s infinite;
}

@keyframes pulseRecord {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.unlocked-tag {
    display: inline-block;
    background: linear-gradient(90deg, #10b981, #059669);
    color: #ffffff;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 900;
    margin-bottom: 10px;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.5);
}

.new-record-tag.hidden,
.unlocked-tag.hidden {
    display: none;
}

/* Level Select Modal Stats */
.level-select-stats {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.stat-pill {
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #cbd5e1;
}

.stat-pill strong {
    color: var(--accent-yellow);
    font-family: var(--font-game);
}

.level-card.active {
    border-color: var(--accent-yellow) !important;
    background: rgba(51, 65, 85, 0.95);
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.45);
}

.level-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
    background: rgba(15, 23, 42, 0.6);
    border-color: rgba(255, 255, 255, 0.08);
}

.level-card.locked:hover {
    transform: none;
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(15, 23, 42, 0.6);
}

.level-card-highscore {
    font-size: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #38bdf8;
    font-weight: 700;
}

.level-card-lock-tag {
    font-size: 11px;
    color: #94a3b8;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 600;
}
