@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
    --ink: #191a16;
    --muted: #66685f;
    --paper: #fbfbf5;
    --panel: #ffffff;
    --line: #d9dacd;
    --strong-line: #aeb2a1;
    --green: #baf23b;
    --green-strong: #77a80f;
    --blue: #2854ff;
    --blue-soft: #dce5ff;
    --coral: #ff6847;
    --coral-soft: #ffe1d8;
    --yellow: #ffe166;
    --yellow-soft: #fff6c8;
    --teal: #1ca68b;
    --teal-soft: #d8fff6;
    --shadow: 0 18px 48px rgba(27, 29, 20, 0.12);
    --mono: "JetBrains Mono", "Courier New", monospace;
    --sans: "Space Grotesk", "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(40, 84, 255, 0.08) 1px, transparent 1px) 0 0 / 44px 44px,
        linear-gradient(rgba(255, 104, 71, 0.08) 1px, transparent 1px) 0 0 / 44px 44px,
        linear-gradient(135deg, #fbfbf5 0%, #f4f8ef 46%, #f8f3e9 100%);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    font-family: var(--sans);
    color: var(--ink);
}

button,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

svg {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
}

svg path {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.app-shell {
    width: min(1720px, calc(100% - 28px));
    margin: 0 auto;
    padding: 18px 0 28px;
}

.topbar {
    position: sticky;
    top: 12px;
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(210px, 1fr) auto minmax(260px, 1fr);
    align-items: center;
    gap: 16px;
    min-height: 72px;
    padding: 12px;
    border: 1px solid rgba(25, 26, 22, 0.14);
    border-radius: 8px;
    background: rgba(251, 251, 245, 0.9);
    box-shadow: 0 10px 30px rgba(25, 26, 22, 0.08);
    backdrop-filter: blur(16px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: var(--ink);
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border: 2px solid var(--ink);
    border-radius: 7px;
    background: var(--green);
    box-shadow: 5px 5px 0 var(--ink);
    font-weight: 700;
}

.brand-name,
.brand-subtitle {
    display: block;
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 700;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.25;
}

.mode-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-width: 280px;
    padding: 4px;
    border: 1px solid var(--ink);
    border-radius: 8px;
    background: #ecefe4;
}

.mode-tab {
    position: relative;
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    font-weight: 700;
}

.mode-tab.active {
    color: #fff;
    background: var(--ink);
}

.mode-tab.locked:not(.active) {
    color: var(--muted);
}

.lock-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 6px;
    border-radius: 999px;
    background: var(--coral);
    vertical-align: middle;
}

.mode-tab.unlocked .lock-dot {
    background: var(--green);
}

.top-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.icon-button,
.primary-action,
.secondary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1.5px solid var(--ink);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.icon-button:hover,
.primary-action:hover,
.secondary-action:hover {
    transform: translateY(-1px);
    box-shadow: 4px 4px 0 rgba(25, 26, 22, 0.2);
}

.icon-button {
    width: 44px;
    padding: 0;
}

.file-button {
    position: relative;
}

.file-button input {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
}

.primary-action,
.secondary-action {
    gap: 8px;
    padding: 0 16px;
    font-weight: 700;
}

.primary-action {
    background: var(--blue);
    color: #fff;
}

.primary-action svg path {
    fill: currentColor;
    stroke: currentColor;
}

.secondary-action {
    background: var(--yellow);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(310px, 0.62fr);
    gap: 16px;
    margin-top: 16px;
}

.panel {
    border: 1px solid rgba(25, 26, 22, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.code-panel {
    grid-row: span 2;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 126px);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.panel-header.tight {
    padding-bottom: 12px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--blue);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1,
h2 {
    margin-bottom: 0;
    line-height: 1.05;
}

h1 {
    max-width: 680px;
    font-size: clamp(1.7rem, 3vw, 3.6rem);
}

h2 {
    font-size: 1.06rem;
}

.meter {
    display: grid;
    min-width: 132px;
    gap: 7px;
    justify-items: end;
    color: var(--muted);
    font-weight: 700;
}

.meter-track {
    display: block;
    width: 132px;
    height: 12px;
    overflow: hidden;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: #f0f1e8;
}

#progressBar {
    display: block;
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--coral), var(--yellow), var(--green));
    transition: width 220ms ease;
}

