/* Global portal scale.
   Change ONLY these two values to resize the whole UI.
   Examples: 100% = normal, 120% = 1.2x, 70% = 0.7x. */
/* Chat text multiplier: 1 = original size, 1.25 = 25% bigger, 1.5 = 50% bigger.
   Applies on desktop. Mobile uses the portal's font and 1rem base size.
   Edge gaps shared with My Way: --portal-page-inset (sides), --portal-spacing (top/bottom).
   The mobile --portal-page-inset override is below in the 864px media query. */
:root {
  --chat-font-scale: 1.25;
  --portal-scale-desktop: 100%;
  --portal-scale-mobile: 70%;

  color-scheme: light;
  /* Shared page-edge inset, search-column gap, and theme-button offsets.
     Change this one length (for example 20px or 32px); global zoom scales it. */
  --portal-spacing: 1.5rem;
  /* Shared horizontal inset between page content and the viewport edge. */
  --portal-page-inset: 1rem;
  /* Full-width outer layout keeps the edge inset equal on every page. */
  --page-max-width: none;
  --way-sidebar-width: 417.6px;
  --way-column-gap: var(--portal-spacing);
  --way-layout-max-width: var(--page-max-width);
  --color-primary: #333;
  --color-page-bg: #fff;
  --color-surface: #fff;
  --color-control-bg: #333;
  --color-hover: #62655f;
  --color-active: #555;
  --color-secondary: #686868;
  --color-bg-light: #f0f0f0;
  --color-soft-hover: #e2e2e2;
  --color-avatar-bg: #e5e5e5;
  --color-text-light: #fff;
  --color-muted: #5c6063;
  --color-subtle: #757575;
  --color-placeholder: #737373;
  --color-border: #ccc;
  --color-border-soft: #dedede;
  --color-accent: #3498db;
  --color-spinner-bg: #f3f3f3;
  --color-focus: #315f93;
  --color-link: #245c91;
  --color-error: #b42318;
  --color-selection-outline: #aaa;
  --color-highlight-bg: #ffe58a;
  --color-highlight-text: #222;
  --color-cover-start: #ececec;
  --color-cover-end: #f8f8f8;
  --color-dock-bg: rgba(255, 255, 255, 0.96);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --color-primary: #dedbd5;
  --color-page-bg: #181b1c;
  --color-surface: #202425;
  --color-control-bg: #2c3133;
  --color-hover: #41484a;
  --color-active: #4a5356;
  --color-secondary: #41484a;
  --color-bg-light: #292e30;
  --color-soft-hover: #3b4245;
  --color-avatar-bg: #353c3f;
  --color-text-light: #f2efe9;
  --color-muted: #bbbcb9;
  --color-subtle: #a6aaa9;
  --color-placeholder: #a1a7a7;
  --color-border: #4a5254;
  --color-border-soft: #373e40;
  --color-accent: #79b9ed;
  --color-spinner-bg: #343b3d;
  --color-focus: #9cbfe8;
  --color-link: #9bc7ed;
  --color-error: #ff9990;
  --color-selection-outline: #a5b3b9;
  --color-highlight-bg: #6e561b;
  --color-highlight-text: #fff3bf;
  --color-cover-start: #303739;
  --color-cover-end: #252a2c;
  --color-dock-bg: rgba(32, 36, 37, 0.96);
}

body {
  zoom: var(--portal-scale-desktop);
  background: var(--color-page-bg);
  color: var(--color-primary);
}

/* Mobile can use a different global scale without changing individual components. */
@media (max-width: 864px) {
  :root {
    --portal-page-inset: 0.7rem;
  }
  body {
    zoom: var(--portal-scale-mobile);
  }
}

button {
  color: inherit;
}

input,
textarea,
select,
dialog {
  background: var(--color-surface);
  color: var(--color-primary);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-placeholder);
  opacity: 1;
}

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

hr {
  border: 0;
  border-top: 1.44px solid var(--color-border);
}

/* Keep the main menu exactly one global spacing unit below its divider. */
#header > hr {
  margin-bottom: var(--portal-page-inset);
}

:focus-visible {
  outline: 2.88px solid var(--color-focus);
  outline-offset: 4.32px;
}

/* The theme control occupies the page's top-right corner, away from menu pairs. */
.theme-toggle {
  box-sizing: border-box;
  position: absolute;
  top: var(--portal-spacing);
  right: var(--portal-spacing);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40.32px;
  height: 40.32px;
  padding: 8.64px;
  border: 0;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-primary);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--color-soft-hover);
}

.theme-toggle svg {
  width: 23.04px;
  height: 23.04px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .theme-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .theme-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .theme-moon {
  display: none;
}

@media (max-width: 864px) {
  #header .header-container {
    padding-top: var(--portal-spacing);
  }
}

/* Shared account identity and Maker status. */
[hidden] {
  display: none !important;
}

.auth-account-button {
  display: inline-flex;
  align-items: center;
  gap: 8.64px;
  min-width: 0;
  padding: 0 5.76px;
  border: 0;
  border-radius: 7.2px;
  background: transparent;
  color: var(--color-primary);
  cursor: pointer;
}

.auth-account-button:hover {
  background: var(--color-soft-hover);
}

.avatar-wrap {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 46.08px;
  width: 46.08px;
  height: 46.08px;
  border-radius: 50%;
  background: var(--color-avatar-bg);
  color: var(--color-primary);
  font-size: 23.04px;
  font-weight: 700;
}

.maker-badge {
  position: absolute;
  right: -7.2px;
  bottom: -4.32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 28.8px;
  height: 28.8px;
  flex: 0 0 28.8px;
  border: 2.88px solid var(--color-surface);
  border-radius: 50%;
  background: #18783d;
  color: white;
  font: 700 17.28px/1 Arial, sans-serif;
}

#maker-form,
#maker-form label {
  display: grid;
  gap: 14.4px;
}

#maker-form {
  gap: 25.92px;
}

#maker-form input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 12.96px;
}

#maker-status {
  text-indent: 0;
}

.world-feed {
  display: grid;
  gap: var(--portal-spacing);
}

.world-author {
  display: flex;
  align-items: center;
  gap: 17.28px;
  margin-bottom: 25.92px;
  flex-wrap: wrap;
}

.world-audience {
  color: var(--color-muted);
  font-size: 20.16px;
  margin-left: auto;
}

#world-status {
  margin: 0 0 var(--portal-spacing);
  text-indent: 0;
}

/* Do not let the empty status paragraph push the first World post downward. */
#world-status:empty {
  display: none;
}

#world-more {
  display: block;
  margin: 34.56px auto 0;
}

.way-world-controls {
  display: flex;
  align-items: center;
  gap: 17.28px;
  flex-wrap: wrap;
}

.way-world-controls label {
  display: flex;
  align-items: center;
  gap: 11.52px;
  font-size: 20.16px;
}

.way-world-controls select {
  padding: 11.52px;
  max-width: 100%;
}

.way-publication-status {
  margin-right: auto;
  color: var(--color-muted);
  font-size: 20.16px;
}

.way-editor-actions,
.way-block-actions {
  flex-wrap: wrap;
}

@media (max-width: 864px) {
  .auth-account-button .auth-username {
    max-width: 103.68px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    line-height: 50.4px;
    white-space: nowrap;
  }

  .way-world-controls {
    width: 100%;
  }
}

html {
  scrollbar-gutter: stable;
}

html,
body {
  margin: 0;
  padding: 0;
  font-size: clamp(23.04px, 1.728vw, 28.8px);
}

input,
select,
button {
  font-size: 1rem;
  font-family: inherit;
}

/* ---------- Header ---------- */
.header-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--portal-page-inset);
  flex-wrap: wrap;
  margin: var(--portal-spacing) 0;
}

.header-quote {
  margin: var(--portal-spacing) 0.3rem;
  text-align: center;
}

.home-button a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: var(--color-control-bg);
  text-decoration: none;
  transition: background-color 0.3s;
}

.home-button a img {
  width: 50.4px;
  height: 50.4px;
}

.home-button a:hover {
  background-color: var(--color-hover);
}

.home-button a.active {
  background-color: var(--color-active);
}

h1 {
  margin: 0;
  font-size: 60.48px;
  color: var(--color-primary);
  text-align: center;
}

/* ---------- Навигация ---------- */
.menu {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14.4px;
}

.menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7.2px;
}

.btn,
.menu a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: none;
  color: var(--color-text-light);
  background-color: var(--color-control-bg);
  height: 50.4px;
  padding: 0 12.96px;
  border-radius: 7.2px;
  transition: background-color 0.3s;
  cursor: pointer;
}

.btn:hover,
.menu a:hover {
  background-color: var(--color-hover);
}

/* Pages that are listed but not released yet remain clickable so they can
   explain their status instead of navigating to a missing page. */
.menu a.development-page {
  opacity: 0.45;
}

.menu a.development-page:hover,
.menu a.development-page:focus-visible {
  opacity: 0.7;
}

.btn.active,
.menu a.active {
  background-color: var(--color-active);
}

/* ---------- Menu editor (add/remove items) ---------- */
.hidden {
  display: none !important;
}

/* Toolbar sits on the right from the menu items */
.menu-toolbar {
  display: flex;
  align-items: center;
  gap: 11.52px;
}

#menu-edit-toggle,
#menu-add-btn,
#menu-remove-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40.32px;
  height: 40.32px;
  border-radius: 50%;
  background-color: var(--color-control-bg);
  cursor: pointer;
  transition: background-color 0.3s, opacity 0.3s;
}

#menu-edit-toggle img,
#menu-add-btn img,
#menu-remove-btn img {
  width: 23.04px;
  height: 23.04px;
}

#menu-edit-toggle:hover,
#menu-add-btn:hover,
#menu-remove-btn:hover {
  background-color: var(--color-hover);
}

/* The "on" icons draw their own circle, so clear the button background */
#menu-add-btn.active,
#menu-remove-btn.active {
  background-color: transparent;
}

#menu-edit-toggle.active {
  background-color: var(--color-active);
}

/* Add-page form (visible only in edit mode) */
#menu-add-form {
  display: none;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14.4px;
  margin-top: 21.6px;
}

#menu-add-form select {
  padding: 11.52px 14.4px;
  border: 1.44px solid var(--color-border);
  border-radius: 7.2px;
  min-width: 288px;
  background-color: var(--color-surface);
}

