/* The pieces pages are built from. Each takes its numbers from tokens.css; every
   one is on /styleguide, which is the place to see a change before the pages do. */

/* ==== Buttons ============================================================
   .btn                 the main action, gold
   .btn-ghost           a second action beside it
   .btn-danger          taking something away
   .btn-steam           everything that goes to Steam
   .btn-sm / .btn-lg    in a table row / a lone big action
   .btn-block           the full width of its box                         */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    color var(--transition);
}

.btn:hover {
  background: var(--color-accent-hover);
  color: var(--color-on-accent);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn-ghost {
  background: transparent;
  border-color: var(--color-line-strong);
  color: var(--color-text);
}

.btn-ghost:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.btn-danger {
  background: transparent;
  border-color: var(--color-danger-line);
  color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.btn-steam {
  background: var(--color-steam);
  border-color: var(--color-steam-line);
  color: var(--color-steam-text);
}

.btn-steam:hover {
  background: var(--color-steam-hover);
  color: var(--color-steam-text);
}

.btn-sm {
  min-height: var(--control-height-sm);
  padding: 6px 12px;
  font-size: var(--text-md);
}

.btn-lg {
  min-height: var(--control-height-lg);
  padding: 12px 24px;
  font-size: var(--text-lg);
}

.btn-block {
  width: 100%;
}

/* The buttons of one row as one block: they share its width equally. With room,
   side by side and all the same width; without, one under another, each the full
   width of the block. Never narrower than its own label. Before this each button
   kept its own width, and two of them wrapped into a ragged stair. */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 160px;
}

.row-actions > .btn {
  flex: 1 1 0;
  min-width: max-content;
  white-space: nowrap;
}

/* A setting's words with «?» beside them (.field-head): the button opens what the setting
   does in full. Round and quiet, so that a form of twenty settings is not twenty buttons. */
.field-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.help-button {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  line-height: 1;
  cursor: pointer;
}

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

/* A game server's address for the game's «Добавить сервер», and the button that copies
   it: in a row of «Серверы» and under the title of a server's page. */
.address {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.address code {
  white-space: nowrap;
}

/* ==== Forms ==============================================================
   .form        fields one under another
   .field       a <label> holding its caption, the control and a .hint
   .toggle      a switch with its caption; .toggle-on / .toggle-off say the state
   .choice      buttons to choose one of, the one chosen standing out;
                .choice-list stacks them, each with a line about it
   .toolbar     a short form in one row, above a table                     */

.form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
}

.field input,
.field textarea,
.field select,
.number-field input {
  width: 100%;
  min-height: var(--control-height);
  padding: 10px 12px;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  background: var(--color-field);
  color: var(--color-text);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  transition: border-color var(--transition);
}

.field input:hover,
.field textarea:hover,
.field select:hover,
.number-field input:hover {
  border-color: var(--color-accent-line);
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

/* A list to choose from. The arrow is ours, thin and 16 px in from the edge: the
   browser's sat against it. It is two gradient strokes, not a picture: a picture
   file would carry a colour from outside tokens.css, and the page's policy lets no
   data: images in. The list that opens is drawn in the site's colours where it can
   be drawn whole (appearance: base-select, Chromium since 2025); elsewhere at least
   its lines are dark. Left to itself, the browser gave the list the field's own
   half-transparent colour, which came out grey, with the system's blue on top. */
.field select {
  appearance: none;
  padding-right: 44px;
  background-image:
    linear-gradient(
      45deg,
      transparent calc(50% - 1px),
      var(--color-text-muted) calc(50% - 1px),
      var(--color-text-muted) calc(50% + 1px),
      transparent calc(50% + 1px)
    ),
    linear-gradient(
      -45deg,
      transparent calc(50% - 1px),
      var(--color-text-muted) calc(50% - 1px),
      var(--color-text-muted) calc(50% + 1px),
      transparent calc(50% + 1px)
    );
  background-position:
    right 22px center,
    right 16px center;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.field select option {
  background-color: var(--color-surface-solid);
  color: var(--color-text);
}

@supports (appearance: base-select) {
  .field select,
  .field select::picker(select) {
    appearance: base-select;
  }

  /* The arrow is in the background already; the browser's would be a second one. */
  .field select::picker-icon {
    display: none;
  }

  .field select:open {
    border-color: var(--color-accent-line);
  }

  .field select::picker(select) {
    margin-block: 6px;
    padding: 4px;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface-solid);
    box-shadow: var(--shadow-card);
  }

  .field select option {
    padding: 10px 12px;
    border-radius: 6px;
  }

  .field select option:hover {
    background: var(--color-hover);
  }

  .field select option:checked {
    background: var(--color-accent-soft);
    color: var(--color-accent);
  }

  .field select option::checkmark {
    display: none;
  }
}

.field ::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

.field [aria-invalid="true"],
.number-field [aria-invalid="true"] {
  border-color: var(--color-danger);
}

/* A number typed into a line of a .list, with its unit and bounds after it: the
   field's look, the height of a small button, digits lined up on the right. */
.number-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* 16 px, as every field the keyboard types into: Safari on a phone zooms the page in
   on a field set smaller as it takes the focus, and leaves it zoomed (the owner,
   28.09.2026: «вьюпорт как бы приближается нужно пальчиками отдалять потом»). The
   number dialog puts the focus in this one as it opens. */
.number-field input {
  width: var(--width-number-field);
  min-height: var(--control-height-sm);
  padding: 6px 10px;
  font-size: var(--text-base);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.number-field input:disabled {
  opacity: 0.55;
}

.number-unit {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.field :disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.hint {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
}

/* A file to choose. The input itself is unseen and its label is the button: the
   browser's own button speaks the browser's language and wears its look. Beside it,
   the file chosen, or what it came to. */
.file-pick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

/* Unseen, it still is a .field's input, and would wear its width and padding: past
   the dialog's edge, not seen and yet scrolled to. */
.file-pick input {
  width: 1px;
  min-height: 0;
  padding: 0;
  border: 0;
}

.file-pick input:focus-visible + label {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.file-pick-name {
  min-width: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  overflow-wrap: anywhere;
}

/* A switch. The checkbox itself is the track and its ::before the knob, so it still
   takes the keyboard, a click on its caption and a screen reader's "on/off" as any
   checkbox does. Off: dark, the knob on the left; on: gold, the knob on the right.
   The caption can say the state as well: .toggle-on shows only when on, .toggle-off
   only when off. A tick in a small box was too easy to miss (the owner, 25.09.2026:
   "чтобы переключалась и это было видно в ней же"). */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: var(--control-height-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  appearance: none;
  position: relative;
  flex: none;
  width: var(--toggle-width);
  height: var(--toggle-height);
  margin: 0;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-pill);
  background: var(--color-field);
  cursor: pointer;
  transition:
    background-color var(--transition),
    border-color var(--transition);
}

.toggle input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(var(--toggle-height) - 6px);
  height: calc(var(--toggle-height) - 6px);
  border-radius: 50%;
  background: var(--color-text-muted);
  transition:
    transform var(--transition),
    background-color var(--transition);
}

.toggle:hover input {
  border-color: var(--color-accent-line);
}

.toggle input:checked {
  border-color: var(--color-accent);
  background: var(--color-accent);
}

.toggle input:checked::before {
  background: var(--color-on-accent);
  transform: translateX(calc(var(--toggle-width) - var(--toggle-height)));
}

.toggle input:disabled {
  opacity: 0.55;
  cursor: default;
}

.toggle input:checked ~ .toggle-off,
.toggle input:not(:checked) ~ .toggle-on {
  display: none;
}

.toggle-off {
  color: var(--color-text-muted);
}

/* A choice of one out of a few, as buttons: the one chosen is gold, the others are
   outlines (the owner, 27.09.2026: «сделай выбор кнопками, а не переключателем»).
   Under the look they are radio buttons, one <label> each with its <input> and a
   <span> of words, so a click on the words, the arrow keys and a screen reader all
   take them as one choice. The input lies over its button, unseen, and takes the
   click itself. The buttons share the row's width equally; without room each
   takes the full width, one under another. The button is the label's own <span>:
   a choice's words may have spans of their own inside it. */
.choice {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  /* The whole width of its place: in a cell that lays its content out in a row,
     the choice would otherwise be only as wide as its words. */
  width: 100%;
}

.choice label {
  position: relative;
  flex: 1 1 0;
  min-width: max-content;
}

.choice input {
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.choice label > span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height-sm);
  padding: 6px 12px;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  text-align: center;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    color var(--transition);
}

.choice input:hover + span {
  background: var(--color-hover);
  color: var(--color-text);
}

.choice input:checked + span {
  border-color: var(--color-accent-line);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

/* The input is unseen, so its button wears its ring. */
.choice input:focus-visible + span {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.choice input:disabled {
  cursor: default;
}

.choice input:disabled + span {
  opacity: 0.55;
}

/* The options one under another, each the full width, its words at the start and
   a line about it under them: how a rule's choice and a server's way with requests
   are chosen in their dialog, where more options may come (the owner, 27.09.2026:
   «чтобы можно было добавлять в будущем разные варианты»). */
.choice-list {
  flex-direction: column;
}

/* Side by side a button is never narrower than its words; one under another an
   option is as wide as the list, and its line about it wraps. Without this a long
   line pushed a phone's dialog 150 px past its edge. */
.choice-list label {
  min-width: 0;
}

.choice-list label > span {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 14px;
  text-align: left;
}

.choice-label {
  font-size: var(--text-base);
}

/* A path or an address in it wraps rather than pushes the page sideways: one word of
   sixty letters stretched the setup page on a phone 90 px past its edge. */
.choice-about {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-3);
}

.toolbar .field {
  flex: 1 1 260px;
}

/* A toolbar in rows whose fields line up: a field under a field of the same width,
   the button at the end of the first row. «Доступ на сервер» asked for a search
   under the server's picker (the owner, 27.09.2026), and a flex row would have made
   a lone field in a second row as wide as the whole page. */
.toolbar-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

@media (max-width: 640px) {
  .toolbar-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ==== Messages ===========================================================
   .message             words standing in their place: a form's error over
                        its buttons. News, gold; .ok it worked; .error it did
                        not, and why
   .toasts, .toast      news of something just done, beside the page (below) */

.message {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) 14px;
  border: 1px solid var(--color-accent-line);
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  font-size: var(--text-md);
}

.message.ok {
  border-color: var(--color-ok-line);
  background: var(--color-ok-soft);
}

.message.error {
  border-color: var(--color-danger-line);
  background: var(--color-danger-soft);
  color: var(--color-danger-text);
}

.form .message {
  margin: 0;
}

/* A toast comes in the bottom right corner, over the page, and goes by itself: the
   line along its bottom is the time left, and it stops while the pointer or the
   focus is on the toast. Its colours are a .message's, on a solid ground, as it
   stands over whatever is under it. js/toast.js makes them: toast(text, kind).
   News used to stand on the page, above the table it was about, and pushed the
   page down when it came (the owner, 25.09.2026: «чтобы не ломали вёрстку»).
   It is as wide as its words, between --width-toast-min and --width-toast, and
   toasts of several widths line up on the right. At a fixed 360 px a line as short
   as "«Основной»: новые заявки снова ждут админа." broke in two (the owner: «сделай
   пошире, а то даже маленький текст не влазит»); now it takes one line, and only
   the longest news wraps. */
.toasts {
  position: fixed;
  right: var(--space-6);
  bottom: var(--space-6);
  z-index: var(--layer-toast);
  display: grid;
  /* The column is the corner's own width. An auto one grew to the longest toast's
     one line, and a long toast ran past the edge of the screen. */
  grid-template-columns: minmax(0, 1fr);
  justify-items: end;
  gap: var(--space-2);
  /* Never nearer the left edge than a gutter, when the screen is narrow for it. */
  width: min(var(--width-toast), calc(100% - var(--space-6) - var(--gutter)));
  /* The empty corner lets clicks through to the page under it. */
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-2) var(--space-3) 14px;
  overflow: hidden;
  border: 1px solid var(--color-accent-line);
  border-radius: var(--radius-sm);
  background: linear-gradient(var(--color-accent-soft), var(--color-accent-soft)), var(--color-surface-solid);
  box-shadow: var(--shadow-card);
  font-size: var(--text-md);
  pointer-events: auto;
  width: max-content;
  min-width: min(var(--width-toast-min), 100%);
  max-width: 100%;
  transition:
    opacity var(--transition),
    transform var(--transition);
}

/* Comes in from the right, and leaves the same way. */
@starting-style {
  .toast {
    opacity: 0;
    transform: translateX(var(--space-4));
  }
}

.toast.leaving {
  opacity: 0;
  transform: translateX(var(--space-4));
}

.toast.ok {
  border-color: var(--color-ok-line);
  background: linear-gradient(var(--color-ok-soft), var(--color-ok-soft)), var(--color-surface-solid);
}

.toast.error {
  border-color: var(--color-danger-line);
  background: linear-gradient(var(--color-danger-soft), var(--color-danger-soft)), var(--color-surface-solid);
  color: var(--color-danger-text);
}

.toast-text {
  flex: 1;
  min-width: 0;
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.toast-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -4px 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-xl);
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.toast-time {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--color-accent);
  opacity: 0.6;
  transform-origin: left;
  /* The length is set by js/toast.js: longer words stay longer. */
  animation: toast-time 6s linear forwards;
}

.toast.ok .toast-time {
  background: var(--color-ok);
}

.toast.error .toast-time {
  background: var(--color-danger);
}

.toast:hover .toast-time,
.toast:focus-within .toast-time {
  animation-play-state: paused;
}

@keyframes toast-time {
  to {
    transform: scaleX(0);
  }
}

/* On a phone, along the bottom edge, every toast the full width. */
@media (max-width: 480px) {
  .toasts {
    right: var(--gutter);
    bottom: var(--gutter);
    left: var(--gutter);
    justify-items: stretch;
    width: auto;
  }

  .toast {
    width: auto;
  }
}

/* ==== Badges =============================================================
   .badge         a short state; .ok, .danger, .muted
   .badge-stack   badges one under another in a cell: who, and under it when
   .count         a number beside a link                                   */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.badge.ok {
  background: var(--color-ok-soft);
  color: var(--color-ok);
}

.badge.danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.badge.muted {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-muted);
}