#codeInput {
    width: calc(100% - 36px);
    min-height: 210px;
    margin: 18px;
    padding: 16px;
    resize: vertical;
    border: 1px solid var(--strong-line);
    border-radius: 8px;
    outline: none;
    background: #151710;
    color: #f6ffe7;
    font-family: var(--mono);
    font-size: 0.91rem;
    line-height: 1.65;
    tab-size: 4;
}

#codeInput:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px rgba(40, 84, 255, 0.16);
}

.reader-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
    gap: 14px;
    min-height: 0;
    padding: 0 18px 18px;
}

.line-list {
    min-height: 380px;
    max-height: 52vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background:
        linear-gradient(90deg, rgba(186, 242, 59, 0.16) 0 10px, transparent 10px 100%),
        #fff;
}

.empty-state {
    display: grid;
    min-height: 260px;
    place-items: center;
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

.line-row {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    align-items: stretch;
    width: 100%;
    border: 0;
    border-bottom: 1px solid #eff0e7;
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.line-row:hover {
    background: var(--yellow-soft);
}

.line-row.active {
    background: var(--blue-soft);
}

.line-row.read .line-number::after {
    content: "";
    position: absolute;
    right: 7px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--green-strong);
    transform: translateY(-50%);
}

.line-number {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 11px 18px 11px 8px;
    color: #787a70;
    border-right: 1px solid #e4e6d8;
    font-family: var(--mono);
    font-size: 0.78rem;
    user-select: none;
}

.line-code {
    display: block;
    min-width: 0;
    padding: 10px 12px;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    font-family: var(--mono);
    font-size: 0.86rem;
    line-height: 1.55;
}

.line-badge {
    display: inline-flex;
    align-items: center;
    min-width: 78px;
    min-height: 22px;
    margin-right: 10px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #ebeee0;
    color: #51544a;
    font-family: var(--sans);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    vertical-align: text-bottom;
}

.type-definition .line-badge,
.type-class .line-badge {
    background: var(--blue-soft);
    color: var(--blue);
}

.type-branch .line-badge,
.type-loop .line-badge {
    background: var(--yellow-soft);
    color: #735f00;
}

.type-return .line-badge,
.type-effect .line-badge {
    background: var(--coral-soft);
    color: #a83017;
}

.type-assignment .line-badge {
    background: var(--teal-soft);
    color: #087560;
}

.focus-card {
    display: flex;
    flex-direction: column;
    min-height: 380px;
    padding: 16px;
    border: 1px solid var(--ink);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(255, 225, 102, 0.32), transparent 34%),
        linear-gradient(315deg, rgba(186, 242, 59, 0.26), transparent 28%),
        #fffef8;
}

.focus-kicker {
    width: fit-content;
    margin-bottom: 16px;
    padding: 4px 8px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--green);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}

.focus-card h2 {
    margin-bottom: 12px;
    font-size: 1.3rem;
    line-height: 1.15;
}

.focus-card p {
    color: #34362f;
    line-height: 1.55;
}

.trace-box {
    margin-top: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.74);
}

.trace-box span {
    display: block;
    margin-bottom: 5px;
    color: var(--blue);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.trace-box p {
    margin-bottom: 0;
    font-family: var(--mono);
    font-size: 0.78rem;
}

.focus-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
}

.focus-actions .secondary-action {
    flex: 1;
}

.side-rail,
.coach-panel {
    min-width: 0;
}

.side-rail {
    display: grid;
    gap: 16px;
}

.compact-panel {
    overflow: hidden;
}

.step-list,
.compartment-list,
.check-list,
.critique-grid {
    display: grid;
    gap: 10px;
    padding: 14px;
}

.step-card,
.compartment-card,
.check-card,
.critique-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.step-card {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
}

.step-index {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    font-weight: 700;
}

.step-card h3,
.compartment-card h3,
.check-card h3,
.critique-card h3 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    line-height: 1.2;
}

.step-card p,
.compartment-card p,
.check-card p,
.critique-card p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.line-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 9px;
}

.line-chip {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 7px;
    background: #f6f7ee;
    color: #4c5045;
    font-family: var(--mono);
    font-size: 0.72rem;
}

