/* מגילת אסתר - משחק תלת מימד לילדים */
/* עיצוב מלכותי וצבעוני */

:root {
    --gold: #D4AF37;
    --gold-light: #F4E4BC;
    --purple: #6B2D5C;
    --purple-dark: #4A1E42;
    --cream: #FFF8E7;
    --royal-blue: #1E3A5F;
    --coral: #E8A87C;
    --emerald: #41B3A3;
    --shadow: rgba(75, 45, 92, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

#player-name {
    -webkit-user-select: text;
    user-select: text;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Heebo', 'Rubik', sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    direction: rtl;
    min-height: 100%;
    min-height: -webkit-fill-available;
    position: fixed;
    width: 100%;
    touch-action: manipulation;
    overscroll-behavior: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

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

#game-canvas:active {
    cursor: grabbing;
}

/* Mission Panel */
#mission-panel {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: max(15px, env(safe-area-inset-left));
    z-index: 98;
    background: linear-gradient(135deg, rgba(107, 45, 92, 0.95), rgba(74, 30, 66, 0.98));
    border: 3px solid var(--gold);
    border-radius: 15px;
    padding: 15px 20px;
    max-width: 280px;
    box-shadow: 0 8px 30px var(--shadow);
}

#mission-panel h3 {
    color: var(--gold);
    font-size: 1.1rem;
    margin-bottom: 12px;
    text-align: center;
}

#mission-list {
    list-style: none;
    color: var(--cream);
    font-size: 0.95rem;
    line-height: 1.9;
}

#mission-list li {
    padding: 2px 0;
}

#mission-list li[data-done="true"] {
    color: var(--emerald);
    text-decoration: line-through;
}

#mission-list li[data-done="true"]::before {
    content: "✓ ";
    color: var(--emerald);
}

.mission-hint {
    font-size: 0.8rem;
    color: var(--gold-light);
    margin-top: 10px;
    opacity: 0.9;
}

#mission-toggle {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: max(15px, env(safe-area-inset-left));
    z-index: 99;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(107, 45, 92, 0.9);
    border: 2px solid var(--gold);
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
}

@media (max-width: 768px) {
    #mission-panel {
        max-width: 260px;
        padding: 12px 15px;
        top: 70px;
    }
    
    #mission-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Riddle Popup */
#riddle-popup {
    position: absolute;
    top: 50%;
    right: 50%;
    transform: translate(50%, -50%);
    z-index: 190;
}

.riddle-content {
    background: linear-gradient(135deg, var(--purple), var(--purple-dark));
    border: 4px solid var(--gold);
    border-radius: 25px;
    padding: 30px;
    max-width: min(90vw, 450px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.riddle-content h3 {
    color: var(--gold);
    text-align: center;
    margin-bottom: 15px;
}

#riddle-question {
    color: var(--cream);
    font-size: 1.2rem;
    margin-bottom: 20px;
    line-height: 1.6;
}

.riddle-option {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    background: rgba(255,255,255,0.15);
    border: 2px solid var(--gold);
    border-radius: 12px;
    color: var(--cream);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-align: right;
}

.riddle-option:hover {
    background: rgba(212, 175, 55, 0.3);
}

.riddle-option.correct {
    background: rgba(65, 179, 163, 0.5);
    border-color: var(--emerald);
}

.riddle-option.wrong {
    background: rgba(200, 80, 80, 0.4);
    border-color: #c85050;
}

.riddle-feedback {
    margin: 15px 0;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
}

.riddle-feedback.correct {
    color: var(--emerald);
}

.riddle-feedback.wrong {
    color: #ff6b6b;
}

#riddle-skip {
    margin-top: 10px;
    width: 100%;
}

.riddle-option:disabled {
    cursor: default;
    opacity: 0.8;
}

/* Stage Display */
#stage-display {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: 50%;
    transform: translateX(50%);
    z-index: 97;
    background: rgba(107, 45, 92, 0.9);
    border: 2px solid var(--gold);
    border-radius: 12px;
    padding: 8px 20px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.stage-label { color: var(--gold-light); font-size: 0.9rem; }
