/* The typefaces come from the build (mk/fonts.mk puts them in fonts/).
   Without them the page falls back to the system's faces. */
@font-face {
    font-family: "Oswald";
    font-weight: 200 700;
    font-display: swap;
    src: url("fonts/oswald-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
        U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
        U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Oswald";
    font-weight: 200 700;
    font-display: swap;
    src: url("fonts/oswald-cyrillic.woff2") format("woff2");
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: "Manrope";
    font-weight: 200 800;
    font-display: swap;
    src: url("fonts/manrope-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
        U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
        U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "Manrope";
    font-weight: 200 800;
    font-display: swap;
    src: url("fonts/manrope-cyrillic.woff2") format("woff2");
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
    font-family: "JetBrains Mono";
    font-weight: 100 800;
    font-display: swap;
    src: url("fonts/jetbrains-mono-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
        U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
        U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: "JetBrains Mono";
    font-weight: 100 800;
    font-display: swap;
    src: url("fonts/jetbrains-mono-cyrillic.woff2") format("woff2");
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* The Kerasi look (kerasi.css holds its tokens): paper grounds, hairlines,
   uppercase Oswald for headings and buttons, mono for labels and numbers,
   one accent per theme. Corners are square; only filled elements get the
   chamfer. */
:root {
    /* Kerasi's status colours are too dark to read on its dark grounds */
    --success: var(--status-success);
    --danger: var(--status-danger);

    --fs-head: 20px;
    --fs-body: 15px;
    --fs-small: 13px;
    --fs-label: 12px;

    /* The column: 1200 = (1fr) 816 + 24 gap + 360 settings */
    --column: 1200px;
    --gutter: clamp(16px, 4vw, 32px);
    --gap: 24px;
    --pad: 24px;
    --settings: 360px;
    --row: 60px;
    --control-height: 36px;
    --cell: 8px;
    /* Kerasi's least touch target on phones */
    --touch: 44px;
}

[data-theme$="-dark"] {
    --success: color-mix(in srgb, var(--status-success) 55%, var(--fg-1));
    --danger: color-mix(in srgb, var(--status-danger) 55%, var(--fg-1));
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg-1);
    font: var(--fs-body) / 1.6 var(--font-body);
    -webkit-font-smoothing: antialiased;
}

h2 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

p {
    margin: 0;
}

a {
    color: var(--accent-ink);
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
}

a:hover {
    color: var(--fg-1);
}

::selection {
    background: var(--accent-soft);
    color: var(--fg-1);
}

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    transition: background var(--dur-1) var(--ease-out),
        color var(--dur-1) var(--ease-out),
        border-color var(--dur-1) var(--ease-out);
}

button:disabled {
    cursor: default;
}

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

/* --- top bar --------------------------------------------------------- */

.bar {
    border-bottom: 1px solid var(--line);
}

.bar-inner,
main {
    max-width: calc(var(--column) + 2 * var(--gutter));
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 22px;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.mark {
    width: 24px;
    height: 28px;
}

.mark-top {
    fill: var(--line-strong);
}

.mark-left {
    fill: var(--accent);
}

.mark-right {
    fill: var(--fg-1);
}

.mark-lines {
    fill: var(--accent-soft);
}

.bar-controls {
    display: flex;
    gap: 12px;
}

.picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    color: var(--fg-2);
    font: 500 var(--fs-label) / 1 var(--font-mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    transition: border-color var(--dur-1) var(--ease-out),
        color var(--dur-1) var(--ease-out);
}

.picker:hover {
    border-color: var(--fg-1);
    color: var(--fg-1);
}

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

.picker svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

/* invisible, but it is what is clicked and what reads the choice aloud */
.picker select {
    position: absolute;
    inset: 0;
    width: 100%;
    opacity: 0;
    cursor: pointer;
}

/* The accent of the theme on its ground */
.swatch {
    --chamfer: 4px;
    width: 14px;
    height: 14px;
    background: var(--accent);
    clip-path: var(--clip-chamfer);
}

/* --- title ----------------------------------------------------------- */

.title {
    padding: 40px 0 32px;
}

.lede {
    max-width: 62ch;
    color: var(--fg-2);
    font-size: 18px;
}

.lede + .lede {
    margin-top: 12px;
}

/* --- the two panels -------------------------------------------------- */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--settings);
    gap: var(--gap);
}

.panel {
    background: var(--bg-raised);
    border: 1px solid var(--line);
    padding: var(--pad);
}

.panel h2 {
    font-size: var(--fs-head);
    line-height: 1.2;
}

.text-button {
    padding: 4px 0;
    white-space: nowrap;
    border: none;
    background: none;
    color: var(--accent-ink);
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.text-button:hover {
    color: var(--fg-1);
}

.text-button:disabled {
    color: var(--fg-3);
}

/* --- files ----------------------------------------------------------- */

.files {
    display: flex;
    flex-direction: column;
    container-type: inline-size;
}

.panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    padding-bottom: 16px;
}

.count,
.version {
    color: var(--fg-3);
    font: var(--fs-label) var(--font-mono);
    letter-spacing: 0.04em;
}

.panel-head .text-button {
    margin-left: auto;
    font-size: var(--fs-small);
}

.files:not(.has-files) .panel-head .text-button {
    display: none;
}

.tasks {
    list-style: none;
    margin: 0;
    padding: 0;
    user-select: none;
}

.tasks li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 248px 104px 64px;
    align-items: center;
    gap: 16px;
    min-height: var(--row);
    margin: 0 -8px;
    padding: 8px;
    border-top: 1px solid var(--line);
    cursor: default;
}

