/* ============================================
   FORGE — Procedural Education Platform
   Design System (Vitsoe / Dieter Rams)
   ============================================
   
   Principles applied:
   - Good design is as little design as possible
   - Good design is unobtrusive
   - Good design makes a product understandable
   - Good design is honest
   ============================================ */

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Monochrome palette — Vitsoe-derived */
    --bg-primary: #f0efed;
    --bg-hero: #e8e7e5;
    --bg-white: #fafaf9;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-tertiary: #888;
    --rule: #ccc;
    --rule-light: #ddd;
    --accent: #0079bf;
    /* Vitsoe teal-blue, the ONLY color */
    --accent-hover: #006aa3;
    --correct: #2d7d46;
    --incorrect: #a63d2f;
    --input-border: #bbb;
    --input-focus: #1a1a1a;

    /* Typography scale */
    --font-family: 'Helvetica Neue', Helvetica, Arial, -apple-system, sans-serif;
    --font-size-numeral: clamp(6rem, 10vw, 10rem);
    --font-size-h1: clamp(1.75rem, 3vw, 2.5rem);
    --font-size-h2: clamp(1.4rem, 2.5vw, 2rem);
    --font-size-h3: clamp(1.1rem, 1.5vw, 1.35rem);
    --font-size-body: clamp(0.95rem, 1.1vw, 1.1rem);
    --font-size-small: 0.85rem;
    --font-size-caption: 0.75rem;
    --line-height: 1.6;
    --letter-spacing-tight: -0.02em;
    --letter-spacing-wide: 0.05em;

    /* Layout */
    --max-width: 1200px;
    --margin-outer: clamp(1.5rem, 5vw, 6rem);
    --section-gap: clamp(3rem, 8vw, 8rem);
    --rule-weight: 1px;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    line-height: var(--line-height);
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

/* --- Typography --- */
h1,
h2,
h3,
h4 {
    font-weight: 700;
    letter-spacing: var(--letter-spacing-tight);
    line-height: 1.15;
}

h1 {
    font-size: var(--font-size-h1);
}

h2 {
    font-size: var(--font-size-h2);
}

h3 {
    font-size: var(--font-size-h3);
}

p {
    color: var(--text-secondary);
    max-width: 38em;
}

a {
    color: var(--text-primary);
    text-decoration: none;
    border-bottom: var(--rule-weight) solid transparent;
    transition: border-color 0.2s ease;
}

a:hover {
    border-bottom-color: var(--text-primary);
}

