/* The site kit's tokens and the shell every site shares, dark by default; ThemeSwitch.js sets
   data-theme (light or dark). The palette is named by what each color does in any game
   (feud-guidelines.md §2), so it can make any of them any color:
   neutrals run from the page backdrop (1) up to body text (6), on-fill is text on a player's color,
   and bright and deep stay the same in light and dark. A site defines no colors of its own. */
:root {
    color-scheme: dark;

    --bright: #ffffff;
    --deep: #000000;

    --text-tiny: 11px;
    --text-small: 13px;
    --text-body: 15px;
    --text-display: 32px;
    /* The sidebars' titles, level with their buttons. */
    --text-title: 24px;
    /* Phones zoom into any field set smaller than this when it gets focus. */
    --text-field: 16px;

    --space-small: 4px;
    --space-medium: 8px;
    --space-large: 16px;
    /* The margin round every bar and sidebar, and between what they hold; a phone's is narrower. */
    --space-margin: 24px;

    --radius: 8px;
    --radius-pill: 999px;

    --border-width: 2px;

    --size-avatar: 32px;
    --size-badge: 18px;
    /* The chat's field, which sets the chat's width beside the arena. */
    --size-field: 240px;
    --nav-height: 48px;

    --opacity-faint: 0.2;
    --opacity-dim: 0.35;
    --opacity-medium: 0.5;
    --opacity-strong: 0.7;

    --duration-quick: 0.25s;
    --duration-fade: 0.35s;
    --duration-move: 0.6s;
    --duration-pulse: 1.4s;
    --ease-bounce: cubic-bezier(0.34, 1.8, 0.64, 1);
}

/* Blue-grey neutrals, blue for you, red for the opponent. */
:root {
    --neutral-1: #0f1115;
    --neutral-2: #171a21;
    --neutral-3: #1f232c;
    --neutral-4: #2a2f3a;
    --neutral-5: #8b93a3;
    --neutral-6: #e7e9ee;
    --self: #4a7fc1;
    --opponent: #cf5447;
    --alert: #d99a00;
    --prize: #d99a00;
    --good: #3fbf6f;
    --bad: #cf5447;
    --hue-1: #ddd4c4;
    --hue-2: #3fbf6f;
    --hue-3: #4a7fc1;
    --on-fill: #ffffff;
}

:root[data-theme="light"] {
    color-scheme: light;
    --neutral-1: #f1f4f9;
    --neutral-2: #ffffff;
    --neutral-3: #e3e9f2;
    --neutral-4: #c6cedb;
    --neutral-5: #5f6775;
    --neutral-6: #1b2027;
    --self: #2e62a8;
    --opponent: #b03f33;
    --alert: #c98600;
    --prize: #c98600;
    --good: #2a9d5a;
    --bad: #b03f33;
    --hue-1: #8f8170;
    --hue-2: #2a9d5a;
    --hue-3: #2e62a8;
    --on-fill: #ffffff;
}

* { box-sizing: border-box; }
.is-switching-theme *, .is-switching-theme *::before, .is-switching-theme *::after { transition: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--neutral-1);
    color: var(--neutral-6);
    font: var(--text-body)/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: var(--opacity-dim); }
[hidden] { display: none !important; }

/* -- Gate -- */

.gate {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: var(--space-large);
}

.gate__card {
    width: min(380px, 100%);
    display: grid;
    gap: var(--space-medium);
    padding: var(--space-large);
    background: var(--neutral-2);
    border-radius: var(--radius);
}

.gate__logo { margin: 0; font-size: var(--text-display); letter-spacing: 0.02em; }

.gate__input {
    width: 100%;
    padding: var(--space-medium);
    border: 0;
    border-radius: var(--radius);
    background: var(--neutral-3);
    color: var(--neutral-6);
    font: inherit;
}
/* A field in use rims itself in your colour, fading in and out, instead of the browser's outline. */
:is(.gate__input, .chat-form__input) { outline: none; box-shadow: inset 0 0 0 var(--border-width) transparent; transition: box-shadow var(--duration-quick) ease-out; }
:is(.gate__input, .chat-form__input):focus { box-shadow: inset 0 0 0 var(--border-width) var(--self); }