.badge-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}

.count {
  margin-left: 6px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}

/* ==== Tabs ===============================================================
   .tabs     a row of buttons over a panel, one per part of it; the part chosen
             shows, the others hide. role="tablist" with role="tab" buttons,
             the one chosen aria-selected="true". Wraps on a narrow screen. */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tab {
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-5);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  cursor: pointer;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    color var(--transition);
}

.tab:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.tab[aria-selected="true"] {
  border-color: var(--color-accent-line);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

/* ==== Boxes ==============================================================
   .card     the one box in the middle of the login pages
   .panel    a block of content on a page
   .stats    big numbers in a row, as the admin panel's overview has them  */

.card {
  width: min(var(--width-card), 100%);
  padding: 36px var(--space-8);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.panel {
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
}

.panel > :last-child {
  margin-bottom: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
}

.stat {
  display: grid;
  gap: var(--space-1);
  padding: 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
}

.stat-value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-heavy);
  line-height: 1;
}

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

/* ==== Builds by category ==================================================
   .category          a category of builds: its bar, then its cards
   .category-head     the bar: a gold edge, the name in gold (.category-name) and
                      how many builds are in it (.category-count), as over «Мои
                      постройки» in the game (the owner, 28.09.2026: «сделай более
                      явную подсветку категории и постройки карточками»)
   .build-cards       the cards, as many to a row as fit
   .build-card        a build: its name, a line about it, what it is now under
                      the word for that (.build-card-label), its button last   */

