/* ==========================================================================
   CHEMISTRY CRAFT — Molecular Alchemy & Atomic Bond Puzzle
   Styles: High-Tech Micro-Laboratory, Bioluminescent Neons, Viewport-Locked
   ========================================================================== */

:root {
    --bg-dark: #070c1e;
    --bg-panel: rgba(13, 23, 46, 0.92);
    --bg-card: rgba(18, 30, 60, 0.85);
    --border-cyan: rgba(0, 240, 255, 0.4);
    --border-glow: #00f0ff;
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --accent-cyan: #00f0ff;
    --accent-green: #00ff88;
    --accent-ruby: #ef4444;
    --accent-gold: #ffd700;
    --accent-cobalt: #3b82f6;
    --font-stack: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-stack);
    color: var(--text-primary);
}

#app-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: 500px;
    margin: 0 auto;
    overflow: hidden;
    background: radial-gradient(circle at 50% 20%, #0d1b38 0%, #060a17 100%);
    box-shadow: 0 0 50px rgba(0, 240, 255, 0.15);
}

/* ==========================================================================
   SCREENS
   ========================================================================== */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    padding: 16px;
    z-index: 10;
}

.screen.active {
    display: flex;
}

/* ==========================================================================
   MAIN MENU
   ========================================================================== */
#screen-main-menu {
    justify-content: space-between;
    align-items: center;
    padding: 32px 20px 24px;
    background: radial-gradient(circle at 50% 30%, #112347 0%, #070c1e 80%);
}

.menu-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.app-logo-box {
    width: 108px;
    height: 108px;
    background: radial-gradient(circle, rgba(0, 240, 255, 0.25) 0%, rgba(0, 240, 255, 0.05) 70%);
    border: 2px solid var(--border-cyan);
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 25px rgba(0, 240, 255, 0.4);
    margin-bottom: 12px;
    animation: pulse-glow 3s infinite ease-in-out;
}

.app-logo-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.game-title {
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #00f0ff 0%, #ffffff 50%, #00ff88 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
    margin-bottom: 4px;
    white-space: nowrap;
}

.game-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.menu-buttons-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}

/* Strictly 5 buttons on main menu */
.btn-menu {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-cyan);
    border-radius: 14px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.btn-menu:hover, .btn-menu:active {
    transform: translateY(-2px);
    border-color: #00ff88;
    box-shadow: 0 0 18px rgba(0, 255, 136, 0.4);
    background: rgba(22, 38, 77, 0.95);
}

.btn-menu.primary {
    background: linear-gradient(135deg, #0088cc 0%, #00b4d8 100%);
    border-color: #00f0ff;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
}

.btn-menu.primary:hover {
    box-shadow: 0 0 26px rgba(0, 240, 255, 0.7);
}

/* Styled icon box container behind EVERY button icon */
.btn-icon-box {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: rgba(0, 240, 255, 0.12);
    border: 1px solid rgba(0, 240, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 14px;
    flex-shrink: 0;
}

.btn-icon-box.gold {
    background: rgba(255, 215, 0, 0.15);
    border-color: rgba(255, 215, 0, 0.4);
}

.btn-icon-box.green {
    background: rgba(0, 255, 136, 0.15);
    border-color: rgba(0, 255, 136, 0.4);
}

.btn-icon-box.blue {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
}

.btn-icon-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.btn-label {
    flex-grow: 1;
    text-align: left;
}

.menu-footer {
    font-size: 12px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* ==========================================================================
   HEADER / NAVBAR
   ========================================================================= */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    margin-bottom: 8px;
}

.screen-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--accent-cyan);
}

.btn-nav-back {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
}

/* ==========================================================================
   LEVEL SELECT SCREEN
   ========================================================================== */
#screen-levels {
    background: #070c1e;
}

.tier-tabs-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.tier-tabs-bar::-webkit-scrollbar {
    display: none;
}

.tier-tab {
    flex: 1;
    min-width: 52px;
    text-align: center;
    padding: 7px 4px;
    background: var(--bg-card);
    border: 1px solid rgba(0, 240, 255, 0.25);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tier-tab:hover {
    border-color: var(--accent-cyan);
    color: #ffffff;
}

.tier-tab.active {
    background: linear-gradient(135deg, rgba(0, 240, 255, 0.25) 0%, rgba(0, 255, 136, 0.2) 100%);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.levels-scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.levels-scroll-container::-webkit-scrollbar {
    width: 4px;
}
.levels-scroll-container::-webkit-scrollbar-thumb {
    background: var(--border-cyan);
    border-radius: 4px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding-bottom: 20px;
}

.level-card {
    background: var(--bg-card);
    border: 1px solid rgba(0, 240, 255, 0.25);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.level-card.unlocked:hover {
    border-color: var(--accent-cyan);
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0, 240, 255, 0.25);
}

.level-card.locked {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.8);
}

.level-card-number {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.level-card-formula {
    font-size: 20px;
    font-weight: 900;
    color: var(--accent-cyan);
    margin: 4px 0 2px;
}

.level-card-name {
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 6px;
}

.level-card-stars {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.2);
}

.star-mini.earned {
    color: var(--accent-gold);
}

/* ==========================================================================
   GAMEPLAY SCREEN
   ========================================================================== */
#screen-gameplay {
    padding: 8px 12px 12px;
}