#stage-number { color: var(--gold); font-weight: 800; font-size: 1.2rem; }
#stage-name { color: var(--cream); font-size: 0.95rem; }

/* Stage Transition */
#stage-transition {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 280;
}

.transition-content {
    text-align: center;
    padding: 40px;
    max-width: 500px;
}

.transition-content h2 {
    color: var(--gold);
    font-size: 2rem;
    margin-bottom: 25px;
}

.transition-content p {
    color: var(--cream);
    font-size: 1.2rem;
    line-height: 1.9;
    margin-bottom: 30px;
}

/* Victory enhancements */
.victory-quote {
    font-size: 1.3rem;
    color: var(--gold-light);
    font-style: italic;
    margin-bottom: 25px;
}

.victory-text {
    font-size: 1.1rem;
    line-height: 1.9;
    margin: 15px 0;
}

.victory-punch {
    font-size: 1.4rem;
    color: var(--gold);
    margin-top: 30px;
    font-weight: 700;
}

#victory-message {
    max-height: 50vh;
    overflow-y: auto;
    padding: 0 10px;
}

/* HUD */
#hud {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    display: flex;
    gap: clamp(10px, 3vw, 25px);
    z-index: 100;
    padding: clamp(8px, 2vw, 15px) clamp(12px, 3vw, 25px);
    background: linear-gradient(135deg, rgba(107, 45, 92, 0.9), rgba(74, 30, 66, 0.95));
    border-radius: clamp(12px, 4vw, 20px);
    border: 3px solid var(--gold);
    box-shadow: 0 8px 32px var(--shadow);
}

#hud .label {
    display: block;
    font-size: 0.85rem;
    color: var(--gold-light);
    margin-bottom: 3px;
}

#score-panel, #collectibles-panel, #health-panel {
    text-align: center;
}

#score, #collectibles {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gold);
}

#hearts {
    font-size: 1.3rem;
}

/* Start Screen */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, 
        rgba(26, 26, 46, 0.95) 0%, 
        rgba(107, 45, 92, 0.9) 50%,
        rgba(26, 26, 46, 0.95) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 1s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.start-content {
    text-align: center;
    padding: 40px;
    max-width: 500px;
}

.start-content h1 {
    font-size: 3.5rem;
    color: var(--gold);
    text-shadow: 0 0 30px rgba(212, 175, 55, 0.5);
    margin-bottom: 10px;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from { text-shadow: 0 0 20px rgba(212, 175, 55, 0.4); }
    to { text-shadow: 0 0 40px rgba(212, 175, 55, 0.8); }
}

.start-content h2 {
    font-size: 1.8rem;
    color: var(--cream);
    margin-bottom: 20px;
}

.subtitle {
    color: var(--gold-light);
    font-size: 1.2rem;
    margin-bottom: 30px;
}

.character-preview {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 30px 0;
}

.char-icon {
    font-size: 4rem;
    animation: bounce 1.5s ease-in-out infinite;
}

.char-icon:nth-child(1) { animation-delay: 0s; }
.char-icon:nth-child(2) { animation-delay: 0.2s; }
.char-icon:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

#player-name {
    width: 100%;
    padding: clamp(12px, 3vw, 15px) clamp(16px, 4vw, 20px);
    font-size: clamp(1rem, 4vw, 1.2rem);
    border: 3px solid var(--gold);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--cream);
    margin-bottom: 20px;
    text-align: center;
}

#player-name::placeholder {
    color: rgba(255, 248, 231, 0.5);
}

#player-name:focus {
    outline: none;
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}

/* Buttons - min 44px touch target for accessibility */
.btn-primary {
    padding: clamp(14px, 3vw, 18px) clamp(30px, 8vw, 45px);
    font-size: clamp(1.1rem, 4vw, 1.3rem);
    min-height: 48px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--gold), #B8860B);
    color: var(--purple-dark);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.4);
}

.btn-primary:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(212, 175, 55, 0.6);
}

.btn-secondary {
    padding: clamp(12px, 3vw, 14px) clamp(24px, 6vw, 30px);
    font-size: clamp(0.95rem, 3vw, 1rem);
    min-height: 44px;
    background: rgba(255, 255, 255, 0.2);
    color: var(--cream);
    border: 2px solid var(--gold);
    border-radius: 30px;
    cursor: pointer;
    margin: 5px;
    font-family: inherit;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: rgba(212, 175, 55, 0.3);
}

