:root {
    color-scheme: dark;
    --bg: #0d1117;
    --panel: #161b22;
    --line: #30363d;
    --text: #e6edf3;
    --muted: #9198a1;
    --faint: #6e7681;
    --accent: #4493f8;
    --run: #238636;
    --run-hover: #2ea043;
    --err: #ff7b72;
    --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 var(--ui);
}

button, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

/* Top bar */

.bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.bar h1 {
    margin: 0 auto 0 0;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
}

select {
    appearance: none;
    padding: 6px 30px 6px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%239198a1' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center / 12px;
    cursor: pointer;
}

.run {
    padding: 6px 18px;
    border: 0;
    border-radius: 6px;
    background: var(--run);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.run:hover { background: var(--run-hover); }
.run:disabled { opacity: 0.6; cursor: progress; }

.subtle {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: none;
    color: var(--muted);
    cursor: pointer;
}

.subtle:hover { color: var(--text); }
.clear { padding: 2px 10px; font-size: 12px; }
.logout { padding: 6px 10px; }
.bar form { margin: 0; }

/* A phone has no room for the title next to the controls; the tab shows it anyway. */
@media (max-width: 440px) {
    .bar h1 { display: none; }
    .bar select { margin-right: auto; }
}

/* Panes: side by side when there is room, stacked otherwise */

.panes {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
}

.pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.pane + .pane { border-left: 1px solid var(--line); }

.pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 36px;
    padding: 0 16px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 800px) {
    .panes { grid-template-columns: 1fr; grid-template-rows: 3fr 2fr; }
    .pane + .pane { border-left: 0; border-top: 1px solid var(--line); }
}

/* Editor: a transparent textarea over a highlighted <pre> with the same text.
   Both sit in one scroll container, so they can never drift apart. */

.editor {
    flex: 1;
    display: flex;
    align-items: flex-start;
    overflow: auto;
    font: 14px/22px var(--mono);
    tab-size: 4;
    font-variant-ligatures: none;
    scrollbar-color: var(--line) transparent;
}

/* iOS zooms into any input under 16px when it gets focus. */
@media (pointer: coarse) {
    .editor { font-size: 16px; line-height: 24px; }
}

.gutter {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 3.5em;
    padding: 12px 12px 12px 8px;
    background: var(--bg);
    color: var(--faint);
    text-align: right;
    white-space: pre;
    user-select: none;
}

.code {
    position: relative;
    flex: 1 0 auto;
    min-height: 100%;
}

.highlight, .code textarea {
    margin: 0;
    padding: 12px 16px 12px 4px;
    border: 0;
    font: inherit;
    letter-spacing: normal;
    white-space: pre;
}

.highlight { pointer-events: none; }

.code textarea {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    resize: none;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: var(--text);
}

.code textarea::selection { background: rgba(68, 147, 248, 0.35); }

.t-keyword { color: #ff7b72; }
.t-string { color: #a5d6ff; }
.t-number { color: #79c0ff; }
.t-comment { color: var(--muted); font-style: italic; }
.t-function { color: #d2a8ff; }
.t-type { color: #ffa657; }

/* Output */

.output {
    flex: 1;
    overflow: auto;
    padding: 12px 16px;
    font: 13px/20px var(--mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    scrollbar-color: var(--line) transparent;
}

.output:empty::before {
    content: attr(data-hint);
    color: var(--faint);
    font-family: var(--ui);
}

.stderr { color: var(--err); }
.note { color: var(--muted); }

.meta {
    margin-top: 4px;
    color: var(--muted);
    font: 12px/20px var(--ui);
}

.meta.fail { color: var(--err); }

/* Login page */

.login-page {
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
    max-width: 340px;
    padding: 28px 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.login h1 { margin: 0; font-size: 18px; }
.login p { margin: 0; }

.login label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.login input {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font: 16px var(--ui); /* under 16px, iOS zooms in on focus */
}

.login .run { margin-top: 4px; padding: 9px; }

.login-error { color: var(--err); font-size: 13px; }
