/*
 * Page defaults shared by every screen.
 *
 * The reset is deliberately small: only what the design system actually contradicts in the
 * browser defaults. A blanket reset would hide, not solve, the differences.
 */

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

html {
    /* The page itself never scrolls sideways at any phone width (core.md §5.5);
       a wide table scrolls inside its own box instead. */
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: var(--fs-body);
    line-height: var(--lh-text);
    /* A flat colour. No gradients, textures, patterns or background images anywhere. */
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
}

h1 {
    font-size: var(--fs-page);
}

h2 {
    font-size: var(--fs-h2);
}

h3 {
    font-size: var(--fs-section);
}

p {
    margin: 0;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-link-hover);
}

/*
 * The hover underline belongs to links that read as text. Written through :where() so its
 * specificity is zero: a component that styles a link as a control — a tab, a card, a cell —
 * turns it off with a plain `text-decoration: none` of its own, instead of every module
 * re-fighting `a:hover` at higher specificity.
 */
:where(a:hover) {
    text-decoration: underline;
}

ul,
ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

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

/* Every figure is tabular, so digits keep their column from row to row. */
.app-num {
    font-variant-numeric: var(--numeric);
    /* A number is never broken across two lines (core.md §3.4). */
    white-space: nowrap;
}

/* Visible focus is kept: it is the only affordance a keyboard user has. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-glyph);
}

/* Glyphs sit on a 20x20 grid and inherit the current colour. */
.app-icon {
    display: block;
    flex: none;
    width: var(--glyph);
    height: var(--glyph);
}

/* Inside a control with text the glyph equals the type size and drops to the optical
   centre of the lowercase letters. */
.app-icon--inline {
    width: var(--glyph-inline);
    height: var(--glyph-inline);
    transform: translateY(var(--glyph-nudge));
}

.app-icon--head {
    width: var(--glyph-head);
    height: var(--glyph-head);
}

/* Screen-reader only: used where a control is a glyph and its name must still be read. */
.app-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The only two animations in the system: this ring and the toast entry below. The 120ms state
   change of a control is a transition, not an animation. */
@keyframes app-spin {
    to {
        transform: rotate(360deg);
    }
}

