/*
 * A challenge's workspace (challenges/show.php, challenge.js): it fills the window under the navbar, with no footer and
 * nothing to scroll. A top bar with Run and Submit in its middle; the problem on the left; on the right the editor
 * above the console; the splits between them come from --ws-h and --ws-v (fractions, set by challenge.js from
 * localStorage "op-ws-split"). Under 860px the panes stack (problem, editor, console), the page scrolls, and Run and
 * Submit sit on the editor's head. On learn-shell.css's tokens; the statement's prose is learn-content.css's.
 */
.ws {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: calc(100dvh - var(--nav-h));
    min-height: 520px;
    padding: 10px 12px 12px;
}

/* The window is the workspace: nothing below it to scroll to (wide screens; stacked, the page scrolls) */
@media (min-width: 861px) {
    body.is-workspace {
        overflow: hidden;
    }
}

/* ---------- The top bar: the list, previous, next, Pick one for me; Run and Submit; the XP ---------- */
.ws-bar {
    position: relative;
    display: grid;
    flex: none;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
}

.ws-bar-start {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.ws-bar-end {
    display: flex;
    justify-content: flex-end;
}

.ws-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ws-bar .ws-actions .btn-sm {
    min-height: 34px;
    padding: 0 16px;
}

.ws-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--ink-2);
}

.ws-icon:hover {
    background: var(--surface);
    color: var(--ink);
}

.ws-xp {
    border-color: transparent;
    background: color-mix(in srgb, var(--hi) 22%, transparent);
    color: var(--ink);
    font-weight: 700;
}

/* The list: a drawer under the bar */
.ws-list {
    position: absolute;
    z-index: 35;
    top: calc(100% + 6px);
    left: 0;
    width: min(380px, calc(100vw - 24px));
    max-height: min(70vh, 560px);
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.ws-list ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ws-list a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    color: var(--ink);
    font-size: 14px;
}

.ws-list a:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.ws-list a[aria-current="page"] {
    background: var(--hi-soft);
    font-weight: 650;
}

.ws-list-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- The panes and the splits ---------- */
.ws-split {
    display: grid;
    flex: 1;
    grid-template-columns: minmax(0, calc(var(--ws-h, .44) * 100% - 5px)) 10px minmax(0, 1fr);
    min-height: 0;
}

.ws-pane,
.ws-editor,
.ws-console {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}

.ws-code {
    display: grid;
    grid-template-rows: minmax(0, calc(var(--ws-v, .58) * 100% - 5px)) 10px minmax(0, 1fr);
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
}

.ws-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.ws-problem .ws-scroll {
    padding: 18px 22px 24px;
}

.ws-console .ws-scroll {
    padding: 12px 16px 16px;
}

/* The handles: a grip always shows where a split can move; hover, focus or a drag lights the whole split. Arrow keys
   move them too, and a double-click puts them back (challenge.js) */
.ws-handle {
    position: relative;
    cursor: col-resize;
    touch-action: none;
}

.ws-code > .ws-handle {
    cursor: row-resize;
}

.ws-handle:focus-visible {
    outline: none;
}

.ws-handle::before,
.ws-handle::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 3px;
    transform: translate(-50%, -50%);
    transition: background-color .15s;
}

/* The line along the split, lit while it's in use */
.ws-handle::before {
    width: 2px;
    height: calc(100% - 12px);
}

.ws-code > .ws-handle::before {
    width: calc(100% - 12px);
    height: 2px;
}

/* The grip */
.ws-handle::after {
    width: 4px;
    height: 40px;
    background: color-mix(in srgb, var(--ink-3) 65%, transparent);
}

.ws-code > .ws-handle::after {
    width: 40px;
    height: 4px;
}

.ws-handle:hover::before,
.ws-handle:hover::after,
.ws-handle:focus-visible::before,
.ws-handle:focus-visible::after,
.ws-handle.is-active::before,
.ws-handle.is-active::after {
    background: var(--brand);
}

body[data-resizing] {
    user-select: none;
}

body[data-resizing="h"] {
    cursor: col-resize;
}

body[data-resizing="v"] {
    cursor: row-resize;
}