/* Story Dialog */
#story-dialog {
    position: absolute;
    bottom: max(20px, env(safe-area-inset-bottom));
    right: 50%;
    transform: translateX(50%);
    width: min(90vw, 600px);
    z-index: 150;
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateX(50%) translateY(30px);
    }
    to { 
        opacity: 1;
        transform: translateX(50%) translateY(0);
    }
}

.dialog-content {
    background: linear-gradient(135deg, rgba(107, 45, 92, 0.98), rgba(74, 30, 66, 0.98));
    border: 4px solid var(--gold);
    border-radius: clamp(15px, 5vw, 25px);
    padding: clamp(20px, 5vw, 30px);
    box-shadow: 0 15px 50px var(--shadow);
}

.dialog-character {
    font-size: 4rem;
    text-align: center;
    margin-bottom: 15px;
}

#story-text {
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    color: var(--cream);
    line-height: 1.8;
    margin-bottom: 20px;
}

/* Character Popup */
#character-popup {
    position: absolute;
    top: 50%;
    right: 50%;
    transform: translate(50%, -50%);
    z-index: 180;
    animation: popIn 0.4s ease;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: translate(50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(50%, -50%) scale(1);
    }
}

.popup-content {
    background: linear-gradient(135deg, var(--purple), var(--purple-dark));
    border: 4px solid var(--gold);
    border-radius: clamp(15px, 5vw, 25px);
    padding: clamp(25px, 6vw, 40px);
    max-width: min(90vw, 400px);
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.popup-close {
    position: absolute;
    top: 15px;
    left: 20px;
    font-size: 2rem;
    cursor: pointer;
    color: var(--gold-light);
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-character {
    font-size: 5rem;
    text-align: center;
    margin-bottom: 15px;
}

.popup-name {
    color: var(--gold);
    font-size: 1.8rem;
    text-align: center;
    margin-bottom: 15px;
}

.popup-desc {
    color: var(--cream);
    font-size: 1.1rem;
    line-height: 1.7;
}

/* Controls Help */
#controls-help {
    position: absolute;
    bottom: max(15px, env(safe-area-inset-bottom));
    left: max(15px, env(safe-area-inset-left));
    display: flex;
    gap: 15px;
    font-size: clamp(0.75rem, 2.5vw, 0.9rem);
    color: rgba(255, 248, 231, 0.7);
    z-index: 90;
}

/* Mobile Touch Controls */
#mobile-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    pointer-events: none;
    z-index: 95;
}

#mobile-controls > * {
    pointer-events: auto;
}

#joystick-area {
    position: absolute;
    bottom: max(80px, calc(env(safe-area-inset-bottom) + 60px));
    right: max(30px, env(safe-area-inset-right));
    width: 120px;
    height: 120px;
}

#joystick-base {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(107, 45, 92, 0.6);
    border: 3px solid var(--gold);
    border-radius: 50%;
    box-shadow: 0 4px 20px var(--shadow);
}

#joystick-stick {
    position: absolute;
    width: 50px;
    height: 50px;
    background: var(--gold);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    touch-action: none;
    transition: transform 0.05s ease-out;
}

.touch-btn {
    position: absolute;
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
    border-radius: 50%;
    background: rgba(107, 45, 92, 0.8);
    border: 3px solid var(--gold);
    color: white;
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: max(80px, calc(env(safe-area-inset-bottom) + 60px));
    left: max(30px, env(safe-area-inset-left));
    box-shadow: 0 4px 15px var(--shadow);
    touch-action: manipulation;
}

#action-buttons {
    display: flex;
    gap: 15px;
}

#interact-btn {
    left: max(30px, env(safe-area-inset-left));
}

#pause-btn {
    left: max(105px, calc(env(safe-area-inset-left) + 75px));
}

/* Show/hide by device */
.desktop-only {
    display: flex;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    
    .mobile-only {
        display: block !important;
    }
}

/* Pause Menu */
#pause-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 250;
}

