/* ==========================================================================
   DESIGN SYSTEM & GLOBAL STYLES (Cyber-Dark & Glassmorphism)
   ========================================================================== */

:root {
    --bg-dark: #070913;
    --bg-card: rgba(13, 17, 30, 0.7);
    --bg-terminal: rgba(5, 7, 16, 0.95);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.25);
    
    /* Neon Accent Colors */
    --neon-cyan: #00f2fe;
    --neon-blue: #3b82f6;
    --neon-indigo: #6366f1;
    --neon-emerald: #10b981;
    --neon-rose: #f43f5e;
    --neon-yellow: #eab308;
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Typography */
    --font-ui: 'Outfit', sans-serif;
    --font-code: 'Space Mono', monospace;
    

}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-ui);
    min-block-size: 100dvh;
    overflow-x: hidden;
    position: relative;
    line-height: 1.5;
}

/* Background Grid Overlay */
.background-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center;
    z-index: -1;
    pointer-events: none;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.3);
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 8px var(--neon-indigo);
}

/* Utility Helpers */
.hidden {
    display: none !important;
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */

.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 100vh;
}

/* Toolbar controls */
.toolbar-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.difficulty-selector {
    display: flex;
    gap: 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.diff-btn {
    padding: 0.55rem 1rem;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.diff-btn + .diff-btn {
    border-left: 1px solid var(--border-color);
}

.diff-btn.active {
    background: rgba(99, 102, 241, 0.2);
    color: var(--neon-cyan);
    box-shadow: inset 0 0 12px rgba(0, 242, 254, 0.1);
}

.diff-btn:hover:not(.active) {
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.icon-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--neon-indigo);
    box-shadow: 0 0 12px var(--border-glow);
    color: var(--neon-cyan);
    transform: translateY(-2px);
}

.icon-btn:active {
    transform: translateY(1px);
}

/* MAIN BODY PANELS */
.main-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    flex: 1;
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 380px 1fr;
    }
}

/* GLASS CARDS */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.25);
    overflow: hidden;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.2);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.35);
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
}

/* CARD HEADERS */
.card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.01);
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.card-header svg {
    color: var(--neon-indigo);
}

.card-body {
    padding: 1.5rem;
}

/* ==========================================================================
   TUX MASCOT & CHAT BUBBLE
   ========================================================================= */

.tux-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    gap: 1.25rem;
    text-align: center;
}

.tux-container {
    position: relative;
    padding: 0.5rem;
}

/* Dialogue Bubble */
.dialogue-bubble {
    position: relative;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    text-align: left;
    width: 100%;
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.02);
}

.bubble-arrow {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 16px;
    height: 16px;
    background: rgba(15, 23, 42, 0.6);
    border-left: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
}

.tux-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--neon-cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.speech-text {
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.5;
}

/* Dynamic SVG Tux Expression Animations */
#tux-svg.thinking,
#tux-svg.confused,
#tux-svg.celebrating .left-flipper,
#tux-svg.celebrating .right-flipper,
#tux-svg.celebrating .beak,
#tux-svg.celebrating .left-foot,
#tux-svg.celebrating .right-foot,
#tux-svg.thinking .left-eyebrow,
#tux-svg.thinking .right-eyebrow,
#tux-svg.thinking .pupils,
#tux-svg.confused .left-eyebrow,
#tux-svg.confused .right-eyebrow,
#tux-svg.confused .left-pupil,
#tux-svg.confused .right-pupil,
#tux-svg.confused .beak,
#tux-svg.confused .left-flipper {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* SVG state: Normal / Idle */
.left-flipper { transform-origin: 55px 105px; }
.right-flipper { transform-origin: 145px 105px; }
.left-foot { transform-origin: 65px 200px; }
.right-foot { transform-origin: 135px 200px; }

@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.98) translateY(1px); }
}
#tux-svg {
    animation: breathe 4s ease-in-out infinite;
}

/* SVG state: Thinking (.thinking) */
#tux-svg.thinking .left-eyebrow {
    transform: translateY(3px) rotate(8deg);
}
#tux-svg.thinking .right-eyebrow {
    transform: translateY(3px) rotate(-8deg);
}
#tux-svg.thinking .pupils {
    transform: translateY(1px) scale(0.95);
}