/* Remove mode: menu items become deletable */
.menu ul.removable a {
  cursor: pointer;
}

.menu ul.removable a:hover {
  background-color: #c0392b;
}

.menu ul.removable a.development-page:hover {
  opacity: 1;
}

/* ---------- Контент ---------- */
main {
  margin: var(--portal-spacing) auto;
  max-width: var(--page-max-width);
  padding: 0 var(--portal-page-inset);
  text-align: justify;
}

#add-button {
  display: flex;
  position: relative;
  cursor: pointer;
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: var(--color-control-bg);
  text-decoration: none;
  transition: background-color 0.3s;
}

#add-button img {
  width: 50.4px;
  height: 50.4px;
}

#add-button:hover {
  background-color: var(--color-hover);
}

#add-button.active {
  background-color: var(--color-active);
}


p {
  text-indent: 3%;
}

/* ---------- My Way ---------- */
.way-page {
  max-width: var(--page-max-width);
}

/* Author display rules must not override the HTML hidden attribute. */
.way-page [hidden] {
  display: none !important;
}

.way-empty {
  min-height: 42vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 28.8px;
  text-align: center;
}

.way-intro {
  max-width: 1008px;
  margin: 0;
  text-indent: 0;
  color: var(--color-muted);
  line-height: 1.55;
}

.way-big-add {
  position: relative;
  margin-bottom: 40.32px;
  width: 103.68px;
  height: 103.68px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-control-bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.way-big-add img {
  width: 48.96px;
  height: 48.96px;
}

.way-big-add:hover:not(:disabled),
.way-big-add:focus-visible:not(:disabled) {
  background: var(--color-hover);
  transform: scale(1.04);
}

.way-big-add:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.way-sync {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14.4px;
  min-height: 60.48px;
  margin: 14.4px 0 28.8px;
  color: var(--color-subtle);
  font-size: 0.85rem;
  text-align: center;
}

.way-sync p,
.way-editor-hint,
.way-editor-message,
.way-media-title,
.way-torrent-placeholder {
  margin: 0;
  text-indent: 0;
}

.way-timeline {
  display: grid;
  gap: 25.92px;
}

.way-add-inline {
  justify-self: start;
  min-height: 60.48px;
}

.way-block {
  padding: 28.8px;
  border: 1.44px solid var(--color-border-soft);
  border-radius: 17.28px;
  background: var(--color-surface);
  text-align: left;
  box-shadow: 0 2.88px 14.4px rgba(0, 0, 0, 0.06);
}

.way-block-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 23.04px;
  margin-bottom: 20.16px;
}

.way-block-title {
  margin: 0;
  color: var(--color-primary);
}

.way-block-date {
  flex: 0 0 auto;
  color: var(--color-subtle);
  font-size: 0.78rem;
}

.way-content {
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.way-content p {
  text-indent: 0;
}

.way-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 17.28px 0;
  border-radius: 11.52px;
}

.way-block-media {
  display: grid;
  gap: 17.28px;
  margin-top: 25.92px;
}

.way-media {
  display: grid;
  gap: 8.64px;
}

.way-media video,
.way-media audio {
  width: 100%;
  max-height: 633.6px;
}

.way-torrent-placeholder {
  padding: 14.4px 17.28px;
  border-radius: 11.52px;
  background: var(--color-bg-light);
  color: var(--color-muted);
  font-size: 0.84rem;
}

.way-block-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12.96px;
  margin-top: 23.04px;
}

.way-dialog {
  width: min(1180.8px, calc(100% - 34.56px));
  height: min(94dvh, 1296px);
  max-height: 94dvh;
  overflow: hidden;
  box-sizing: border-box;
  padding: 0;
  border: 0;
  border-radius: 20.16px;
  color: var(--color-primary);
  box-shadow: 0 25.92px 86.4px rgba(0, 0, 0, 0.28);
}

.way-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

body:has(.way-dialog[open]) {
  overflow: hidden;
}

.way-dialog-shell {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto auto auto;
  gap: 14.4px;
  padding: 23.04px;
  box-sizing: border-box;
  height: 100%;
  min-height: 0;
}

.way-dialog-header,
.way-editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 17.28px;
}

.way-dialog-header h2 {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.btn.close-button,
.way-dialog .way-icon-button {
  width: 50.4px;
  height: 50.4px;
  padding: 0;
  flex: 0 0 auto;
}

.btn.close-button {
  border-radius: 50%;
}

.close-button svg,
.way-icon-button svg {
  width: 28.8px;
  height: 28.8px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.way-toolbar .btn[aria-pressed="true"] {
  background-color: var(--color-active);
  box-shadow: inset 0 0 0 2.88px var(--color-selection-outline);
}

.way-toolbar .btn[aria-pressed="true"]:hover {
  background-color: var(--color-secondary);
}

.way-toolbar .btn[aria-pressed="mixed"] {
  box-shadow: inset 0 -4.32px var(--color-selection-outline);
}

.btn.close-button:focus-visible,
.way-dialog .btn:focus-visible {
  outline: 2.88px solid var(--color-focus);
  outline-offset: 2.88px;
}

.way-title-field,
.way-media-form {
  display: grid;
  gap: 8.64px;
  font-size: 0.84rem;
  font-weight: 700;
}

.way-title-field input,
.way-media-form input,
.way-media-form select,
.way-toolbar select {
  box-sizing: border-box;
  width: 100%;
  min-height: 60.48px;
  border: 1.44px solid var(--color-border);
  border-radius: 11.52px;
  padding: 11.52px 14.4px;
  background: var(--color-surface);
  color: var(--color-primary);
  font: inherit;
  font-weight: 400;
}

.way-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10.08px;
}

.way-toolbar select {
  width: auto;
  min-width: 208.8px;
}

.way-file-button {
  position: relative;
  overflow: hidden;
}

.way-file-button input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.way-writing-area {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 17.28px;
  border: 1.44px solid var(--color-border);
  border-radius: 11.52px;
  background: var(--color-surface);
}

.way-editor-content {
  min-height: 100%;
  outline: none;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.way-writing-area:focus-within {
  outline: 2.88px solid rgba(52, 152, 219, 0.35);
  outline-offset: 1.44px;
}

.way-editor-content p {
  text-indent: 0;
}

.way-editor-content img {
  max-width: 100%;
  height: auto;
}

.way-editor-content h1,
.way-editor-content h2,
.way-editor-content h3,
.way-content h1,
.way-content h2,
.way-content h3 {
  text-align: left;
}

.way-editor-content:empty::before {
  content: attr(data-placeholder);
  color: var(--color-placeholder);
  pointer-events: none;
}

.way-media-form {
  grid-template-columns: 172.8px minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: end;
}

.way-media-form label {
  display: grid;
  gap: 8.64px;
}

.way-media-form .btn {
  min-height: 60.48px;
}

.way-editor-hint {
  color: var(--color-subtle);
  font-size: 0.78rem;
}

.way-editor-message {
  min-height: 1.2em;
  color: var(--color-error);
  font-size: 0.82rem;
}

.way-media-list {
  display: grid;
  gap: 10.08px;
}

.way-media-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14.4px;
  padding: 10.08px 12.96px;
  border-radius: 10.08px;
  background: var(--color-bg-light);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

@media (max-width: 1008px) {
  .way-media-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }

  .way-dialog {
    width: calc(100% - 17.28px);
    height: 98dvh;
    max-height: 98dvh;
  }

  .way-dialog-shell {
    padding: 14.4px;
    gap: 8.64px;
  }

  .way-toolbar {
    gap: 5.76px;
    font-size: 0.8rem;
  }

  .way-toolbar .btn {
    font-size: inherit;
  }

  .way-title-field input,
  .way-toolbar select,
  .way-media-form input,
  .way-media-form select,
  .way-media-form .btn {
    min-height: 46.08px;
    padding: 5.76px 8.64px;
  }

  .way-editor-hint {
    font-size: 0.7rem;
  }

  .way-block-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 7.2px;
  }
}

/* ---------- Downloader ---------- */
@media (max-height: 864px) {
  .way-dialog {
    width: calc(100% - 11.52px);
    height: 99dvh;
    max-height: 99dvh;
  }

  .way-dialog-shell {
    padding: 8.64px;
    gap: 5.76px;
  }

  .way-dialog-header h2 {
    font-size: 1rem;
  }

  .way-dialog .close-button,
  .way-dialog .way-icon-button {
    width: 40.32px;
    height: 40.32px;
  }

  .way-title-field {
    font-size: 0;
    gap: 0;
  }

  .way-title-field input {
    font-size: 0.8rem;
  }

  .way-toolbar,
  .way-media-form,
  .way-editor-actions {
    font-size: 0.75rem;
  }

  .way-dialog .btn {
    height: 40.32px;
    font-size: inherit;
  }

  .way-title-field input,
  .way-toolbar select,
  .way-media-form input,
  .way-media-form select,
  .way-media-form .btn {
    min-height: 40.32px;
    padding: 4.32px 7.2px;
  }

  .way-editor-hint {
    font-size: 0.65rem;
  }

  .way-editor-message {
    font-size: 0.7rem;
    min-height: 0;
  }

  .way-editor-message:empty {
    display: none;
  }
}

.downloader-container {
  max-width: var(--page-max-width);
  margin: 28.8px auto 0 auto;
  padding: 14.4px 0;
  background-color: var(--color-bg-light);
  border-radius: 11.52px;
}

.downloader-container h2 {
  text-align: center;
  margin: 0;
  color: var(--color-primary);
}

.input-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14.4px;
  margin-bottom: 28.8px;
}

.input-group input,
.input-group select {
  padding: 11.52px 14.4px;
  border: 1.44px solid var(--color-border);
  border-radius: 7.2px;
}

.input-group input[type="url"] {
  flex: 1;
  /* растягивает поле на всё доступное место */
  max-width: 864px;
  /* ограничение, чтобы не было слишком длинным */
}

.input-group button {
  padding: 11.52px 21.6px;
  border: none;
  border-radius: 7.2px;
  background-color: var(--color-control-bg);
  color: var(--color-text-light);
  cursor: pointer;
  transition: background-color 0.3s;
}

