/* ==========================================================================
   CodeClass - reset, typography, form primitives
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior-y: none;
}

/* Paper tooth. Cheap, static, and it stops large flat fills reading as plastic. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: var(--grain-opacity);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd {
    margin: 0;
}

h1, h2, h3, h4 {
    line-height: var(--leading-tight);
    font-weight: 600;
    letter-spacing: -0.011em;
}

.display {
    font-family: var(--font-display);
    /* The serif carried weight through stroke contrast; a sans has to be told. */
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

ul, ol {
    margin: 0;
    padding: 0;
}

li {
    list-style: none;
}

img, svg, canvas, video {
    display: block;
    max-width: 100%;
}

a {
    color: var(--brand);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--brand-ink);
}

/* Anchors that are dressed as controls are controls, not links. */
a.btn,
a.nav-item,
a.queue-item,
a.chip,
a.menu-item,
a.tab,
a.card,
a.brand {
    text-decoration: none;
    color: inherit;
}

a.btn.btn-primary {
    color: var(--on-brand);
}

code, kbd, pre, samp {
    font-family: var(--font-mono);
    font-size: 0.92em;
    font-variant-ligatures: none;
}

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: var(--s5) 0;
}

:focus {
    outline: none;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--r-sm);
}

::selection {
    background: color-mix(in srgb, var(--brand) 26%, transparent);
}

/* ---- scrollbars -------------------------------------------------------- */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

*::-webkit-scrollbar {
    width: 11px;
    height: 11px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--line-2);
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: var(--r-pill);
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--line-strong);
    background-clip: content-box;
}

/* ==========================================================================
   Form primitives
   ========================================================================== */

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

.field {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    min-width: 0;
}

.field-row {
    display: grid;
    gap: var(--s4);
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.label {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.label .req {
    color: var(--bad);
    margin-left: 2px;
}

.hint {
    font-size: var(--text-xs);
    color: var(--ink-3);
    line-height: var(--leading-snug);
}

.err-text {
    font-size: var(--text-xs);
    color: var(--bad);
    line-height: var(--leading-snug);
    display: flex;
    gap: var(--s1);
    align-items: flex-start;
}

.input,
.select,
.textarea {
    width: 100%;
    min-width: 0;
    padding: 0 var(--s3);
    height: 36px;
    background: var(--surface);
    /* Not --line-2: a field on a white card has no fill to distinguish it, so
       the outline is the only thing saying "you can type here". */
    border: 1px solid var(--line-control);
    border-radius: var(--r);
    color: var(--ink);
    font-size: var(--text-sm);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease),
        background-color var(--dur-fast) var(--ease);
}

.textarea {
    height: auto;
    min-height: 84px;
    padding: var(--s2) var(--s3);
    line-height: var(--leading-snug);
    resize: vertical;
}

.input:hover:not(:disabled),
.select:hover:not(:disabled),
.textarea:hover:not(:disabled) {
    border-color: var(--line-strong);
}

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

.input:disabled,
.select:disabled,
.textarea:disabled {
    background: var(--surface-3);
    color: var(--ink-4);
    cursor: not-allowed;
}

.input::placeholder,
.textarea::placeholder {
    color: var(--ink-4);
}

.input[aria-invalid='true'],
.textarea[aria-invalid='true'],
.select[aria-invalid='true'] {
    border-color: var(--bad);
}

.input[aria-invalid='true']:focus,
.textarea[aria-invalid='true']:focus {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 18%, transparent);
}

.input-mono {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
}

.select {
    appearance: none;
    padding-right: var(--s8);
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
        linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    cursor: pointer;
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group > .input {
    border-radius: var(--r) 0 0 var(--r);
}

.input-group > .btn {
    border-radius: 0 var(--r) var(--r) 0;
    margin-left: -1px;
}

.input-affix {
    display: flex;
    align-items: center;
    padding: 0 var(--s3);
    background: var(--surface-3);
    border: 1px solid var(--line-2);
    border-left: 0;
    border-radius: 0 var(--r) var(--r) 0;
    font-size: var(--text-xs);
    color: var(--ink-3);
    white-space: nowrap;
}

/* ---- check / radio / switch -------------------------------------------- */
.check {
    display: flex;
    align-items: flex-start;
    gap: var(--s2);
    cursor: pointer;
    font-size: var(--text-sm);
    line-height: 1.35;
    user-select: none;
}

.check input[type='checkbox'],
.check input[type='radio'] {
    appearance: none;
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    margin: 1px 0 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    cursor: pointer;
    display: grid;
    place-content: center;
    transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.check input[type='radio'] {
    border-radius: 50%;
}

.check input[type='checkbox']::after {
    content: '';
    width: 9px;
    height: 5px;
    border: 2px solid var(--on-brand);
    border-top: 0;
    border-right: 0;
    transform: rotate(-45deg) translate(0px, -1px) scale(0);
    transition: transform var(--dur-fast) var(--ease);
}

.check input[type='radio']::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--on-brand);
    transform: scale(0);
    transition: transform var(--dur-fast) var(--ease);
}

.check input:checked {
    background: var(--brand);
    border-color: var(--brand);
}

.check input:checked::after {
    transform: rotate(-45deg) translate(0px, -1px) scale(1);
}

.check input[type='radio']:checked::after {
    transform: scale(1);
}

.check input:indeterminate {
    background: var(--brand);
    border-color: var(--brand);
}

.check input:indeterminate::after {
    content: '';
    width: 9px;
    height: 2px;
    border: 0;
    background: var(--on-brand);
    transform: none;
}

.check input:disabled {
    background: var(--surface-3);
    border-color: var(--line-2);
    cursor: not-allowed;
}

.check:has(input:disabled) {
    color: var(--ink-4);
    cursor: not-allowed;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: var(--s3);
    cursor: pointer;
    font-size: var(--text-sm);
    user-select: none;
}

.switch input {
    appearance: none;
    position: relative;
    width: 34px;
    height: 20px;
    flex: 0 0 auto;
    margin: 0;
    border-radius: var(--r-pill);
    background: var(--line-strong);
    cursor: pointer;
    transition: background-color var(--dur) var(--ease);
}

.switch input::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform var(--dur) var(--ease);
}

.switch input:checked {
    background: var(--brand);
}

.switch input:checked::after {
    transform: translateX(14px);
}

.switch input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================================================
   Utilities - a deliberately short list
   ========================================================================== */
.row { display: flex; align-items: center; gap: var(--s2); }
.row-wrap { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--s3); }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }
.center { display: grid; place-items: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--ink-3); }
.dim { color: var(--ink-4); }
.small { font-size: var(--text-xs); }
.tiny { font-size: var(--text-2xs); }
.strong { font-weight: 600; }
.right { text-align: right; }
.hidden { display: none !important; }
.gap-1 { gap: var(--s1); }
.gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); }
.mt-2 { margin-top: var(--s2); }
.mt-4 { margin-top: var(--s4); }
.mt-6 { margin-top: var(--s6); }

.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;
}

.skip-link {
    position: absolute;
    left: var(--s4);
    top: -60px;
    z-index: var(--z-popover);
    padding: var(--s2) var(--s4);
    background: var(--brand);
    color: var(--on-brand);
    border-radius: var(--r);
    transition: top var(--dur) var(--ease);
}

.skip-link:focus {
    top: var(--s3);
}