/* -- Buttons -- */

.primary-button {
    padding: var(--space-medium) var(--space-large);
    border: 0;
    border-radius: var(--radius);
    background: var(--self);
    color: var(--neutral-1);
    font-weight: 600;
}

.secondary-button {
    padding: var(--space-medium);
    border: 0;
    border-radius: var(--radius);
    background: var(--neutral-3);
}

.text-button {
    padding: var(--space-small);
    border: 0;
    background: none;
    color: inherit;
}

.text-button--danger { color: var(--bad); }

/* -- Layout: navigator, arena and aside side by side on desktop, a page stack on phones -- */

.app {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr;
}

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--neutral-2);
}

.panel--arena { background: var(--neutral-1); }

.nav-bar {
    grid-column: 1 / -1;
    padding-top: env(safe-area-inset-top);
    background: var(--neutral-2);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: calc(var(--nav-height) + env(safe-area-inset-top));
    padding-left: var(--space-margin);
    padding-right: var(--space-margin);
}

/* The large title sits in the bar, level with its buttons, and keeps the list's side margin; the
   bar's own small title only shows on a phone's inner pages. */
.nav-bar > * { grid-row: 1; }
.nav-bar__side:first-child { grid-column: 1; }
.nav-bar__title { grid-column: 2; visibility: hidden; font-weight: 600; text-align: center; }
.nav-bar__side { min-width: 0; }
.nav-bar__side--end { grid-column: 3; display: flex; justify-content: flex-end; align-items: center; gap: var(--space-margin); }
.nav-bar__back, .nav-bar__chat, .sidebar-button { display: none; }

.large-title { grid-column: 1 / 3; justify-self: start; margin: 0; font-size: var(--text-title); font-weight: 700; text-transform: capitalize; line-height: var(--size-avatar); white-space: nowrap; }

/* -- Account: an initial in the bar opens a small menu below it -- */

.user-button {
    width: var(--size-avatar);
    height: var(--size-avatar);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--self);
    color: var(--on-fill);
    font-weight: 600;
    transition: opacity var(--duration-fade) ease-out;
}
/* Your initial in the navigator's bottom bar, which stays at the bottom while the list scrolls. */
.navigator-footer { position: sticky; bottom: 0; padding: var(--space-margin); padding-bottom: max(var(--space-margin), env(safe-area-inset-bottom)); background: inherit; }
.user-button { anchor-name: --account; }
/* While the event stream reconnects, your initial fades. */
body.is-offline .user-button { opacity: var(--opacity-dim); }

.user-popover {
    /* Above your initial, opening upwards. */
    position: fixed;
    top: auto;
    right: auto;
    bottom: calc(var(--space-margin) + var(--size-avatar) + var(--space-medium));
    left: var(--space-margin);
    height: auto;
    margin: 0;
    padding: var(--space-medium);
    min-width: 200px;
    border: var(--border-width) solid var(--neutral-4);
    border-radius: var(--radius);
    background: var(--neutral-3);
    color: var(--neutral-6);
}
@supports (anchor-name: --account) {
    .user-popover { position-anchor: --account; bottom: calc(anchor(top) + var(--space-medium)); left: anchor(left); }
}
.user-popover:popover-open { display: grid; }
/* The name parts from the rows by space, as the games menu's sections do. */
.user-popover__name { margin: 0 0 var(--space-large); padding: var(--space-medium); font-weight: 600; }
.user-popover__row { padding: var(--space-medium); border: 0; border-radius: var(--radius); background: none; text-align: left; }
.user-popover__row:hover { background: var(--neutral-4); }

/* -- Family: the large title opens the portfolio's sites below it -- */

.title-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-medium);
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
}