.input-group button:hover {
  background-color: var(--color-hover);
}

#preview {
  position: relative;
  width: 100%;
  /* max-width: 1152px;  можно подстраивать под свой сайт */
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  /* изначально нет лишнего отступа */
  overflow: hidden;
  display: none;
  /* скрыт по умолчанию */
}

#preview iframe,
#preview img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}


.downloads-list {
  margin-top: 28.8px;
  padding: 0;
}

.downloads-list li {
  padding: 11.52px;
  margin-bottom: 7.2px;
  background-color: var(--color-surface);
  border-radius: 7.2px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.downloads-list li button {
  padding: 5.76px 14.4px;
  border: none;
  border-radius: 7.2px;
  background-color: var(--color-control-bg);
  color: var(--color-text-light);
  cursor: pointer;
  transition: background-color 0.3s;
}

.downloads-list li button:hover {
  background-color: var(--color-hover);
}

#errorMsg {
  text-align: center;
  color: var(--color-error);
  margin-bottom: 14.4px;
}

/* ---------- Спиннеры ---------- */
.spinner {
  border: 8.64px solid var(--color-spinner-bg);
  border-top: 8.64px solid var(--color-accent);
  border-radius: 50%;
  width: 72px;
  height: 72px;
  animation: spin 1s linear infinite;
  margin: auto;
}

.button-spinner {
  border: 4.32px solid var(--color-spinner-bg);
  border-top: 4.32px solid var(--color-accent);
  border-radius: 50%;
  width: 23.04px;
  height: 23.04px;
  animation: spin 1s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Books ---------- */
.sr-only {
  position: absolute;
  width: 1.44px;
  height: 1.44px;
  padding: 0;
  margin: -1.44px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.books-page {
  max-width: var(--page-max-width);
}

.books-empty {
  min-height: 52vh;
  display: grid;
  place-items: center;
}

.books-big-add {
  width: 103.68px;
  height: 103.68px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-control-bg);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.books-big-add img {
  width: 48.96px;
  height: 48.96px;
}

.books-big-add:hover,
.books-big-add:focus-visible {
  background: var(--color-hover);
  transform: scale(1.04);
}

.books-toolbar {
  display: flex;
  gap: 17.28px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 34.56px;
}

.books-filter {
  flex: 1;
  max-width: 777.6px;
}

.books-filter input,
.book-search-row input,
.book-search-row select,
.book-editor input,
.book-file-row input,
.book-file-row select {
  box-sizing: border-box;
  width: 100%;
  min-height: 63.36px;
  border: 1.44px solid var(--color-border);
  border-radius: 11.52px;
  background: var(--color-surface);
  padding: 12.96px 17.28px;
  color: var(--color-primary);
}

.books-add-button {
  min-height: 63.36px;
  gap: 5.76px;
  white-space: nowrap;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(273.6px, 1fr));
  gap: 31.68px;
  align-items: stretch;
}

.book-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1.44px solid var(--color-border-soft);
  border-radius: 17.28px;
  background: var(--color-surface);
  text-align: left;
  box-shadow: 0 2.88px 14.4px rgba(0, 0, 0, 0.06);
}

.book-cover,
.search-result-cover,
.editor-cover-inner,
.audio-cover-inner {
  position: relative;
  overflow: hidden;
  background: var(--color-bg-light);
}

.book-cover {
  aspect-ratio: 2 / 3;
}

.book-cover img,
.search-result-cover img,
.editor-cover-inner img,
.audio-cover-inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-cover-fallback {
  width: 100%;
  height: 100%;
  min-height: 103.68px;
  display: grid;
  place-items: center;
  font-size: clamp(43.2px, 7.2vw, 92.16px);
  font-weight: 700;
  color: var(--color-subtle);
  background: linear-gradient(145deg, var(--color-cover-start), var(--color-cover-end));
}

.book-card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding: 18.72px;
}

.book-card h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
  color: var(--color-primary);
  overflow-wrap: anywhere;
}

.book-card p.book-author {
  margin: 8.64px 0 17.28px;
  text-indent: 0;
  color: var(--color-muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.book-format-list {
  display: flex;
  gap: 8.64px;
  flex-wrap: wrap;
  margin-top: auto;
}

.book-format-chip {
  display: inline-flex;
  align-items: center;
  min-height: 43.2px;
  box-sizing: border-box;
  border: 1.44px solid var(--color-border-soft);
  border-radius: 1438.56px;
  padding: 5.76px 12.96px;
  background: var(--color-bg-light);
  color: var(--color-primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.book-format-chip.audio {
  font-family: inherit;
}

.book-format-chip:hover,
.book-format-chip:focus-visible {
  background: var(--color-soft-hover);
}

.book-no-files {
  color: var(--color-subtle);
  font-size: 0.76rem;
}

.book-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10.08px;
  margin-top: 20.16px;
  padding-top: 14.4px;
  border-top: 1.44px solid var(--color-border-soft);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 54.72px;
  height: 54.72px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-bg-light);
  color: var(--color-primary);
  font: inherit;
  font-size: 34.56px;
  cursor: pointer;
}

.icon-button img {
  width: 24.48px;
  height: 24.48px;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: var(--color-soft-hover);
}

.icon-button.danger:hover,
.icon-button.danger:focus-visible {
  background: #c0392b;
  color: var(--color-text-light);
}

.books-no-match {
  text-align: center;
  color: var(--color-subtle);
  text-indent: 0;
  padding: 57.6px 0;
}

.book-dialog {
  width: min(1094.4px, calc(100% - 34.56px));
  max-height: min(86vh, 1238.4px);
  box-sizing: border-box;
  padding: 0;
  border: 0;
  border-radius: 20.16px;
  color: var(--color-primary);
  box-shadow: 0 25.92px 86.4px rgba(0, 0, 0, 0.28);
}

.book-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.book-dialog-shell {
  padding: 28.8px;
}

.book-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 23.04px;
  margin-bottom: 25.92px;
}

.book-dialog-header h2,
.book-files-header h3 {
  margin: 0;
}

.book-dialog-header p,
.book-files-header p {
  margin: 7.2px 0 0;
  text-indent: 0;
  color: var(--color-subtle);
  font-size: 0.82rem;
}

.book-search-row {
  display: grid;
  grid-template-columns: 259.2px 1fr;
  gap: 14.4px;
}


.book-search-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 10.08px 20.16px;
  margin: 14.4px 0 11.52px;
  padding: 12.96px 15.84px;
  border: 1.44px solid var(--color-border);
  border-radius: 11.52px;
}

.book-search-sources legend {
  padding: 0 7.2px;
  font-size: 0.82rem;
  font-weight: 600;
}

.book-search-sources label {
  display: inline-flex;
  align-items: center;
  gap: 7.2px;
  font-size: 0.86rem;
  cursor: pointer;
  white-space: nowrap;
}

.book-search-sources input {
  margin: 0;
}

.book-search-state {
  min-height: 34.56px;
  margin: 10.08px 2.88px;
  color: var(--color-subtle);
  font-size: 0.8rem;
}

.book-search-results {
  display: grid;
  gap: 10.08px;
  max-height: 655.2px;
  /* roughly five search cards */
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 5.76px;
  scrollbar-gutter: stable;
}

.book-more-results {
  display: flex;
  margin: 14.4px auto 0;
}

.book-search-result {
  display: grid;
  grid-template-columns: 69.12px 1fr;
  gap: 15.84px;
  align-items: center;
  width: 100%;
  padding: 11.52px;
  border: 1.44px solid transparent;
  border-radius: 12.96px;
  background: var(--color-bg-light);
  text-align: left;
  cursor: pointer;
}

.book-search-result:hover,
.book-search-result:focus-visible {
  border-color: var(--color-border);
  background: var(--color-soft-hover);
}

.search-result-cover {
  width: 69.12px;
  aspect-ratio: 2 / 3;
  border-radius: 7.2px;
}

.search-result-cover .book-cover-fallback {
  min-height: 103.68px;
  font-size: 31.68px;
}

.book-search-result-text {
  min-width: 0;
  display: grid;
  gap: 2.88px;
}

.book-search-result-text strong,
.book-search-result-text span,
.book-search-result-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-search-result-text span,
.book-search-result-text small {
  color: var(--color-subtle);
}

.book-search-result-text small {
  font-size: 0.72rem;
}

.book-search-source {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  padding: 2.88px 8.64px;
  border: 1.44px solid var(--color-border);
  border-radius: 1438.56px;
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: 0.64rem;
  line-height: 1.25;
}

.book-search-result.resolving {
  opacity: 0.65;
  cursor: wait;
}

.book-editor-book {
  display: grid;
  grid-template-columns: 187.2px 1fr;
  gap: 25.92px;
}

.editor-cover-preview,
.editor-cover-inner {
  width: 187.2px;
  aspect-ratio: 2 / 3;
  border-radius: 11.52px;
}

.editor-cover-inner .book-cover-fallback {
  font-size: 54.72px;
}

.book-editor-fields {
  display: grid;
  gap: 14.4px;
}

.book-editor-fields label {
  display: grid;
  gap: 7.2px;
  font-size: 0.8rem;
  font-weight: 700;
}

.book-files-header {
  display: flex;
  justify-content: space-between;
  gap: 25.92px;
  align-items: flex-end;
  margin: 31.68px 0 14.4px;
}

.book-file-row {
  display: grid;
  grid-template-columns: 40.32px 158.4px minmax(0, 1fr) auto 54.72px;
  gap: 11.52px;
  margin-bottom: 11.52px;
  align-items: center;
}


.book-file-select {
  display: grid;
  place-items: center;
  min-height: 63.36px;
}

.book-file-select input {
  width: 25.92px;
  height: 25.92px;
  margin: 0;
  cursor: pointer;
}

.book-file-row:has(.book-file-include:not(:checked)) {
  opacity: 0.62;
}

.book-file-open {
  min-width: 118.08px;
  white-space: nowrap;
}

.book-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12.96px;
  margin-top: 25.92px;
}

.btn.secondary {
  background: var(--color-secondary);
}