.pause-content {
    text-align: center;
    padding: 40px;
}

.pause-content h2 {
    color: var(--gold);
    font-size: 2.5rem;
    margin-bottom: 30px;
}

.pause-content button {
    display: block;
    margin: 15px auto;
    width: 250px;
}

/* Leaderboard */
#leaderboard {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 220;
}

.leaderboard-content {
    background: linear-gradient(135deg, var(--purple), var(--purple-dark));
    border: 4px solid var(--gold);
    border-radius: 25px;
    padding: 40px;
    max-width: 400px;
    text-align: center;
}

.leaderboard-content h2 {
    color: var(--gold);
    margin-bottom: 25px;
}

#leaders-list {
    text-align: right;
    color: var(--cream);
    font-size: 1.2rem;
    line-height: 2;
    margin: 20px 0;
    padding-right: 20px;
}

/* Victory Screen */
#victory-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(107, 45, 92, 0.95), rgba(26, 26, 46, 0.98));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.victory-content {
    text-align: center;
    padding: 50px;
}

.victory-content h1 {
    font-size: 3rem;
    color: var(--gold);
    margin-bottom: 15px;
}

.victory-content h2 {
    font-size: 2rem;
    color: var(--cream);
    margin-bottom: 25px;
}

.purim-message {
    font-size: 1.8rem;
    color: var(--gold-light);
    margin: 20px 0;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Collectible glow effect */
.collectible-glow {
    animation: collectiblePulse 1.5s ease-in-out infinite;
}

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

/* Mobile responsive - comprehensive */
@media (max-width: 768px) {
    .start-content {
        padding: 20px 15px;
        max-width: 95vw;
    }
    
    .start-content h1 {
        font-size: clamp(2rem, 10vw, 2.5rem);
    }
    
    .start-content h2 {
        font-size: clamp(1.3rem, 5vw, 1.8rem);
    }
    
    .subtitle {
        font-size: clamp(1rem, 4vw, 1.2rem);
    }
    
    .character-preview {
        gap: 20px;
        margin: 20px 0;
    }
    
    .char-icon {
        font-size: clamp(2.5rem, 12vw, 4rem);
    }
    
    #hud {
        flex-direction: row;
        flex-wrap: wrap;
        top: max(10px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        padding: 10px 15px;
        gap: 15px;
    }
    
    #score, #collectibles {
        font-size: 1.2rem;
    }
    
    .dialog-character {
        font-size: clamp(2.5rem, 15vw, 4rem);
    }
    
    .popup-character {
        font-size: clamp(3rem, 20vw, 5rem);
    }
    
    .popup-name {
        font-size: clamp(1.3rem, 5vw, 1.8rem);
    }
    
    .popup-desc {
        font-size: clamp(0.95rem, 3.5vw, 1.1rem);
    }
    
    .victory-content h1 {
        font-size: clamp(2rem, 10vw, 3rem);
    }
    
    .victory-content h2 {
        font-size: clamp(1.4rem, 6vw, 2rem);
    }
    
    .purim-message {
        font-size: clamp(1.3rem, 6vw, 1.8rem);
    }
    
    .leaderboard-content {
        max-width: 95vw;
        padding: 25px 20px;
    }
    
    .pause-content button {
        width: min(250px, 90vw);
    }
}

/* Small phones */
@media (max-width: 380px) {
    #joystick-area {
        width: 100px;
        height: 100px;
        bottom: max(70px, calc(env(safe-area-inset-bottom) + 50px));
    }
    
    .touch-btn {
        width: 50px;
        height: 50px;
        min-width: 50px;
        min-height: 50px;
        font-size: 1.5rem;
        bottom: max(70px, calc(env(safe-area-inset-bottom) + 50px));
    }
    
    #pause-btn {
        left: max(85px, calc(env(safe-area-inset-left) + 65px));
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #joystick-area {
        bottom: max(30px, env(safe-area-inset-bottom));
    }
    
    .touch-btn {
        bottom: max(30px, env(safe-area-inset-bottom));
    }
    
    .start-content h1 {
        font-size: 2rem;
    }
    
    .character-preview {
        margin: 15px 0;
    }
}
