.profile-menu {
  position: fixed;
  z-index: 100;
  width: min(280px, calc(100vw - 24px));
  padding: 8px;
  color: var(--color-text);
}
.profile-menu[hidden], .profile-menu-action[hidden] { display: none; }
.profile-menu-label {
  margin: 0;
  padding: 8px 12px;
  font: var(--type-caption-size)/var(--type-caption-line) var(--font-body);
  color: var(--color-text-secondary);
}
.profile-menu-action {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: var(--type-body-size)/var(--type-body-line) var(--font-body);
  cursor: pointer;
}
.profile-menu-action:hover { background: var(--color-background); }
.profile-menu-action:focus-visible { outline: var(--focus-ring); outline-offset: -2px; }
.profile-menu-action:disabled { opacity: .48; cursor: wait; }
.profile-menu-action svg {
  width: 20px;
  height: 20px;
}
.profile-menu-action svg:not(.rm-icon) {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.profile-menu-action svg.rm-icon {
  fill: currentColor;
  stroke: none;
}
@media (max-width: 1199px) {
  .topbar > .profile-menu-slot,
  .topbar-actions > .profile-menu-slot {
    display: none;
  }

  .compact-home-actions .profile-menu-slot,
  .compact-library-panel .profile-menu-slot,
  .compact-history-panel .profile-menu-slot {
    display: block;
  }

  .compact-home-actions #profile-menu-trigger,
  .compact-library-panel #profile-menu-trigger,
  .compact-history-panel #profile-menu-trigger,
  .compact-home-actions #capture-global-trigger,
  .compact-library-panel #capture-global-trigger,
  .compact-history-panel #capture-global-trigger {
    display: inline-grid;
    place-items: center;
    padding: 0;
  }
  .home-sheet-handle-row .profile-menu-slot {
    display: none !important;
  }
}

#profile-view.is-active {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  padding-bottom: 100px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (min-width: 1200px) {
  /* Compact settings column — about 40% of a typical desktop content rail. */
  #profile-view.is-active {
    max-width: 560px;
  }
}
.profile-page-header { margin-bottom: 0; }
@media (max-width: 1199px) {
  #profile-view .history-back {
    width: 44px;
    height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-round);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-selected);
    font-size: 0;
  }
  #profile-view .history-back span { display: none; }
  #profile-view .history-back svg {
    width: var(--ds-icon-glyph-size, 22px);
    height: var(--ds-icon-glyph-size, 22px);
  }
}

#profile-view > .hist-panel {
  margin: 0;
  padding: 20px;
  display: grid;
  gap: 14px;
  align-content: start;
  /* Own surface: history-page.css loads only on the history route. */
  background: var(--color-surface);
  border: 0;
  border-radius: var(--radius-panel);
}
#profile-view > .hist-panel[hidden],
#profile-view .reader-profile-tools[hidden] {
  display: none;
}
#profile-view > .hist-panel > .hist-panel-title,
#profile-view .reader-profile-tools > .hist-panel-title,
#profile-view #profile-backups > .hist-panel-title {
  margin: 0;
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 24px;
  font-weight: var(--weight-semibold);
}
#profile-view > #profile-logout {
  width: fit-content;
  align-self: start;
  padding-inline: 32px;
  border-radius: var(--radius-pill);
  background: var(--color-text);
  color: var(--color-surface);
}

#profile-view > #profile-logout:hover {
  background: #303030;
}

#profile-logout .rm-icon {
  color: inherit;
  fill: currentColor;
  stroke: none;
}

.profile-sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.profile-sync-row[hidden] {
  display: none;
}
.profile-sync-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}
.profile-sync-title {
  font: var(--weight-medium, 500) var(--type-body-size)/var(--type-body-line) var(--font-body);
  color: var(--color-text);
}
.profile-sync-note,
.profile-sync-status {
  margin: 0;
  font: var(--type-caption-size)/var(--type-caption-line) var(--font-body);
  color: var(--color-text-secondary);
}
.profile-sync-switch {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  cursor: pointer;
}
.profile-sync-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.profile-sync-track {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #e5e5e5;
  box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.04);
  transition: background .18s ease;
  pointer-events: none;
}
.profile-sync-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(17, 17, 17, 0.18);
  transition: transform .18s ease;
}
.profile-sync-switch input:checked + .profile-sync-track {
  background: var(--color-text, #111);
}
.profile-sync-switch input:checked + .profile-sync-track::after {
  transform: translateX(20px);
}
.profile-sync-switch input:disabled + .profile-sync-track {
  opacity: .48;
}

.profile-calendar-legend {
  margin: 0;
  font: var(--weight-medium, 500) var(--type-body-size)/var(--type-body-line) var(--font-body);
  color: var(--color-text);
}
.profile-calendar-options {
  display: grid;
  gap: 12px;
}
.profile-calendar-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  cursor: pointer;
}
.profile-calendar-option input {
  margin: 3px 0 0;
  width: 16px;
  height: 16px;
  accent-color: var(--color-text);
  cursor: pointer;
}
.profile-calendar-option-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.profile-calendar-option-title {
  font: var(--weight-medium, 500) var(--type-body-size)/var(--type-body-line) var(--font-body);
  color: var(--color-text);
}
.profile-calendar-option-hint {
  font: var(--type-caption-size)/var(--type-caption-line) var(--font-body);
  color: var(--color-text-secondary);
}

