/** Load fonts **/
@font-face {
    font-family: 'FontAwesome';
    font-display: block;
    src: url("/fonts/fontawesome-6.4.2/webfonts/fa-solid-900.woff2") format("woff2");
}

@font-face {
    font-family: 'FontAwesome';
    font-display: block;
    src: url("/fonts/fontawesome-6.4.2/webfonts/fa-brands-400.woff2") format("woff2");
}

:root {
    --page-background: #f5f8fc;
    --surface: #ffffff;
    --surface-muted: #f1f5f9;
    --border: #e2e8f0;
    --input-border: #cbd5e1;
    --heading: #0b1f4d;
    --text: #334155;
    /* at least 4.5:1 contrast on the page background, white and --surface-muted */
    --text-muted: #607087;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-active: #1e40af;
    --primary-tint: #eff6ff;
    --error: #dc2626;
    --radius: 0.75rem;
    --content-width: 72rem;
    --gutter: 1.5rem;
    --header-height: 4rem;
}

/*************************************************************************************************************
 * Page layout
 *************************************************************************************************************/

/* the header stays at the top, so the browser keeps focused and linked-to content below it */
html {
    scroll-padding-top: calc(var(--header-height) + 1rem);
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    color: var(--text);
    background-color: var(--page-background);
    overflow-x: hidden;

    /* Make sure footer is at the bottom of page */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#page {
    flex-grow: 1;
}

#main {
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 var(--gutter) 3rem;
}

h1, h2, h3 {
    color: var(--heading);
    font-weight: 700;
    line-height: 1.2;
}

h1 {
    font-size: 2rem;
    margin: 0 0 0.5rem;
}

h2 {
    font-size: 1.5rem;
    margin: 1rem 0;
}

h3 {
    font-size: 1.15rem;
    margin: 1rem 0;
}

a {
    color: var(--primary);
}

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

.logo-small {
    display: block;
    width: 7rem;
    aspect-ratio: 3.09278;
}

/* Font Awesome glyphs */
.caret, .menu-icon, .app-chevron, .see-all-chevron, #menubutton, .search-button, #footer-social a {
    font-family: FontAwesome, system-ui;
    font-weight: normal;
}

/*************************************************************************************************************
 * Header and top navigation
 *************************************************************************************************************/

#header {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
}

#header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    max-width: var(--content-width);
    height: var(--header-height);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

#topnav {
    display: flex;
    align-self: stretch;
    gap: 2rem;
}

.topnav-item {
    display: flex;
    align-items: center;
    padding: 0 0.25rem;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--heading);
    text-decoration: none;
    background: none;
    border: 0;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    cursor: pointer;
}

.topnav-item:hover, .topnav-item.active {
    color: var(--primary);
}

.topnav-item.active {
    border-bottom-color: var(--primary);
}

.caret {
    margin-left: 0.4rem;
    font-size: 0.85rem;
}

/* The search box, in the header */
.search-form {
    position: relative;
    display: flex;
    align-items: center;
}

.search-form input {
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
    height: 2.4rem;
    padding: 0 2.6rem 0 1rem;
    font: inherit;
    font-size: 0.9rem;
    color: var(--heading);
    background-color: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.search-form input:focus {
    outline: none;
    background-color: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-tint);
}

.search-button {
    position: absolute;
    right: 0.3rem;
    width: 2rem;
    height: 2rem;
    padding: 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    background: none;
    border: 0;
    cursor: pointer;
}

.search-button:hover {
    color: var(--primary);
}

#header-logo {
    margin-right: 1rem;
}

#header-search {
    flex: 1;
    min-width: 0;
    max-width: 18rem;
    margin: 0 2.5rem 0 auto;
}

/*
 * The Categories menu opens below its button with the menu icons aligned with the button's text: the menu starts
 * its border (1px), padding (0.5rem) and item padding (0.75rem) to the left of the text, which starts after the
 * button's padding (0.25rem). The button's box is as wide as the menu from there, so the navigation sits far
 * enough left for the menu to end at the right edge of the content. Only the button and the menu take the mouse.
 */
.topnav-dropdown {
    position: relative;
    display: flex;
    width: calc(16.25rem - 1rem - 1px);
    pointer-events: none;
}

