:root {
    /* Palette */
    --bg-color: #121212;
    --text-main: #e0e0e0;
    --text-user: #ff6b6b;
    /* Soft Red */
    --text-dim: #888888;
    --text-success: #50fa7b;
    /* Soft Green */
    --text-error: #ff5555;
    --highlight: #f1fa8c;
    /* Soft Yellow */
    --hud-bg: #1a1a1a;
    --hud-border: #333;
    --font-stack: 'Fira Code', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-stack);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-size: 16px;
    line-height: 1.6;
}

/* Scanline Effect */
body::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%);
    background-size: 100% 4px;
    z-index: 5;
    pointer-events: none;
}

/* --- WARNING OVERLAY --- */
.warning-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: warningFlash 0.5s infinite;
}

.warning-overlay.hidden {
    display: none;
}

.warning-content {
    text-align: center;
    padding: 40px;
    border: 4px solid var(--text-error);
    background: rgba(255, 85, 85, 0.1);
    box-shadow: 0 0 50px rgba(255, 85, 85, 0.8);
}

.warning-icon {
    font-size: 5rem;
    margin-bottom: 20px;
    animation: pulse 1s infinite;
}

.warning-text {
    font-size: 2rem;
    color: var(--text-error);
    font-weight: bold;
    text-shadow: 0 0 20px var(--text-error);
    margin-bottom: 10px;
}

.warning-subtext {
    font-size: 1.5rem;
    color: var(--text-error);
    text-shadow: 0 0 10px var(--text-error);
}

@keyframes warningFlash {

    0%,
    100% {
        background: rgba(0, 0, 0, 0.95);
        border-color: var(--text-error);
    }

    50% {
        background: rgba(255, 0, 0, 0.3);
        border-color: #fff;
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }
}

/* --- HUB SCREEN --- */
#hub-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
    overflow-y: auto;
}

.hub-title {
    font-size: 2.5rem;
    color: var(--text-error);
    margin-bottom: 10px;
    text-shadow: 0 0 10px rgba(255, 85, 85, 0.5);
    letter-spacing: 5px;
}

.hub-subtitle {
    color: var(--text-dim);
    margin-bottom: 40px;
    font-size: 0.9rem;
}

.mission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 1000px;
    padding: 10px;
}

.mission-card {
    background: #1a1a1a;
    border: 1px solid #333;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.mission-card:hover:not(.locked) {
    border-color: var(--text-user);
    transform: translateY(-2px);
    background: #222;
}

.mission-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    border-style: dashed;
}

.mission-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-weight: bold;
    color: var(--text-main);
}

.mission-desc {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.status-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 2px;
    background: #333;
}

.status-open {
    color: var(--text-success);
    border: 1px solid var(--text-success);
}

.status-locked {
    color: var(--text-dim);
}

.status-done {
    background: var(--text-success);
    color: #000;
}

#ghost-avatar {
    position: absolute;
    right: 40px;
    top: 40px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--text-success);
    object-fit: cover;
    box-shadow: 0 0 20px rgba(80, 250, 123, 0.3);
    z-index: 15;
    pointer-events: none; /* avoid blocking clicks in UI */
}

/* --- TERMINAL SCREEN --- */
#terminal {
    display: none;
    /* Hidden initially */
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    padding: 20px;
    padding-top: 60px;
    /* Space for HUD */
}

/* HUD Styling */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 40px;
    background: var(--hud-bg);
    border-bottom: 1px solid var(--hud-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    font-size: 0.8rem;
    color: var(--text-dim);
    z-index: 20;
}

#hud span {
    margin-right: 20px;
}

#hud-target {
    color: var(--text-error);
    font-weight: bold;
}

#hud-user {
    color: var(--text-success);
}

#hud-objective {
    color: var(--highlight);
}

#back-btn {
    position: absolute;
    top: 50px;
    right: 20px;
    background: #333;
    color: #fff;
    border: none;
    padding: 5px 10px;
    cursor: pointer;
    font-family: var(--font-stack);
    font-size: 0.8rem;
    z-index: 20;
    opacity: 0.5;
}