/* --- Navigation (Global + Sub) --- */
.nav-global {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem var(--margin-outer);
    border-bottom: var(--rule-weight) solid var(--rule-light);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-wordmark {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: var(--letter-spacing-tight);
    color: var(--text-primary);
    text-decoration: none;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.nav-wordmark svg {
    width: 24px;
    height: 24px;
}

.nav-wordmark span {
    font-size: var(--font-size-small);
    font-weight: 400;
    color: var(--text-tertiary);
    margin-left: 0.4rem;
}

.nav-subjects {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 var(--margin-outer);
    border-bottom: var(--rule-weight) solid var(--rule-light);
    background: var(--bg-primary);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-subject-btn {
    appearance: none;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.85rem 1.25rem;
    font-family: var(--font-family);
    font-size: var(--font-size-small);
    font-weight: 400;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-subject-btn:hover {
    color: var(--text-primary);
}

.nav-subject-btn.active {
    font-weight: 700;
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
}

.nav-subject-btn svg {
    width: 16px;
    height: 16px;
    opacity: 0.6;
}

.nav-subject-btn.active svg {
    opacity: 1;
}

.nav-stats {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: var(--font-size-small);
    color: var(--text-tertiary);
}

.nav-stats svg {
    width: 16px;
    height: 16px;
    opacity: 0.5;
}

/* --- Hero Section --- */
.hero {
    background: var(--bg-hero);
    padding: clamp(2.5rem, 6vw, 5rem) var(--margin-outer);
    border-bottom: var(--rule-weight) solid var(--rule);
}

.hero h1 {
    margin-bottom: 0.3em;
}

.hero p {
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    font-weight: 300;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* --- Main Content Area --- */
.main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--margin-outer);
}

/* --- Lesson Card (Rams-style section) --- */
.lesson-section {
    padding: var(--section-gap) 0;
    border-bottom: var(--rule-weight) solid var(--rule-light);
}

.lesson-section:last-child {
    border-bottom: none;
}

.lesson-layout {
    display: grid;
    grid-template-columns: minmax(80px, 0.25fr) 1fr;
    gap: clamp(1.5rem, 4vw, 4rem);
    align-items: start;
}

.lesson-numeral {
    font-size: var(--font-size-numeral);
    font-weight: 700;
    line-height: 0.85;
    color: var(--text-primary);
    letter-spacing: -0.04em;
    user-select: none;
}

.lesson-content {
    max-width: 640px;
}

.lesson-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    font-size: var(--font-size-caption);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    color: var(--text-tertiary);
    font-weight: 600;
}

.lesson-meta .subject-label {
    color: var(--text-secondary);
}

.lesson-meta .difficulty-label {
    color: var(--text-tertiary);
}

.lesson-title {
    margin-bottom: 1rem;
}

.lesson-body {
    margin-bottom: 2rem;
}

.lesson-body p {
    margin-bottom: 1em;
}

.lesson-body p:last-child {
    margin-bottom: 0;
}

/* Passage blocks for reading comprehension */
.lesson-passage {
    border-left: 3px solid var(--rule);
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    background: var(--bg-hero);
    font-style: italic;
    color: var(--text-secondary);
}

.lesson-passage p {
    font-style: italic;
}

/* Code blocks for AI/computing */
.lesson-code {
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
    font-size: 0.9rem;
    background: var(--bg-hero);
    padding: 1.25rem 1.5rem;
    margin: 1.5rem 0;
    border: var(--rule-weight) solid var(--rule-light);
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre;
    color: var(--text-primary);
}

/* Math expressions */
.lesson-math {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 1.2em;
    text-align: center;
    padding: 1.5rem 0;
    letter-spacing: 0.02em;
}

/* Options for multiple choice */
.lesson-options {
    list-style: none;
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lesson-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: var(--rule-weight) solid var(--rule-light);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
    font-size: var(--font-size-body);
}

.lesson-option:hover {
    border-color: var(--text-secondary);
    background: var(--bg-hero);
}

.lesson-option.selected {
    border-color: var(--text-primary);
    background: var(--bg-hero);
}

.lesson-option.correct {
    border-color: var(--correct);
    background: rgba(45, 125, 70, 0.06);
}

.lesson-option.incorrect {
    border-color: var(--incorrect);
    background: rgba(166, 61, 47, 0.06);
}

.option-letter {
    font-weight: 700;
    min-width: 1.5em;
    color: var(--text-tertiary);
}

.lesson-option.selected .option-letter {
    color: var(--text-primary);
}

/* Text input answer */
.answer-input-wrap {
    margin: 1.5rem 0;
}

.answer-input {
    width: 100%;
    max-width: 400px;
    padding: 0.75rem 0;
    border: none;
    border-bottom: 2px solid var(--input-border);
    background: transparent;
    font-family: var(--font-family);
    font-size: var(--font-size-body);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s ease;
}

.answer-input:focus {
    border-bottom-color: var(--input-focus);
}

.answer-input::placeholder {
    color: var(--text-tertiary);
}

.answer-input.correct {
    border-bottom-color: var(--correct);
}

.answer-input.incorrect {
    border-bottom-color: var(--incorrect);
}

/* Numeric input */
.answer-numeric {
    max-width: 200px;
    font-family: 'SF Mono', 'Menlo', monospace;
}

/* --- Buttons --- */
.btn-primary {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 2px;
    font-family: var(--font-family);
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
    letter-spacing: 0.01em;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary svg {
    width: 14px;
    height: 14px;
}

.btn-secondary {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    background: transparent;
    color: var(--text-primary);
    border: var(--rule-weight) solid var(--text-primary);
    border-radius: 2px;
    font-family: var(--font-family);
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-secondary:hover {
    background: var(--text-primary);
    color: #fff;
}

.btn-group {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
    align-items: center;
}

/* --- Feedback --- */
.feedback {
    margin-top: 1.5rem;
    padding: 1.25rem 0;
    border-top: var(--rule-weight) solid var(--rule-light);
}

.feedback-correct {
    color: var(--correct);
    font-weight: 600;
}

.feedback-incorrect {
    color: var(--incorrect);
    font-weight: 600;
}

.feedback-explanation {
    margin-top: 0.75rem;
    color: var(--text-secondary);
    font-size: var(--font-size-body);
}

/* --- Progress Bar (thin, Rams-style) --- */
.progress-bar-wrap {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--rule-light);
    z-index: 90;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.4s ease;
    width: 0%;
}

/* --- Stats Panel --- */
.stats-panel {
    padding: var(--section-gap) 0 2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1.5rem;
}

.stat-item {
    border-top: var(--rule-weight) solid var(--rule);
    padding-top: 1rem;
}

.stat-numeral {
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 700;
    line-height: 1;
    letter-spacing: var(--letter-spacing-tight);
}

.stat-label {
    font-size: var(--font-size-caption);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    color: var(--text-tertiary);
    font-weight: 600;
    margin-top: 0.4rem;
}

/* --- Footer --- */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 2rem var(--margin-outer);
    border-top: var(--rule-weight) solid var(--rule);
    font-size: var(--font-size-caption);
    color: var(--text-tertiary);
    letter-spacing: var(--letter-spacing-wide);
    text-transform: uppercase;
}

.footer-quote {
    flex-shrink: 0;
}

.kofi-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    border: var(--rule-weight) solid var(--text-tertiary);
    border-bottom: var(--rule-weight) solid var(--text-tertiary);
    border-radius: 2px;
    font-family: var(--font-family);
    font-size: var(--font-size-caption);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    text-decoration: none;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.kofi-btn:hover {
    color: #fff;
    background: var(--text-primary);
    border-color: var(--text-primary);
    border-bottom-color: var(--text-primary);
}

.kofi-btn svg {
    width: 14px;
    height: 14px;
}

/* --- Welcome Screen (shown before first subject selection) --- */
.welcome {
    padding: var(--section-gap) 0;
}

.welcome-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2.5rem;
}

.welcome-card {
    border-top: var(--rule-weight) solid var(--rule);
    padding-top: 1.5rem;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.welcome-card:hover {
    border-top-color: var(--text-primary);
}

.welcome-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.welcome-card-header svg {
    width: 20px;
    height: 20px;
    opacity: 0.7;
}

.welcome-card h3 {
    font-size: var(--font-size-h3);
}

.welcome-card p {
    font-size: var(--font-size-small);
    color: var(--text-tertiary);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .lesson-layout {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .lesson-numeral {
        font-size: clamp(3rem, 15vw, 5rem);
    }

    .nav-subjects {
        padding: 0 1rem;
    }

    .nav-subject-btn {
        padding: 0.75rem 0.85rem;
        font-size: var(--font-size-caption);
    }

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

    .welcome-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .hero {
        padding: 1.5rem var(--margin-outer);
    }

    .btn-group {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-primary,
    .btn-secondary {
        justify-content: center;
    }
}

/* --- Utility --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden {
    display: none !important;
}

/* --- Print --- */
@media print {

    .nav-global,
    .nav-subjects,
    .progress-bar-wrap,
    .btn-group {
        display: none;
    }

    body {
        background: #fff;
        color: #000;
    }

    .lesson-section {
        break-inside: avoid;
    }
}
/* -------------------------------------------------------------
   Calculator
   ------------------------------------------------------------- */
.calc-toggle {
    position: absolute;
    top: 2rem;
    right: 2rem;
    width: 2.5rem;
    height: 2.5rem;
    background: transparent;
    border: 1px solid var(--text-color);
    border-radius: 4px; /* Slightly rounded */
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    z-index: 100;
}

.calc-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.calc-toggle svg {
    width: 1.2rem;
    height: 1.2rem;
}

/* Calculator Panel */
.calculator-panel {
    position: fixed;
    top: 5rem;
    right: 2rem;
    width: 320px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px; /* Slightly more rounded than correct/incorrect */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    font-family: 'Space Mono', monospace; /* Use monospace for calculator */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(10px); /* Glassmorphism */
}

/* Header */
.calc-header {
    background: var(--secondary-color);
    color: var(--bg-color);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: grab; /* Indicating draggability */
}

.calc-header:active {
    cursor: grabbing;
}

.calc-close-btn {
    background: none;
    border: none;
    color: var(--bg-color);
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
}

/* Display */
.calc-display {
    background: rgba(0, 0, 0, 0.2); /* Slightly darker background */
    color: var(--text-color);
    padding: 1rem;
    text-align: right;
    font-size: 1.5rem;
    min-height: 4rem;
    word-break: break-all;
    display: flex; /* Vertically center if single line */
    align-items: center;
    justify-content: flex-end;
}

/* Grid */
.calc-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border-color); /* Acts as border between buttons */
    padding: 1px;
}

.calc-btn {
    background: var(--bg-color);
    border: none;
    color: var(--text-color);
    font-size: 1rem;
    padding: 1rem 0;
    cursor: pointer;
    transition: background 0.1s;
    font-family: inherit;
}

.calc-btn:hover {
    background: var(--surface-color); /* SLight highlight */
}

.calc-btn:active {
    filter: brightness(0.9);
}

.calc-btn.op {
    color: var(--secondary-color); /* Highlight operators */
    font-weight: 700;
}

.calc-btn.fn {
    font-size: 0.85rem; /* Smaller font for functions */
    font-style: italic;
    opacity: 0.8;
}

.calc-btn.eq {
    background: var(--secondary-color);
    color: var(--bg-color);
    font-weight: 700;
}

.calc-btn.eq:hover {
    opacity: 0.9;
}

/* Responsive */
@media (max-width: 600px) {
    .calc-toggle {
        top: 1rem;
        right: 1rem;
    }

    .calculator-panel {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        border-radius: 12px 12px 0 0;
        border-bottom: none;
    }
}