/* ---------- Tabs ---------- */
.ws-tabs {
    display: flex;
    flex: none;
    align-items: center;
    gap: 2px;
    min-height: 42px;
    padding: 4px 6px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    background: var(--code-head);
}

.ws-tabs [role="tab"] {
    display: inline-flex;
    flex: none;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 620;
    white-space: nowrap;
}

.ws-tabs [role="tab"]:hover {
    color: var(--ink);
}

.ws-tabs [aria-selected="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(13, 27, 51, .1);
}

.ws-count {
    padding: 0 6px;
    border-radius: 999px;
    background: var(--line);
    color: var(--ink-2);
    font-size: 12px;
}

.ch-status {
    margin-left: auto;
    padding: 0 8px;
    color: var(--ink-3);
    font-size: 13px;
    white-space: nowrap;
}

.ch-status.is-ok {
    color: var(--done);
    font-weight: 650;
}

.ch-status.is-err {
    color: var(--bad);
    font-weight: 650;
}

/* ---------- The problem ---------- */
.ws-problem h1 {
    margin: 0 0 10px;
    font-size: 26px;
    letter-spacing: -.015em;
}

.ws-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0 0 16px;
}

.ws-solved {
    padding: 1px 9px;
    border-radius: 999px;
    background: var(--done-soft);
    color: var(--done);
    font-size: 13px;
    font-weight: 650;
}

/* The learner's own fastest time on it (challenge.js) */
.ws-time {
    padding: 1px 9px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
}

/* A challenge's example (LessonMarkdown::example()): Input, Output and Explanation, labelled, on a tinted panel with
   an accent edge; the values as code, the explanation as prose */
.ch-example {
    display: grid;
    gap: 7px;
    margin: 8px 0 20px;
    padding: 13px 16px;
    border-left: 3px solid color-mix(in srgb, var(--brand) 60%, var(--line));
    border-radius: 0 10px 10px 0;
    background: var(--surface-2);
}

.ch-ex-row {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 2px 12px;
    align-items: baseline;
}

.ch-ex-label {
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
}

.learn-content code.ch-ex-val {
    padding: 0;
    border-radius: 0;
    background: none;
    color: var(--ink);
    font: 14px/1.6 var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ch-ex-row.is-why .ch-ex-val {
    color: var(--ink-2);
    font-size: 14.5px;
    line-height: 1.55;
}

@media (max-width: 480px) {
    .ch-ex-row {
        grid-template-columns: minmax(0, 1fr);
    }
}

.ws-statement {
    font-size: 16px;
    line-height: 1.65;
}

.ws-statement pre {
    font-size: 13.5px;
}

.ws-note {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 14.5px;
}

.ws-note .ic {
    color: var(--ink-3);
}

.ch-hints {
    display: grid;
    gap: 10px;
    margin: 0 0 14px;
    padding-left: 20px;
}

.ch-hints li {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--hi-soft);
    color: var(--ink);
}

.ch-hints .ic,
[data-ch-hint] .ic {
    color: var(--lv2);
}

.ch-solution pre {
    margin: 14px 0 0;
    padding: 12px 14px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--code-bg);
    color: var(--code-ink);
    font: 14px/1.55 var(--mono);
}

/* Coloured by challenge.js (Ace's static highlighter): the box keeps its own background and type */
.ch-solution pre .ace_static_highlight,
.ws-attempt pre .ace_static_highlight {
    background: transparent;
    font: inherit;
}

.ws-stars-note {
    margin: 16px 0 0;
    color: var(--ink-3);
    font-size: 13.5px;
}

.ws-attempts-empty {
    color: var(--ink-3);
}

.ws-attempts {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ws-attempt {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.ws-attempt-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 8px 10px 8px 12px;
    background: var(--surface-2);
    font-size: 13.5px;
}

.ws-attempt-head span {
    color: var(--ink-3);
}

.ws-attempt-head .btn {
    margin-left: auto;
}

.ws-attempt.is-pass b {
    color: var(--done);
}

.ws-attempt.is-fail b {
    color: var(--bad);
}

/* Code from the account (signed in): another device's draft */
.ws-attempt.is-other b {
    color: var(--brand);
}

.ws-attempt pre {
    max-height: 160px;
    margin: 0;
    padding: 10px 12px;
    overflow: auto;
    background: var(--code-bg);
    color: var(--code-ink);
    font: 13px/1.5 var(--mono);
}

/* ---------- The editor ---------- */
.ws-editor-head {
    display: flex;
    flex: none;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 6px 8px 6px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--code-head);
}