#back-btn:hover {
    background: var(--text-error);
    opacity: 1;
}

#output {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 10px;
}

/* Scrollbar */
#output::-webkit-scrollbar {
    width: 6px;
}

#output::-webkit-scrollbar-track {
    background: #111;
}

#output::-webkit-scrollbar-thumb {
    background: #444;
}

.input-area {
    display: flex;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid #333;
}

.prompt {
    color: var(--text-user);
    margin-right: 10px;
    font-weight: bold;
}

#command-input {
    background: transparent;
    border: none;
    color: var(--text-user);
    font-family: var(--font-stack);
    font-size: 16px;
    flex: 1;
    outline: none;
    caret-color: var(--text-user);
    font-weight: bold;
}

/* Log Colors */
.log-entry {
    margin-bottom: 4px;
}

.log-user {
    color: var(--text-user);
    font-weight: bold;
}

.log-system {
    color: var(--text-main);
}

.log-error {
    color: var(--text-error);
}

.log-success {
    color: var(--text-success);
}

.log-info {
    color: var(--text-dim);
    font-style: italic;
}

.typing-cursor::after {
    content: '█';
    animation: blink 1s step-end infinite;
    color: var(--text-user);
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.input-locked #command-input {
    opacity: 0.5;
    pointer-events: none;
}

/* Profile Card Styling */
.profile-card {
    border: 2px solid var(--text-error);
    padding: 15px;
    margin: 10px 0;
    background: rgba(255, 85, 85, 0.1);
    font-family: var(--font-stack);
    color: var(--text-error);
    text-shadow: 0 0 5px rgba(255, 85, 85, 0.5);
}

/* --- CATEGORY HUB (NEW) --- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    width: 100%;
    max-width: 900px;
    padding: 20px;
}

@media (max-width: 768px) {
    .category-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .category-grid {
        grid-template-columns: 1fr;
    }
}

.category-card {
    background: linear-gradient(145deg, #1a1a1a, #252525);
    border: 2px solid #333;
    border-radius: 8px;
    padding: 25px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-accent, #ff5555);
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border-color: var(--card-accent, #ff5555);
}

.category-card.coming-soon {
    opacity: 0.7;
}

.category-card.coming-soon:hover {
    opacity: 0.9;
}

.category-cover {
    width: 100%;
    height: 100px;
    background-size: cover;
    background-position: center;
    border-radius: 4px 4px 0 0;
    margin: -15px -15px 15px -15px;
    width: calc(100% + 30px);
}

.category-info {
    text-align: center;
}

.category-title {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text-main);
    margin-bottom: 6px;
    letter-spacing: 1px;
}

.category-subtitle {
    font-size: 0.75rem;
    color: var(--text-dim);
}

.category-progress {
    margin-top: 8px;
    font-size: 0.7rem;
    color: var(--card-accent, var(--text-success));
}

.badge-coming-soon {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ff5555;
    color: #000;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
}

.badge-open {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--text-success);
    color: #000;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
}

/* --- FRAGMAN PAGE --- */
.fragman-container {
    width: 100%;
    max-width: 800px;
    padding: 20px 30px 60px;
    text-align: left;
    margin: 0 auto;
}

.fragman-title {
    font-size: 2.5rem;
    color: var(--text-error);
    margin-bottom: 5px;
    text-shadow: 0 0 30px rgba(255, 85, 85, 0.4);
    letter-spacing: 4px;
}

.fragman-subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 30px;
    font-style: italic;
}

.fragman-divider {
    border: none;
    border-top: 1px solid #333;
    margin: 30px 0;
}

.fragman-section {
    margin: 25px 0;
    padding: 0;
    background: none;
    border-left: none;
}

.fragman-section h3 {
    color: #fff;
    margin-bottom: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 1px;
}

.fragman-section p {
    color: #aaa;
    font-size: 0.95rem;
    line-height: 1.8;
    margin-bottom: 10px;
}

.fragman-section ul {
    list-style: none;
    padding-left: 0;
    margin-top: 15px;
}

