/* --- Base and Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    /* --- Default: Nord Dark Theme Variables --- */
    --bg-primary: #2e3440; /* Nord dark background */
    --bg-secondary: #3b4252; /* Nord slightly lighter dark */
    --bg-tertiary: #434c5e; /* Nord even lighter dark */
    --bg-description: #2e3c42; /* Slightly modified for description background */
    --text-primary: #eceff4; /* Nord snow storm light */
    --text-secondary: #d8dee9; /* Nord snow storm */
    --text-placeholder: #aeb3bb; /* Nord lighter text */
    --accent-primary: #88c0d0; /* Nord frost cyan */
    --accent-secondary: #81a1c1; /* Nord frost blue */
    --accent-progress: #a3be8c; /* Nord aurora green */
    --accent-due: #ebcb8b; /* Nord aurora yellow */
    --border-color: #4c566a; /* Nord dark gray */
    --danger-color: #bf616a; /* Nord aurora red */

    /* Syntax Highlighting */
    --syntax-keyword: #b48ead; /* Nord purple */
    --syntax-string: #a3be8c; /* Nord green */
    --syntax-number: #d08770; /* Nord orange */
    --syntax-function: #88c0d0; /* Nord cyan */
    --syntax-parameter: #d8dee9; /* Nord light text */
    --syntax-comment: #636f88; /* Nord darker text */
    --syntax-variable: #5e81ac; /* Nord darker blue */
    --syntax-highlight-bg: #434c5e; /* Nord lighter background */

    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 15px;
}

/* --- Light Theme Variables (MDN-like) --- */
body.light-theme {
    --bg-primary: #f9f9fb; /* MDN light background */
    --bg-secondary: #ffffff; /* MDN white */
    --bg-tertiary: #eaeaea; /* MDN light gray */
    --bg-description: #e9f2ff; /* MDN light blue */
    --text-primary: #1b1b1b; /* MDN dark text */
    --text-secondary: #333333; /* MDN medium text */
    --text-placeholder: #757575; /* MDN gray text */
    --accent-primary: #0069c2; /* MDN blue */
    --accent-secondary: #5b87c5; /* MDN lighter blue */
    --accent-progress: #3eaf7c; /* MDN green */
    --accent-due: #e27e36; /* MDN orange */
    --border-color: #ccc; /* MDN border */
    --danger-color: #e53935; /* MDN red */

    /* Syntax Highlighting */
    --syntax-keyword: #5a32ad; /* MDN purple */
    --syntax-string: #178217; /* MDN green */
    --syntax-number: #aa5d00; /* MDN orange */
    --syntax-function: #0069c2; /* MDN blue */
    --syntax-parameter: #333333; /* MDN dark text */
    --syntax-comment: #747474; /* MDN gray */
    --syntax-variable: #0069c2; /* MDN blue */
    --syntax-highlight-bg: #e9f2ff; /* MDN light blue */
}

/* --- Layout --- */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 15px;
}

/* --- Header --- */
.app-header {
    padding: 10px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.url-bar {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
}

.url-bar .icon {
    color: var(--accent-progress);
    margin-right: 5px;
}

.main-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}

.progress-bar-container {
    flex-grow: 1;
    height: 8px;
    background-color: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-bar-fill {
    height: 100%;
    background-color: var(--accent-primary);
    border-radius: 4px;
    transition: width 0.3s ease; /* Added transition */
}

/* --- Lesson Info --- */
.lesson-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    align-items: center;
    gap: 15px;
    margin-bottom: 25px;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 15px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.lesson-info a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
}
.lesson-info a:hover {
    text-decoration: underline;
}

/* --- Icon Help --- */
.icon-help {
    display: inline-block;
    width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    border: 1px solid var(--text-placeholder);
    border-radius: 50%;
    font-size: 11px;
    color: var(--text-placeholder);
    cursor: help;
    margin-left: 5px;
    transition: all 0.2s ease;
    user-select: none; /* Prevent selection of the ? character */
}