.topnav-dropdown > * {
    pointer-events: auto;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: calc(-1rem - 1px);
    box-sizing: border-box;
    width: 16.25rem;
    padding: 0.5rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    /* the header doesn't scroll away, so on a short screen the menu scrolls instead; dvh leaves out browser toolbars */
    max-height: calc(100vh - var(--header-height));
    max-height: calc(100dvh - var(--header-height));
    overflow-y: auto;
}

.topnav-dropdown.open .dropdown-menu {
    display: block;
}

/* hovering shows the menu too, unless it was just closed with a click or Escape */
@media (hover: hover) {
    .topnav-dropdown:not(.closed):hover .dropdown-menu {
        display: block;
    }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    color: var(--heading);
    text-decoration: none;
    white-space: nowrap;
}

.menu-item:hover {
    background-color: var(--surface-muted);
    color: var(--primary);
}

.menu-item.active {
    color: var(--primary);
    font-weight: 600;
}

.menu-icon {
    display: flex;
    justify-content: center;
    width: 1.25rem;
    color: var(--text-muted);
}

.menu-item:hover .menu-icon, .menu-item.active .menu-icon {
    color: var(--primary);
}

#menubutton {
    display: none;
    padding: 0.5rem;
    font-size: 1.5rem;
    color: var(--heading);
    background: none;
    border: 0;
    cursor: pointer;
}

#sidenav-mobile {
    display: none;
}

#sidenav-mobile hr {
    margin: 0.5rem 0.75rem;
}

/*************************************************************************************************************
 * Breadcrumb and footer
 *************************************************************************************************************/

.breadcrumb ol {
    margin: 1.5rem 0 1.25rem;
    padding: 0;
    list-style: none;
    font-size: 0.9rem;
    color: var(--heading);
}

.breadcrumb li {
    display: inline;
}

.breadcrumb li + li::before {
    content: "/";
    padding: 0 0.6rem;
    color: var(--text-muted);
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

#footer {
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
}

#footer-content {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 2rem var(--gutter);
    text-align: left;
}

#footer a {
    color: var(--text-muted);
    text-decoration: none;
}

#footer a:hover {
    color: var(--primary);
}

#footer-social {
    display: flex;
    justify-content: left;
    gap: 1.5rem;
    font-size: 1.25rem;
}

#footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: left;
    gap: 0.5rem 2rem;
    margin-top: 2rem;
}

#footer-links a:hover {
    text-decoration: underline;
}

#footer-copyright {
    margin-top: 3rem;
}

/*************************************************************************************************************
 * Advertisements
 *************************************************************************************************************/

.ad {
    max-width: 100%;
    margin: 1.5rem auto;
    text-align: center;
}

.ad hr {
    display: none;
}

.advertisement-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.25rem;
}

/* the app page's ads have a fixed height; the listing pages' responsive ad reuses #header-ad and sizes itself */
#app-header ~ .ad #header-ad, #app-header ~ .ad #main-content-ad {
    height: 280px;
}

/*************************************************************************************************************
 * Information pages (about, privacy, terms and errors)
 *************************************************************************************************************/

.text {
    /* long words and URLs wrap rather than run off narrow screens */
    overflow-wrap: anywhere;
    max-width: 52rem;
    line-height: 1.7;
}

.text .title h1 {
    margin-bottom: 1rem;
}

/*************************************************************************************************************
 * Home page
 *************************************************************************************************************/

#hero {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 20rem;
    margin-top: 1.5rem;
    overflow: hidden;
    background-color: #dfeffc;
    border-radius: 1rem;
}

#hero-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 80% center;
}

#hero-text {
    position: relative;
    z-index: 1;
    max-width: 55%;
    padding: 2.5rem 3rem;
}

/* Between phone and desktop widths, the text covers more of the artwork; a light wash keeps it readable */
@media (40rem < width < 60rem) {
    #hero::after {
        content: "";
        position: absolute;
        inset: 0;
        background: linear-gradient(to right, rgb(240 247 255 / 0.92) 0%, rgb(240 247 255 / 0.8) 55%,
                rgb(240 247 255 / 0) 80%);
    }
}

#hero h1 {
    font-size: 2.75rem;
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
}

#hero p {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text);
}

.home-section {
    margin-top: 1.25rem;
    padding: .75rem 1.25rem 1.25rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .75rem;
}

