/* Linux Puzzles — helle Lernoberfläche mit dunkler Variante.
   Farbwelt: tiefes Petrolgrün als Marke, Aprikose als Akzent für Fortschritt
   und Erfolg. Das schwarze Terminal bleibt der Blickfang. */

@font-face {
    font-family: "Iosevka";
    src: url("fonts/iosevka-regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}

:root {
    --sans:
        system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    --mono:
        "Iosevka", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas,
        monospace;

    --radius: 16px;
    --radius-sm: 10px;

    --bg: #f2f6f5;
    --surface: #ffffff;
    --surface-2: #eaf1ef;
    --border: #dbe4e1;
    --border-strong: #c6d3cf;
    --text: #13201d;
    --muted: #5b6d68;
    --brand: #14796a;
    --brand-ink: #ffffff;
    --brand-soft: #dff0ec;
    --accent: #e0812f;
    --ok: #2b8a4e;
    --ok-soft: #e0f2e5;
    --bad: #c4433f;
    --bad-soft: #fbe6e4;
    --shadow:
        0 1px 2px rgba(16, 32, 28, 0.05),
        0 10px 26px -14px rgba(16, 32, 28, 0.3);
    --terminal-bg: #0b0f0e;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d1412;
        --surface: #151f1c;
        --surface-2: #1c2926;
        --border: #26332f;
        --border-strong: #33443f;
        --text: #e7efec;
        --muted: #94a6a1;
        --brand: #4ecfae;
        --brand-ink: #06211b;
        --brand-soft: #14332c;
        --accent: #eda15f;
        --ok: #63c283;
        --ok-soft: #16301f;
        --bad: #ef7a72;
        --bad-soft: #34201e;
        --shadow:
            0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 34px -18px rgba(0, 0, 0, 0.8);
        --terminal-bg: #050a09;
    }
}

:root[data-theme="dark"] {
    --bg: #0d1412;
    --surface: #151f1c;
    --surface-2: #1c2926;
    --border: #26332f;
    --border-strong: #33443f;
    --text: #e7efec;
    --muted: #94a6a1;
    --brand: #4ecfae;
    --brand-ink: #06211b;
    --brand-soft: #14332c;
    --accent: #eda15f;
    --ok: #63c283;
    --ok-soft: #16301f;
    --bad: #ef7a72;
    --bad-soft: #34201e;
    --shadow:
        0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 34px -18px rgba(0, 0, 0, 0.8);
    --terminal-bg: #050a09;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

a {
    color: var(--brand);
    text-underline-offset: 3px;
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0.5rem;
    z-index: 10;
    background: var(--surface);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.skip-link:focus {
    left: 1rem;
}

.app {
    max-width: 84rem;
    margin: 0 auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-height: 100vh;
}

/* ---------- Kopfzeile ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.0625rem;
    letter-spacing: -0.01em;
}

.brand-logo {
    font-size: 1.5rem;
    line-height: 1;
}

img.brand-logo {
    height: 1.75rem;
    width: auto;
    max-width: 10rem;
    object-fit: contain;
}

.progress-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
    flex: 1 1 14rem;
    max-width: 30rem;
}

.progress {
    flex: 1;
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.progress-fill {
    display: block;
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), var(--accent));
    transition: width 0.4s ease;
}

.counter {
    color: var(--muted);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.icon-button {
    width: 2.25rem;
    height: 2.25rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 1rem;
}

.icon-button:hover {
    border-color: var(--brand);
    color: var(--brand);
}

/* ---------- Raster ---------- */

/* Zwei eigenständige Spalten statt eines 2x2-Rasters: sonst richten sich die
   Karten zeilenweise aneinander aus und unter der kurzen Aufgabenkarte bliebe
   eine Lücke in Höhe des Terminals. */
.grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 46rem);
    gap: 1.25rem;
    align-items: start;
    flex: 1;
}

.col {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.card-note {
    font-size: 0.8125rem;
    color: var(--muted);
}

/* ---------- Aufgabe ---------- */

.eyebrow {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand);
}

.task-title {
    font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.25rem);
    line-height: 1.15;
    letter-spacing: -0.025em;
    font-weight: 800;
    margin: 0.35rem 0 1rem;
    text-wrap: balance;
}

.prose {
    color: var(--text);
}

.prose p + p {
    margin-top: 0.85em;
}

.prose .muted {
    color: var(--muted);
}

.prose b,
.prose strong {
    font-weight: 700;
    background: var(--brand-soft);
    color: var(--brand);
    padding: 0.05em 0.35em;
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 0.9em;
}

.prose code {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 0.08em 0.4em;
    border-radius: 5px;
    white-space: nowrap;
}