/* A toast slides up and fades in; leaving is instant (an exit motion needs a timer for no gain). */
@keyframes app-toast-in {
    from {
        opacity: 0;
        transform: translateY(var(--space-1));
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* Under reduced motion every animation and transition collapses to nothing. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* `hidden` always hides: a component class that sets `display` (.app-btn is inline-flex) would
   otherwise beat the browser's own `[hidden]` rule, so one rule here instead of one per component. */
[hidden] {
    display: none !important;
}

/* An absent value, said with a dash rather than with emptiness: an empty cell reads as a
   forgotten one. */
.app-muted {
    color: var(--text-4);
}

/* An explanation next to a figure or a control: quieter than the text it explains, and never
   wider than a line the eye takes in at once. */
.app-note {
    max-width: var(--w-prose);
    margin: 0;
    color: var(--text-3);
    font-size: var(--fs-caption);
    line-height: var(--lh-text);
}

.app-note + .app-note {
    margin-top: var(--space-2);
}

.app-note code {
    font-size: inherit;
}

/* A body paragraph of a static public page: normal text size, held to the reading width so a line at desktop
   width stays a line the eye takes in (core.md §4.15). */
.app-prose {
    max-width: var(--w-prose);
    margin: 0 0 var(--space-3);
    /* A word with no break (a pasted address, a long description) wraps instead of widening the page. */
    overflow-wrap: anywhere;
}

/* Rendered Markdown inside a prose block (the legal pages, the article editor's preview): a reading rhythm. Blocks
   are spaced, a heading takes more room above than below, and the headings stay under the page title (--fs-h2). */
.app-prose > * + * {
    margin-top: var(--space-3);
}

/* A code fence keeps its lines (no wrap) and scrolls in its own box instead of widening the page (core.md §19.3). */
/* The fence is drawn as a box, so a line that runs past its edge reads as «scrolls here», not as a cut-off page; the
   prose block's break-anywhere would otherwise shrink the box's minimum width to one letter. */
.app-prose pre {
    max-width: 100%;
    padding: var(--space-2) var(--space-3);
    overflow-x: auto;
    overflow-wrap: normal;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--surface-2);
    line-height: var(--lh-text);
}

.app-prose h1,
.app-prose h2,
.app-prose h3,
.app-prose h4 {
    margin-bottom: 0;
    font-family: var(--font-display);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
}

.app-prose > * + h1,
.app-prose > * + h2,
.app-prose > * + h3,
.app-prose > * + h4 {
    margin-top: var(--space-6);
}

.app-prose h1,
.app-prose h2 {
    font-size: var(--fs-section);
}

.app-prose h3,
.app-prose h4 {
    font-size: var(--fs-card);
}

.app-prose h1 + *,
.app-prose h2 + *,
.app-prose h3 + *,
.app-prose h4 + * {
    margin-top: var(--space-1);
}

.app-prose ul,
.app-prose ol {
    padding-left: var(--space-5);
    list-style-position: outside;
}

.app-prose ul {
    list-style-type: disc;
}

.app-prose ol {
    list-style-type: decimal;
}

.app-prose li + li {
    margin-top: var(--space-0);
}

/* A Markdown task list (`- [ ] text`, `- [x] text`, SafeMarkdown::taskItems): a box or a ticked box instead of the
   literal «[ ]». Drawn here, never an `<input>`: nothing on a public page posts or toggles. */
.app-prose li.app-task {
    position: relative;
    list-style: none;
}

.app-prose li.app-task::before {
    content: '';
    position: absolute;
    top: 0.3em;
    left: calc(-1 * var(--space-4));
    box-sizing: border-box;
    width: 1em;
    height: 1em;
    border: 1px solid var(--border-control);
    border-radius: var(--radius-glyph);
    background: var(--surface);
}

.app-prose li.app-task--done::before {
    border-color: var(--accent);
    background: var(--accent);
}

/* The tick: the right and bottom borders of a small box, turned. */
.app-prose li.app-task--done::after {
    content: '';
    position: absolute;
    top: 0.42em;
    left: calc(-1 * var(--space-4) + 0.33em);
    box-sizing: border-box;
    width: 0.34em;
    height: 0.6em;
    border: solid var(--surface);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* --- The blog (З.Б5 list, З.Б6 post) ---------------------------------------------------- */

/* The list: an entry is title, language badge and description in one grid. Desktop — the badge in the right column
   across both rows; a phone — the badge under the title, then the description. */
.app-blog-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    max-width: var(--w-wide);
}

.app-blog-entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'title' 'badge' 'text';
    gap: var(--space-1);
    justify-items: start;
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.app-blog-entry:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.app-blog-entry__title {
    grid-area: title;
    font-family: var(--font-display);
    font-size: var(--fs-section);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
}

.app-blog-entry > .app-badge {
    grid-area: badge;
}

.app-blog-entry__text {
    grid-area: text;
    max-width: var(--w-prose);
    margin: 0;
}

/* 721px = --bp-unfolded + 1 (var() does not work in a media condition). */
@media (min-width: 721px) {
    .app-blog-entry {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: 'title badge' 'text badge';
        column-gap: var(--space-5);
    }

    .app-blog-entry > .app-badge {
        align-self: start;
        justify-self: end;
    }
}

.app-blog-meta {
    margin: 0 0 var(--space-3);
}

/* SHARE and READ NEXT: the buttons wrap under each other on a phone; the cards' heads keep the badge on the right. */
.app-share-links {
    max-width: var(--w-prose);
}

.app-share-links__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.app-read-next__card {
    color: inherit;
    text-decoration: none;
}

.app-read-next__card:hover .app-card__title {
    text-decoration: underline;
}

.app-read-next__head {
    align-items: flex-start;
}

/* The description line is always there (an empty one keeps its height, so the cards of a row stay equal) and is cut
   at one line; the full text shows in a tooltip only when cut (data-tooltip-if-clipped). */
.app-read-next__text {
    margin: 0;
    overflow: hidden;
    min-height: 1lh;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-read-next__head .app-card__title {
    min-width: 0;
    overflow-wrap: anywhere;
}
