﻿:root {
    --dark: #0f1419;
    --darker: #1a1d23;
    --card: #242930;
    --accent: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --purple: #8b5cf6;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --gold: #fbbf24;
    --code-bg: #1e1e1e;
    --ai-glow: #8b5cf6;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Cairo', sans-serif;
    background: linear-gradient(135deg, var(--dark) 0%, var(--darker) 100%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    flex: 1;
    width: 100%;
}

/* ============ Header ============ */
.game-header {
    text-align: center;
    padding: 30px 0;
    border-bottom: 2px solid var(--accent);
    margin-bottom: 30px;
}

.game-title {
    font-family: 'Amiri', serif;
    font-size: 2.5em;
    background: linear-gradient(135deg, var(--accent), var(--info));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

.game-subtitle {
    color: var(--muted);
    font-size: 1.1em;
}

/* ============ Screens ============ */
.screen {
    display: none;
}

.screen.active {
    display: block;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ Menu Grid ============ */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.menu-card {
    background: linear-gradient(135deg, var(--card) 0%, rgba(36, 41, 48, 0.8) 100%);
    border: 2px solid transparent;
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.menu-card:hover,
.menu-card:focus-visible {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: 0 10px 40px rgba(16, 185, 129, 0.3);
}

.menu-card:active {
    transform: translateY(-2px);
}

/* Special AI Card */
.menu-card.ai-card {
    border: 1px solid var(--purple);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(15, 20, 25, 0.9) 100%);
}
.menu-card.ai-card:hover,
.menu-card.ai-card:focus-visible {
    box-shadow: 0 0 20px var(--purple);
    border-color: var(--purple);
}

/* Coding Card */
.menu-card.coding-card {
    border: 1px solid var(--info);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(15, 20, 25, 0.9) 100%);
}
.menu-card.coding-card:hover,
.menu-card.coding-card:focus-visible {
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
    border-color: var(--info);
}
.coding-card .menu-card-title { color: var(--info); }

.menu-card-icon { font-size: 3.5em; margin-bottom: 15px; }
.menu-card-title { font-size: 1.3em; font-weight: 700; margin-bottom: 10px; color: var(--accent); }
.ai-card .menu-card-title { color: var(--purple); }
.menu-card-desc { color: var(--muted); line-height: 1.6; font-size: 0.95em; }

/* ============ Battle Elements ============ */
.battle-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.enemy-section {
    background: linear-gradient(180deg, rgba(239, 68, 68, 0.1) 0%, transparent 100%);
    border: 2px solid var(--danger);
    border-radius: 20px;
    padding: 25px;
    text-align: center;
}

.enemy-avatar {
    font-size: 5em;
    margin-bottom: 15px;
    animation: enemyFloat 2s ease-in-out infinite;
    filter: drop-shadow(0 0 20px var(--danger));
}

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

.enemy-name {
    font-family: 'Amiri', serif;
    font-size: 1.6em;
    color: var(--danger);
    margin-bottom: 8px;
}

.enemy-type { color: var(--muted); font-size: 0.9em; margin-bottom: 15px; }

.health-bars { display: flex; gap: 12px; margin-bottom: 15px; flex-wrap: wrap; }
.health-bar-container { flex: 1; min-width: 120px; }
.health-label { font-size: 0.8em; color: var(--muted); margin-bottom: 5px; }

.health-bar {
    height: 18px;
    background: rgba(0,0,0,0.5);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    border: 2px solid var(--danger);
}

.health-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger) 0%, var(--warning) 100%);
    transition: width 0.8s ease-out;
    border-radius: 8px;
}

.player-health-bar { border-color: var(--accent); }
.player-health-fill { background: linear-gradient(90deg, var(--accent) 0%, var(--info) 100%); }

/* ============ Dialogue & Responses ============ */
.dialogue-area {
    background: var(--card);
    border: 2px solid var(--danger);
    border-radius: 20px;
    padding: 20px;
    min-height: 120px;
}

.dialogue-speaker { font-weight: 700; color: var(--danger); margin-bottom: 8px; font-size: 1.05em; }
.dialogue-text {
    font-size: 1.1em; line-height: 1.8; color: var(--text);
    margin-bottom: 15px; font-family: 'Tajawal', sans-serif; font-weight: 500;
    word-break: break-word;
}
.dialogue-text.positive { color: var(--accent); }

.response-options { display: flex; flex-direction: column; gap: 10px; }

.response-btn {
    background: linear-gradient(135deg, var(--card) 0%, rgba(36, 41, 48, 0.8) 100%);
    border: 2px solid var(--accent);
    border-radius: 15px;
    padding: 18px;
    text-align: right;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    word-break: break-word;
}