.audio-dock {
  position: sticky;
  bottom: 17.28px;
  z-index: 20;
  display: grid;
  grid-template-columns: 89.28px minmax(0, 1fr) 54.72px;
  gap: 17.28px;
  align-items: center;
  margin: 40.32px auto 0;
  padding: 14.4px;
  border: 1.44px solid var(--color-border-soft);
  border-radius: 17.28px;
  background: var(--color-dock-bg);
  box-shadow: 0 11.52px 34.56px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(11.52px);
}

.audio-dock-cover,
.audio-cover-inner {
  width: 89.28px;
  height: 89.28px;
  border-radius: 11.52px;
}

.audio-cover-inner .book-cover-fallback {
  min-height: 89.28px;
  font-size: 37.44px;
}

.audio-dock-main {
  min-width: 0;
}

.audio-dock-title,
.audio-dock-subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-dock-title {
  font-weight: 700;
}

.audio-dock-subtitle,
.audio-status {
  color: var(--color-subtle);
  font-size: 0.74rem;
}

.audio-dock audio {
  width: 100%;
  margin-top: 7.2px;
}

.audio-status:not(:empty) {
  margin-top: 7.2px;
}

@media (max-width: 892.8px) {

  .books-toolbar,
  .book-files-header {
    align-items: stretch;
    flex-direction: column;
  }

  .books-filter {
    max-width: none;
  }

  .books-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 17.28px;
  }

  .book-card-body {
    padding: 14.4px;
  }

  .book-search-row,
  .book-editor-book,
  .book-file-row {
    grid-template-columns: 1fr;
  }

  .editor-cover-preview,
  .editor-cover-inner {
    width: 151.2px;
  }

  .book-file-row .icon-button {
    justify-self: end;
  }

  .audio-dock {
    grid-template-columns: 69.12px minmax(0, 1fr) 54.72px;
  }

  .audio-dock-cover,
  .audio-cover-inner {
    width: 69.12px;
    height: 69.12px;
  }
}

@media (max-width: 532.8px) {
  .books-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Books: WebTorrent audiobook controls ---------- */
.book-format-chip.audio.torrent {
  border-style: dashed;
}

.audio-chapter-row {
  display: grid;
  grid-template-columns: 54.72px minmax(0, 1fr) 54.72px auto;
  gap: 10.08px;
  align-items: center;
  margin-top: 10.08px;
}

.audio-chapter-row select {
  box-sizing: border-box;
  min-width: 0;
  min-height: 51.84px;
  border: 1.44px solid var(--color-border);
  border-radius: 10.08px;
  background: var(--color-surface);
  padding: 7.2px 11.52px;
}

.audio-small-button {
  width: 54.72px;
  height: 51.84px;
  border: 0;
  border-radius: 10.08px;
  background: var(--color-control-bg);
  color: var(--color-text-light);
  font: inherit;
  font-size: 34.56px;
  line-height: 1;
  cursor: pointer;
}

.audio-small-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.audio-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 51.84px;
  box-sizing: border-box;
  padding: 0 14.4px;
  border-radius: 10.08px;
  background: var(--color-control-bg);
  color: var(--color-text-light);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.76rem;
}

.audio-torrent-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 7.2px 17.28px;
  margin-top: 10.08px;
  padding: 10.08px 12.96px;
  border-radius: 10.08px;
  background: var(--color-bg-light);
  color: var(--color-muted);
  font-size: 0.70rem;
}

.audio-torrent-panel strong {
  color: var(--color-primary);
}

@media (max-width: 892.8px) {
  .audio-chapter-row {
    grid-template-columns: 54.72px minmax(0, 1fr) 54.72px;
  }

  .audio-download {
    grid-column: 1 / -1;
  }
}


/* ---------- Books v2: structured search + loading + cover upload ---------- */
.book-search-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-items: end;
}

.book-search-button {
  min-height: 60.48px;
  padding-inline: var(--portal-page-inset);
}

.book-search-fields label {
  display: grid;
  gap: 7.2px;
  color: var(--color-muted);
  font-size: 0.8rem;
}

.book-search-state.loading {
  display: flex;
  align-items: center;
  gap: 11.52px;
}

.book-search-state.loading::before {
  content: "";
  width: 20.16px;
  height: 20.16px;
  flex: 0 0 20.16px;
  border: 2.88px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.book-cover-upload-row {
  display: flex;
  align-items: center;
  gap: 14.4px;
  flex-wrap: wrap;
}

.book-cover-upload-state {
  color: var(--color-subtle);
  font-size: 0.75rem;
}

@media (max-width: 936px) {
  .book-search-fields {
    grid-template-columns: 1fr;
  }

  .book-search-button {
    width: 100%;
  }
}


/* ---------- My World account/navigation v1 ---------- */

/*
  Keep the navigation aligned with the same horizontal geometry as <main>:
  the shared page width and --portal-spacing side padding.
*/
.top-nav-shell {
  width: 100%;
}

.top-nav-shell .menu {
  width: auto;
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: 0 var(--portal-page-inset);

  /* Two independent columns:
     left = page menu, right = language/account controls */
  display: grid;
  grid-template-columns: minmax(0, 1fr) fit-content(45%);
  align-items: start;
  column-gap: 17.28px;
}

.auth-controls {
  display: flex;
  align-items: center;
  gap: 8.64px;
}

.menu-left {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  min-width: 0;
  gap: 11.52px;
}

.menu-left #menu-list {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.menu-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  align-self: start;
  gap: 8.64px;
  margin-left: 0;
}

.nav-text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 50.4px;
  border: 0;
  border-radius: 7.2px;
  padding: 0 12.96px;
  background: var(--color-control-bg);
  color: var(--color-text-light);
  font: inherit;
  cursor: pointer;
  transition: background-color 0.3s, opacity 0.3s;
}

.nav-text-button:hover:not(:disabled),
.nav-text-button:focus-visible:not(:disabled) {
  background: var(--color-hover);
}

.nav-text-button:disabled {
  opacity: 0.58;
  cursor: default;
}

.auth-username {
  display: inline-flex;
  align-items: center;
  min-height: 50.4px;
  box-sizing: border-box;
  padding: 0 5.76px;
  font-weight: 700;
  color: var(--color-primary);
}

.auth-dialog {
  width: min(619.2px, calc(100% - 34.56px));
  box-sizing: border-box;
  padding: 0;
  border: 0;
  border-radius: 17.28px;
  color: var(--color-primary);
  box-shadow: 0 25.92px 86.4px rgba(0, 0, 0, 0.28);
}

.auth-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.auth-dialog-shell {
  padding: 28.8px;
}

.auth-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 23.04px;
  margin-bottom: 25.92px;
}

.auth-dialog-header h2 {
  margin: 0;
}

.auth-close {
  width: 51.84px;
  height: 51.84px;
  border: 0;
  border-radius: 50%;
  background: var(--color-bg-light);
  color: var(--color-primary);
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
}

.auth-close:hover {
  background: var(--color-soft-hover);
}

#auth-form {
  display: grid;
  gap: 20.16px;
}

#auth-form label {
  display: grid;
  gap: 8.64px;
  font-size: 0.84rem;
  font-weight: 700;
}

#auth-form input {
  box-sizing: border-box;
  width: 100%;
  min-height: 63.36px;
  border: 1.44px solid var(--color-border);
  border-radius: 11.52px;
  padding: 12.96px 17.28px;
  background: var(--color-surface);
  color: var(--color-primary);
}

.auth-message {
  min-height: 1.2em;
  margin: 0;
  text-indent: 0;
  color: var(--color-error);
  font-size: 0.8rem;
}

.auth-submit {
  min-height: 60.48px;
}

@media (max-width: 1094.4px) {
  .top-nav-shell .menu {
    column-gap: 11.52px;
  }

  .menu-right {
    width: auto;
  }

  .menu-right button,
  .menu-right a,
  .menu-right span {
    white-space: nowrap;
  }
}

/* Memo search and calendar controls reuse the existing neutral page styles. */
.way-big-add>span {
  position: absolute;
  top: calc(100% + 11.52px);
  white-space: nowrap;
  font-size: 20.16px;
  color: var(--color-primary);
}

.memo-filters {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 17.28px;
  margin-bottom: 28.8px;
  padding: 23.04px;
  border: 1.44px solid var(--color-border);
  border-radius: 17.28px;
  background: var(--color-surface);
}

.memo-filters label {
  display: grid;
  gap: 8.64px;
  font-size: 20.16px;
  min-width: 0;
}

.memo-search {
  flex: 1 1 374.4px;
}

.memo-filters input,
.memo-filters select,
.article-import-row input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 60.48px;
  padding: 11.52px 14.4px;
  border: 1.44px solid var(--color-border);
  border-radius: 8.64px;
  background: var(--color-surface);
  color: var(--color-primary);
  font-size: 23.04px;
}

.memo-custom-period {
  display: flex;
  gap: 20.16px;
  flex-wrap: wrap;
  flex-basis: 100%;
  order: 2;
}

.memo-custom-period>label {
  flex: 1 1 374.4px;
}

.memo-date-field {
  display: flex;
  align-items: stretch;
  gap: 11.52px;
}

.memo-date-field .btn {
  flex: 0 0 auto;
  font-size: 20.16px;
}

.memo-filter-message {
  flex-basis: 100%;
  order: 3;
  margin: 0;
  text-indent: 0;
  font-size: 20.16px;
  color: var(--color-muted);
}

.memo-filters input[aria-invalid="true"] {
  border-color: var(--color-error);
}

.memo-calendar {
  box-sizing: border-box;
  width: min(504px, calc(100vw - 34.56px));
  padding: 23.04px;
  border: 1.44px solid var(--color-border);
  border-radius: 17.28px;
  color: var(--color-primary);
}

.memo-calendar::backdrop {
  background: rgb(0 0 0 / 35%);
}

.memo-calendar-heading,
.memo-calendar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14.4px;
}

.memo-calendar-heading h2 {
  margin: 0;
  font-size: 25.92px;
}

.memo-calendar-week,
.memo-calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5.76px;
}

.memo-calendar-week {
  margin: 23.04px 0 11.52px;
  font-size: 20.16px;
  text-align: center;
}

.memo-calendar-days button {
  min-width: 0;
  min-height: 54.72px;
  padding: 4.32px;
  border: 1.44px solid transparent;
  border-radius: 8.64px;
  background: var(--color-bg-light);
  color: var(--color-primary);
  font-size: 20.16px;
  cursor: pointer;
}