.section-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

.see-all {
    flex-shrink: 0;
    font-weight: 600;
    text-decoration: none;
}

.see-all:hover {
    text-decoration: underline;
}

.see-all-chevron {
    margin-left: 0.4rem;
    font-size: 0.8rem;
}

/*************************************************************************************************************
 * App cards
 *************************************************************************************************************/

.app-listing {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
    gap: 1rem;
}

/*
 * A home page section shows only the cards that fit on one row. The others are hidden, so they can't be reached with
 * Tab or read by screen readers: the row fits n cards of 12rem with 1rem gaps when it is n * 13rem - 1rem wide.
 * Phones show four cards, one per row (below). As a fallback, cards past the first row get no height and are cut off.
 */
.app-row {
    container-type: inline-size;
    grid-template-rows: auto;
    grid-auto-rows: 0;
    row-gap: 0;
    overflow: hidden;
    /* room inside the clipped area for a card's focus ring, without changing where the cards are */
    padding: 0.25rem;
    margin: -0.25rem;
}

@media (width > 40rem) {
    @container (width < 25rem) {
        .app-row > .app:nth-child(n+2) { display: none; }
    }
    @container (25rem <= width < 38rem) {
        .app-row > .app:nth-child(n+3) { display: none; }
    }
    @container (38rem <= width < 51rem) {
        .app-row > .app:nth-child(n+4) { display: none; }
    }
    @container (51rem <= width < 64rem) {
        .app-row > .app:nth-child(n+5) { display: none; }
    }
    @container (64rem <= width < 77rem) {
        .app-row > .app:nth-child(n+6) { display: none; }
    }
    @container (77rem <= width < 90rem) {
        .app-row > .app:nth-child(n+7) { display: none; }
    }
    @container (90rem <= width < 103rem) {
        .app-row > .app:nth-child(n+8) { display: none; }
    }
}

.app {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "icon chevron"
        "text text";
    gap: 0.9rem 0.5rem;
    align-content: start;
    padding: 1rem 1.1rem 1.15rem;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s, background-color 0.15s;
}

.app:hover {
    border-color: #93c5fd;
    background-color: #fafcff;
}

.app-icon-image {
    grid-area: icon;
    display: block;
    width: 7rem;
    aspect-ratio: 1;
    box-sizing: border-box;
    padding: 1px;
    background-color: #cccccc;
    border-radius: 22%;
    object-fit: cover;
}

.app-chevron {
    grid-area: chevron;
    align-self: start;
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: var(--primary);
}

.app-text {
    grid-area: text;
    display: block;
    min-width: 0;
}

.app-name {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--heading);
}

.app-description {
    /* long descriptions are cut off after three lines */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    margin-top: 0.35rem;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-muted);
}

/* Search results: one app per row, its icon beside its name and description */
.app-list {
    grid-template-columns: 1fr;
    max-width: 48rem;
    gap: 0.75rem;
}

.app-list .app {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "icon text chevron";
    align-items: center;
    gap: 1.1rem;
    padding: 0.9rem 1.1rem;
}

.app-list .app-icon-image {
    width: 4.5rem;
}

.app-list .app-chevron {
    align-self: center;
    margin-top: 0;
}

.app-list .app-description {
    margin-top: 0.2rem;
}

/*************************************************************************************************************
 * Listing pages
 *************************************************************************************************************/

.search-header {
    max-width: 48rem;
    margin: 0.5rem 0 1rem;
}

/* a long query without spaces breaks onto the next line instead of running past the page */
.search-header h1 {
    overflow-wrap: anywhere;
}

.listing-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
}

/* The sort orders of a category, as links side by side, the current one highlighted */
.sort-options {
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

#sort-label {
    margin-right: 0.5rem;
}

.sort-option {
    padding: 0.4rem 0.75rem;
    color: var(--heading);
    text-decoration: none;
    background-color: var(--surface);
    border: 1px solid var(--input-border);
}

.sort-option:first-of-type {
    border-radius: 0.5rem 0 0 0.5rem;
}

.sort-option:last-of-type {
    border-radius: 0 0.5rem 0.5rem 0;
}

.sort-option + .sort-option {
    border-left: 0;
}

.sort-option:hover {
    color: var(--primary);
}