.category + .category {
  margin-top: var(--space-6);
}

.category-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-left: 3px solid var(--color-accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--color-accent-soft);
}

.category-name {
  margin: 0;
  color: var(--color-accent);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  overflow-wrap: anywhere;
}

.category-count {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.build-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--width-build-card), 100%), 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* The card fills its cell, so the cards of a row stand as tall as the tallest and
   their buttons line up at the bottom. */
.build-cards > li {
  display: grid;
}

.build-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--color-field);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}

.build-card:hover {
  border-color: var(--color-line-strong);
}

.build-card-name {
  margin: 0;
  font-size: var(--text-base);
  overflow-wrap: anywhere;
}

.build-card-note {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.build-card-state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: start;
  gap: var(--space-2);
  margin: 0;
}

.build-card-label {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.build-card .btn {
  justify-self: start;
}

/* ==== A long list: tiles to narrow it by, lines to mark ====================
   .chips        tiles in a row that wraps, each a button with its name and a number
                 (.chip-count). The one pressed, aria-pressed="true", is gold. A
                 .chip-own has a gold dot before its name: a shelf made on the site,
                 not the mod's own.
   .pick         a line's name as a checkbox that marks it: the box, then the name
                 and its .list-note (.pick-text)
   .pick-bar     over such a list: what is found and marked (.pick-bar-said) and the
                 buttons for the marked
   .panel-parts  a panel of several parts one under another, a step apart
   «Полки» in the admin panel: a game has a thousand things, and the shelves they
   lie on are both the count of them and the way to a few of them. */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height-sm);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  cursor: pointer;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    color var(--transition);
}