.memo-calendar-days button:hover {
  background: var(--color-soft-hover);
}

.memo-calendar-days button[aria-current="date"] {
  border-color: var(--color-primary);
}

.memo-calendar-days button[aria-pressed="true"] {
  background: var(--color-active);
  color: var(--color-text-light);
  border-color: var(--color-focus);
}

.memo-calendar-days button:focus-visible {
  outline: 2.88px solid var(--color-focus);
  outline-offset: 1.44px;
}

.memo-calendar-actions {
  margin-top: 23.04px;
}

/* Wrap navigation as units: Edit + language, avatar + account name. */
.menu-right {
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  white-space: normal;
}

.menu-right .menu-toolbar,
.menu-right .auth-controls {
  display: contents;
}

.menu-tools-pair {
  display: inline-flex;
  align-items: center;
  gap: 8.64px;
  flex: 0 0 auto;
}

.menu-right .auth-account-button {
  max-width: 100%;
  min-width: 0;
}

.menu-right .auth-account-button .auth-username {
  display: block;
  min-width: 0;
  max-width: none;
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
  text-overflow: clip;
  line-height: 1.25;
  min-height: 0;
}

.menu-right .nav-text-button {
  white-space: normal;
  max-width: 100%;
}

/* Shared page insets and a flexible content column beside search. */
#way-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--way-sidebar-width);
  align-items: start;
  gap: var(--way-column-gap);
  max-width: var(--way-layout-max-width);
  padding-inline: var(--portal-page-inset);
}

.way-main-column {
  min-width: 0;
}

#way-page:has(> .memo-filters[hidden]) {
  grid-template-columns: minmax(0, 1fr);
  max-width: var(--page-max-width);
  padding-inline: var(--portal-page-inset);
}

@media (min-width: 1297.44px) {
  body:has(#way-page > .memo-filters:not([hidden])) .top-nav-shell .menu {
    max-width: var(--way-layout-max-width);
    padding-inline: var(--portal-page-inset);
  }
}

#way-page>.memo-filters {
  position: sticky;
  top: 23.04px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 23.04px;
  margin: 0;
  max-height: calc(100dvh - 46.08px);
  overflow-y: auto;
}

#way-page .memo-custom-period {
  display: grid;
  gap: 20.16px;
}

#way-page .memo-filters>*,
#way-page .memo-custom-period>label {
  min-width: 0;
  order: 0;
}

#way-page .memo-date-field .btn {
  padding: 8.64px;
}

.memo-search-match {
  background: var(--color-highlight-bg);
  color: var(--color-highlight-text);
  border-radius: 2.88px;
  padding: 0;
}

/* Unformatted content starts justified; explicit paragraph alignment still wins. */
.way-content,
.way-editor-content {
  text-align: justify;
}

.way-content img,
.way-editor-content img {
  display: inline-block;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

/* An image selected directly can also carry its own sanitized alignment. */
.way-content img[data-align],
.way-editor-content img[data-align] {
  display: block;
}

.way-content img[data-align="left"],
.way-editor-content img[data-align="left"],
.way-content img[data-align="justify"],
.way-editor-content img[data-align="justify"] {
  margin-left: 0;
  margin-right: auto;
}

.way-content img[data-align="center"],
.way-editor-content img[data-align="center"] {
  margin-left: auto;
  margin-right: auto;
}

.way-content img[data-align="right"],
.way-editor-content img[data-align="right"] {
  margin-left: auto;
  margin-right: 0;
}

@media (max-width: 1296px) {
  #way-page {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--portal-spacing);
    max-width: var(--page-max-width);
    padding-inline: var(--portal-page-inset);
  }

  #way-page>.memo-filters {
    position: static;
    max-height: none;
    overflow: visible;
    grid-row: 1;
  }

  #way-page>.way-main-column {
    grid-row: 2;
  }
}


/* World layout: large unboxed ratings and open, connected comment threads. */
:root {
  --world-positive: #376f50;
  --world-negative: #a34a4a;
}

:root[data-theme="dark"] {
  --world-positive: #8bb79c;
  --world-negative: #d49b9b;
}

.world-post {
  /* Keep the desktop rating aligned to the page edge and use the same
     global spacing between the rating and the post as elsewhere in the layout. */
  --rating-width: 1rem;
  --rating-gap: var(--portal-page-inset);
  min-width: 0;
}

.world-post-main {
  display: grid;
  grid-template-columns: var(--rating-width) minmax(0, 1fr);
  gap: var(--rating-gap);
  align-items: start;
  min-width: 0;
}

.world-post-box,
.world-discussion,
.world-comment-list,
.world-comment-box {
  min-width: 0;
}

.world-post-box {
  --post-padding: 1.25rem;
  padding: var(--post-padding);
}

.world-votes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  color: var(--color-muted);
  background: none;
  border: 0;
  box-shadow: none;
}

.world-votes-post {
  position: sticky;
  top: .6rem;
  align-self: start;
  flex-direction: column;
  padding: .15rem 0;
}

.world-vote {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: inherit;
  background: none;
  box-shadow: none;
  cursor: pointer;
}

.world-vote svg {
  width: 1.05rem;
  height: 1.05rem;
}

.world-vote:hover:not(:disabled) {
  color: var(--color-primary);
}

.world-vote:disabled {
  opacity: 1;
  cursor: default;
}

.world-vote[aria-pressed="true"].world-vote-up {
  color: var(--world-positive);
}

.world-vote[aria-pressed="true"].world-vote-down {
  color: var(--world-negative);
}

.world-vote:focus-visible {
  border-radius: .2rem;
}

.world-score {
  font-size: 1.35rem;
  font-weight: 400;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: center;
}

.world-score.is-positive {
  color: var(--world-positive);
}

.world-score.is-negative {
  color: var(--world-negative);
}

.world-expand {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .4rem;
  width: 100%;
  margin-top: .9rem;
  padding: .5rem;
  border: 0;
  border-top: 1px solid var(--color-border-soft);
  color: var(--color-muted);
  background: transparent;
  cursor: pointer;
  font-size: .85rem;
}

.world-expand svg {
  width: 1rem;
  height: 1rem;
}

.world-expand[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.world-expand:hover {
  color: var(--color-primary);
}

.world-preview {
  overflow: hidden;
}

.world-preview img {
  max-height: 24rem;
  width: auto;
  object-fit: contain;
}

.world-post .way-block-title,
.world-comment-author {
  overflow-wrap: anywhere;
}

.world-post .way-content pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.world-post-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  margin: .65rem calc(-1 * var(--post-padding)) calc(-1 * var(--post-padding));
  padding: .55rem var(--post-padding);
  border-top: 1px solid var(--color-border-soft);
}

/* Explicit columns keep the rating centered even when Save is absent. */
.world-post-footer > .world-comments-toggle {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
}

.world-post-footer > .world-save {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  margin-left: 0;
}

.world-comments-toggle {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  min-height: 2rem;
  padding: .2rem 0;
  border: 0;
  background: transparent;
  color: var(--color-muted);
  font-size: 1rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.world-comments-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

.world-comments-toggle:hover,
.world-comments-toggle[aria-expanded="true"] {
  color: var(--color-primary);
}

.world-discussion {
  margin: 1.3rem 0 1rem calc(var(--rating-width) + var(--rating-gap));
}

.world-text-button {
  padding: .25rem 0;
  min-height: 1.8rem;
  border: 0;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  text-align: left;
  font-size: .9rem;
}

.world-text-button:hover {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: .15rem;
}

.world-text-button:disabled {
  opacity: .6;
  cursor: wait;
}

.world-reply-button,
.world-show-branch {
  color: var(--world-positive);
}

.world-show-branch {
  margin-top: .55rem;
}

.world-composer {
  display: grid;
  gap: .6rem;
  margin: 1rem 0;
}

.world-composer label {
  display: grid;
  gap: .45rem;
  font-size: .9rem;
}

.world-composer textarea {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 5rem;
  max-height: 20rem;
  resize: vertical;
  padding: .65rem;
  border: 1px solid var(--color-border);
  border-radius: .35rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
}

.world-composer .btn {
  justify-self: start;
}

.world-message,
.world-login-note {
  text-indent: 0;
  font-size: .85rem;
  color: var(--color-muted);
  margin: .4rem 0;
  overflow-wrap: anywhere;
}

.world-message:empty {
  display: none;
}

.world-comment-items {
  display: grid;
  gap: 1.25rem;
}

.world-comment {
  position: relative;
  min-width: 0;
  padding-left: 1.3rem;
}

.world-comment-box {
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.world-comment-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: .55rem;
  row-gap: .15rem;
}

.world-comment-header time {
  flex: 0 1 auto;
  font-size: .85rem;
}

.world-comment-author {
  font-size: .95rem;
}

.world-comment-avatar {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  color: var(--color-primary);
  background: var(--color-avatar-bg);
  font-size: .8rem;
}

.world-votes-inline {
  flex-direction: row;
  gap: .15rem;
  margin-right: .25rem;
}

.world-votes-inline .world-score {
  font-size: 1.1rem;
}

.world-votes-inline .world-vote {
  width: 1.6rem;
  height: 1.8rem;
}

.world-votes-inline .world-vote svg {
  width: 1rem;
  height: 1rem;
}

.world-comment-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-indent: 0;
  text-align: left;
  line-height: 1.6;
  margin: .6rem 0 .35rem;
}

.world-comment-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: .2rem;
}

.world-edit-button:disabled {
  cursor: not-allowed;
}

.world-delete-button:hover {
  color: var(--world-negative);
}

.world-comment-lock,
.world-comment-edited {
  color: var(--color-muted);
  font-size: .85rem;
}

.world-comment.is-deleted>.world-comment-box>.world-comment-body>.world-comment-text {
  color: var(--color-muted);
  font-style: italic;
}

.world-comment-editor[hidden] {
  display: none;
}