.chipset {
    margin-top: 1.5rem;
}

.chipset-label {
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.6rem;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.875rem;
    text-decoration: none;
}

.chip:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.chip--search {
    font-family: var(--sans);
}

/* ---------- Terminal ---------- */

.term-actions {
    display: flex;
    gap: 0.5rem;
}

/* fit-content, damit der schwarze Rahmen das Terminal umschließt statt als
   große leere Fläche über die ganze Karte zu laufen. */
.screen-frame {
    background: var(--terminal-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    overflow: auto;
    width: fit-content;
    max-width: 100%;
    margin-inline: auto;
}

#screen_container {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Diese Maße nicht ändern: v86 misst daran die Zeichengröße. */
#screen {
    white-space: pre;
    font-size: 16px;
    font-family: "Iosevka", monospace;
    line-height: 120%;
    user-select: text;
    cursor: text;
}

/* Der Cursor ist ein absolut positioniertes Kästchen mitten in der Zeile und
   würde sonst als Zeichen mitkopiert. */
#screen div[style*="position: absolute"] {
    user-select: none;
}

.term-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    margin-top: 0.85rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.term-note[data-state="ok"] {
    color: var(--ok);
    font-weight: 600;
}

.term-note[data-state="bad"] {
    color: var(--bad);
    font-weight: 600;
}

kbd {
    font-family: var(--mono);
    font-size: 0.8em;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 0.05em 0.35em;
    background: var(--surface-2);
    color: var(--text);
}

/* ---------- Tipps ---------- */

.hints {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.hint {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    overflow: hidden;
}

.hint-reveal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: none;
    border: 0;
    font: inherit;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.hint-reveal:hover {
    color: var(--brand);
}

.hint-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
}

.hint-index {
    width: 1.5rem;
    height: 1.5rem;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--muted);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.hint-action {
    font-size: 0.8125rem;
    color: var(--muted);
    white-space: nowrap;
}

.hint-text {
    padding: 0 0.9rem 0.85rem;
    color: var(--text);
}

.hint-text code {
    font-family: var(--mono);
    font-size: 0.9em;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.08em 0.4em;
    border-radius: 5px;
}

.hint[data-open="true"] {
    background: var(--surface);
    border-color: var(--brand-soft);
}

.hint[data-open="true"] .hint-index {
    background: var(--brand-soft);
    border-color: var(--brand-soft);
    color: var(--brand);
}

/* ---------- Lösung ---------- */

.solve {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.solve input {
    flex: 1 1 12rem;
    min-width: 0;
    font-family: var(--mono);
    font-size: 0.9375rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
}

.solve input::placeholder {
    color: var(--muted);
    font-family: var(--sans);
}

.solve input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.primary-button {
    padding: 0.6rem 1.4rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--brand);
    background: var(--brand);
    color: var(--brand-ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.primary-button:hover:not(:disabled) {
    filter: brightness(1.08);
}

.primary-button:disabled,
.ghost-button:disabled {
    opacity: 0.45;
    cursor: default;
}

.ghost-button {
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.875rem;
    cursor: pointer;
}

.ghost-button:hover:not(:disabled) {
    border-color: var(--brand);
    color: var(--brand);
}

.status {
    min-height: 1.6em;
    margin-top: 0.75rem;
    font-size: 0.9375rem;
    color: var(--muted);
}

.status[data-state="ok"] {
    color: var(--ok);
    font-weight: 600;
}

.status[data-state="bad"] {
    color: var(--bad);
    font-weight: 600;
}

.level-nav {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

/* ---------- Fußzeile ---------- */

.footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem 1.5rem;
    padding-top: 0.5rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.footer-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.1rem;
}

.link-button {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.link-button:hover {
    color: var(--brand);
}

.filelabel input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.filelabel:focus-within {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ---------- Dialog ---------- */

#popup {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
    max-width: min(48rem, 92vw);
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    font-family: var(--sans);
}

#popup::backdrop {
    background: rgba(8, 18, 15, 0.55);
    backdrop-filter: blur(2px);
}

#popup h2 {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.dialog-intro {
    color: var(--muted);
    margin-bottom: 1.25rem;
}

.dialog-close-form {
    position: sticky;
    top: 0;
    float: right;
    z-index: 1;
}

#popup-close {
    background: none;
    border: 0;
    color: var(--muted);
    font: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

#popup-close:hover {
    color: var(--brand);
}

#popup label {
    display: block;
    font-weight: 600;
    margin-top: 1.25rem;
}

.field-note {
    color: var(--muted);
    font-size: 0.8125rem;
    margin-bottom: 0.4rem;
}

.field-note code {
    font-family: var(--mono);
}