.icon-help:hover, .icon-help:focus {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background-color: var(--bg-tertiary);
    transform: scale(1.1);
}

/* --- Tooltips --- */
.tooltip {
    position: absolute;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    max-width: 250px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

/* Default tooltip arrow (pointing down) */
.tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--border-color);
}

.tooltip::before {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--bg-secondary);
    z-index: 1;
}

/* Arrow for tooltips below elements (pointing up) */
.tooltip.below::after {
    top: -6px;
    bottom: auto;
    border-top: none;
    border-bottom: 6px solid var(--border-color);
}

.tooltip.below::before {
    top: -5px;
    bottom: auto;
    border-top: none;
    border-bottom: 5px solid var(--bg-secondary);
}

.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.tooltip.persistent {
    pointer-events: auto;
}

/* Light theme tooltip adjustments */
body.light-theme .tooltip {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.lesson-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-dots {
    display: flex;
    gap: 5px;
    border: 1px solid var(--border-color);
    padding: 3px 6px;
    border-radius: 10px;
}

.dot {
    width: 10px;
    height: 10px;
    background-color: var(--bg-tertiary);
    border-radius: 50%;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease-in-out; /* Smooth transitions */
}

.dot:hover {
    transform: scale(1.2);
    border-color: var(--accent-primary);
}

.dot.filled {
    background-color: var(--accent-secondary);
    border-color: var(--accent-secondary);
}
.dot.current {
     background-color: var(--bg-primary); /* Hollow effect */
     border: 2px solid var(--accent-secondary);
}

/* Style for due dots */
.dot.due {
    border: 2px solid var(--accent-due);
    /* Optional: different background or animation */
     background-color: color-mix(in srgb, var(--accent-due) 30%, var(--bg-tertiary) 70%);
}

.review-frequency {
    text-align: right;
}

/* --- Lesson Navigation --- */
.lesson-navigation {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

.lesson-navigation button {
    min-width: 120px;
}

.lesson-navigation button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Problem Description --- */
.problem-description {
    background-color: var(--bg-description);
    padding: 15px 20px;
    margin-bottom: 25px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    color: var(--text-primary); /* Ensure good contrast on description bg */
}

.problem-description p {
    margin-bottom: 10px;
}
.problem-description p:last-child {
    margin-bottom: 0;
}

.problem-description code,
.problem-description .inline-code {
    font-family: 'Fira Code', monospace;
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid var(--border-color);
}

/* --- Code Area --- */
.code-area {
    margin-bottom: 25px;
}

.code-area pre {
    background-color: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    margin-bottom: 10px; /* Space between blocks if needed */
}

.code-area code {
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.7;
    display: block; /* Ensure block display for line breaks */
    white-space: pre; /* Preserve whitespace and line breaks */
    color: var(--text-primary);
}

.line-number {
    display: inline-block;
    width: 2.5em; /* Adjust as needed */
    text-align: right;
    margin-right: 1em;
    color: var(--text-placeholder);
    user-select: none; /* Prevent selection */
}

/* Syntax Highlighting Styles */
.keyword { color: var(--syntax-keyword); font-weight: 500; }
.string { color: var(--syntax-string); }
.number { color: var(--syntax-number); }
.function-name { color: var(--syntax-function); }
.param { color: var(--syntax-parameter); font-style: italic; }
.comment { color: var(--syntax-comment); font-style: italic; }
.variable { color: var(--syntax-variable); }
.placeholder { color: var(--text-placeholder); font-style: italic;}

/* Highlight for assertions */
.highlight {
    background-color: var(--syntax-highlight-bg);
    padding: 1px 4px;
    border-radius: 3px;
    display: inline-block; /* Needed for padding/bg */
}

/* --- Status Info --- */
.status-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--text-secondary);
    padding: 0 5px;
}

.status-info .label {
    font-weight: 500;
    color: var(--text-primary);
    margin-right: 5px;
}

/* --- Controls --- */
.controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 0;
    border-top: 1px solid var(--border-color);
}