.world-branch-toggle {
  position: absolute;
  top: .25rem;
  left: 0;
  display: grid;
  place-items: center;
  width: .9rem;
  height: .9rem;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: .15rem;
  background: var(--color-page-bg);
  color: var(--color-muted);
  font-size: .8rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.world-branch-toggle:hover {
  color: var(--color-primary);
  border-color: var(--color-muted);
}

.world-inline-maker {
  display: inline-grid;
  place-items: center;
  background: #326949;
  color: #fff;
  border-radius: 50%;
  font-size: .6rem;
  width: 1rem;
  height: 1rem;
}

/* A vertical guide and a curved connector show each reply's parent. */
.world-comment-body>.world-comment-list {
  margin: .6rem 0 0 .45rem;
  padding: .1rem 0 .3rem 1.35rem;
  border-left: 1px solid var(--color-border);
}

.world-comment-list .world-comment-list>.world-comment-items>.world-comment {
  padding-left: .4rem;
}

.world-comment-list .world-comment-list>.world-comment-items>.world-comment::before {
  content: "";
  position: absolute;
  left: -1.35rem;
  top: -.1rem;
  width: 1.35rem;
  height: 1rem;
  border-left: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  border-bottom-left-radius: .7rem;
  pointer-events: none;
}

.world-comment-list .world-comment-list>.world-comment-items>.world-comment>.world-branch-toggle {
  left: -1.82rem;
}

/* At depth four, stop adding indentation; each branch still folds independently. */
.world-comment-deep>.world-comment-box>.world-comment-body>.world-comment-list {
  margin-left: -.4rem;
  padding-left: 0;
  border-left: 0;
}

.world-comment-deep>.world-comment-box>.world-comment-body>.world-comment-list>.world-comment-items>.world-comment::before {
  display: none;
}

.world-comment-deep>.world-comment-box>.world-comment-body>.world-comment-list>.world-comment-items>.world-comment>.world-branch-toggle {
  left: -1rem;
}

@media (max-width: 840px) {
  .world-post {
    --rating-width: 2.15rem;
    --rating-gap: .3rem;
  }

  .world-post-box {
    --post-padding: .65rem;
  }

  .world-votes-post .world-score {
    font-size: 1rem;
  }

  .world-votes-post .world-vote {
    height: 1.7rem;
  }

  .world-votes-post .world-vote svg {
    width: .9rem;
    height: .9rem;
  }

  .world-discussion {
    margin-left: 0;
  }

  .world-comment {
    padding-left: 1.15rem;
  }

  .world-comment-header {
    column-gap: .4rem;
  }

  .world-comment-header time {
    font-size: .8rem;
  }

  .world-comment-avatar {
    display: none;
  }

  .world-votes-inline .world-score {
    font-size: 1rem;
  }

  .world-comment-mobile-deep>.world-comment-box>.world-comment-body>.world-comment-list {
    margin-left: -.4rem;
    padding-left: 0;
    border-left: 0;
  }

  .world-comment-mobile-deep>.world-comment-box>.world-comment-body>.world-comment-list>.world-comment-items>.world-comment::before {
    display: none;
  }

  .world-comment-mobile-deep>.world-comment-box>.world-comment-body>.world-comment-list>.world-comment-items>.world-comment>.world-branch-toggle {
    left: -1rem;
  }

  .world-audience {
    margin-left: 0;
  }
}

/* Articles reuse the My Way editor, cards, column widths and global scale. */
.article-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  margin-bottom: 1rem;
}

.article-import {
  display: grid;
  gap: 17.28px;
  margin-block: 23.04px;
}

.article-import-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 17.28px;
  max-width: 950px;
}

.article-import-row input {
  flex: 1 1 300px;
  width: auto;
}

.article-import-message:empty {
  display: none;
}

.article-import-message,
.article-source {
  overflow-wrap: anywhere;
}

.article-source {
  color: var(--color-muted);
  font-size: .9em;
}

/* Save uses the same quiet icon treatment as the comment control. */
.world-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  margin-left: auto;
  padding: .35rem;
  border: 0;
  border-radius: .2rem;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
}

.world-save svg {
  width: 1.25rem;
  height: 1.25rem;
}

.world-save:hover:not(:disabled) {
  color: var(--color-primary);
}

.world-save.is-saved {
  color: var(--world-positive);
}

.world-save:disabled {
  opacity: 1;
  cursor: default;
}

.world-save[aria-busy="true"] {
  opacity: .55;
  cursor: wait;
}

.search-fields {
  display: grid;
  gap: 23.04px;
  min-width: 0;
}

.search-toggle {
  display: none;
  text-align: left;
  width: 100%;
}

@media (max-width: 1296px) {
  .search-toggle:not([hidden]) {
    display: block;
  }

  /* Avoid a flash of expanded fields before the disclosure script runs. */
  .search-toggle[aria-expanded="false"]+.search-fields {
    display: none;
  }

  #way-page>.memo-filters {
    padding: 12px;
  }
}

/* Shared search layout and full-width centered result counters. */
.memo-filter-message {
  width: 100%;
  text-align: center;
}

.world-sort {
  display: flex;
  gap: 11.52px;
}

.world-sort .btn {
  flex: 1;
}

.world-sort .btn[aria-pressed="true"] {
  background: var(--color-soft-hover);
}

/* Videos, phase 1. Uses the portal's existing spacing, theme and body zoom.
   Card columns: 4 desktop, 3 small desktop, 2 tablet, 1 phone. */
.videos-page,
.videos-dialog {
  text-align: left;
  font-family: Arial, sans-serif;
  font-size: .78rem;
}

.videos-page *,
.videos-dialog * {
  box-sizing: border-box;
}

.videos-page [hidden],
.videos-dialog [hidden] {
  display: none !important;
}

.videos-page p,
.videos-dialog p {
  text-indent: 0;
  margin: 0;
}

.videos-page button,
.videos-page input,
.videos-dialog button,
.videos-dialog input,
.videos-dialog select {
  font: inherit;
}

.videos-page button,
.videos-dialog button {
  -webkit-tap-highlight-color: transparent;
}

.videos-page button:disabled,
.videos-dialog button:disabled {
  opacity: .45;
  cursor: default;
}

.videos-toolbar {
  display: flex;
  align-items: flex-start;
  gap: var(--portal-spacing);
  min-width: 0;
}

.videos-category-bar {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: .4rem;
  overflow-x: auto;
  padding: 4px 4px 10px;
  margin: -4px -4px -10px;
  scrollbar-width: thin;
}

.videos-categories,
.videos-category-form {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex: 0 0 auto;
}

.videos-chip {
  flex: 0 0 auto;
  min-height: 40.32px;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: .3rem .65rem;
  border: 0;
  border-radius: 7.2px;
  background: var(--color-bg-light);
  color: var(--color-primary);
  font-weight: 600 !important;
  white-space: nowrap;
  cursor: pointer;
}

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

.videos-chip[aria-pressed="true"] {
  background: var(--color-primary);
  color: var(--color-page-bg);
}

.videos-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40.32px;
  height: 40.32px;
  flex: 0 0 40.32px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: var(--color-bg-light);
  color: var(--color-primary);
  font-size: 1.15rem !important;
  line-height: 1;
  cursor: pointer;
}

.videos-icon-button:hover {
  background: var(--color-soft-hover);
}

.videos-page input,
.videos-dialog input:not([type="radio"]),
.videos-dialog select {
  width: 100%;
  min-width: 0;
  min-height: 40.32px;
  padding: .4rem .55rem;
  border: 1px solid var(--color-border);
  border-radius: 7.2px;
  background: var(--color-surface);
}

.videos-page .videos-category-form input {
  width: 9rem;
}

.videos-search {
  flex: 0 1 12rem;
  min-width: 7rem;
}

.videos-search input {
  border-radius: 1.5rem;
}

.videos-page .btn,
.videos-dialog .btn {
  height: auto;
  min-height: 40.32px;
  padding: .35rem .7rem;
  font-size: inherit;
  background: var(--color-bg-light);
  color: var(--color-primary);
}

.videos-page .btn:hover,
.videos-dialog .btn:hover {
  background: var(--color-soft-hover);
}

.videos-dialog .btn[type="submit"] {
  background: var(--color-primary);
  color: var(--color-page-bg);
}

.videos-collection-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem;
  margin: .65rem 0 var(--portal-spacing);
}

.videos-note {
  color: var(--color-muted);
  font-size: .67rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.videos-status {
  color: var(--color-muted);
  font-size: .7rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.videos-status:empty {
  display: none;
}

.videos-page .videos-status:not(:empty) {
  margin: 0 0 .7rem;
}

.videos-status.is-error {
  color: var(--color-error);
}

.videos-text-button {
  background: transparent;
  border: 0;
  padding: .2rem 0;
  color: var(--color-muted);
  font-size: .67rem !important;
  min-height: 32px;
  cursor: pointer;
  text-align: left;
}

.videos-text-button:hover {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.videos-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: var(--portal-spacing);
  row-gap: calc(var(--portal-spacing) * 1.25);
  align-items: start;
}

.videos-card {
  min-width: 0;
  position: relative;
}

.videos-card-open,
.videos-add-card {
  display: block;
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--color-primary);
  text-align: left;
  cursor: pointer;
}

.videos-thumbnail,
.videos-add-preview {
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12.96px;
  overflow: hidden;
  background: var(--color-bg-light);
}

.videos-thumbnail img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.videos-thumbnail-fallback {
  color: var(--color-muted);
  font-size: 1.8rem;
}

.videos-card-open:hover .videos-thumbnail {
  outline: 1px solid var(--color-border);
  outline-offset: -1px;
}

.videos-card-open:hover .videos-card-title {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.videos-source-badge {
  position: absolute;
  right: .35rem;
  bottom: .35rem;
  max-width: calc(100% - .7rem);
  padding: .12rem .28rem;
  border-radius: 4px;
  color: #fff;
  background: rgba(0, 0, 0, .8);
  font-size: .52rem;
  line-height: 1.3;
}

.videos-card-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: .5rem 0 .15rem;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.videos-card-bottom {
  display: flex;
  align-items: flex-start;
  gap: .3rem;
}

.videos-card-meta {
  flex: 1 1 auto;
  color: var(--color-muted);
  font-size: .62rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.videos-card-edit {
  background: transparent;
  margin-top: -.3rem;
}

.videos-add-preview {
  border: 1.5px dashed var(--color-border);
  background: transparent;
}

.videos-add-preview>span {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: var(--color-bg-light);
  font-size: 1.7rem;
  font-weight: 400;
}

.videos-add-card:hover .videos-add-preview {
  border-color: var(--color-primary);
  background: var(--color-bg-light);
}

.videos-add-card:hover .videos-add-preview>span {
  background: var(--color-soft-hover);
}

.videos-add-label {
  display: block;
  margin: .5rem 0 .15rem;
  font-weight: 600;
}

.videos-add-card>.videos-note {
  display: block;
}

.videos-page #videos-empty {
  margin-top: var(--portal-spacing);
}

.videos-dialog {
  box-sizing: border-box;
  width: min(740px, calc(100% - 2 * var(--portal-spacing)));
  max-width: none;
  max-height: calc(100% - 2 * var(--portal-spacing));
  margin: auto;
  padding: 0;
  border: 1px solid var(--color-border-soft);
  border-radius: 17.28px;
  color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 20px 80px #0004;
}

.videos-dialog::backdrop {
  background: rgba(0, 0, 0, .6);
}

body:has(.videos-dialog[open]) {
  overflow: hidden;
}

.videos-dialog-shell {
  padding: var(--portal-spacing);
}

.videos-dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  margin-bottom: .8rem;
}

.videos-dialog-heading h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.videos-dialog form,
.videos-dialog form>label {
  display: grid;
  gap: .3rem;
}

.videos-dialog form {
  gap: .65rem;
}

.videos-dialog input[type="file"] {
  font-size: .65rem;
}

.videos-source-options {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.videos-source-options legend {
  margin-bottom: .3rem;
}

.videos-source-options label {
  display: flex;
  align-items: center;
  gap: .25rem;
  min-height: 40.32px;
  padding: .25rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: 7.2px;
  cursor: pointer;
}

.videos-source-options label:has(:checked) {
  background: var(--color-soft-hover);
  border-color: var(--color-primary);
}

.videos-source-options input {
  margin: 0;
  accent-color: var(--color-primary);
}

.videos-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .4rem;
}

.videos-remove-video,
#videos-category-delete {
  margin-right: auto;
}