.title-button__chevron {
    width: 10px;
    height: 10px;
    margin-top: -2px;
    border-right: 3px solid var(--neutral-5);
    border-bottom: 3px solid var(--neutral-5);
    border-radius: 1px;
    transform: rotate(45deg);
    transition: transform var(--duration-quick) ease, margin var(--duration-quick) ease, border-color var(--duration-quick) ease;
}
.title-button:hover .title-button__chevron, .title-button[aria-expanded="true"] .title-button__chevron { border-color: var(--neutral-6); }
.title-button[aria-expanded="true"] .title-button__chevron { margin-top: 8px; transform: rotate(225deg); }

.family-menu {
    position: fixed;
    inset: auto;
    margin: 0;
    padding: var(--space-medium);
    width: max-content;
    height: max-content;
    max-height: calc(100dvh - var(--space-large) * 2);
    overflow: auto;
    border: var(--border-width) solid var(--neutral-4);
    border-radius: var(--radius);
    background: var(--neutral-3);
    color: var(--neutral-6);
}
/* Packed at the top: should a browser size the box taller than its rows, they must not spread. */
.family-menu:popover-open { display: grid; align-content: start; }
/* Sections part by space, not by a line. */
.family-menu__heading { margin: 0; padding: var(--space-medium) var(--space-medium) var(--space-small); font-size: var(--text-small); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--neutral-5); }
.family-menu__heading:not(:first-child) { margin-top: var(--space-large); }
.family-menu__entry { display: grid; align-content: start; padding: var(--space-medium); border-radius: var(--radius); color: inherit; text-decoration: none; white-space: nowrap; }
.family-menu__entry:hover { background: var(--neutral-4); }
.family-menu__name { font-weight: 600; }
.family-menu__tagline { font-size: var(--text-small); color: var(--neutral-5); }

/* On desktop there is no bar: the large title and the account button float over the top of the
   navigator, the list starting below them. */
@media (min-width: 761px) {
    .app { grid-template-rows: 1fr; }
    .panel { grid-row: 1; }
    .panel--navigator { grid-column: 1; }
    .panel--arena { grid-column: 2; }
    .panel--aside { grid-column: 3; }
    /* The bar is the navigator's top row: the toggle that hides it at the outer edge, where the
       arena's toggle brings it back, then the title. The navigator is as wide as its bar needs,
       the chat as its field needs; rows and messages fit that width rather than set it. */
    .nav-bar { grid-column: 1; grid-row: 1; align-self: start; z-index: 1; display: flex; align-items: center; gap: var(--space-large); min-height: 0; padding: var(--space-margin); background: none; }
    .nav-bar__side, .nav-bar__title { display: none; }
    .nav-bar > .sidebar-button, .aside-bar > .sidebar-button { display: grid; }
    /* In its sidebar the toggle is a bare glyph, where a filled one would stand. */
    .nav-bar > .sidebar-button, .aside-bar > .sidebar-button { background: none; }
    .aside-bar > .sidebar-button { margin-left: auto; }
    .panel--aside .chat-form__input { width: var(--size-field); }
    .panel--navigator .list { padding-top: calc(var(--space-margin) * 2 + var(--size-avatar)); contain: inline-size; }
    .messages { contain: inline-size; }
    /* A closed sidebar gives its column to the arena, the navigator's bar with it. */
    body[data-navigator="closed"] .app { --navigator-column: 0px; }
    body[data-aside="closed"] .app { --aside-column: 0px; }
    .app { grid-template-columns: var(--navigator-column, auto) minmax(0, 1fr) var(--aside-column, auto); }
    body[data-navigator="closed"] :is(.panel--navigator, .nav-bar) { display: none; }
    body[data-aside="closed"] .panel--aside { display: none; }
}

.sidebar-button { place-items: center; width: var(--size-avatar); height: var(--size-avatar); padding: 0; border: 0; border-radius: 50%; background: var(--neutral-3); color: var(--neutral-5); }
.sidebar-button:hover { color: var(--neutral-6); }
.sidebar-icon { width: var(--size-badge); height: var(--size-badge); fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }

@media (max-width: 760px) {
    :root { --space-margin: var(--space-large); }
    .app { grid-template-columns: 1fr; }
    .panel { display: none; }
    body[data-active-panel="navigator"] .panel--navigator { display: flex; }
    body[data-active-panel="arena"] .panel--arena { display: flex; }
    body[data-active-panel="aside"] .panel--aside { display: flex; }
    .nav-bar__chat { display: inline-flex; align-items: center; gap: var(--space-small); }
    body:not([data-active-panel="navigator"]) .nav-bar__back { display: inline-block; }
    body:not([data-active-panel="navigator"]) .nav-bar__title { visibility: visible; }
    body:not([data-active-panel="navigator"]) .large-title { display: none; }
    body[data-active-panel="aside"] .nav-bar__side--end > button { display: none; }
    /* The bar already names the conversation. */
    .panel--aside .aside-bar { display: none; }
    .chat-form { padding-bottom: max(var(--space-margin), env(safe-area-inset-bottom)); }
    .chat-form__input { font-size: var(--text-field); }
    /* The navigator scrolls with the page, under a bar that stays put. */
    body[data-active-panel="navigator"] .app { position: static; display: flex; flex-direction: column; min-height: 100dvh; }
    body[data-active-panel="navigator"] .panel--navigator { flex: 1 0 auto; }
    body[data-active-panel="navigator"] .nav-bar { position: sticky; top: 0; z-index: 1; }
    body[data-active-panel="navigator"] .list { overflow: visible; }
}

/* -- The arena's top row: pills, and the ways back at its ends -- */

/* Pills: the players, and every button that sits beside a board. */
.pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-medium);
    height: var(--size-avatar);
    padding: 0 var(--space-large);
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--neutral-2);
    font-weight: 600;
    /* Enabled and disabled fade into each other. */
    transition: opacity var(--duration-quick) ease-out;
}
:root[data-theme="light"] .pill { background: var(--neutral-1); }
.pill--self { color: var(--self); }
.pill.pill--filled, :root[data-theme="light"] .pill.pill--filled { background: var(--self); color: var(--neutral-1); }

/* Along the arena's top, as far in as from the sides, over whatever the site draws: the way back
   to the games leads, then what the site places, and the way back to a hidden chat ends it. On a
   phone the way back is a chevron to the games' page; above one each sidebar's toggle shows
   while that sidebar is hidden. */
.panel--arena { position: relative; }
.arena-bar { position: absolute; top: calc(env(safe-area-inset-top) + var(--space-margin)); left: var(--space-margin); right: var(--space-margin); z-index: 1; display: flex; align-items: center; gap: var(--space-margin); pointer-events: none; }
.arena-bar :is(.pill, button) { pointer-events: auto; }
.arena-bar__navigator, .arena-bar__aside { display: none; }
.arena-bar__navigator { width: var(--size-avatar); padding: 0; justify-content: center; }
.arena-bar__aside { padding: 0 calc((var(--size-avatar) - var(--size-badge)) / 2); }
/* A chevron of two strokes meeting at the point. */
.arena-bar__chevron { position: relative; width: calc(var(--space-large) * 0.75); height: calc(var(--space-large) * 1.25); }
.arena-bar__chevron::before, .arena-bar__chevron::after {
    content: '';
    position: absolute;
    left: 0;
    width: var(--space-small);
    height: calc(var(--space-large) * 0.75);
    border-radius: var(--space-small);
    background: currentColor;
    transform-origin: 50% calc(100% - var(--space-small) / 2);
}
.arena-bar__chevron::before { bottom: 50%; transform: translateY(calc(var(--space-small) / 2)) rotate(45deg); }
.arena-bar__chevron::after { top: 50%; transform-origin: 50% calc(var(--space-small) / 2); transform: translateY(calc(var(--space-small) / -2)) rotate(-45deg); }
.arena-bar__navigator .sidebar-icon { display: none; }
@media (min-width: 761px) {
    body[data-navigator="closed"] .arena-bar__navigator, body[data-aside="closed"] .arena-bar__aside { display: inline-flex; }
    .arena-bar__navigator .arena-bar__chevron { display: none; }
    .arena-bar__navigator .sidebar-icon { display: block; }
    /* Chat beside a board is a phone's: above one the chat is a sidebar. */
    .chat-pill { display: none; }
}
@media (max-width: 760px) {
    /* The arena's page has no bar: its way back leads the top row instead. */
    body[data-active-panel="arena"] .nav-bar { display: none; }
    body[data-active-panel="arena"] .app { grid-template-rows: 1fr; }
    body[data-active-panel="arena"] .arena-bar__navigator { display: inline-flex; }
}