/* SVG state: Confused (.confused) */
#tux-svg.confused .left-eyebrow {
    transform: translateY(-2px) rotate(-15deg);
}
#tux-svg.confused .right-eyebrow {
    transform: translateY(-2px) rotate(15deg);
}
#tux-svg.confused .left-pupil {
    transform: scale(1.4) translate(-2px, -1px);
}
#tux-svg.confused .right-pupil {
    transform: scale(0.7) translate(2px, 1px);
}
#tux-svg.confused .beak {
    transform: scale(0.9) translateY(-1px);
}
#tux-svg.confused .left-flipper {
    transform: rotate(30deg);
}

/* SVG state: Celebrating (.celebrating) */
@keyframes celebratory-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-15px) scale(0.95, 1.05); }
}
#tux-svg.celebrating {
    animation: celebratory-bounce 0.6s ease infinite;
}
#tux-svg.celebrating .left-flipper {
    transform: rotate(-70deg);
}
#tux-svg.celebrating .right-flipper {
    transform: rotate(70deg);
}
#tux-svg.celebrating .beak {
    transform: scale(1.1) translateY(1px);
}
#tux-svg.celebrating .left-foot {
    transform: rotate(-10deg);
}
#tux-svg.celebrating .right-foot {
    transform: rotate(10deg);
}

/* ==========================================================================
   QUEST OBJECTIVES
   ========================================================================== */

.quest-title-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--neon-indigo);
    margin-bottom: 0.5rem;
}

.quest-description-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.objective-list {
    list-style-type: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.objective-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.objective-item.completed {
    border-color: rgba(16, 185, 129, 0.25);
    background: rgba(16, 185, 129, 0.05);
    color: var(--text-muted);
    text-decoration: line-through;
}

.obj-checkbox {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid var(--neon-indigo);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.objective-item.completed .obj-checkbox {
    border-color: var(--neon-emerald);
    background-color: var(--neon-emerald);
}

.obj-checkbox svg {
    color: white;
    width: 12px;
    height: 12px;
    display: none;
}

.objective-item.completed .obj-checkbox svg {
    display: block;
}

.obj-text {
    line-height: 1.2;
}

.objective-item.completed .obj-text {
    color: var(--text-muted);
}

/* ==========================================================================
   LINUX TERMINAL EMULATOR
   ========================================================================== */

.terminal-card {
    flex: 1;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    background: var(--bg-terminal);
    border: 1px solid var(--border-color);
    box-shadow: 0 16px 48px 0 rgba(0, 0, 0, 0.45);
}

.terminal-card:hover {
    border-color: rgba(0, 242, 254, 0.25);
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.15);
}

.terminal-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: rgba(15, 23, 42, 0.7);
    border-bottom: 1px solid var(--border-color);
    user-select: none;
}

#terminal-title {
    flex: 1;
    text-align: center;
    font-size: 0.8rem;
    font-family: var(--font-code);
    color: var(--text-muted);
    font-weight: 500;
}

.terminal-body {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    font-family: var(--font-code);
    font-size: 0.95rem;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
}

#terminal-output {
    display: flex;
    flex-direction: column;
}

.output-line {
    white-space: pre-wrap;
    word-break: break-all;
    margin-bottom: 0.25rem;
}

.output-line.system {
    color: var(--neon-indigo);
    font-weight: bold;
}

.output-line.error {
    color: var(--neon-rose);
}

.output-line.success {
    color: var(--neon-emerald);
}

.output-line.info {
    color: var(--text-muted);
}

.cmd-highlight {
    color: var(--neon-cyan);
    font-weight: bold;
    background: rgba(0, 242, 254, 0.1);
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
}

.ls-dir {
    color: var(--neon-blue);
    font-weight: bold;
}

/* Simulated command lines in output */
.history-command {
    color: var(--text-primary);
    font-weight: 500;
}

/* Prompt Styles */
.prompt-prefix {
    display: inline-flex;
    gap: 0.1rem;
    user-select: none;
    flex-shrink: 0;
}