.ws-file {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-right: auto;
    color: var(--ink);
    font-size: 14px;
    font-weight: 650;
}

.ws-editor-head .btn-sm {
    min-height: 30px;
    padding: 0 12px;
}

.ws-editor-head .ws-actions {
    gap: 4px;
}

/* Run: outlined, in the go colour; a pass makes its icon pop green */
.ws-run {
    border-color: color-mix(in srgb, var(--go) 55%, var(--line));
    color: var(--go);
}

.ws-run:hover {
    border-color: var(--go);
}

.ws-run.is-pop .ic {
    animation: ws-pop .5s ease-out;
    color: var(--done);
}

@keyframes ws-pop {
    40% { transform: scale(1.45); }
}

.ws-stop {
    border-color: var(--bad);
    color: var(--bad);
}

/* Run and Stop take turns in one place: the same width wherever they sit, so nothing shifts when one replaces the
   other (wider in the desktop bar, whose buttons are) */
.ws-run,
.ws-stop {
    justify-content: center;
    min-width: 80px;
}

.ws-bar .ws-actions .ws-run,
.ws-bar .ws-actions .ws-stop {
    min-width: 90px;
}

.ch-editor {
    flex: 1;
    min-height: 0;
    font-size: 15px;
}

.ch-editor-fallback,
.ch-textarea {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 12px 16px;
    border: 0;
    background: var(--code-bg);
    color: var(--code-ink);
    font: 15px/1.5 var(--mono);
    resize: none;
}

/* ---------- The console: test cases and the result ---------- */
.ws-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.ws-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 620;
}

.ws-pill:hover {
    color: var(--ink);
}

.ws-pill.is-own {
    border-style: dashed;
}

.ws-pill.is-on {
    border-color: var(--brand);
    border-style: solid;
    background: var(--brand-soft);
    color: var(--brand);
}

.ws-pill .ic {
    width: 13px;
    height: 13px;
    stroke-width: 2.2;
}

.ws-pill.is-pass .ic {
    color: var(--done);
}

.ws-pill.is-fail .ic {
    color: var(--bad);
}

.ws-add {
    padding: 0 9px;
}

.ws-field {
    display: grid;
    gap: 4px;
    margin-bottom: 10px;
}

.ws-field > span {
    color: var(--ink-3);
    font: 12.5px var(--mono);
}

.ws-field pre,
.ws-input {
    width: 100%;
    margin: 0;
    padding: 8px 12px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink);
    font: 13.5px/1.5 var(--mono);
    white-space: pre-wrap;
}

.ws-input {
    background: var(--surface);
    resize: vertical;
}

.ws-input:focus {
    border-color: var(--brand);
    outline: none;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

.ws-field.is-wrong pre {
    border-color: color-mix(in srgb, var(--bad) 45%, var(--line));
    background: var(--bad-soft);
}

.ws-field.is-note pre {
    color: var(--ink-2);
    font-family: var(--font);
}

/* What the code printed comes first, so a long print scrolls after 8 lines rather than push the rest down */
.ws-field.is-printed pre {
    max-height: calc(8 * 1.5em + 18px);
    overflow-y: auto;
}

.ws-hint,
.ws-empty {
    margin: 6px 0 10px;
    color: var(--ink-3);
    font-size: 13.5px;
}

.ws-verdict {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 12px;
    margin-bottom: 12px;
}

.ws-verdict b {
    font-size: 21px;
    font-weight: 750;
}

.ws-verdict.is-pass b {
    color: var(--done);
}

.ws-verdict.is-fail b {
    color: var(--bad);
}

.ws-verdict span {
    color: var(--ink-3);
    font-size: 13.5px;
}

.ws-verdict .ws-gain {
    padding: 1px 9px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--hi) 30%, transparent);
    color: var(--ink);
    font-weight: 700;
}