.chip:hover {
  background: var(--color-hover);
}

.chip[aria-pressed="true"] {
  border-color: var(--color-accent-line);
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.chip-count {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.chip-own::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent);
}

.pick {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
}

/* The box beside the first line of the name, whatever the name's length. */
.pick input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.pick-text {
  min-width: 0;
}

.pick-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

/* The words take the room, and the buttons stand at the end of the row. */
.pick-bar-said {
  flex: 1 1 200px;
  color: var(--color-text-muted);
  font-size: var(--text-md);
}

.panel-parts {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

.panel-parts > * {
  margin-block: 0;
}

/* ==== Pages in a dialog ====================================================
   .menu-list         links one under another, each its title (.menu-list-title)
                      and a line about it (.menu-list-about); the page open now is
                      gold. «Настройки Valheim» in the admin panel opens one.      */

.menu-list {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.menu-list a {
  display: grid;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  transition:
    background-color var(--transition),
    border-color var(--transition);
}

.menu-list a:hover {
  border-color: var(--color-accent-line);
  background: var(--color-hover);
}

.menu-list a[aria-current="page"] {
  border-color: var(--color-accent-line);
  background: var(--color-accent-soft);
}

.menu-list-title {
  font-weight: var(--weight-bold);
}

.menu-list a[aria-current="page"] .menu-list-title {
  color: var(--color-accent);
}

.menu-list-about {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ==== A profile ==========================================================
   .person        the head of a profile: an .avatar beside .person-name and
                  a .person-line under it
   .avatar        a round face: the first letter of the name, until there
                  is a picture
   .list          what an account has, as a grid: one .list-item per line and
                  a rule between every two. <dt> what, <dd> where it stands
                  (badges side by side), a button in <dd class="list-action">.
                  On a phone the button goes up beside the name, and the state
                  takes the line below.
   .list-detail   more about the line, in a box under its state, in the
                  state's colour: when a request was sent (gold), why it was
                  refused (.danger); a .list-detail-label opens it
   .list-heading  a small title over a .list, when one panel holds several
   .list-note     a quiet second line under the name in a <dt>
   .list-controls a .list of settings: the name and what it means take the room,
                  then a column says what the setting is now and whether the
                  change has reached the game, and the control stands last
   .list-group    a .list-controls with its head: the group's name, and over
                  the column of what it is now the word for it (.list-head-label) */

.person {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.person-text {
  min-width: 0;
}

.person-name {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  overflow-wrap: anywhere;
}

.person-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-md);
}

.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border: 1px solid var(--color-accent-line);
  border-radius: 50%;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: 1;
}

.list-heading {
  margin: 0 0 var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.list + .list-heading {
  margin-top: var(--space-6);
}

.list {
  margin: 0;
}

/* Every line has its rule on top, so the first one under a .list-heading is drawn
   too, as a table's head is. One cell holds one thing: a second line of small text
   under a badge made the grid ragged (the owner, 25.09.2026: «сделай это тоже
   сеткой»), and it is a .list-detail of its own now. */
.list-item {
  display: grid;
  grid-template-columns: minmax(0, var(--width-list-label)) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-line);
}

.list-item:last-child {
  padding-bottom: 0;
}

.list dt {
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.list dd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px var(--space-2);
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.list-action {
  justify-self: end;
}

/* More about the line, in a box of the grid's value column, under the state: the
   box takes the colour of the badge it tells more about. Someone's own words may
   be in it, a refusal's reason: line breaks are kept. It was a line of its own with
   a quiet name, and read as left unstyled (the owner, 25.09.2026: «стилизируй и
   это в наш стиль»). */
.list .list-detail {
  display: block;
  grid-column: 2 / -1;
  padding: 10px 14px;
  border: 1px solid var(--color-accent-line);
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  font-size: var(--text-md);
  white-space: pre-line;
}

.list-detail-label {
  color: var(--color-accent);
  font-weight: var(--weight-medium);
}

.list .list-detail.danger {
  border-color: var(--color-danger-line);
  background: var(--color-danger-soft);
}

.list-detail.danger .list-detail-label {
  color: var(--color-danger);
}

.list-note {
  display: block;
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
}

/* Settings are read across: the name and what it means, then what the setting is
   now, then how to change it (the owner, 27.09.2026, by an arrow swapping the two
   columns on a screenshot: what it is comes before the buttons that change it).
   The names get the room; the other two are columns of one width, lined up from
   line to line and from group to group: an auto column is measured in each line on
   its own, and the switches stood ragged. What it is now stands in a column of its
   own although the chosen button's gold says it too, as it reads at a glance (the
   owner: «чтобы было видно какой режим сейчас выбран»), and under it «ждёт сервер»
   while the game has not taken the change. */
.list-controls .list-item {
  grid-template-columns: minmax(0, 1fr) var(--width-list-status) var(--width-list-control);
}

.list-controls .list-action {
  flex-direction: column;
  align-items: flex-start;
  justify-self: start;
}

/* The words of a long setting wrap in their badge rather than run past the column. */
.list-controls .list-action .badge {
  white-space: normal;
}

/* A group of settings is measured as a container: a narrow panel stacks its lines
   whatever the screen, and in the admin panel the menu takes a column beside it. */
.list-group {
  container-type: inline-size;
}

.list-group + .list-group {
  margin-top: var(--space-6);
}

.list-controls-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--width-list-status) var(--width-list-control);
  align-items: end;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-2);
}