.fragman-section ul li {
    color: #888;
    font-size: 0.9rem;
    padding: 6px 0;
    border-bottom: 1px solid #222;
}

.fragman-section ul li strong {
    color: var(--text-success);
}

.fragman-warning {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid #333;
    padding: 20px;
    margin: 40px 0;
    text-align: left;
}

.fragman-warning h3 {
    color: #ff6b6b;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.fragman-warning p {
    color: #666;
    font-size: 0.8rem;
    line-height: 1.6;
}

.fragman-btn {
    display: inline-block;
    margin-top: 20px;
    padding: 14px 50px;
    background: transparent;
    color: var(--text-success);
    font-family: var(--font-stack);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 2px;
    border: 1px solid var(--text-success);
    cursor: pointer;
    transition: all 0.3s;
}

.fragman-btn:hover {
    background: #3ad168;
    transform: scale(1.05);
    color: #000;
}

/* Mobile tap optimization */
.back-button,
.fragman-btn {
    touch-action: manipulation;
}

/* --- SEASON HUB --- */
.season-header {
    text-align: center;
    margin-bottom: 30px;
}

.season-title {
    font-size: 1.8rem;
    color: var(--text-main);
    margin-bottom: 10px;
}

.season-tagline {
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.9rem;
}

.episode-list {
    width: 100%;
    max-width: 600px;
}

.episode-card {
    background: #1a1a1a;
    border: 1px solid #333;
    padding: 15px 20px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.episode-card:hover {
    border-color: #555;
    background: #222;
}

.episode-card.locked {
    opacity: 0.5;
}

.episode-title {
    color: var(--text-main);
    font-size: 0.9rem;
}

.episode-status {
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 3px;
}

.episode-status.coming-soon {
    background: #333;
    color: var(--text-dim);
}

.episode-status.open {
    background: var(--text-success);
    color: #000;
}

.back-button {
    background: transparent;
    border: 1px solid #555;
    color: var(--text-dim);
    padding: 10px 20px;
    font-family: var(--font-stack);
    cursor: pointer;
    margin-bottom: 20px;
    transition: all 0.2s;
}

.back-button:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

.season-notice {
    margin-top: 30px;
    padding: 15px;
    background: rgba(255, 85, 85, 0.1);
    border: 1px dashed var(--text-error);
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* Solutions Box */
.solutions-box {
    width: 100%;
    max-width: 600px;
    margin-top: 20px;
    padding: 15px 20px;
    background: linear-gradient(135deg, #2d1f4e 0%, #1a1333 100%);
    border: 1px solid #a855f7;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.solutions-box:hover {
    border-color: #c084fc;
    background: linear-gradient(135deg, #3d2a6e 0%, #2a1d44 100%);
    transform: translateY(-2px);
}

.solutions-icon {
    font-size: 1.2rem;
}

.solutions-text {
    color: #c084fc;
    font-size: 0.9rem;
    font-weight: bold;
    letter-spacing: 2px;
}

/* ===========================================
   MOBILE & iOS RESPONSIVE STYLES
   =========================================== */

/* iOS Safe Area Support */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }

    .input-area {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* Prevent iOS text size adjustment */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling for iOS */
#output,
#hub-screen {
    -webkit-overflow-scrolling: touch;
}

/* Mobile Breakpoint - Tablets and Below */
@media screen and (max-width: 768px) {
    body {
        font-size: 14px;
    }

    /* Hub Screen */
    #hub-screen {
        padding: 15px;
        padding-top: 20px;
    }

    .hub-title {
        font-size: 1.8rem;
        letter-spacing: 3px;
    }

    .hub-subtitle {
        font-size: 0.8rem;
        margin-bottom: 25px;
    }

    #ghost-avatar {
        width: 50px;
        height: 50px;
        right: 15px;
        top: 15px;
    }

    .mission-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 5px;
    }

    .mission-card {
        padding: 15px;
        min-height: 80px;
        /* Touch-friendly */
    }

    /* Terminal Screen */
    #terminal {
        padding: 10px;
        padding-top: 80px;
    }

    /* HUD - Stack vertically on mobile */
    #hud {
        height: auto;
        min-height: 60px;
        flex-wrap: wrap;
        padding: 8px 10px;
        gap: 5px;
    }

    #hud span {
        font-size: 0.7rem;
        margin-right: 0;
        width: 100%;
        text-align: center;
    }

    #hud-target {
        order: 1;
    }

    #hud-objective {
        order: 2;
        font-size: 0.65rem;
    }

    #hud-user {
        order: 3;
        display: none;
        /* Hide user on mobile - less important */
    }

    #back-btn {
        position: fixed;
        top: 70px;
        bottom: auto;
        right: 10px;
        padding: 8px 12px;
        font-size: 0.75rem;
        z-index: 100;
        background: rgba(0, 0, 0, 0.9);
    }

    /* Input Area */
    .input-area {
        padding: 12px 5px;
        flex-wrap: nowrap;
    }

    .prompt {
        font-size: 0.8rem;
        margin-right: 5px;
        white-space: nowrap;
    }

    #command-input {
        font-size: 16px;
        /* Prevents iOS zoom on focus */
        min-height: 44px;
        /* iOS touch target */
    }

    /* Output */
    #output {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .log-entry {
        word-break: break-word;
    }

    /* Profile Card */
    .profile-card {
        padding: 10px;
        font-size: 0.8rem;
    }

    /* Season Hub */
    .season-title {
        font-size: 1.4rem;
    }

    .season-tagline {
        font-size: 0.8rem;
    }

    .episode-list {
        max-width: 100%;
    }

    .episode-card {
        padding: 12px 15px;
        min-height: 50px;
    }

    /* Warning Overlay */
    .warning-content {
        padding: 25px;
        margin: 10px;
    }

    .warning-icon {
        font-size: 3rem;
    }

    .warning-text {
        font-size: 1.3rem;
    }

    .warning-subtext {
        font-size: 1rem;
    }

    /* Fragman Section */
    .fragman-section {
        padding: 30px 15px;
    }

    .fragman-title {
        font-size: 1.5rem;
    }

    .fragman-btn {
        padding: 12px 30px;
        font-size: 0.85rem;
    }
}