.prompt-user { color: var(--neon-emerald); font-weight: bold; }
.prompt-at { color: var(--text-muted); }
.prompt-host { color: var(--neon-blue); }
.prompt-colon { color: var(--text-primary); }
.prompt-path { color: var(--neon-cyan); font-weight: bold; }
.prompt-symbol { color: var(--text-primary); margin-left: 0.25rem; }

/* Interactive command input block */
.input-line {
    display: flex;
    align-items: center;
    width: 100%;
}

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    padding-left: 0.4rem;
}

#terminal-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: transparent; /* Hide text, let simulated display show it */
    font-family: var(--font-code);
    font-size: 0.95rem;
    caret-color: transparent; /* Hide native blinking cursor */
    position: absolute;
    top: 0;
    left: 0.4rem;
    height: 100%;
    z-index: 10;
}

.input-wrapper::after {
    content: attr(data-content);
    position: absolute;
    left: 0.4rem;
    color: var(--text-primary);
    pointer-events: none;
    font-family: var(--font-code);
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-all;
    z-index: 5;
}

#terminal-cursor {
    display: inline-block;
    width: 8px;
    height: 1.2em;
    background: var(--neon-cyan);
    animation: blink 1s step-end infinite;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 6;
    pointer-events: none;
}

@keyframes blink {
    from, to { background-color: transparent }
    50% { background-color: var(--neon-cyan); box-shadow: 0 0 6px var(--neon-cyan); }
}

/* ASCII Steam Locomotive (sl) animation classes */
.train-wrapper {
    overflow: hidden;
    width: 100%;
    position: relative;
    height: 160px;
    margin: 1rem 0;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.train-content {
    position: absolute;
    left: 100%;
    white-space: pre;
    font-family: var(--font-code);
    color: var(--neon-yellow);
    line-height: 1.1;
    animation: moveTrain 5s linear forwards;
}

@keyframes moveTrain {
    0% { left: 100%; }
    100% { left: -600px; }
}

/* ==========================================================================
   GRADUATION OVERLAY MODAL & CERTIFICATE
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(5, 7, 16, 0.85);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s ease;
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 24px 64px 0 rgba(0, 0, 0, 0.6), 0 0 40px rgba(99, 102, 241, 0.15);
    border-radius: 24px;
    width: 90%;
    max-width: 900px;
    padding: 2rem;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.scale-up-animation {
    transform: scale(0.9);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay:not(.hidden) .scale-up-animation {
    transform: scale(1);
}

.confetti-canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.modal-header-confetti {
    text-align: center;
    position: relative;
    z-index: 2;
}

.trophy-glow {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    animation: pulseTrophy 2s infinite ease-in-out;
}

@keyframes pulseTrophy {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 10px rgba(234, 179, 8, 0.5)); }
    50% { transform: scale(1.1); filter: drop-shadow(0 0 25px rgba(234, 179, 8, 0.8)); }
}

.modal-header-confetti h2 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--neon-yellow), var(--neon-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.modal-header-confetti p {
    color: var(--text-muted);
    font-size: 1rem;
}

/* Certificate Layout */
.certificate-container {
    position: relative;
    z-index: 2;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

#certificate-canvas {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* Controls inside graduation modal */
.graduation-controls {
    position: relative;
    z-index: 2;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.name-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.name-input-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.name-input-group input {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

.name-input-group input:focus {
    border-color: var(--neon-indigo);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    width: 100%;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    font-family: var(--font-ui);
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 10px;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
}

.primary-btn {
    background: linear-gradient(135deg, var(--neon-indigo), var(--neon-blue));
    color: white;
}
.primary-btn:hover {
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
    transform: translateY(-2px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.success-btn {
    background: linear-gradient(135deg, var(--neon-emerald), #059669);
    color: white;
}
.success-btn:hover {
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(1px);
}

/* ==========================================================================
   ACCESSIBILITY & RESPONSIVENESS
   ========================================================================== */

@media (max-width: 768px) {
    .toolbar-controls {
        justify-content: center;
    }
    
    .app-container {
        padding: 0.75rem;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
}