.list-controls-head .list-heading {
  margin: 0;
}

/* Over the column of what it is now, whether or not the group has a heading. */
.list-head-label {
  grid-column: 2;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

@media (max-width: 640px) {
  .list-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .list dd:not(.list-action) {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  /* Under the state, each box a row of its own: a line may have two, a waiting
     request and the runes. A fixed third row laid the second over the first. */
  .list dd.list-detail {
    grid-row: auto;
  }
}

/* A game server's tables in the profile (.table-compact): a row of their own under
   its name, the whole width, and on a phone below the button beside the name. Here,
   after the phone's rules, so that neither puts them in a column of the line. */
.list dd.list-facts {
  display: grid;
  gap: var(--space-2);
  grid-column: 1 / -1;
  grid-row: auto;
}

/* A refusal's reason under the tables, as wide as they are. */
.list .list-facts + .list-detail {
  grid-column: 1 / -1;
}

/* The heading of a second table in the line — a server's prices, its sorting zones:
   apart from what stands above it, close to its own table. */
.list-facts .list-heading {
  margin: var(--space-2) 0 0;
}

/* No room for the name beside the two columns: one column, in the same order — the
   name, what it is now, saying so itself as there is no column to head, and the
   control. What it is now once stood beside the name, and on a phone a long «из
   сумки и сундуков» squeezed the name and its words into a strip 150 px wide and
   300 tall. 504 px is the two columns (--width-list-status, --width-list-control),
   their gaps and 200 px for the name; a container query takes no variable, so
   change it with them. A .list-controls always lives in a .list-group, which is
   what this measures. It comes after the phone's rules above: the one putting a
   list's value in the second row would put the control over what it is now. */
@container (max-width: 504px) {
  .list-controls .list-item,
  .list-controls-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .list-controls dd:not(.list-action) {
    grid-row: auto;
  }

  .list-controls .list-action {
    flex-direction: row;
    align-items: center;
  }

  .list-controls .list-action::before {
    content: "Сейчас";
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
  }

  /* A list whose column heads otherwise — «Игрокам», «Итог» — says so in each line's
     data-label: attr() reads the element's own attribute, not its list's. */
  .list-controls .list-action[data-label]::before {
    content: attr(data-label);
  }

  .list-head-label {
    display: none;
  }
}

@media (max-width: 480px) {
  .person-name {
    font-size: var(--text-xl);
  }
}

/* ==== Tables =============================================================
   .table-wrap around .table: a wide table scrolls inside its own box, the page
   itself never scrolls sideways. A person's own words do not go into a cell:
   a "Прочитать" button opens them in .dialog-text.
   position: relative matters. The hidden "Действия" caption in the last column
   is .sr-only, positioned absolutely; with no positioned box around it, it
   escaped the scrolling box and made the whole admin page 698 px wide on a
   375 px phone, with the table itself scrolling correctly inside.          */

.table-wrap {
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-md);
}

.table th,
.table td {
  padding: var(--space-3) 14px;
  border-bottom: 1px solid var(--color-line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.table th {
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}

.table tbody tr:hover {
  background: var(--color-hover);
}

.table tr:last-child td {
  border-bottom: 0;
}

/* A few rows about one thing — a player's standing on a game server in the
   profile and their sorting zones there, and a server's card on the front page (the owner, 28.09.2026, on a picture of the profile: «сделай это
   отображение таблицей, а не карточками», and of the card: «сделай тоже более
   компактной табличкой»). They took the place of a grid of boxes in both. Closer cells, and words that wrap to a phone's width instead of
   scrolling it — between words: `anywhere` would let the table count every letter
   as a place to break, and it cut «Скопировать» in two to make room. A row that
   reads across keeps its name in a th of the body: quiet, as a head is, and of one
   width in every such table, so the values line up. */
.table-compact th,
.table-compact td {
  padding: var(--space-2) var(--space-3);
  white-space: normal;
  overflow-wrap: break-word;
  vertical-align: top;
}

.table-compact tbody tr:last-child th {
  border-bottom: 0;
}

.table-compact tbody th {
  width: var(--width-list-label);
}

/* The servers' table in «Серверы»: a row says what a server is at a glance, and the
   rest of it, and all that is done to it, opens in its dialog (the owner, 03.10.2026, by
   a screenshot of ten columns running past the page: «сделай это окно более сжатым,
   раскидай всё по модалкам лучше»). The name and its line wrap rather than widen the
   table; on a phone a row is a card — the name and «Управление» on top, what it is
   doing and who may play under them. */
.table-servers td:first-child {
  white-space: normal;
  overflow-wrap: break-word;
}

@media (max-width: 640px) {
  .table-servers thead {
    display: none;
  }

  .table-servers tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) 14px;
    border-bottom: 1px solid var(--color-line);
  }

  .table-servers tbody tr:last-child {
    border-bottom: 0;
  }

  .table-servers tbody td {
    display: block;
    padding: 0;
    border: 0;
  }

  .table-servers tbody td:last-child {
    grid-column: 2;
    grid-row: 1;
  }

  .table-servers tbody td:not(:first-child):not(:last-child) {
    grid-column: 1 / -1;
  }

  .table-servers .row-actions {
    min-width: 0;
  }
}

/* An address in a dialog breaks where it must: a phone's dialog is narrower than it. */
.dialog .address code {
  white-space: normal;
  overflow-wrap: anywhere;
}

/* ==== A block of a page =================================================
   .panel-block  a panel of its own between the parts of a page, and as wide as
                 they are: what the installer says of the machine or of a server on
                 it, and the mod with the admin panel in «Обзор». The owner,
                 03.10.2026, over «Эта машина» narrower than the list of servers
                 above it: «проверь что бы все такие окна на сайте растягивались как
                 окно сервера на всю доступную длинну».                         */

.panel-block {
  margin-block: var(--space-6);
}

.panel-block h2 {
  margin: 0;
}

/* ==== Dialog =============================================================
   <dialog class="dialog">: the panel's own question instead of confirm(),
   a person's text to read, or a form needed once in a while.
   .dialog-wide   for lines that are long and kept as they are, a log's.
   .dialog-read   for words to read, a setting's «Подробнее»: wider than a
                  question, no wider than a line reads well.               */

.dialog {
  width: min(440px, calc(100% - 2 * var(--gutter)));
  padding: var(--space-6);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius);
  background: var(--color-surface-solid);
  color: var(--color-text);
  box-shadow: var(--shadow-card);
}