.ws-problem-text {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--bad-soft);
    color: var(--ink);
    font: 13.5px/1.5 var(--mono);
    white-space: pre-wrap;
}

.ws-win {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--done-soft);
}

.ws-win p {
    margin: 0;
}

/* Was this challenge helpful? (challenges/show.php, challenge.js): one quiet line of its own under Next, left aligned */
.ch-vote {
    display: flex;
    flex-basis: 100%;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid color-mix(in srgb, var(--done) 25%, transparent);
    color: var(--ink-2);
    font-size: 13.5px;
    text-align: left;
}

.ch-vote-ask {
    margin-right: 4px;
}

.ch-vote-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink-3);
    cursor: pointer;
}

.ch-vote-btn:hover {
    color: var(--ink);
}

.ch-vote-btn .ic {
    width: 15px;
    height: 15px;
}

.ch-vote-btn.is-down .ic {
    transform: rotate(180deg);
}

.ch-vote-btn[aria-pressed="true"] {
    border-color: var(--brand);
    background: var(--brand-soft);
    color: var(--brand);
}

.ch-vote-thanks {
    margin-left: 4px;
    color: var(--ink-3);
}

.ch-vote-why {
    display: flex;
    flex: 1 1 100%;
    gap: 6px;
    max-width: 440px;
    margin-top: 4px;
}

.ch-vote-why input {
    flex: 1;
    min-width: 0;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.ws-win-stars {
    margin-right: 6px;
    font-size: 20px;
}

/* ---------- Narrower: Problem and Code take turns (challenge.js sets data-view); without it the panes stack ---------- */
.ws-switch {
    display: none;
}

@media (max-width: 860px) {
    .ws-switch {
        display: grid;
        flex: none;
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        padding: 4px;
        border-radius: 12px;
        background: color-mix(in srgb, var(--line) 70%, var(--page));
    }

    .ws-switch [role="tab"] {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        height: 38px;
        border: 0;
        border-radius: 9px;
        background: none;
        color: var(--ink-2);
        font-size: 14.5px;
        font-weight: 650;
    }

    .ws-switch [aria-selected="true"] {
        background: var(--surface);
        color: var(--ink);
        box-shadow: 0 1px 3px rgba(13, 27, 51, .12);
    }

    /* A result came in while the problem showed */
    .ws-switch-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--brand);
    }

    /* The window is the workspace on phones too: each view scrolls inside itself */
    body.is-workspace:has(.ws[data-view]) {
        overflow: hidden;
    }

    .ws[data-view] {
        height: calc(100dvh - var(--nav-h));
    }

    .ws[data-view] .ws-split {
        display: flex;
        flex: 1;
        flex-direction: column;
        min-height: 0;
    }

    .ws[data-view="problem"] .ws-code,
    .ws[data-view="code"] .ws-problem,
    .ws[data-view] .ws-split > .ws-handle {
        display: none;
    }

    .ws[data-view] .ws-problem {
        flex: 1;
    }

    /* Code: the editor above the console, the handle between them still drags */
    .ws[data-view="code"] .ws-code {
        display: grid;
        flex: 1;
        grid-template-rows: minmax(0, calc(var(--ws-v, .58) * 100% - 7px)) 14px minmax(0, 1fr);
        gap: 0;
        min-height: 0;
    }

    .ws[data-view="code"] .ws-code > .ws-handle {
        display: block;
    }

    .ws[data-view] .ch-editor {
        flex: 1;
        height: auto;
    }
    .ws {
        height: auto;
        min-height: 0;
    }

    /* Run and Submit have moved to the editor's head: the bar is the way around, and the XP */
    .ws-bar {
        grid-template-columns: 1fr auto;
    }

    .ws-split,
    .ws-code {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .ws-handle {
        display: none;
    }

    .ws-problem .ws-scroll {
        padding: 16px;
    }

    .ch-editor {
        flex: none;
        height: 340px;
    }

    .ws-console .ws-scroll {
        max-height: none;
    }
}

@media (max-width: 480px) {
    .ws {
        padding: 8px;
    }
}