#profile-view .reader-profile-tools { margin: 0; }
.reader-storage-sync {
  margin: 0;
  min-height: 20px;
  font: var(--type-caption-size)/var(--type-caption-line) var(--font-body);
  color: var(--color-text-secondary);
}
.reader-storage-sync[hidden] { display: none; }
.reader-storage-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.reader-storage-metric {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 72px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--color-background, #f5f5f5);
}
.reader-storage-metric-icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  color: var(--color-text-secondary, var(--muted, #737373));
}
.reader-storage-metric-icon svg,
.reader-storage-metric-icon .rm-icon {
  display: block;
  width: 20px;
  height: 20px;
  color: inherit;
  fill: currentColor;
}
.reader-storage-metric-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}
.reader-storage-metric-label {
  font: var(--type-caption-size)/var(--type-caption-line) var(--font-body);
  color: var(--color-text-secondary);
}
.reader-storage-metric-value {
  font: var(--weight-semibold) 16px/22px var(--font-body);
  color: var(--color-text);
  overflow-wrap: anywhere;
}
#profile-view .reader-storage-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 0;
}
#profile-view .reader-storage-tools > :is(button, label) {
  margin: 0;
  min-height: 40px;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--color-background, #f5f5f5);
  color: var(--color-text);
  box-shadow: none;
  font: 500 14px/20px var(--font-body);
  cursor: pointer;
}
#profile-view .reader-storage-tools > :is(button, label):hover {
  background: #ececec;
}
#profile-view .reader-storage-tools > :is(button, label):focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

#profile-backups-host {
  margin: 0;
  overflow-wrap: anywhere;
  display: contents;
}
#profile-view #profile-backups {
  margin: 0;
  padding: 20px;
  display: grid;
  gap: 14px;
  align-content: start;
}
#profile-view #profile-backups > .hist-muted {
  margin: 0;
  color: var(--color-text-secondary);
  font: var(--type-body-size)/var(--type-body-line) var(--font-body);
}
#profile-view #profile-backups > .ds-btn {
  justify-self: start;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 999px;
}
#profile-view #profile-backups > .profile-backup-latest {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font: var(--type-caption-size)/var(--type-caption-line) var(--font-body);
  text-align: left;
  cursor: pointer;
}
#profile-view #profile-backups > .profile-backup-latest:hover {
  color: var(--color-text);
}
#profile-view #profile-backups > .profile-backup-latest:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}
#profile-view #profile-backups > .profile-backup-latest:disabled {
  opacity: .48;
  cursor: wait;
}
#profile-view #profile-backups .hist-backup-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#profile-view #profile-backups .hist-backup-detail {
  display: grid;
  gap: 12px;
}

@media (max-width: 767px) {
  #profile-view.is-active { gap: 12px; }
  #profile-view > .hist-panel,
  #profile-view #profile-backups { padding: 16px; gap: 14px; }
  .reader-storage-metrics { grid-template-columns: 1fr; gap: 10px; }
  .reader-storage-metric { min-height: 0; }
  #profile-view .reader-storage-tools { flex-direction: column; align-items: stretch; }
  #profile-view .reader-storage-tools > :is(button, label) {
    width: 100%;
    justify-content: center;
  }
  #profile-view #profile-backups > .ds-btn { width: 100%; justify-self: stretch; }
}

@media (min-width: 768px) and (max-width: 1199px) {
  #profile-view > .hist-panel,
  #profile-view #profile-backups { padding: 18px; }
  .reader-storage-metrics { gap: 10px; }
}

.demo-mode-note {
  position: fixed;
  inset-block-end: 16px;
  inset-inline-end: 16px;
  z-index: 10;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--color-text);
  color: var(--color-surface);
  font-size: var(--type-caption-size);
  pointer-events: none;
}

html.public-catalog-home .demo-mode-note {
  display: none;
}

@media (max-width: 1199px) {
  .demo-mode-note {
    inset-block-end: calc(76px + env(safe-area-inset-bottom));
  }
}

/* Demo keeps the Читалка opt-in; file uploads and device sync stay off. */
html[data-demo-account] :is(#reader-profile-content, #profile-view .profile-storage, [data-qaction="add-from-file"], [data-qaction="transfer-files"], [data-qaction="poster-upload"], [data-qaction="character-image-upload"]) {
  display: none !important;
}

.demo-save-note {
  margin: 0;
  font-size: var(--type-caption-size);
  color: var(--color-text);
}