.dialog::backdrop {
  background: var(--color-backdrop);
}

.dialog-wide {
  width: min(var(--width-dialog-wide), calc(100% - 2 * var(--gutter)));
}

.dialog-read {
  width: min(var(--width-dialog-read), calc(100% - 2 * var(--gutter)));
}

/* What each choice of a setting gives, under the words about it: the choice, and what it
   does in a quieter voice; the one standing in the form now carries a badge. */
.help-cases {
  display: grid;
  gap: var(--space-3);
  margin: var(--space-4) 0 0;
}

.help-cases dt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-bold);
}

.help-cases dd {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
}

.dialog p {
  margin: 0;
}

.dialog p + p {
  margin-top: var(--space-3);
}

.dialog h2 {
  margin-bottom: var(--space-3);
}

/* Someone's own words in a dialog: their line breaks kept, a long one scrolls. */
.dialog-text {
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

/* A form in a dialog ends with the dialog's buttons; the form's own gap is
   already between them and the last field. */
.form .dialog-actions {
  margin-top: var(--space-1);
}

/* ==== A server's setup ==================================================
   The page that makes a game server with all its settings (src/serverSetup.js
   names them, the owner, 02.10.2026). Its groups stand one under another, each a
   .setup-group with its title; a choice says under its buttons what the chosen
   value does (.choice-now), as the game's world menu says it under a slider; the
   seed has its dice beside it (.seed-row); a world brought along shows what it is
   and how far it got (.world-upload, .progress); and the launch the installer
   will give the game stands under the form (.code-block).                   */

.setup-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  /* A fieldset will not shrink below its content without this. */
  min-width: 0;
  margin: 0;
  padding: var(--space-4) var(--space-6) var(--space-6);
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.setup-group legend {
  padding: 0 var(--space-2);
  color: var(--color-accent);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

#setup-groups {
  display: grid;
  gap: 14px;
}

/* A field is a grid of one column, and an auto column grows with its longest word. */
.setup-group .field {
  grid-template-columns: minmax(0, 1fr);
}

/* What the chosen value does: plain words, not the grey of a hint, and room kept
   for a line so the page does not jump as the choice changes. */
.choice-now {
  min-height: 1.5em;
  color: var(--color-text);
}

.seed-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.seed-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.world-upload {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px dashed var(--color-line-strong);
  border-radius: var(--radius-sm);
}

.world-upload p {
  margin: 0;
}

.world-summary {
  margin: 0;
  font-weight: var(--weight-normal);
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--color-field);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--color-accent);
  transition: width var(--transition);
}

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

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.setup-launch {
  margin-top: var(--space-8);
}