.tasks li.selected {
    background: var(--bg-sunken);
}

.task-name {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.task-name span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.sub {
    color: var(--fg-3);
    font-size: var(--fs-small);
}

.task-pages {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    font: var(--fs-label) var(--font-mono);
}

.cells {
    display: flex;
    gap: 2px;
}

.cells i {
    width: var(--cell);
    height: var(--cell);
    background: var(--bg-sunken);
    outline: 1px solid var(--line-strong);
    outline-offset: -1px;
}

.cells i.read {
    background: var(--accent);
    outline: none;
}

.task-pages .none,
.waiting .task-state,
.cancelled .task-state {
    color: var(--fg-3);
}

.task-state {
    font: var(--fs-label) var(--font-mono);
}

/* Kerasi's badge: mono capitals in a hairline box */
.pill {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border: 1px solid currentColor;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.done .pill {
    color: var(--success);
}

.failed .pill {
    color: var(--danger);
}

.task-action {
    text-align: right;
    font-size: var(--fs-small);
}

.drop {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-height: 320px;
    padding: 24px;
    border: 1px dashed var(--line-strong);
    background: var(--bg-sunken);
    text-align: center;
}

.drop:hover {
    border-color: var(--accent);
}

.drop-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 26px;
    line-height: 1.1;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.drop-more {
    max-width: 36ch;
    color: var(--fg-2);
}

/* Touch screens cannot drag files onto the page */
.touch {
    display: none;
}

@media (pointer: coarse) {
    .pointer {
        display: none;
    }

    .touch {
        display: revert;
    }
}

.drop-again,
.has-files .drop-title,
.has-files .drop-more {
    display: none;
}

.has-files .drop {
    min-height: 52px;
    margin-top: 12px;
}

.has-files .drop-again {
    display: inline;
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.panel-foot {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 16px;
}

.status {
    white-space: pre-line;
    font-size: 14px;
}

.status:empty {
    display: none;
}

progress {
    appearance: none;
    width: 100%;
    height: 4px;
    border: none;
    background: var(--bg-sunken);
    color: var(--accent);
}

progress::-webkit-progress-bar {
    background: var(--bg-sunken);
}

progress::-webkit-progress-value {
    background: var(--accent);
}

progress::-moz-progress-bar {
    background: var(--accent);
}

.files:not(.has-files) progress {
    display: none;
}

/* --- settings -------------------------------------------------------- */

.settings {
    display: flex;
    flex-direction: column;
    gap: 28px;
    align-self: start;
    position: sticky;
    top: 24px;
}

.group h2 {
    padding-bottom: 8px;
}

.choice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    cursor: pointer;
}

.choice:has(input:disabled) {
    color: var(--fg-3);
    cursor: default;
}

.note {
    padding-top: 10px;
    border-top: 1px solid var(--line);
    color: var(--fg-3);
    font-size: var(--fs-small);
}

input[type="checkbox"] {
    appearance: none;
    display: grid;
    place-content: center;
    flex: none;
    width: 18px;
    height: 18px;
    margin: 3px 0 0;
    border: 1px solid var(--line-strong);
    background: var(--bg-raised);
    cursor: inherit;
    transition: background var(--dur-1) var(--ease-out);
}

/* The tick, drawn in the theme's colour on the accent */
input[type="checkbox"]::before {
    content: "";
    width: 12px;
    height: 12px;
    background: var(--accent-fg);
    clip-path: polygon(10% 52%, 0 64%, 38% 98%, 100% 18%, 88% 6%,
        37% 74%);
    visibility: hidden;
}

input[type="checkbox"]:hover:enabled {
    border-color: var(--fg-1);
}

input[type="checkbox"]:checked {
    border-color: var(--accent);
    background: var(--accent);
}

input[type="checkbox"]:checked::before {
    visibility: visible;
}

input[type="checkbox"]:disabled {
    opacity: 0.5;
}

/* Kerasi's primary button: an accent block with a cut corner */
.start {
    height: 54px;
    border: none;
    background: var(--accent);
    color: var(--accent-fg);
    clip-path: var(--clip-chamfer);
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 18px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.start:hover {
    background: var(--accent-hover);
}

.start.running {
    border: 1px solid var(--danger);
    background: transparent;
    color: var(--danger);
    clip-path: none;
}

.start.running:hover {
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

/* While an update downloads (app.js) */
.start:disabled,
.update:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* --- footer ---------------------------------------------------------- */

.foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0 40px;
    font-size: var(--fs-small);
}

.release {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Shown next to the version when a newer release is out (update.js) */
.update {
    --chamfer: 6px;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    background: var(--accent);
    color: var(--accent-fg);
    clip-path: var(--clip-chamfer);
}

.update:hover {
    background: var(--accent-hover);
}

.update[hidden] {
    display: none;
}

.update svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: square;
}

/* --- dialogs --------------------------------------------------------- */

dialog {
    --chamfer: var(--chamfer-lg);
    max-width: min(560px, calc(100vw - 32px));
    padding: 28px;
    border: none;
    background: var(--bg-raised);
    color: var(--fg-1);
    clip-path: var(--clip-chamfer);
}

dialog::backdrop {
    background: color-mix(in srgb, var(--fg-1) 35%, transparent);
    backdrop-filter: blur(6px);
}

dialog.wide {
    width: 900px;
    max-width: min(900px, calc(100vw - 32px));
}

dialog h3 {
    margin: 0 0 16px;
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 500;
    line-height: 1.05;
    text-transform: uppercase;
}

.dialog-body {
    white-space: pre-line;
    color: var(--fg-2);
}

/* Plain messages keep their line breaks; the About text is HTML */
.dialog-body:has(> p) {
    white-space: normal;
}

.dialog-body p {
    margin: 0 0 10px;
}

.dialog-body b {
    color: var(--fg-1);
}

dialog details {
    margin-top: 12px;
}

dialog summary {
    cursor: pointer;
    font: var(--fs-label) var(--font-mono);
    letter-spacing: var(--tracking-overline);
    text-transform: uppercase;
    color: var(--fg-3);
}

dialog pre {
    max-height: 60vh;
    overflow: auto;
    background: var(--bg-sunken);
    padding: 12px;
    font: 12px / 1.5 var(--font-mono);
    white-space: pre-wrap;
}

.dialog-buttons {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}

/* Kerasi's secondary button: an ink outline that fills on hover */
.dialog-buttons button {
    height: 42px;
    padding: 0 20px;
    border: 1px solid var(--fg-1);
    background: transparent;
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.dialog-buttons button:hover {
    background: var(--fg-1);
    color: var(--bg);
}

/* --- narrow windows -------------------------------------------------- */

/* A narrow list puts the file name on a line of its own, so the name is
   never the column that gets cut */
@container (max-width: 680px) {
    .tasks li {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "name action" "pages state";
        gap: 6px 16px;
        --cell: 7px;
    }

    .task-name {
        grid-area: name;
    }

    .task-pages {
        grid-area: pages;
    }

    .task-state {
        grid-area: state;
        text-align: right;
    }

    .task-action {
        grid-area: action;
        align-self: start;
    }

    .unit {
        display: none;
    }
}

/* Kerasi's tablets and phones: the settings drop below the files */
@media (max-width: 1023px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .settings {
        position: static;
    }
}

@media (max-width: 639px) {
    :root {
        --pad: 16px;
        --control-height: var(--touch);
    }

    .theme-name {
        display: none;
    }

    .bar-controls {
        gap: 8px;
    }

    .picker {
        padding: 0 11px;
    }

    .locale svg {
        display: none;
    }

    .title {
        padding: 24px 0 20px;
    }

    .lede {
        font-size: 16px;
    }

    .drop {
        min-height: 200px;
    }

    .text-button {
        min-height: var(--touch);
    }

    /* Kerasi's bottom sheet, its main button on top */
    dialog,
    dialog.wide {
        width: 100%;
        max-width: 100%;
        max-height: 88vh;
        margin: auto 0 0;
        overflow-y: auto;
        padding: 24px 16px calc(16px + env(safe-area-inset-bottom));
    }

    .dialog-buttons {
        flex-direction: column-reverse;
    }

    .dialog-buttons button {
        height: var(--touch);
    }
}
