/* Styles shared by every app except muOS: fonts, colour tokens, reset and control basics.
   Each app loads this file first, then its own layout.css. */

@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("../fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("../fonts/inter-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url("../fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 700; font-display: swap; src: url("../fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2"); }

:root {
    /* Palette: six colours, named after the colour itself.
       Black (not truly black, just dark) and white for backgrounds and text, the same in every theme.
       Red, yellow, blue and green for highlights: lighter in the dark theme, so the text on them is dark, and darker in the light theme (below), so the text on them is white. */
    --black: #1a1a1b;
    --white: #dadedf;
    --red: #ef2142;
    --yellow: #f89520;
    --blue: #1782db;
    --green: #1cc93d;

    /* Roles: they change with the theme and are derived from the palette. Components use role names.
       Each theme has two grays, mixes of white and black: --neutral for secondary text, --neutral-soft for lines and the second background. */
    --neutral: color-mix(in srgb, var(--white) 60%, var(--black));
    --neutral-soft: color-mix(in srgb, var(--white) 15%, var(--black));
    --bg: var(--black);
    --bg-1: var(--neutral-soft);
    --border: var(--neutral-soft);
    --fg: var(--white);
    --fg-1: var(--neutral);
    --accent: var(--white);
    --accent-ink: var(--black);
    --accent-text: var(--white);
    --danger: var(--red);
    --ok: var(--green);

    /* The text on a fill of red, yellow, blue, green or danger: one role for all of them, dark in the dark theme and white in the light theme.
       The text on a neutral fill is the opposite role (--accent-ink on --accent, --bg on --fg); the text on the colour of an app is --brand-ink (assets/js/i18n.js). */
    --on-color: var(--black);

    /* The units. A layout.css writes no unit (rem, px, vh, vw): it writes calc(var(--unit) * n), a line as --border-width,
       and a viewport length as calc(var(--vw) * n) or calc(var(--vh) * n). */
    --unit: 0.2rem;
    --border-width: 1px;
    --border-width-thick: 2px;
    --vw: 1vw;
    --vh: 1vh;
    --cqw: 1cqw;   /* a hundredth of the width of the container (a card of Assetmu): calc(var(--cqw) * n), so a card is the same at any width */
    --height: 2.4rem;
    /* The scales. An app uses these, and does not write a size of its own where one of them fits. */
    --border-radius-small: 0.2rem;   /* small things: a tag, a thumbnail */
    --border-radius-medium: 0.3rem;  /* what stands alone: a button, an input, a select, a card */
    --border-radius-large: 0.4rem;   /* what floats above the page: a dialog, a menu, a toast */
    --border-radius-extra-large: 0.8rem;   /* what is a picture in itself: the card of the splash screen */
    --gap-extra-small: 0.2rem;
    --gap-small: 0.4rem;             /* the default gap, between the items of a row, a list, or a card */
    --gap-medium: 0.8rem;            /* between areas: the blocks of a page or of a dialog */
    --gap-large: 1.2rem;
    --gap-extra-large: 1.6rem;       /* between big parts of a page */
    --padding-extra-small: 0.2rem;
    --padding-small: 0.4rem;
    --padding-medium: 0.8rem;        /* the default padding at the start and end of a button, input, and select */
    --padding-large: 1.2rem;         /* the inside of a card or a bar */
    --padding-extra-large: 1.6rem;   /* the inside of a dialog or a panel */
    --icon-size-extra-small: 0.8rem;
    --icon-size-small: 1rem;         /* an icon in a button or a line of text */
    --icon-size-medium: 1.2rem;
    --icon-size-large: 1.6rem;       /* the mark of a logo */
    --icon-size-extra-large: 3.2rem; /* the icon of a project, a big icon */
    --sidebar-width: 16rem;          /* the width of the sidebar of every app (an app whose sidebar can be dragged starts from it) */
    --font-size-extra-small: 0.6rem; /* labels, hints, tags */
    --font-size-small: 0.8rem;       /* the text of the page */
    --font-size-medium: 1rem;
    --font-size-large: 1.2rem;       /* names and headings */
    --font-size-extra-large: 1.4rem;
    --font-sans: "Inter", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, monospace;   /* code */
    color-scheme: dark;
}

:root[data-theme="light"] {
    --red: #d21129;
    --yellow: #f37800;
    --blue: #126bc3;
    --green: #11aa38;
    --on-color: var(--white);
    --neutral: color-mix(in srgb, var(--black) 60%, var(--white));
    --neutral-soft: color-mix(in srgb, var(--black) 15%, var(--white));
    --bg: var(--white);
    --bg-1: var(--neutral-soft);
    --border: var(--neutral-soft);
    --fg: var(--black);
    --fg-1: var(--neutral);
    --accent: var(--black);
    --accent-ink: var(--white);
    --accent-text: var(--black);
    color-scheme: light;
}

* {
    -webkit-tap-highlight-color: transparent;   /* no blue flash where a finger touches, on a phone: the elements show their own pressed state */
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
    border: none;
    background: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    -webkit-user-select: none;
    user-select: none;
}

/* Text cannot be selected, except in an input, a textarea, and an area with the class "selectable". */
input,
textarea,
[contenteditable],
.selectable,
.selectable * {
    -webkit-user-select: text;
    user-select: text;
}

html, body {
    width: 100%;
    height: 100%;
    background: var(--bg);
}

html {
    color: var(--fg);
    font-family: var(--font-sans);
    font-size: 16px;
}

body {
    font-size: var(--font-size-small);
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* The suggestions under a search input (assets/js/autocomplete.js). */
.autocomplete-list {
    position: fixed;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: var(--border-width) solid var(--border);
    border-radius: var(--border-radius-large);
    overflow: hidden;
}

.autocomplete-option {
    height: var(--height);
    padding: 0 var(--padding-medium);
    display: flex;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.autocomplete-option.active {
    background: var(--bg-1);
}

.autocomplete-match {
    font-weight: 700;
}

/* The popups of every app (assets/js/popup.js): the question and message dialog, and the toasts. They are in the #popups element of the body, which has no box of its own. */
.popups {
    display: contents;
}

.shared-dialog {
    width: min(26rem, calc(var(--vw) * 100 - 2.4rem));
    padding: 0;
    color: var(--fg);
    background: var(--bg);
    border: var(--border-width) solid var(--border);
}

.shared-dialog::backdrop {
    background: color-mix(in srgb, var(--black) 60%, transparent);
}

.shared-dialog-form {
    display: flex;
    flex-direction: column;
    gap: var(--gap-medium);
    padding: var(--padding-extra-large);
}

.shared-dialog-title {
    font-size: var(--font-size-large);
    font-weight: 700;
}

.shared-dialog-text {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.shared-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--gap-small);
}

/* The sheet (a panel at an edge: popups.sheet) and the command (a search with a list: popups.command). */
.shared-sheet {
    position: fixed;
    margin: 0;
    padding: 0;
    max-width: none;
    max-height: none;
    color: var(--fg);
    background: var(--bg);
    border: 0 solid var(--border);
}

.shared-sheet::backdrop,
.shared-command::backdrop {
    background: color-mix(in srgb, var(--black) 60%, transparent);
}

.shared-sheet[open] {
    display: flex;
    flex-direction: column;
}

.shared-sheet[data-side="end"],
.shared-sheet[data-side="start"] {
    inset-block: 0;
    width: min(26rem, calc(var(--vw) * 100 - 2.4rem));
    height: 100%;
}

.shared-sheet[data-side="end"] {
    inset-inline: auto 0;
    border-inline-start-width: var(--border-width);
}

.shared-sheet[data-side="start"] {
    inset-inline: 0 auto;
    border-inline-end-width: var(--border-width);
}

.shared-sheet[data-side="top"],
.shared-sheet[data-side="bottom"] {
    inset-inline: 0;
    width: 100%;
    height: auto;
    max-height: 70%;
}

.shared-sheet[data-side="top"] {
    inset-block: 0 auto;
    border-bottom-width: var(--border-width);
}

.shared-sheet[data-side="bottom"] {
    inset-block: auto 0;
    border-top-width: var(--border-width);
}

.shared-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-small);
    padding: var(--padding-large);
    border-bottom: var(--border-width) solid var(--border);
}

.shared-sheet-title {
    font-size: var(--font-size-large);
    font-weight: 700;
}

.shared-sheet-close {
    width: calc(var(--height) * 3);
}

.shared-sheet-body {
    flex: 1;
    min-height: 0;
    padding: var(--padding-large);
    overflow: auto;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.shared-command {
    width: min(32rem, calc(var(--vw) * 100 - 2.4rem));
    padding: 0;
    color: var(--fg);
    background: var(--bg);
    border: var(--border-width) solid var(--border);
}

.shared-command-input {
    width: 100%;
    border-width: 0 0 var(--border-width);
    border-radius: 0;
}

.shared-command-list {
    display: flex;
    flex-direction: column;
    max-height: 16rem;
    padding: var(--padding-small);
    overflow: auto;
}

.shared-command-item {
    justify-content: space-between;
    border: 0;
    background: transparent;
    font-weight: 400;
    text-align: start;
    text-transform: none;
}

.shared-command-item.on {
    background: var(--bg-1);
}

.shared-command-hint {
    color: var(--fg-1);
    font-size: var(--font-size-extra-small);
}

.shared-command-empty {
    padding: var(--padding-medium);
    color: var(--fg-1);
}

/* The toasts: the short notes at the bottom of the page. */
.shared-toasts {
    inset: auto auto var(--height) 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: var(--gap-small);
    width: min(26rem, calc(var(--vw) * 100 - 2.4rem));
    padding: 0;
    border: 0;
    background: transparent;
    overflow: visible;
    pointer-events: none;
}

.shared-toasts:not(:popover-open) {
    display: none;
}

.shared-toast {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: var(--gap-small);
    padding: var(--padding-medium) var(--padding-large);
    color: var(--fg);
    background: var(--bg);
    border: var(--border-width) solid var(--border);
    border-radius: var(--border-radius-large);
    font-size: var(--font-size-small);
    overflow-wrap: anywhere;
    animation: shared-toast-in 0.2s;
}

/* The kind of a toast and of a dialog is a colour with a meaning: green is good, blue is neutral, yellow is careful, red is bad or sensitive. */
.shared-toast,
.shared-dialog {
    --kind: var(--border);
}

.shared-toast.success,
.shared-dialog[data-kind="success"] {
    --kind: var(--ok);
}

.shared-toast.info,
.shared-dialog[data-kind="info"] {
    --kind: var(--blue);
}

.shared-toast.warning,
.shared-dialog[data-kind="warning"] {
    --kind: var(--yellow);
}

.shared-toast.error,
.shared-dialog[data-kind="error"] {
    --kind: var(--danger);
}

.shared-toast,
.shared-dialog {
    border-color: var(--kind);
}

.shared-toast-icon {
    width: var(--icon-size-medium);
    height: var(--icon-size-medium);
    color: var(--kind);
    background: currentColor;
    -webkit-mask: url(../icons/check.svg) center / contain no-repeat;
    mask: url(../icons/check.svg) center / contain no-repeat;
}

.shared-toast.info .shared-toast-icon {
    -webkit-mask-image: url(../icons/info.svg);
    mask-image: url(../icons/info.svg);
}

.shared-toast.warning .shared-toast-icon {
    -webkit-mask-image: url(../icons/warning.svg);
    mask-image: url(../icons/warning.svg);
}

.shared-toast.error .shared-toast-icon {
    -webkit-mask-image: url(../icons/alert.svg);
    mask-image: url(../icons/alert.svg);
}

.shared-toast.with-bar .shared-toast-icon {
    -webkit-mask-image: url(../icons/upload.svg);
    mask-image: url(../icons/upload.svg);
}

.shared-toast-bar {
    grid-column: 1 / -1;
    height: var(--border-width-thick);
    background: var(--border);
    overflow: hidden;
}

.shared-toast-fill {
    display: block;
    width: 0;
    height: 100%;
    background: var(--kind);
    transition: width 0.2s;
}

@keyframes shared-toast-in {
    from {
        opacity: 0;
        transform: translateY(0.4rem);
    }
}

.hidden {
    display: none !important;
}

dialog {
    margin: auto;
}

/* Corners. An element that stands alone is rounded with --radius: a button, an input, a select, a textarea, a dialog, a menu.
   An element that touches another one (a bar, a group of buttons, a row of a table) is square: its app sets border-radius: 0 on it. */
button,
input,
select,
textarea {
    border-radius: var(--border-radius-medium);
}

dialog,
.menu {
    border-radius: var(--border-radius-large);
}

dialog,
.menu {
    overflow: hidden;
}

input[type="checkbox"],
input[type="radio"],
input[type="range"],
input[type="file"] {
    border-radius: 0;
}

/* A colour input is rounded like the other inputs, as wide as it is high, and its colour fills the whole box, with no gap around it. */
input[type="color"] {
    width: var(--height);
    padding: 0;
    border: var(--border-width) solid var(--fg-1);
    border-radius: var(--border-radius-medium);
    overflow: hidden;
    cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 0;
    border-radius: 0;
}

input[type="color"]::-moz-color-swatch {
    border: 0;
    border-radius: 0;
}

select, input {
    background: transparent;
    height: var(--height);
    padding: 0 var(--padding-medium);
    border: 1px solid var(--border);

    &:focus {
        border-color: var(--fg);
    }
}

select {
    appearance: none;
    cursor: pointer;
    padding-inline-end: calc(var(--padding-medium) + var(--icon-size-small) + var(--gap-small));   /* room for the arrow, so a select as wide as its text does not put the text under it */
    background-image: url("../icons/chevron-down-white.svg");
    background-size: 1rem;
    background-repeat: no-repeat;
    background-position: right 0.6rem center;

    & > option {
        background: var(--bg);
    }
}

:root[data-theme="light"] select {
    background-image: url("../icons/chevron-down-black.svg");
}

:root[dir="rtl"] select {
    background-position: left 0.6rem center;
}

input::placeholder {
    color: var(--fg-1);
}

/* Keyboard focus: a 2px blue line a little outside the element, the same everywhere. The reset above removes the browser's own. */
:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 0.2rem;
}

/* The default look of button, input, select and textarea: no colour of their own (text and background follow the parent) and a gray border.
   Hovering turns the background gray (and the border a little lighter). Checkboxes, radios, ranges, file and
   color inputs keep their own look, and so do buttons that are selected (.active, .on, .invert) or that have
   their own look (.primary, .danger). A layout.css may still give any of them a look of its own. */
button,
textarea {
    background-color: transparent;
    border: 1px solid var(--border);
}

input:hover:not(:disabled, [type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"]),
textarea:hover:not(:disabled),
select:hover:not(:disabled),
button:hover:not(:disabled, .active, .on, .invert, .primary, .danger) {
    background-color: var(--bg-1);
    border-color: var(--fg-1);
}

/* The account app is shown in this dialog (assets/js/account.js). */
dialog.account-dialog {
    width: min(56rem, calc(100vw - 2.4rem));
    padding: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--fg-1);

    &::backdrop {
        background: color-mix(in srgb, var(--black) 60%, transparent);
    }

    & > iframe {
        display: block;
        width: 100%;
        height: min(40rem, calc(100vh - 3.2rem));
        border: 0;
        background: var(--bg);
    }
}

/* A button with the class "account" shows the avatar instead of its icon once signed in. */
button.account.signed-in {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;

    & > * {
        display: none;
    }
}

/* Effects (the Appearance page of the account app). An effect is a layer: a div of its own, directly in the body, that assets/js/theme.js adds when the effect is on and takes away
   when it is off. It covers the page and takes no click. Nothing here styles another element, and no attribute or style is written on html, body, or any element of the page.
   The amount of an effect, 0 to 100, is --effect-amount on its own div. */
.effect {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

/* The monochrome filters what is behind its layer (backdrop-filter), so no element of the page is touched; it lies under the noise */
.effect-monochrome {
    z-index: 2147483646;
    -webkit-backdrop-filter: grayscale(calc(var(--effect-amount, 100) / 100));
    backdrop-filter: grayscale(calc(var(--effect-amount, 100) / 100));
}

/* The noise is a fine grain. It blends as an overlay, so it looks the same on the dark and on the light theme. */
.effect-noise {
    z-index: 2147483647;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: calc(var(--unit) * 100);
    mix-blend-mode: overlay;
    opacity: calc(var(--effect-amount, 30) / 100);
}

/* The moving noise: the grain jumps a few times a second, like the grain of old film */
.effect-noise.moving {
    animation: noise-move 0.6s steps(1) infinite;
}

@keyframes noise-move {
    0% { background-position: 0 0; }
    17% { background-position: calc(var(--unit) * -37) calc(var(--unit) * 23); }
    33% { background-position: calc(var(--unit) * 19) calc(var(--unit) * -41); }
    50% { background-position: calc(var(--unit) * -53) calc(var(--unit) * -17); }
    67% { background-position: calc(var(--unit) * 31) calc(var(--unit) * 47); }
    83% { background-position: calc(var(--unit) * -11) calc(var(--unit) * 7); }
}

@media (prefers-reduced-motion: reduce) {
    .effect-noise.moving {
        animation: none;
    }
}

/* A button has 0.8rem of padding at its start and end. A button that holds only an icon has the class "square":
   no padding, and a width equal to its height, so it is a perfect square. */
button {
    padding: 0 var(--padding-medium);
}

button.square {
    width: var(--height);
    padding: 0;
    flex: none;
}

/* Focus stays the strongest, also while the pointer is over the field. */
input:focus:not(:disabled, [type="checkbox"], [type="radio"], [type="range"], [type="file"], [type="color"]),
textarea:focus:not(:disabled),
select:focus:not(:disabled) {
    border-color: var(--fg);
}