/* -- Navigator lists -- */

/* Rows run edge to edge; everything else keeps the list's side margin. */
.list { flex: 1; overflow: auto; padding: var(--space-margin) 0; display: grid; gap: var(--space-margin); align-content: start; }
.list > :not(.list__group), .list__title { margin-left: var(--space-margin); margin-right: var(--space-margin); }
.list__title { margin-top: 0; margin-bottom: var(--space-small); font-size: var(--text-small); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--neutral-5); }
.list__title-button { display: inline-flex; align-items: center; gap: var(--space-medium); padding: 0; border: 0; background: none; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; }
.list__title-button:hover { color: var(--neutral-6); }
.list__items { list-style: none; margin: 0; padding: 0; }

.entry {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-medium);
    padding: var(--space-medium) var(--space-margin);
    border: 0;
    background: none;
    text-align: left;
}

.entry:hover { background: var(--neutral-3); }
/* Selected, a row is tinted a step past hovering. */
.entry.is-selected { background: var(--neutral-4); }

.entry__dot { flex: none; width: var(--space-medium); height: var(--space-medium); border-radius: 50%; }
.entry__dot--online { background: var(--good); }
.entry__dot--idle { background: var(--neutral-5); }
.entry__dot--offline { box-shadow: inset 0 0 0 1px var(--neutral-5); }

.entry__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry__note { flex: none; font-size: var(--text-small); color: var(--neutral-5); white-space: nowrap; }
.entry__note--win { color: color-mix(in srgb, var(--good) 35%, var(--neutral-5)); }

/* Something is due from you: a quiet pill in the panel's own colour. */
.entry__pill {
    flex: none;
    padding: 0 var(--space-medium);
    line-height: var(--size-badge);
    border-radius: var(--radius-pill);
    background: var(--neutral-2);
    font-size: var(--text-tiny);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--neutral-6);
}

.count-badge {
    flex: none;
    min-width: var(--size-badge);
    padding: 0 var(--space-small);
    border-radius: var(--radius);
    background: var(--neutral-6);
    color: var(--neutral-1);
    font-size: var(--text-small);
    font-weight: 600;
    line-height: var(--size-badge);
    letter-spacing: 0;
    text-align: center;
}

/* -- Chat -- */

/* The chat's bar, level with the navigator's: the name of whoever you talk to, set like the
   navigator's title, and above a phone at the outer edge the toggle that hides it. */
.aside-bar { display: flex; align-items: center; gap: var(--space-large); padding: var(--space-margin) var(--space-margin) var(--space-medium); }
.chat-title { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-title); font-weight: 700; line-height: var(--size-avatar); }
.messages { flex: 1; min-height: 0; overflow: auto; list-style: none; margin: 0; padding: var(--space-medium) var(--space-margin); display: grid; gap: var(--space-medium); align-content: start; }
.message { overflow-wrap: anywhere; }
.message__from { margin-right: var(--space-medium); font-weight: 600; color: var(--opponent); }
.message--mine .message__from { color: var(--self); }
.chat-form { padding: var(--space-medium) var(--space-margin) var(--space-margin); }
.chat-form__input {
    width: 100%;
    height: var(--size-avatar);
    padding: 0 var(--space-large);
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--neutral-3);
    color: var(--neutral-6);
    font: inherit;
}