.sort-option.selected {
    color: #ffffff;
    background-color: var(--primary);
    border-color: var(--primary);
}

div#pageResults {
    font-size: 0.875rem;
    color: var(--text-muted);
}

div#paginator {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 2rem;
}

.page {
    display: inline-block;
    min-width: 1rem;
    padding: 0.55rem 0.9rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

a.page {
    color: var(--primary);
    background-color: var(--surface);
}

a.page:hover {
    background-color: var(--primary-tint);
}

/* marks the current page */
.page.current {
    color: #ffffff;
    background-color: var(--primary);
    border-color: var(--primary);
}

.page-ellipsis {
    display: inline-block;
    padding: 0.55rem 0.3rem;
    font-weight: 600;
    color: var(--text-muted);
}

/*************************************************************************************************************
 * App page
 *************************************************************************************************************/

/* The header, the app and the overview are each a white card */
#app-header, #main-content, #app-details {
    padding: 2rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#app-header {
    display: flex;
    align-items: flex-start;
    gap: 1.75rem;
    margin: 0.5rem 0 1.5rem;
}

#app-page-icon {
    flex-shrink: 0;
    display: block;
    width: 6.25rem;
    aspect-ratio: 1;
    box-sizing: border-box;
    padding: 1px;
    background-color: #cccccc;
    border-radius: 22%;
    object-fit: cover;
}

#app-data {
    min-width: 0;
    max-width: 48rem;
}

#app-data h1 {
    font-size: 2.5rem;
    margin: 0.25rem 0 0.75rem;
}

#app-data .description {
    font-size: 1.15rem;
    line-height: 1.55;
    color: var(--text);
}

.app-views {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

#app-details {
    margin-top: 1.5rem;
}

.app-details-label {
    font-size: 2rem;
    margin: 0 0 1rem;
}

.app-details-text {
    max-width: 52rem;
    font-size: 1.05rem;
    line-height: 1.75;
}

.app-details-text > :last-child {
    margin-bottom: 0;
}

.app-details-table {
    margin: 1rem auto;
    min-width: 30%;
    border-collapse: collapse;
    background-color: var(--surface);
}

.app-details-table th, .app-details-table td {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--input-border);
}

.app-details-table th {
    background-color: var(--surface-muted);
    color: var(--heading);
}

/* A table wider than a phone scrolls sideways on its own, as the page does not scroll sideways */
@media (max-width: 40rem) {
    .app-details-table {
        display: block;
        width: fit-content;
        max-width: 100%;
        overflow-x: auto;
    }

    /* centered over a scrolling table, the caption would start out of view */
    .app-details-table caption {
        text-align: left;
    }

    /* otherwise a scrolling table shrinks to its narrowest, with a few words per line */
    .app-details-table th, .app-details-table td {
        min-width: 5rem;
    }

    /* a table of three or more columns scrolls anyway, so its later (explanation) columns get room for a phrase */
    .app-details-table th:nth-child(n+3), .app-details-table td:nth-child(n+3) {
        min-width: 11rem;
    }
}

/*************************************************************************************************************
 * App forms (the inside of #main-content)
 *************************************************************************************************************/

.labeledtextarea {
    margin-bottom: 1.25rem;
}

.textarealabel, .selectlabel {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--heading);
}

/* Base field styles, without specificity so the classes below override them */
:where(#main-content) :where(textarea, select, input:not([type]), input[type="text"]) {
    font: inherit;
    color: var(--heading);
    background-color: var(--surface);
    border: 1px solid var(--input-border);
    border-radius: 0.5rem;
}

:where(#main-content) :where(textarea, select, input):focus {
    outline: 2px solid #93c5fd;
    outline-offset: 0;
    border-color: var(--primary);
}

.textarea {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 9rem;
    padding: 0.75rem 1rem;
    font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
    font-size: 0.95rem;
    resize: vertical;
}

.textarea:invalid {
    border-color: var(--error);
}

.textareaerror, .smallinputfielderror {
    min-height: 1.2rem;
    padding-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--error);
}

.options {
    margin-bottom: 1rem;
}

.labeledselect select {
    display: block;
    box-sizing: border-box;
    width: 100%;
    padding: 0.7rem 0.9rem;
}

/* Groups of options and input fields, side by side when they fit */
.inputfieldsection, .outputfieldsection {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.75rem 2.5rem;
    margin: 0 0 1.25rem;
}