.setup-launch h2 {
  margin-bottom: var(--space-2);
}

/* Lines a machine reads, as they are: kept to their lines, scrolled sideways when
   longer than the page. */
.code-block {
  margin: var(--space-3) 0 0;
  padding: var(--space-4);
  overflow-x: auto;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: var(--color-field);
  font: var(--text-md) / 1.5 var(--font-mono);
  white-space: pre;
}

/* A log in a dialog (a .code-block too): its last lines are what is read, so it
   scrolls both ways and opens at the end. After .code-block, whose font shorthand
   would set the size back. */
.log-lines {
  max-height: 60vh;
  overflow-y: auto;
  font-size: var(--text-sm);
}

.back {
  margin: 0 0 var(--space-3);
}

/* ==== Text helpers ======================================================= */

.lead {
  margin: 0 0 var(--space-6);
  color: var(--color-text-muted);
}

.muted,
.empty {
  color: var(--color-text-muted);
}

.link {
  font-weight: var(--weight-medium);
}

/* "Нет аккаунта? Зарегистрироваться" under a form. */
.alt-action {
  margin: var(--space-5) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-md);
  text-align: center;
}

/* A line with words in the middle: "или по нику". */
.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-5) 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-line-strong);
}

/* Read by screen readers, not shown. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ==== Chat ===============================================================
   The players' chat (/chat; layout.css puts its two panes side by side).
   .chat-side, .chat-room   the panes: the list of rooms, and the open room
   .chat-room-item          a room in the list: its mark, its name, the last
                            words said in it, and how much is unread (.count)
   .chat-msg                a message: a face — or, joined to the one above it,
                            its time — and the words; its buttons show under the
                            pointer, or on a tap where there is no pointer
   .chat-day, .chat-new     the line of a day, and the line before the first unread
   .chat-form               the form to write, growing with what is typed
   .chat-avatar             a face of a letter, in its account's own hue        */

.chat-side,
.chat-room {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.chat-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-2);
}

.chat-heading {
  margin: 0;
  font-size: var(--text-xl);
}

.chat-status {
  margin: 0 var(--space-4) var(--space-2);
  color: var(--color-accent);
  font-size: var(--text-sm);
}

.chat-rooms,
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--color-line-strong) transparent;
}

.chat-rooms {
  padding: 0 var(--space-2) var(--space-3);
}

.chat-room-group + .chat-room-group {
  margin-top: var(--space-3);
}

.chat-room-group-title {
  margin: var(--space-2) var(--space-2) var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-room-none {
  margin: 0 var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.chat-room-item {
  display: grid;
  grid-template-columns: var(--chat-face) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  transition: background-color var(--transition);
}

.chat-room-item:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.chat-room-item.is-open {
  background: var(--color-accent-soft);
}

.chat-room-item .count {
  margin-left: 0;
}

.chat-room-mark {
  display: grid;
  place-items: center;
  width: var(--chat-face);
  height: var(--chat-face);
  border: 1px solid var(--color-accent-line);
  border-radius: 50%;
  color: var(--color-accent);
  font-weight: var(--weight-bold);
}

.chat-room-text {
  display: grid;
  min-width: 0;
}

.chat-room-title,
.chat-room-last {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-room-title {
  font-weight: var(--weight-medium);
}

.chat-room-last {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.chat-room-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-line);
}

.chat-room-name {
  flex: 1;
  min-width: 0;
}

.chat-room-name h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-room-about {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Positioned: «Новые сообщения» is measured from its top (js/chat.js, offsetTop). */
.chat-log {
  position: relative;
  padding: var(--space-3) var(--space-2) var(--space-2);
}

.chat-older,
.chat-empty {
  margin: var(--space-4) 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.chat-day,
.chat-new {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) var(--space-2) var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
}

.chat-day::before,
.chat-day::after,
.chat-new::before,
.chat-new::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-line);
}

.chat-new {
  color: var(--color-accent);
}

.chat-new::before,
.chat-new::after {
  background: var(--color-accent-line);
}

.chat-msg {
  position: relative;
  display: grid;
  grid-template-columns: var(--chat-face) minmax(0, 1fr);
  gap: var(--space-3);
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.chat-msg-cont {
  margin-top: 0;
  padding-top: 2px;
  padding-bottom: 2px;
}

.chat-msg.is-open {
  background: var(--color-hover);
}

.chat-msg-main {
  min-width: 0;
}

.chat-avatar {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: var(--chat-face);
  height: var(--chat-face);
  border-radius: 50%;
  background: hsl(var(--hue, 40) var(--chat-face-tone));
  color: hsl(var(--hue, 40) var(--chat-face-ink));
  font-weight: var(--weight-bold);
  line-height: 1;
}

/* In the chat now: a dot on the face. */
.chat-online {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border: 2px solid var(--color-surface-solid);
  border-radius: 50%;
  background: var(--color-ok);
}

.chat-side-time {
  align-self: start;
  padding-top: 3px;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-align: center;
  visibility: hidden;
}

.chat-msg.is-open .chat-side-time {
  visibility: visible;
}

.chat-msg-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
}

.chat-author {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text);
  font: inherit;
  font-weight: var(--weight-bold);
  cursor: pointer;
}

