* { 
    margin: 0; padding: 0; box-sizing: border-box; 
    touch-action: none; 
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

body {
    overflow: hidden;
    background-color: #05070d; /* Outer space background */
    font-family: 'Outfit', sans-serif;
    touch-action: none;
    color: white;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    height: 100vh;
    width: 100vw;
}

#game-container {
    position: absolute;
    width: 540px;   /* Logical base width */
    height: 960px;  /* 9:16 aspect ratio base height */
    background-color: #0a0e1a; /* Actual game background */
    transform-origin: center center;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(0,0,0,0.8);
}

canvas { display: block; touch-action: none; width: 100%; height: 100%; }

/* ── HUD ── */
#ui-layer {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    display: flex; flex-direction: column;
    align-items: center; justify-content: space-between;
    padding: 1.2rem; z-index: 10;
}
.hud-top { text-align: center; width: 100%; }
.hud-row {
    display: flex; align-items: center; justify-content: center; gap: 1.2rem;
}
.hud-box {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px; padding: 6px 16px;
    font-weight: 700; font-size: 0.9rem;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: rgba(255,255,255,0.6);
}
.hud-box span { color: white; }
.hud-score-wrap { position: relative; }
#score-display {
    font-size: 3.5rem; font-weight: 900;
    line-height: 1; letter-spacing: -0.02em;
    text-shadow: 0 0 30px rgba(255,255,255,0.15);
}
.combo-badge {
    position: absolute; top: -4px; right: -36px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white; font-weight: 900; font-size: 0.85rem;
    padding: 2px 8px; border-radius: 8px;
    animation: combo-pop 0.3s ease;
}
@keyframes combo-pop { 0%{transform:scale(0)} 50%{transform:scale(1.3)} 100%{transform:scale(1)} }
.progress-container {
    width: 280px; max-width: 80%; height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 8px; overflow: hidden;
    margin: 10px auto 0; border: 1px solid rgba(255,255,255,0.1);
}
#progress-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #ef4444, #a855f7, #6366f1);
    border-radius: 8px; transition: width 0.15s linear;
}

/* ── Fullscreen Button ── */
.fullscreen-btn {
    position: absolute; top: 12px; right: 12px;
    z-index: 25; pointer-events: auto;
    width: 38px; height: 38px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(8px);
    color: rgba(255,255,255,0.5);
    font-size: 1.2rem; line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease;
}
.fullscreen-btn:hover {
    background: rgba(255,255,255,0.12);
    color: white;
    transform: scale(1.08);
    border-color: rgba(255,255,255,0.25);
}
.fullscreen-btn:active { transform: scale(0.94); }

/* ── Overlay Panels ── */
.overlay-panel {
    pointer-events: auto;
    display: flex; flex-direction: column; align-items: center; gap: 1rem;
    background: rgba(10,14,26,0.92);
    padding: 2.5rem 2.5rem;
    border-radius: 2rem;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 25px 60px rgba(0,0,0,0.6);
    position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    z-index: 20;
}