.videos-small-dialog {
  width: min(580px, calc(100% - 2 * var(--portal-spacing)));
}

.videos-player-dialog {
  width: min(1200px, calc(100% - 2 * var(--portal-spacing)));
}

.videos-player-media {
  background: var(--color-bg-light);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: .6rem;
}

.videos-player-media video,
.videos-player-media iframe {
  display: block;
  border: 0;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 65vh;
  background: #000;
}

.videos-player-placeholder {
  display: grid;
  place-items: center;
  min-height: 7rem;
  padding: 1rem;
  text-align: center;
  color: var(--color-muted);
}

.videos-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1500px) {
  .videos-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1000px) {
  .videos-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 864px) {
  .videos-toolbar {
    flex-direction: column;
    gap: .6rem;
  }

  .videos-category-bar {
    width: 100%;
  }

  .videos-search {
    flex: auto;
    width: 100%;
  }
}

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

.videos-relay-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .6rem;
  margin-block: .6rem;
}

.videos-relay-controls:empty {
  display: none;
}

.videos-relay-controls label {
  flex: 1 1 240px;
  display: grid;
  gap: .2rem;
  font-size: .67rem;
}

.videos-relay-controls input[type="range"] {
  padding: 0;
  border: 0;
  accent-color: var(--color-primary);
}

.videos-relay-controls span {
  font-variant-numeric: tabular-nums;
  color: var(--color-muted);
}

/* Videos peer sharing follows the existing portal spacing and theme controls. */
.videos-sharing-panel {
  margin-bottom: var(--portal-spacing);
  padding: .7rem;
  border: 1px solid var(--color-border-soft);
  border-radius: 12px;
  background: var(--color-surface);
}

.videos-sharing-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
}

.videos-sharing-heading h2 {
  margin: 0;
  font-size: .85rem;
}

.videos-transfer-row {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  padding-top: .7rem;
  margin-top: .7rem;
  border-top: 1px solid var(--color-border-soft);
}

.videos-transfer-info {
  flex: 1 1 300px;
  min-width: 0;
}

.videos-transfer-info strong {
  display: block;
  font-size: .72rem;
  overflow-wrap: anywhere;
}

.videos-transfer-info progress {
  width: 100%;
  height: .3rem;
  accent-color: var(--color-primary);
}

.videos-transfer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
}

.videos-torrent-controls {
  display: grid;
  gap: .35rem;
  margin-block: .6rem;
}

.videos-torrent-controls label {
  display: grid;
  gap: .2rem;
  font-size: .67rem;
}

.videos-torrent-controls select {
  min-width: 0;
  width: 100%;
}

.videos-torrent-controls[hidden],
.videos-sharing-panel[hidden] {
  display: none;
}

/* Video library, retained copies and inline post videos. */
.video-library-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: var(--content-gap, 1.25rem);
}

.video-library-tabs [aria-pressed="true"] {
  background: var(--text-color, #ddd);
  color: var(--bg-color, #171d1d);
}

#videos-shared .videos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 1.4rem;
}

.video-editor-preview {
  width: min(100%, 320px);
  aspect-ratio: 16/9;
  object-fit: contain;
  border-radius: .6rem;
}

.video-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .8rem;
  max-height: 55vh;
  overflow: auto;
  margin-top: 1rem;
}

.video-picker-card {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  text-align: left;
  padding: .6rem;
  color: inherit;
  background: var(--button-bg, #293033);
  border: 1px solid #7774;
  border-radius: .7rem;
  cursor: pointer;
}

.video-picker-card img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: .4rem;
}

#video-cache-dialog {
  padding: 1.25rem;
}

.video-cache-list {
  max-height: 50vh;
  overflow: auto;
}

.videos-dialog>.videos-dialog-heading,
.videos-dialog>div:not(.videos-dialog-shell),
.videos-dialog>p {
  margin: 1rem;
}

a[data-video-ref] {
  display: inline-flex;
  flex-direction: column;
  gap: .4rem;
  width: min(100%, 480px);
  margin: .7rem 0;
  padding: .6rem;
  border: 1px solid #7775;
  border-radius: .65rem;
  text-decoration: none;
  cursor: pointer;
}

a[data-video-ref] img {
  width: 100%;
  max-height: 270px;
  aspect-ratio: 16/9;
  object-fit: contain;
  margin: 0;
}

.library-inline-player {
  width: 100%;
  padding: .6rem 0;
}

.library-inline-player video,
.library-inline-player iframe {
  display: block;
  width: min(100%, 800px);
  aspect-ratio: 16/9;
  max-height: 70vh;
  border: 0;
  border-radius: .6rem;
  background: #080b0b;
}

.video-cache-list .videos-transfer-row {
  gap: .75rem;
}