div.inputfield, div.outputfield {
    line-height: 2.25;
}

.smallinputfieldlabel, .inputfieldlabel, .outputfieldlabel {
    font-weight: 600;
    color: var(--heading);
}

.smallinputfieldlabel {
    margin-right: 0.5rem;
}

.inputfieldlabel, .outputfieldlabel {
    margin: 0 0.6rem;
    font-size: 1.15rem;
}

label.smallinputfield {
    margin: 0 1.1rem 0 0.2rem;
}

input.smallinputfield {
    margin-right: 1rem;
    padding: 0.4rem 0.6rem;
    line-height: normal;
}

.smallinputradio, .smallinputcheckbox {
    margin: 0;
    accent-color: var(--primary);
}

input.inputfield, input.outputfield {
    box-sizing: border-box;
    max-width: 100%;
    padding: 0.65rem 0.9rem;
    font-size: 1.25rem;
    line-height: normal;
}

input.outputfield {
    background-color: var(--surface-muted);
}

.formula {
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--heading);
    text-align: center;
    background-color: var(--surface-muted);
    border-radius: 0.5rem;
}

.outputblock {
    display: block;
    width: 100%;
}

.fileselectordiv {
    padding-bottom: 1rem;
}

.fileselector {
    box-sizing: border-box;
    width: 100%;
    padding: 1rem;
    font: inherit;
    color: var(--text);
    background-color: #f8fafc;
    border: 1px dashed var(--input-border);
    border-radius: 0.5rem;
}

.fileselector::file-selector-button {
    margin-right: 1rem;
    padding: 0.5rem 1rem;
    font: inherit;
    font-weight: 600;
    color: var(--primary);
    background-color: var(--surface);
    border: 1px solid var(--primary);
    border-radius: 0.5rem;
    cursor: pointer;
}

#canvas-div {
    text-align: center;
}

/* a tall image fits the window, keeping its proportions (a percentage height has nothing to refer to here) */
.output-img {
    max-width: 100%;
    max-height: 90vh;
}

/* QR codes and barcodes shrink to fit narrow screens, keeping their proportions */
#qrcode, #barcode {
    max-width: 100%;
}

#qrcode {
    height: auto !important;
}

#qrcode img, #qrcode canvas {
    max-width: 100%;
    height: auto;
}

#barcode {
    height: auto;
}

.loadingimage {
    flex: none;
    align-self: center;
    height: 1.7em;
    vertical-align: middle;
    visibility: hidden;
}

/* A form of text fields, without a textarea to fill the width: centered, with the fields left aligned in it and the
   buttons and errors as wide as the fields. Its sections are not boxes, so their fields and labels share its columns. */
.fieldform {
    --field-column: 1;
    --label-column: 2;
    display: grid;
    grid-template-columns: minmax(0, 20rem) max-content;
    column-gap: 0.6rem;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
}

.fieldform.labelsleft {
    --field-column: 2;
    --label-column: 1;
    grid-template-columns: max-content minmax(0, 20rem);
}

.fieldform .inputfieldsection, .fieldform .outputfieldsection, .fieldform div.inputfield, .fieldform div.outputfield {
    display: contents;
}

.fieldform input, .fieldform .buttons, .fieldform .textareaerror, .fieldform a {
    grid-column: var(--field-column);
}

.fieldform input {
    width: 100%;
}

.fieldform .inputfieldlabel, .fieldform .outputfieldlabel {
    grid-column: var(--label-column);
    margin: 0;
    white-space: nowrap;
}

.fieldform .textareaerror {
    margin-bottom: 0.25rem;
    line-height: 1.4;
}

/* The first button is solid; the buttons after it in the same row are outlined */
.buttons {
    display: flex;
    gap: 1rem;
    margin: 0.25rem 0 1.5rem;
}

.button {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.75rem 1rem;
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    text-align: center;
    text-decoration: none;
    /* long labels wrap rather than being cut off, as on phones */
    overflow-wrap: break-word;
    background-color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 0.5rem;
    cursor: pointer;
}

.button:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.button:active {
    background-color: var(--primary-active);
    border-color: var(--primary-active);
}

.button ~ .button {
    color: var(--primary);
    background-color: var(--surface);
    border-color: var(--primary);
}