.page-panel {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: #0a0e1a; z-index: 30;
    display: flex; flex-direction: column; align-items: center;
    padding: 2.5rem 1.5rem;
    pointer-events: auto;
}
.hidden { display: none !important; }
.title-glow {
    font-size: 2.2rem; font-weight: 900;
    letter-spacing: 0.05em; text-transform: uppercase;
    text-shadow: 0 0 40px rgba(99,102,241,0.6);
}
.text-green { color: #10b981; text-shadow: 0 0 40px rgba(16,185,129,0.6); }
.text-red   { color: #ef4444; text-shadow: 0 0 40px rgba(239,68,68,0.6); }
.desc { color: rgba(255,255,255,0.5); text-align: center; max-width: 300px; line-height: 1.6; }
.key-hint {
    display: inline-block; background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2); border-radius: 6px;
    padding: 1px 8px; font-size: 0.8rem; font-weight: 700;
}
.dice-preview {
    width: 70px; height: 70px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-radius: 16px;
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 14px;
    box-shadow: 0 0 30px rgba(239,68,68,0.4);
    animation: dice-float 2.5s ease-in-out infinite;
}
@keyframes dice-float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
.dice-dot { width: 100%; aspect-ratio: 1; background: white; border-radius: 50%; }

.btn-primary, .btn-danger {
    padding: 14px 40px; font-weight: 900; font-size: 1.1rem;
    border: none; border-radius: 50px; cursor: pointer;
    transition: all 0.15s; text-transform: uppercase;
    letter-spacing: 0.05em;
}
.btn-primary { background: white; color: #0a0e1a; }
.btn-primary:hover { background: #e2e8f0; transform: scale(1.03); }
.btn-primary:active { transform: scale(0.97); }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; transform: scale(1.03); }
.btn-danger:active { transform: scale(0.97); }
.btn-secondary {
    padding: 12px 32px; font-weight: 900; font-size: 0.95rem;
    border: 2px solid rgba(255,255,255,0.2); border-radius: 50px;
    cursor: pointer; transition: all 0.15s; text-transform: uppercase;
    letter-spacing: 0.05em; background: transparent; color: rgba(255,255,255,0.6);
}
.btn-secondary:hover { background: rgba(255,255,255,0.08); color: white; transform: scale(1.03); }
.btn-secondary:active { transform: scale(0.97); }
.btn-row { display: flex; gap: 0.8rem; align-items: center; }

/* ── Rules Overlay Specifics ── */
.rules-header {
    width: 100%; display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.5rem;
}
.btn-lang {
    background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.3);
    color: white; padding: 4px 12px; border-radius: 8px; font-weight: 900;
    cursor: pointer; transition: all 0.2s;
}
.btn-lang:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
.rules-scroll {
    width: 100%; max-height: 720px; overflow-y: auto;
    padding-right: 8px; margin-bottom: 1rem;
}
.rules-section { margin-bottom: 1.5rem; text-align: left; width: 100%; }
.rules-section h3 { 
    font-size: 1.1rem; color: #6366f1; text-transform: uppercase; 
    margin-bottom: 0.6rem; border-bottom: 1px solid rgba(99,102,241,0.3);
    padding-bottom: 4px;
}
.rules-section p { font-size: 0.9rem; line-height: 1.5; color: rgba(255,255,255,0.8); margin-bottom: 0.4rem; }
.pu-list { display: flex; flex-direction: column; gap: 0.8rem; }
.pu-item { display: flex; align-items: flex-start; gap: 10px; font-size: 0.85rem; }
.pu-icon { font-size: 1.2rem; min-width: 24px; text-align: center; }
.pu-info { flex: 1; }
.pu-name { font-weight: 900; color: white; display: block; margin-bottom: 2px; }
.pu-desc { color: rgba(255,255,255,0.6); line-height: 1.4; }

/* Scrollbar styling */
.rules-scroll::-webkit-scrollbar { width: 6px; }
.rules-scroll::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 10px; }
.rules-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }

/* ── Level Grid ── */
.level-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 10px; max-height: 550px; overflow-y: auto;
    padding: 4px; width: 100%;
}
.level-cell {
    width: 52px; height: 52px;
    border-radius: 14px; border: 2px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.05);
    display: flex; align-items: center; justify-content: center;
    font-weight: 900; font-size: 1.1rem; color: white;
    cursor: pointer; transition: all 0.15s;
    position: relative;
}
.level-cell:hover { background: rgba(255,255,255,0.12); transform: scale(1.08); }
.level-cell:active { transform: scale(0.95); }
.level-cell.locked {
    opacity: 0.25; pointer-events: none; cursor: default;
}
.level-cell.locked::after {
    content: '🔒'; position: absolute; font-size: 0.7rem;
    bottom: 2px; right: 4px;
}
.level-cell.current {
    border-color: #6366f1; box-shadow: 0 0 16px rgba(99,102,241,0.4);
    background: rgba(99,102,241,0.15);
}

/* ── Touch Zones ── */
.touch-zone {
    position: fixed; top: 0; width: 50%; height: 100%;
    z-index: 5; cursor: pointer;
}
#touch-left  { left: 0; }
#touch-right { right: 0; }
.zone-label {
    position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
    color: rgba(255,255,255,0.1); font-size: 1rem; font-weight: 800;
    letter-spacing: 0.15em; text-transform: uppercase;
    pointer-events: none; user-select: none;
}

/* ── Floating Notifications ── */
#notif-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 15;
}
.notif {
    position: absolute; left: 50%; transform: translateX(-50%);
    font-weight: 900; font-size: 1.3rem;
    text-shadow: 0 2px 12px rgba(0,0,0,0.6);
    animation: notif-rise 1s ease-out forwards;
    pointer-events: none;
}
@keyframes notif-rise {
    0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.2); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-60px) scale(0.8); }
}

/* ── Screen Shake ── */
.shake {
    animation: shake 0.35s ease-out;
}
@keyframes shake {
    0%,100% { transform: translate(0,0); }
    10% { transform: translate(-6px, 4px); }
    20% { transform: translate(5px, -5px); }
    30% { transform: translate(-4px, 2px); }
    40% { transform: translate(3px, -3px); }
    50% { transform: translate(-2px, 4px); }
    60% { transform: translate(2px, -1px); }
    70% { transform: translate(-1px, 2px); }
}