@media (max-width: 600px) {
  .video-library-tabs {
    gap: .4rem;
  }

  .video-picker-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Mobile post ratings share the same vote state as the desktop control. */
.world-votes-mobile-top,
.world-votes-mobile-bottom {
  display: none;
}

@media (max-width: 840px) {
  .world-post-main {
    display: block;
  }

  .world-post-main>.world-votes-post {
    display: none;
  }

  .world-post-author-row {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
  }

  .world-post-author-row>.world-author {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .world-votes-mobile-top {
    display: flex;
    position: static;
    flex: 0 0 auto;
    margin-left: auto;
  }

  .world-votes-mobile-bottom {
    display: flex;
    position: static;
    flex-direction: row;
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    margin: 0;
    padding: 0;
  }

  .world-votes-mobile-bottom .world-vote {
    font-size: 1.4rem;
  }

  .world-post-footer {
    gap: .25rem;
  }
}

/* ===== Chat: layout and typography ===== */
/* Chat is isolated from the other portal pages; shared theme and spacing remain authoritative. */
.chat-page { margin: var(--portal-spacing) auto; max-width: var(--way-layout-max-width); padding: 0 var(--portal-page-inset); text-align: left; font: calc(16px * var(--chat-font-scale))/1.45 Arial, sans-serif; }
.chat-page *, .chat-dialog * { box-sizing: border-box; }
.chat-page [hidden], .chat-dialog [hidden] { display: none !important; }
.chat-app { display: grid; grid-template-columns: minmax(250px, 30%) minmax(0, 1fr); border: 1px solid var(--color-border); border-radius: 14px; overflow: hidden; height: 70vh; min-height: 430px; background: var(--color-surface); }
.chat-sidebar { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--color-border-soft); }
.chat-sidebar-heading, .chat-thread-heading, .chat-dialog-heading, .chat-picker-heading { display: flex; align-items: center; gap: 12px; padding: 18px; }
.chat-sidebar-heading { justify-content: space-between; }
.chat-page h2, .chat-dialog h2 { font-size: calc(19px * var(--chat-font-scale)); line-height: 1.35; margin: 0; }
.chat-page small, .chat-dialog small { color: var(--color-muted); line-height: 1.45; }
.chat-page button, .chat-dialog button { cursor: pointer; font: inherit; }
.chat-page button:disabled, .chat-dialog button:disabled { cursor: not-allowed; opacity: .5; }
.chat-page button:focus-visible, .chat-dialog button:focus-visible, .chat-page input:focus-visible, .chat-page textarea:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.chat-icon { display: inline-grid; place-items: center; min-width: 40px; height: 40px; padding: 4px; font-size: calc(24px * var(--chat-font-scale)) !important; border: 0; border-radius: 9px; color: var(--color-primary); background: transparent; flex-shrink: 0; }
.chat-icon:hover, .chat-secondary:hover { background: var(--color-soft-hover); }
.chat-secondary { padding: 9px 12px; border: 1px solid var(--color-border); border-radius: 8px; color: var(--color-primary); background: var(--color-surface); }
.chat-page .btn, .chat-dialog .btn { padding: 10px 14px; border: 0; border-radius: 8px; background: var(--color-control-bg); color: var(--color-text-light); }
.chat-toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 14px; }
.chat-search { display: block; margin: 0 16px 14px; }
.chat-page input[type=search], .chat-dialog input:not([type=checkbox]), .chat-dialog select, .chat-dialog textarea { width: 100%; border: 1px solid var(--color-border); padding: 11px 12px; border-radius: 8px; font: inherit; }
.chat-rooms { flex: 1; min-height: 0; overflow: auto; padding: 4px 8px; }
.chat-room { width: 100%; border: 0; border-radius: 9px; background: transparent; color: inherit; display: flex; align-items: center; text-align: left; gap: 12px; padding: 13px 10px; margin-bottom: 3px; }
.chat-room:hover { background: var(--color-bg-light); }
.chat-room[aria-current=true] { background: var(--color-soft-hover); }
.chat-avatar { background: var(--color-avatar-bg); display: grid; place-items: center; border-radius: 50%; width: 42px; height: 42px; flex-shrink: 0; font-size: calc(18px * var(--chat-font-scale)); font-weight: bold; }
.chat-room-copy, .chat-heading-copy { min-width: 0; flex: 1; }
.chat-room-copy strong, .chat-room-copy small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-room-copy small { margin-top: 5px; font-size: calc(12px * var(--chat-font-scale)); }
.chat-badge { border-radius: 16px; min-width: 23px; padding: 3px 6px; background: var(--color-control-bg); color: var(--color-text-light); font-size: calc(12px * var(--chat-font-scale)); text-align: center; }
.chat-connection { margin: 0; padding: 12px 18px; font-size: calc(12px * var(--chat-font-scale)); color: var(--color-muted); border-top: 1px solid var(--color-border-soft); }
.chat-invitations { flex-shrink: 0; max-height: 28%; overflow: auto; }
.chat-invitation { margin: 0 12px 10px; padding: 12px; border: 1px solid var(--color-border); border-radius: 9px; }
.chat-invitation p { margin: 0 0 10px; font-size: calc(13px * var(--chat-font-scale)); overflow-wrap: anywhere; }
.chat-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chat-conversation, .chat-thread { min-width: 0; min-height: 0; position: relative; height: 100%; }
.chat-thread { display: flex; flex-direction: column; }
.chat-thread-heading { border-bottom: 1px solid var(--color-border-soft); flex-shrink: 0; padding: 13px 20px; }
.chat-heading-copy h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: calc(17px * var(--chat-font-scale)); }
.chat-back { display: none; }
.chat-empty, .chat-gate { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; height: 100%; gap: 12px; padding: 24px; }
.chat-gate { min-height: 320px; border: 1px solid var(--color-border-soft); border-radius: 14px; }
.chat-empty-symbol { font-size: calc(55px * var(--chat-font-scale)); color: var(--color-muted); }
.chat-empty p { line-height: 1.75; color: var(--color-muted); margin: 0 0 12px; }
.chat-history { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 22px; background: var(--color-bg-light); }
.chat-older { display: block; margin: 0 auto 15px; font-size: calc(12px * var(--chat-font-scale)) !important; }
#chat-messages { display: flex; flex-direction: column; gap: 10px; }
.chat-message { max-width: 80%; align-self: flex-start; padding: 10px 14px 7px; border: 1px solid var(--color-border-soft); border-radius: 13px 13px 13px 3px; background: var(--color-surface); overflow-wrap: anywhere; }
.chat-message.is-mine { align-self: flex-end; border-radius: 13px 13px 3px 13px; background: var(--color-soft-hover); }
.chat-message-author { display: block; font-size: calc(12px * var(--chat-font-scale)); font-weight: bold; color: var(--color-link); margin-bottom: 5px; }
.chat-message-body { white-space: pre-wrap; line-height: 1.55; font-size: calc(15px * var(--chat-font-scale)); }
.chat-message time { display: block; text-align: right; color: var(--color-muted); font-size: calc(10px * var(--chat-font-scale)); margin-top: 5px; }
.chat-date { text-align: center; font-size: calc(12px * var(--chat-font-scale)); color: var(--color-muted); padding: 10px 0; }
.chat-compose { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 14px 5px; }
#chat-emoji-toggle { display: grid; place-items: center; padding: 0; line-height: 0; }
#chat-emoji-toggle .chat-smiley, #chat-emoji-toggle svg { display: block; }
.chat-compose-label { flex: 1; min-width: 0; }
.chat-compose textarea { display: block; resize: none; width: 100%; min-height: 42px; max-height: 130px; padding: 11px 12px; border: 1px solid var(--color-border); border-radius: 9px; font: calc(15px * var(--chat-font-scale))/1.4 Arial, sans-serif; }
.chat-compose-hint { padding: 0 16px 9px; text-align: center; font-size: calc(10px * var(--chat-font-scale)); }
.chat-thread-note { margin: 0; padding: 0 18px; font-size: calc(12px * var(--chat-font-scale)); color: var(--color-muted); }
.chat-thread-note:not(:empty) { padding-top: 10px; }
.chat-new-below { position: absolute; bottom: 105px; right: 22px; border: 1px solid var(--color-border); background: var(--color-surface); color: inherit; border-radius: 18px; padding: 8px 14px; }
.chat-emoji-picker { position: absolute; bottom: 96px; left: 14px; width: min(355px, calc(100% - 28px)); max-height: 65%; overflow: auto; padding: 10px; z-index: 3; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px; box-shadow: 0 8px 30px #0002; }
.chat-picker-heading { padding: 0 0 6px; justify-content: space-between; font-size: calc(12px * var(--chat-font-scale)); gap: 6px; }
.chat-picker-heading label { display: flex; align-items: center; gap: 4px; }
.chat-emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.chat-emoji-choice { border: 0; border-radius: 8px; background: transparent; height: 46px; display: grid; place-items: center; }
.chat-emoji-choice:hover { background: var(--color-bg-light); }
.chat-smiley { width: 30px; height: 30px; display: inline-block; vertical-align: middle; }
.chat-emoji-choice .chat-smiley { width: 36px; height: 36px; }
.chat-message.only-smileys .chat-smiley { width: 54px; height: 54px; }
.chat-error { color: var(--color-error); font-size: calc(13px * var(--chat-font-scale)); margin: 10px 0 0; }
.chat-error:empty { display: none; }
.chat-dialog { width: min(470px, calc(100% - 24px)); max-height: 85vh; border: 1px solid var(--color-border); border-radius: 14px; padding: 20px; font: calc(14px * var(--chat-font-scale))/1.5 Arial, sans-serif; }
.chat-dialog::backdrop { background: #0006; }
.chat-dialog-heading { padding: 0 0 16px; justify-content: space-between; }
.chat-dialog form { display: grid; gap: 14px; }
.chat-dialog label { display: grid; gap: 6px; }
.chat-dialog p { color: var(--color-muted); }
.chat-member { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--color-border-soft); }
.chat-member span { overflow-wrap: anywhere; }
.chat-member small { display: block; }
.chat-results { margin: 14px 0; }
.chat-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 700px) {
  .chat-app { grid-template-columns: 1fr; min-height: 480px; }
  .chat-conversation { display: none; }
  .chat-app.has-thread .chat-sidebar { display: none; }
  .chat-app.has-thread .chat-conversation { display: block; }
  .chat-sidebar { border: 0; }
  .chat-back { display: inline-grid; }
  .chat-thread-heading { padding: 10px; gap: 8px; }
  .chat-history { padding: 14px 10px; }
  .chat-message { max-width: 90%; }
  .chat-compose { padding-left: 8px; padding-right: 8px; }
  .chat-compose-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { .chat-smiley * { animation: none !important; } }
.chat-no-animation .chat-smiley * { animation: none !important; }
.smiley-blink { transform-origin: center 24px; animation: chat-blink 4.5s infinite; }
.smiley-laugh { transform-origin: center; animation: chat-laugh 1.3s ease-in-out infinite; }
.smiley-heart { animation: chat-heart 1.8s ease-in-out infinite; }
.smiley-tear { animation: chat-tear 1.7s ease-in infinite; }
.smiley-tongue { animation: chat-heart 2s ease-in-out infinite; }
.smiley-halo { animation: chat-heart 3s ease-in-out infinite; }
@keyframes chat-blink { 0%, 90%, 100% { transform: scaleY(1); } 94% { transform: scaleY(.1); } }
@keyframes chat-laugh { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-2px) rotate(3deg); } }
@keyframes chat-heart { 0%, 100% { opacity: 1; } 50% { opacity: .65; } }
@keyframes chat-tear { 0% { transform: translateY(-3px); opacity: 0; } 35% { opacity: 1; } 100% { transform: translateY(8px); opacity: 0; } }


@media (max-width: 700px) {
  /* Reuse the menu's typeface and size; only secondary text is smaller. */
  .chat-page { margin-bottom: 0; }
  .chat-page, .chat-dialog { font-family: inherit; font-size: 1rem; }
  .chat-page h2, .chat-dialog h2, .chat-dialog h3,
  .chat-message-body, .chat-avatar, .chat-invitation p, .chat-error { font-size: 1rem; }
  .chat-compose textarea { font-family: inherit; font-size: 1rem; }
  .chat-page small, .chat-dialog small, .chat-message-author,
  .chat-room-copy small, .chat-connection, .chat-message time,
  .chat-badge, .chat-date, .chat-thread-note, .chat-picker-heading { font-size: .8rem; }
  .chat-older { font-size: .8rem !important; }
  .chat-page button { min-height: 60px; }
  .chat-page .chat-icon { min-width: 56px; }
  .chat-emoji-choice { min-height: 48px !important; }
  .chat-message { padding: 12px 15px 8px; }
  .chat-compose { padding-bottom: 10px; }
}
.chat-dialog h2, .chat-dialog p { overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .chat-dialog button { min-height: 60px; }
}
.chat-settings-image { display: block; width: 30px; height: 30px; }
.chat-smiley > svg { width: 100%; height: 100%; }
.chat-pack-smiley { width: auto; max-width: 96px; height: 34px; }
.chat-pack-smiley img, .chat-pack-smiley canvas { width: auto; max-width: 100%; height: 100%; object-fit: contain; vertical-align: middle; }
.chat-pack-smiley canvas { display: none; }
.chat-emoji-choice .chat-pack-smiley { max-width: 100%; width: 100%; height: 36px; }
.chat-emoji-choice .chat-pack-smiley img, .chat-emoji-choice .chat-pack-smiley canvas { width: 100%; }
.chat-message.only-smileys .chat-pack-smiley { width: auto; max-width: 160px; height: 54px; }
.chat-no-animation .chat-pack-smiley img { display: none; }
.chat-no-animation .chat-pack-smiley canvas { display: inline; }
@media (prefers-reduced-motion: reduce) {
  .chat-pack-smiley img { display: none; }
  .chat-pack-smiley canvas { display: inline; }
}