.shortcut {
    font-size: 13px;
    color: var(--text-secondary);
    margin-right: auto; /* Pushes buttons to the right */
}

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, opacity 0.2s ease; /* Added opacity */
    font-family: 'Inter', sans-serif;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none; /* Prevent active scale on disabled */
}

.btn:active:not(:disabled) { /* Only apply active style if not disabled */
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--accent-primary);
    color: var(--bg-primary); /* Ensure contrast */
}
/* Adjust primary button text color for light theme */
body.light-theme .btn-primary {
     color: #ffffff;
}

.btn-primary:hover:not(:disabled) { /* Only apply hover style if not disabled */
    filter: brightness(1.1);
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) { /* Only apply hover style if not disabled */
    background-color: var(--bg-tertiary);
}

.btn-danger {
    /* Optionally style differently, e.g., red text/border */
     color: var(--danger-color);
     border-color: var(--danger-color);
}
.btn-danger:hover:not(:disabled) { /* Only apply hover style if not disabled */
    background-color: var(--danger-color);
    color: var(--bg-primary); /* Or white for light theme */
    border-color: var(--danger-color);
}
body.light-theme .btn-danger:hover:not(:disabled) {
    color: #ffffff;
}

/* Enhanced Theme Toggle Button Styling */
#theme-toggle {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 100;
    padding: 8px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

#theme-toggle:hover {
    transform: translateY(-2px);
    background-color: var(--bg-tertiary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#theme-toggle:active {
    transform: translateY(0);
}

/* --- CodeMirror Customizations --- */
.CodeMirror {
    height: auto;
    min-height: 150px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-family: 'Fira Code', monospace !important;
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 15px;
}

/* Make sure all code in CodeMirror uses Fira Code */
.CodeMirror pre.CodeMirror-line, 
.CodeMirror span.cm-variable,
.CodeMirror span.cm-operator,
.CodeMirror span.cm-keyword,
.CodeMirror span.cm-string,
.CodeMirror span.cm-number,
.CodeMirror span.cm-comment {
    font-family: 'Fira Code', monospace !important;
}

/* Custom scrollbar for CodeMirror */
.CodeMirror-simplescroll-horizontal div, .CodeMirror-simplescroll-vertical div {
    background-color: var(--bg-tertiary);
    border-radius: 10px;
}

/* Assertion area */
#assertions {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 10px 15px;
}

#assertions pre {
    margin: 0;
    background: none;
    border: none;
    padding: 0;
}

#assertions code {
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    color: var(--text-primary);
}

/* Output Area */
.output-area {
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 10px 15px; /* Adjusted padding slightly */
    margin-bottom: 20px;
    font-family: 'Fira Code', monospace;
    font-size: 13px; /* Slightly smaller for more content */
    line-height: 1.6; /* Adjust line height */
    color: var(--text-primary);
    min-height: 50px;
    max-height: 250px; /* Increased max-height slightly */
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.output-line {
    margin-bottom: 2px; /* Small space between lines */
    word-wrap: break-word; /* Ensure long lines without spaces wrap */
}

.output-line.stdout {
    /* Default text color is fine */
    color: var(--text-primary);
}

.output-line.stderr {
    color: var(--danger-color);
}

/* Hint styling */
.hint {
    color: var(--accent-primary);
    padding: 10px;
    border-left: 3px solid var(--accent-primary);
    background-color: var(--bg-tertiary);
    border-radius: 4px;
}

/* Status text */
#status {
    transition: color 0.3s ease;
}

/* Theme-specific CodeMirror modifications */
body.light-theme .CodeMirror {
    border-color: var(--border-color);
}

/* Ensure good contrast for code in light theme */
body.light-theme .CodeMirror-line {
    color: var(--text-primary);
}

.hint-area {
    margin: 10px 0;
}

/* Hide the hint area when empty */
#hintArea:empty {
    display: none;
}

/* Hide the empty output container when nothing is shown */
.output-area:empty {
    display: none;
}