.compartment-card {
    padding: 12px;
}

.local-coach {
    display: grid;
    gap: 10px;
    padding: 14px;
}

.coach-model {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    white-space: nowrap;
    padding: 0 9px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--blue-soft);
    color: var(--blue);
    font-size: 0.75rem;
    font-weight: 700;
}

.coach-status {
    min-height: 34px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f6f7ee;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.coach-status.ready {
    border-color: var(--green-strong);
    background: var(--teal-soft);
    color: #075f50;
}

.coach-status.error {
    border-color: var(--coral);
    background: var(--coral-soft);
    color: #8b260d;
}

.coach-transcript {
    min-height: 118px;
    max-height: 260px;
    overflow: auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #151710;
    color: #f6ffe7;
    font-family: var(--mono);
    font-size: 0.78rem;
    line-height: 1.55;
    white-space: pre-wrap;
}

#coachQuestion {
    width: 100%;
    min-height: 84px;
    resize: vertical;
    padding: 10px;
    border: 1px solid var(--strong-line);
    border-radius: 8px;
    outline: none;
    background: #fff;
    color: var(--ink);
    line-height: 1.4;
}

#coachQuestion:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px rgba(40, 84, 255, 0.16);
}

.coach-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.coach-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
    box-shadow: none;
}

.compartment-card strong {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    margin-bottom: 8px;
    padding: 2px 7px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--green);
    font-size: 0.72rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    white-space: nowrap;
    padding: 0 10px;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--coral-soft);
    color: #8b260d;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-pill.ready {
    background: var(--green);
    color: var(--ink);
}

.check-card {
    padding: 12px;
}

.answer-grid {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.answer-button {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfbf5;
    cursor: pointer;
    text-align: left;
    line-height: 1.3;
}

.answer-button:hover {
    border-color: var(--ink);
}

.answer-button.correct {
    border-color: var(--green-strong);
    background: var(--teal-soft);
}

.answer-button.incorrect {
    border-color: var(--coral);
    background: var(--coral-soft);
}

.check-result {
    margin-top: 10px;
    font-size: 0.85rem;
    font-weight: 700;
}

.critique-card {
    position: relative;
    overflow: hidden;
    padding: 14px;
}

.critique-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 6px;
    background: var(--blue);
}

.critique-card.high::before {
    background: var(--coral);
}

.critique-card.medium::before {
    background: var(--yellow);
}

.critique-card.low::before {
    background: var(--teal);
}

.critique-card h3,
.critique-card p,
.critique-card .line-chips {
    margin-left: 8px;
}

.hidden {
    display: none;
}

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

    .mode-switch {
        width: 100%;
        min-width: 0;
    }

    .top-actions {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

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

    .code-panel {
        min-height: auto;
    }
}

@media (max-width: 780px) {
    .app-shell {
        width: min(100% - 18px, 1720px);
        padding-top: 9px;
    }

    .topbar {
        top: 8px;
        gap: 12px;
    }

    .brand {
        align-items: flex-start;
    }

    .brand-mark {
        width: 40px;
        height: 40px;
        box-shadow: 4px 4px 0 var(--ink);
    }

    .mode-tab,
    .icon-button,
    .primary-action,
    .secondary-action {
        min-height: 44px;
    }

    .primary-action {
        flex: 1 1 150px;
    }

    .panel-header {
        flex-direction: column;
        padding: 14px;
    }

    h1 {
        font-size: 2rem;
    }

    .meter {
        width: 100%;
        justify-items: stretch;
    }

    .meter-track {
        width: 100%;
    }

    #codeInput {
        width: calc(100% - 28px);
        min-height: 260px;
        margin: 14px;
        font-size: 0.86rem;
    }

    .reader-split {
        grid-template-columns: 1fr;
        padding: 0 14px 14px;
    }

    .line-list {
        max-height: 46vh;
    }

    .line-row {
        grid-template-columns: 44px minmax(0, 1fr);
    }

    .line-number {
        padding-right: 14px;
    }

    .line-badge {
        min-width: 0;
        margin-bottom: 4px;
    }

    .focus-card {
        min-height: 300px;
    }
}