.response-btn:hover,
.response-btn:focus-visible {
    transform: translateX(-5px);
    border-color: var(--gold);
    box-shadow: 0 4px 15px rgba(251, 191, 36, 0.15);
}

.response-btn:active {
    transform: translateX(-2px);
}

.response-type {
    font-size: 0.75em; color: var(--muted); margin-bottom: 8px;
    display: flex; align-items: center; gap: 8px;
}

.stat-tag {
    background: rgba(16, 185, 129, 0.2);
    padding: 4px 10px; border-radius: 8px;
    color: var(--accent); font-size: 0.8em;
    margin-left: 10px; display: inline-block;
}
.stat-tag.damage { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* ============ AI Button ============ */
.ai-assist-btn {
    background: linear-gradient(135deg, var(--purple) 0%, #6d28d9 100%);
    border: none; color: white;
    padding: 12px 20px; border-radius: 12px;
    font-weight: bold; cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-size: 0.95em;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    margin-bottom: 15px;
    transition: all 0.3s;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
    width: 100%;
}
.ai-assist-btn:hover { transform: scale(1.02); box-shadow: 0 0 25px rgba(139, 92, 246, 0.5); }
.ai-assist-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ============ Battle Log ============ */
.battle-log {
    background: rgba(0,0,0,0.4);
    border: 2px solid var(--accent);
    border-radius: 15px;
    padding: 12px;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.85em;
    line-height: 1.8;
    margin-bottom: 15px;
    -webkit-overflow-scrolling: touch;
}

.log-entry { margin-bottom: 4px; padding: 4px 8px; border-radius: 5px; }
.log-entry.player { color: var(--accent); }
.log-entry.enemy { color: var(--danger); }
.log-entry.system { color: var(--gold); }

/* ============ Input & Buttons ============ */
.btn {
    padding: 14px 28px; border: none; border-radius: 12px;
    font-family: 'Cairo', sans-serif; font-size: 1em; font-weight: 700;
    cursor: pointer; transition: all 0.3s ease;
    width: 100%; margin-top: 10px;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    -webkit-user-select: none; user-select: none;
}

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

.btn-primary { background: linear-gradient(135deg, var(--accent) 0%, #059669 100%); color: white; }
.btn-primary:hover { box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary { background: var(--card); color: var(--text); border: 2px solid var(--accent); }
.btn-secondary:hover { background: rgba(16, 185, 129, 0.1); }

.btn-danger { background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%); color: white; }

.text-input {
    width: 100%; background: rgba(0,0,0,0.4);
    border: 2px solid var(--accent);
    border-radius: 12px; padding: 15px;
    color: var(--text); font-family: 'Cairo', sans-serif;
    font-size: 1em; margin-bottom: 15px;
    resize: vertical;
    transition: border-color 0.3s;
}

.text-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.2);
}

.text-input::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

/* ============ Loading Spinner ============ */
.loader {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--purple);
    border-radius: 50%; width: 22px; height: 22px;
    animation: spin 0.8s linear infinite; display: none;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ============ Notification ============ */
.notification {
    position: fixed; top: 20px; left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--accent); color: white;
    padding: 12px 25px; border-radius: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    transition: transform 0.3s ease;
    font-size: 0.95em;
    max-width: 90vw;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.notification.show { transform: translateX(-50%) translateY(0); }

/* ============ Journal Styles ============ */
.journal-entry {
    background: var(--card);
    border: 1px solid var(--muted);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 12px;
    position: relative;
    transition: border-color 0.3s;
}
.journal-entry:hover { border-color: var(--accent); }
.journal-date { font-size: 0.8em; color: var(--muted); margin-bottom: 8px; display: block; }
.journal-text { font-size: 1.05em; color: var(--text); margin-bottom: 12px; line-height: 1.6; word-break: break-word; }
.journal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.journal-btn {
    flex: 1; min-width: 100px; padding: 8px; border-radius: 8px; border: none; font-weight: bold; cursor: pointer; font-family: 'Cairo';
    font-size: 0.9em; transition: all 0.2s;
}
.journal-btn:active { transform: scale(0.97); }
.journal-btn-battle { background: rgba(16, 185, 129, 0.2); color: var(--accent); border: 1px solid var(--accent); }
.journal-btn-battle:hover { background: rgba(16, 185, 129, 0.35); }
.journal-btn-delete { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid var(--danger); }
.journal-btn-delete:hover { background: rgba(239, 68, 68, 0.25); }

/* ============ Stats & Tech ============ */
.study-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 15px; margin-bottom: 20px; }
.tech-card { background: var(--code-bg); border: 2px solid #333; padding: 15px; border-radius: 12px; text-align: center; cursor: pointer; transition: all 0.3s; }
.tech-card:hover { border-color: var(--muted); }
.tech-card.active { border-color: var(--info); box-shadow: 0 0 15px rgba(59, 130, 246, 0.3); }
.xp-bar-container { background: #333; height: 10px; border-radius: 5px; margin-top: 10px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--info), var(--purple)); width: 0%; transition: width 0.5s ease; border-radius: 5px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.stat-box { background: var(--card); padding: 20px 15px; border-radius: 12px; text-align: center; border: 1px solid var(--accent); }
.stat-value { font-size: 1.8em; font-weight: bold; color: var(--accent); display: block; margin-bottom: 5px; }
.player-title-badge { background: linear-gradient(135deg, var(--purple), #6d28d9); color: white; padding: 5px 12px; border-radius: 20px; font-size: 0.8em; margin-top: 5px; display: inline-block; }

/* ============ Phase Indicator ============ */
.phase-indicator {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.phase-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid var(--gold);
    transition: all 0.3s ease;
}

.phase-dot.active {
    background: var(--gold);
    box-shadow: 0 0 10px var(--gold);
}

/* ============ Footer ============ */
.site-footer {
    background: var(--darker);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 25px 20px;
    text-align: center;
    margin-top: 40px;
    flex-shrink: 0;
}

.footer-content {
    max-width: 900px;
    margin: 0 auto;
}

.site-footer p {
    color: var(--muted);
    font-size: 0.9em;
    line-height: 1.8;
}

.footer-copy {
    color: var(--accent);
    font-weight: 700;
    margin-top: 5px;
}

/* ============ Responsive Design ============ */

/* Tablets */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .game-title {
        font-size: 2em;
    }

    .menu-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 15px;
        margin-top: 20px;
    }

    .menu-card {
        padding: 22px;
    }

    .menu-card-icon {
        font-size: 3em;
    }

    .menu-card-title {
        font-size: 1.2em;
    }

    .enemy-avatar {
        font-size: 4em;
    }

    .enemy-name {
        font-size: 1.4em;
    }

    .enemy-section {
        padding: 20px;
    }

    .dialogue-area {
        padding: 18px;
        min-height: 100px;
    }

    .dialogue-text {
        font-size: 1em;
    }

    .response-btn {
        padding: 15px;
    }

    .health-bars {
        flex-direction: column;
        gap: 8px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .game-header {
        padding: 20px 0;
        margin-bottom: 20px;
    }

    .game-title {
        font-size: 1.6em;
    }

    .game-subtitle {
        font-size: 0.9em;
    }

    .menu-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-top: 15px;
    }

    .menu-card {
        padding: 18px;
        border-radius: 15px;
    }

    .menu-card-icon {
        font-size: 2.5em;
        margin-bottom: 10px;
    }

    .menu-card-title {
        font-size: 1.05em;
    }

    .menu-card-desc {
        font-size: 0.85em;
    }

    .enemy-avatar {
        font-size: 3.5em;
    }

    .enemy-name {
        font-size: 1.2em;
    }

    .enemy-section {
        padding: 15px;
        border-radius: 15px;
    }

    .dialogue-area {
        padding: 15px;
        border-radius: 15px;
    }

    .dialogue-text {
        font-size: 0.95em;
        line-height: 1.6;
    }

    .response-btn {
        padding: 12px;
        border-radius: 12px;
    }

    .btn {
        padding: 12px 20px;
        font-size: 0.95em;
    }

    .text-input {
        padding: 12px;
        font-size: 0.95em;
    }

    .battle-log {
        max-height: 120px;
        padding: 10px;
        font-size: 0.8em;
    }

    .stat-value {
        font-size: 1.4em;
    }

    .stats-grid {
        gap: 10px;
    }

    .stat-box {
        padding: 15px 10px;
    }

    .study-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .tech-card {
        padding: 12px;
    }

    .journal-btn {
        padding: 10px 6px;
        font-size: 0.8em;
    }

    .ai-assist-btn {
        font-size: 0.85em;
        padding: 10px 15px;
    }

    .notification {
        font-size: 0.85em;
        padding: 10px 18px;
    }

    .site-footer {
        padding: 20px 15px;
    }

    .site-footer p {
        font-size: 0.8em;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .game-title {
        font-size: 1.4em;
    }

    .menu-card {
        padding: 15px;
    }

    .menu-card-icon {
        font-size: 2em;
    }

    .journal-actions {
        flex-direction: column;
    }

    .journal-btn {
        min-width: auto;
    }
}

/* Prevent layout shift on notch devices */
@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    .site-footer {
        padding-bottom: max(25px, env(safe-area-inset-bottom));
    }
}

/* Focus styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: var(--darker);
}
::-webkit-scrollbar-thumb {
    background: var(--muted);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