.chat-author:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chat-msg-mine .chat-author {
  color: var(--color-accent);
}

.chat-author-gone {
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
  cursor: default;
}

.chat-role {
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.chat-time,
.chat-edited {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

/* A message's own line breaks are kept, and a long word wraps rather than pushes. */
.chat-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-text-gone {
  color: var(--color-text-muted);
  font-style: italic;
}

.chat-quote {
  margin: 2px 0 var(--space-1);
  padding-left: var(--space-2);
  border-left: 3px solid var(--color-accent-line);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-quote-author {
  color: var(--color-accent);
  font-weight: var(--weight-medium);
}

/* Someone wrote @nickname of the reader. */
.chat-mention {
  background: var(--color-accent-soft);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.chat-msg-pending {
  opacity: 0.6;
}

.chat-failed {
  margin: 2px 0 0;
  color: var(--color-danger);
  font-size: var(--text-sm);
}

.chat-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-accent);
  font: inherit;
  font-weight: var(--weight-medium);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* A message's buttons over its top right corner: under the pointer, with the keyboard on
   the message or in it, or after a tap on a screen with no pointer to hover. By the keyboard
   and not by focus alone: a tap focuses too, and a second tap must hide them. */
.chat-msg-actions {
  position: absolute;
  top: -14px;
  right: var(--space-2);
  z-index: 1;
  display: none;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface-solid);
}

.chat-msg:focus-visible .chat-msg-actions,
.chat-msg:has(:focus-visible) .chat-msg-actions,
.chat-msg.is-open .chat-msg-actions {
  display: flex;
}

@media (hover: hover) {
  .chat-msg:hover {
    background: var(--color-hover);
  }

  .chat-mention:hover {
    background: var(--color-accent-soft);
  }

  .chat-msg:hover .chat-msg-actions {
    display: flex;
  }

  .chat-msg:hover .chat-side-time {
    visibility: visible;
  }
}

.chat-act {
  min-height: 28px;
  padding: 2px var(--space-2);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.chat-act:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.chat-act-danger:hover {
  color: var(--color-danger);
}

/* «Новые сообщения ↓» floats over the bottom of the messages: its negative top margin
   takes back the room it takes, so the room does not move when it shows. */
.chat-jump {
  position: relative;
  z-index: 1;
  align-self: center;
  min-height: var(--control-height-sm);
  margin: calc(-1 * (var(--control-height-sm) + var(--space-3))) 0 var(--space-3);
  padding: 6px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-card);
  cursor: pointer;
}

.chat-typing {
  min-height: 20px;
  margin: 0;
  padding: 0 var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-style: italic;
}

.chat-form {
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-top: 1px solid var(--color-line);
}

.chat-form-note {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-3);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
  font-size: var(--text-sm);
}

.chat-form-note-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-note-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-lg);
  line-height: 1;
  cursor: pointer;
}

.chat-note-close:hover {
  background: var(--color-hover);
  color: var(--color-text);
}

.chat-form-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

/* 16 px, as every field the keyboard types into: a phone zooms the page in on a smaller
   one (tokens.css, --text-base). Its height follows what is typed (js/chat.js), up to
   about eight lines, and then it scrolls. */
.chat-input {
  flex: 1;
  min-width: 0;
  min-height: var(--control-height);
  max-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  background: var(--color-field);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-base);
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
  transition: border-color var(--transition);
}

.chat-input:hover,
.chat-input:focus {
  border-color: var(--color-accent-line);
}

.chat-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

.chat-form-hint {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.chat-form-hint:empty {
  display: none;
}

.chat-hint-over {
  color: var(--color-danger);
}

.chat-closed {
  margin: 0;
  padding: var(--space-4);
  border-top: 1px solid var(--color-line);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.chat-person {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.chat-person-name {
  margin: 0;
  overflow-wrap: anywhere;
}

.chat-person-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.chat-person-actions {
  margin-top: var(--space-4);
}

.chat-people {
  display: grid;
  gap: 2px;
  max-height: 50vh;
  margin-top: var(--space-3);
  overflow-y: auto;
}

.chat-person-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 48px;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.chat-person-item:hover {
  background: var(--color-hover);
}

.chat-people-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-weight: var(--weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}