.gameplay-hud-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.hud-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-cyan);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
}

.hud-badge-gold {
    color: var(--accent-gold);
}

.hud-actions-group {
    display: flex;
    gap: 8px;
}

.btn-hud-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-hud-icon:hover {
    border-color: #00ff88;
    transform: scale(1.05);
}

.btn-hud-icon img {
    width: 22px;
    height: 22px;
    object-fit: contain;
}

/* Target Molecule Card */
.target-compound-card {
    background: var(--bg-card);
    border: 1px solid rgba(0, 240, 255, 0.3);
    border-radius: 12px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.target-info-left {
    display: flex;
    flex-direction: column;
}

.target-name {
    font-size: 15px;
    font-weight: 800;
    color: #ffffff;
}

.target-formula {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-cyan);
}

.target-desc {
    font-size: 11px;
    color: var(--text-muted);
}

/* Canvas Container */
#canvas-container {
    flex-grow: 1;
    min-height: 0;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    border: 1.5px solid var(--border-cyan);
    box-shadow: inset 0 0 30px rgba(0, 240, 255, 0.08);
    touch-action: none;
}

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

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

/* ==========================================================================
   VICTORY MODAL
   ========================================================================== */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(4, 8, 20, 0.88);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: radial-gradient(circle at 50% 20%, #112347 0%, #070c1e 100%);
    border: 2px solid var(--accent-green);
    border-radius: 20px;
    padding: 24px 20px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 0 35px rgba(0, 255, 136, 0.35);
    animation: modal-pop 0.3s ease-out;
}

.victory-badge-box {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: rgba(0, 255, 136, 0.15);
    border: 2px solid var(--accent-green);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.4);
}

.victory-badge-box img {
    width: 54px;
    height: 54px;
    object-fit: contain;
}

.victory-title {
    font-size: 20px;
    font-weight: 900;
    color: var(--accent-green);
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.victory-name {
    font-size: 22px;
    font-weight: 900;
    color: #ffffff;
    margin-bottom: 2px;
}

.victory-formula {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-cyan);
    margin-bottom: 12px;
}

.victory-stars {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.victory-star {
    font-size: 28px;
    color: rgba(255, 255, 255, 0.2);
}

.victory-star.active {
    color: var(--accent-gold);
    text-shadow: 0 0 14px rgba(255, 215, 0, 0.7);
}

.victory-fact-box {
    background: rgba(0, 240, 255, 0.08);
    border: 1px dashed rgba(0, 240, 255, 0.3);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12px;
    color: #cbd5e1;
    font-style: italic;
    line-height: 1.4;
    margin-bottom: 20px;
}

.modal-actions-row {
    display: flex;
    gap: 12px;
    width: 100%;
}

.btn-modal {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-modal.secondary {
    background: var(--bg-card);
    border: 1px solid var(--border-cyan);
    color: #ffffff;
}

.btn-modal.primary {
    background: linear-gradient(135deg, #00b4d8 0%, #00ff88 100%);
    color: #070c1e;
    font-weight: 900;
    box-shadow: 0 0 16px rgba(0, 255, 136, 0.4);
}

/* ==========================================================================
   HOW TO PLAY SCREEN
   ========================================================================== */
.guide-scroll {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 16px;
}

.guide-scroll::-webkit-scrollbar {
    width: 4px;
}
.guide-scroll::-webkit-scrollbar-thumb {
    background: var(--border-cyan);
    border-radius: 4px;
}

.guide-card {
    background: var(--bg-card);
    border: 1px solid rgba(0, 240, 255, 0.25);
    border-radius: 12px;
    padding: 14px;
}

.guide-card-title {
    font-size: 15px;
    font-weight: 800;
    color: var(--accent-cyan);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.guide-card-text {
    font-size: 13px;
    color: #cbd5e1;
    line-height: 1.5;
}

.element-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.element-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.25);
    padding: 6px 10px;
    border-radius: 8px;
}

.element-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 900;
    font-size: 14px;
    color: #070c1e;
    margin-right: 8px;
}

/* ==========================================================================
   SETTINGS SCREEN
   ========================================================================== */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex-grow: 1;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid rgba(0, 240, 255, 0.25);
    border-radius: 14px;
    padding: 12px 16px;
}

.setting-info {
    display: flex;
    align-items: center;
}

.setting-text h4 {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
}

.setting-text p {
    font-size: 12px;
    color: var(--text-muted);
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #334155;
    transition: 0.3s;
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-cyan);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--accent-ruby);
    color: #fca5a5;
    padding: 12px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    margin-top: auto;
    margin-bottom: 12px;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
    }
    50% {
        box-shadow: 0 0 35px rgba(0, 240, 255, 0.65);
    }
}

@keyframes modal-pop {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}