#popup textarea {
    width: 100%;
    height: 4.5rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    font-family: var(--mono);
    font-size: 0.875rem;
    resize: vertical;
}

#popup textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.dialog-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

/* ---------- Schmale Fenster ---------- */

/* Zwei Spalten brauchen Platz für die vollen 768px des Terminals. */
@media (max-width: 1280px) {
    .grid {
        grid-template-columns: minmax(0, 1fr);
    }

    /* Das Terminal zuerst, die Aufgabe darunter. */
    .grid > .col:last-child {
        order: -1;
    }
}

/* Das Terminal ist ein festes Raster aus 80x25 Zeichen zu 16px und muss auf
   schmalen Fenstern schrumpfen. `zoom` statt `transform: scale()`, weil zoom
   auch die Layoutbox verkleinert und darunter keine Lücke stehen bleibt.
   Absteigend sortiert: die schmalste Regel muss gewinnen. */
@media (max-width: 900px) {
    #screen_container {
        zoom: 0.9;
    }
}

@media (max-width: 820px) {
    .app {
        padding: 0.85rem;
    }

    .card {
        padding: 1.15rem;
    }

    .screen-frame {
        padding: 0.6rem;
    }

    .topbar {
        gap: 0.75rem;
    }

    .progress-wrap {
        order: 3;
        width: 100%;
        max-width: none;
        margin-left: 0;
    }

    #screen_container {
        zoom: 0.82;
    }
}

@media (max-width: 700px) {
    #screen_container {
        zoom: 0.7;
    }
}

@media (max-width: 620px) {
    #screen_container {
        zoom: 0.62;
    }
}

@media (max-width: 540px) {
    #screen_container {
        zoom: 0.54;
    }
}

@media (max-width: 460px) {
    #screen_container {
        zoom: 0.45;
    }
}

/* Neun Punkte und der Zähler passen nicht mehr nebeneinander; die Punkte
   allein sagen dasselbe. */
@media (max-width: 380px) {
    #screen_container {
        zoom: 0.37;
    }
}

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

/* ---------- Lektion und Aufgabe ---------- */

.eyebrow {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.topic {
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    letter-spacing: 0.04em;
}

.lesson {
    margin-bottom: 1.25rem;
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.lesson-label,
.assignment-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.assignment {
    padding-left: 1.1rem;
    border-left: 3px solid var(--brand);
}

.assignment-label {
    color: var(--brand);
}

.level-select {
    flex: 1;
    min-width: 0;
    max-width: 22rem;
    font: inherit;
    font-size: 0.875rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.level-select:hover:not(:disabled) {
    border-color: var(--brand);
}

.level-select:disabled {
    opacity: 0.45;
    cursor: default;
}

.level-nav {
    align-items: center;
}

/* ---------- Übersichtsseite ---------- */

.overview-link {
    text-decoration: none;
    white-space: nowrap;
}

.overview {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.overview-head {
    max-width: 44rem;
}

.overview-title {
    font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.4rem);
    line-height: 1.1;
    letter-spacing: -0.03em;
    font-weight: 800;
    text-wrap: balance;
}

.overview-intro {
    color: var(--muted);
    margin-top: 0.5rem;
}

.chapter {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem 1.5rem;
    margin-bottom: 1.25rem;
}

.chapter-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.85rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.chapter-title {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.015em;
}

.chapter-number {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--brand);
    margin-bottom: 0.15rem;
}

.chapter-count {
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.chapter-count[data-state="done"] {
    background: var(--brand-soft);
    border-color: var(--brand-soft);
    color: var(--brand);
    font-weight: 700;
}

.task-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr));
    gap: 0.6rem;
}

.task {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    height: 100%;
    padding: 0.8rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    text-decoration: none;
    color: var(--text);
    transition:
        border-color 0.15s ease,
        transform 0.15s ease;
}

.task:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
}

.task[data-state="done"] {
    background: var(--surface);
    border-color: var(--brand-soft);
}

.task-number {
    flex: none;
    width: 1.75rem;
    height: 1.75rem;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--muted);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.task[data-state="done"] .task-number {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-ink);
    font-weight: 700;
}

.task-body {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.task-name {
    font-weight: 600;
    line-height: 1.3;
}

.task-summary {
    font-size: 0.8125rem;
    color: var(--muted);
    line-height: 1.45;
}

.task-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.15rem;
}

.task-tools code {
    font-family: var(--mono);
    font-size: 0.75rem;
    padding: 0.05em 0.4em;
    border-radius: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
}

.overview-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

/* Unsichtbar, aber fokussierbar: hier landet der Inhalt der Zwischenablage bei
   Strg+V, bevor er in die VM getippt wird. */
.paste-catcher {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    resize: none;
    pointer-events: none;
}