.button ~ .button:hover {
    background-color: var(--primary-tint);
}

.button ~ .button:active {
    background-color: #dbeafe;
}

.button:disabled, .button:disabled:hover, .disabledbutton, .disabledbutton:hover, .disabledbutton:active {
    color: #ffffff;
    background-color: #94a3b8;
    border-color: #94a3b8;
    cursor: default;
}

/* Results shown as figures side by side, below the output */
.stats {
    display: flex;
    margin-top: 0.75rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.stat {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.1rem 1.75rem;
    border-left: 1px solid var(--border);
}

.stat:first-child {
    padding-left: 0;
    border-left: 0;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.stat-value {
    margin-top: 0.6rem;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--heading);
    overflow-wrap: anywhere;
}

/*************************************************************************************************************
 * Narrow screens: the header's navigation moves into the menu, leaving the search box room
 *************************************************************************************************************/

@media screen and (max-width: 55rem) {
    #topnav {
        display: none;
    }

    #menubutton {
        display: block;
    }

    #header-search {
        max-width: none;
        margin: 0 0.25rem 0 0;
    }

    #sidenav-mobile.open {
        display: block;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        /* the padding and border fit in the height too, so the last item can be scrolled into view */
        box-sizing: border-box;
        max-height: calc(100vh - var(--header-height));
        max-height: calc(100dvh - var(--header-height));
        overflow-y: auto;
        padding: 0.5rem var(--gutter) 1rem;
        background-color: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 12px 24px rgba(15, 23, 42, 0.1);
    }
}

/*************************************************************************************************************
 * Phones
 *************************************************************************************************************/

@media screen and (max-width: 40rem) {
    :root {
        --gutter: 1rem;
        --header-height: 3.5rem;
    }

    h1 {
        font-size: 1.6rem;
    }

    #hero {
        display: block;
        min-height: 0;
        margin: 1rem calc(-1 * var(--gutter)) 0;
        border-radius: 0;
        background-color: transparent;
    }

    #hero-text {
        max-width: none;
        padding: 0.5rem 0 0;
        margin: 0 var(--gutter);
    }

    #hero h1 {
        font-size: 1.75rem;
        margin-bottom: 0.6rem;
    }

    #hero p {
        font-size: 1rem;
        color: var(--text-muted);
    }

    #hero-image {
        position: static;
        height: 11rem;
        margin-top: 0.5rem;
        object-position: 78% center;
    }

    .home-section {
        margin: 1rem calc(-1 * var(--gutter)) 0;
        padding: 1rem var(--gutter);
        border-width: 1px 0;
        border-radius: 0;
    }

    .section-header h2 {
        font-size: 1.2rem;
    }

    /* Cards become rows: icon, name and description, chevron */
    .app-listing {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }

    .app-row {
        grid-auto-rows: auto;
        row-gap: 0.6rem;
    }

    .app-row .app:nth-child(n+5) {
        display: none;
    }

    .app {
        grid-template-columns: auto 1fr auto;
        grid-template-areas: "icon text chevron";
        align-items: center;
        gap: 0.9rem;
        padding: 0.7rem 0.9rem;
    }

    .app-icon-image, .app-list .app-icon-image {
        width: 4rem;
    }

    .app-chevron {
        align-self: center;
        margin-top: 0;
    }

    .app-name {
        font-size: 0.95rem;
    }

    .app-description {
        margin-top: 0.15rem;
        font-size: 0.85rem;
    }

    #app-header, #main-content, #app-details {
        padding: 1.1rem;
    }

    #app-header {
        gap: 1rem;
        margin-bottom: 1.25rem;
    }

    #app-page-icon {
        width: 4.25rem;
    }

    #app-data h1 {
        font-size: 1.6rem;
        margin: 0 0 0.4rem;
    }

    #app-data .description {
        font-size: 1rem;
    }

    #app-details {
        margin-top: 1.25rem;
    }

    .textarea {
        height: 7rem;
    }

    .button {
        padding: 0.7rem 0.5rem;
    }

    .stats {
        flex-direction: column;
        gap: 0.9rem;
    }

    .stat {
        padding: 0;
        border-left: 0;
    }

    .app-details-label {
        font-size: 1.6rem;
    }

    .app-details-text {
        font-size: 1rem;
    }
}