/* Small Mobile - Phones */
@media screen and (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .hub-title {
        font-size: 1.4rem;
        letter-spacing: 2px;
    }

    .hub-subtitle {
        font-size: 0.75rem;
    }

    #ghost-avatar {
        width: 40px;
        height: 40px;
        right: 10px;
        top: 10px;
        border-width: 2px;
    }

    /* Terminal adjustments */
    #terminal {
        padding-top: 90px;
    }

    .prompt {
        font-size: 0.75rem;
    }

    #output {
        font-size: 0.8rem;
    }

    /* Better touch targets */
    .mission-card,
    .episode-card,
    .back-button,
    #back-btn,
    .fragman-btn {
        min-height: 44px;
        /* Apple HIG touch target */
    }

    /* Scanline effect - reduce on mobile for performance */
    body::before {
        background-size: 100% 3px;
        opacity: 0.5;
    }
}

/* Landscape Mode on Mobile */
@media screen and (max-width: 896px) and (orientation: landscape) {
    #hub-screen {
        padding-top: 10px;
    }

    .hub-title {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }

    .hub-subtitle {
        margin-bottom: 15px;
    }

    #ghost-avatar {
        width: 40px;
        height: 40px;
    }

    .mission-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    #hud {
        min-height: 40px;
        flex-wrap: nowrap;
    }

    #hud span {
        width: auto;
        font-size: 0.65rem;
    }

    #hud-user {
        display: inline;
    }
}

/* Improve touch scroll behavior */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Focus states for accessibility */
#command-input:focus,
.mission-card:focus,
.episode-card:focus,
button:focus {
    outline: 2px solid var(--text-user);
    outline-offset: 2px;
}

/* Prevent pull-to-refresh on iOS */
html {
    overscroll-behavior-y: contain;
}

/* Better text selection on mobile */
::selection {
    background: var(--text-user);
    color: #000;
}

::-moz-selection {
    background: var(--text-user);
    color: #000;
}