:root {
  --internal-color-error: #d26466;
}

body {
  line-height: 1.5;
}

.main-grid * {
  box-sizing: border-box;
}

.main-grid {
  background: var(--color-background);
  color: var(--color-text);
}

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

#dark-mode-toggle {
  margin-right: 16px;
  line-height: 1;
}

ul,
ol,
li {
  padding: 0;
  margin: 0;
}

side-drawer {
  position: absolute;
  width: 500px;
}

/* Hide side-drawer when JavaScript is disabled */
.no-js side-drawer {
  display: none;
}

/* Hide mobile nav toggle when JavaScript is disabled */
.no-js .mobile-nav .toggle {
  display: none;
}

/* Hide TOC toggle when JavaScript is disabled */
.no-js #toc-toggle {
  display: none;
}

/* Hide search button when JavaScript is disabled */
.no-js #search-toggle {
  display: none;
}

/* Hide share button when JavaScript is disabled */
.no-js #share-button {
  display: none;
}

/* Hide QR code button when JavaScript is disabled */
.no-js #qrcode-open {
  display: none;
}

/* Hide export/import/reset links when JavaScript is disabled */
.no-js .export-icon,
.no-js .import-icon,
.no-js .reset-icon {
  display: none;
}

#nav-drawer {
  background: var(--color-nav);
  border-right-color: var(--color-nav-border);
}

.sidebar > .author,
.nav-drawer-content > .author {
  color: var(--color-author-color);
  background: var(--color-author-background);
}

.sidebar > .author:hover,
.nav-drawer-content > .author:hover {
  color: var(--color-brand);
}

/* Three bars for burger menu */
.toggle > .bar1,
.toggle > .bar2,
.toggle > .bar3 {
  background-color: var(--color-brand-text);
}

.inverted .toggle > .bar1,
.inverted .toggle > .bar2,
.inverted .toggle > .bar3 {
  background-color: var(--color-brand);
}

header {
  background: var(--color-brand);
}

header.inverted {
  background: var(--color-brand-text);
}

.branding {
  color: var(--color-brand-text);
  flex: 1;
}

.branding:hover {
  color: var(--color-brand-text);
}

header.inverted > .branding {
  color: var(--color-brand);
}

header.inverted > .branding:hover {
  color: var(--color-brand);
}

.meta {
  border-top-color: var(--color-spacer);
}

.section > .name {
  color: var(--color-text);
  border-color: var(--color-spacer);
}

.section > .name > .label {
  color: var(--color-text);
}

/* `active` and `empty` sit on the <details>, not on the <summary>. */
.section.active > .name > .label {
  color: var(--color-brand);
}

.section > .name:hover {
  background: var(--color-spacer);
}

.section.active > .name {
  background: var(--color-background);
  color: var(--color-brand);
}

.page {
  color: var(--color-text);
}

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

.page.active {
  background: var(--color-background);
  color: var(--color-brand);
}

.section > .links {
  border-left-color: var(--color-spacer);
}

a.jump {
  border-color: var(--color-brand);
}

a.jump:hover {
  background: var(--color-nav);
}

a.jump {
  text-decoration: none;
  flex: 1;
  text-align: center;
  border-style: solid;
  border-width: 1px;
  padding: 8px 16px;
  width: 100%;
  border-radius: 8px;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 1px 2px;
}

a.jump.next {
  margin-left: 8px;
}

a.jump.next::after {
  content: " →";
}

a.jump.previous {
  margin-right: 8px;
}

a.jump.previous::before {
  content: "← ";
}

@media screen and (max-width: 800px) {
  .jump-container {
    flex-direction: column;
  }

  a.jump.next {
    margin-left: 0px;
    margin-top: 16px;
  }

  a.jump.previous {
    margin-right: 0px;
    margin-top: 16px;
  }
}

.border {
  border-color: var(--color-spacer);
}

.loading {
  background: var(--color-nav);
}

.main-grid {
  font-family: hyperbook-body, sans-serif;
  display: grid;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  grid-template-columns: var(--nav-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-areas:
    "header header header"
    "nav article article";
}

.nav-drawer-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  grid-area: nav;
  overflow-y: auto;
}

.sidebar {
  font-size: var(--nav-font-size);
  display: flex;
  flex-direction: column;
  grid-area: nav;
  overflow-y: auto;
  scrollbar-width: thin;
  border-right-style: solid;
  border-right-width: 1px;
  background: var(--color-nav);
  border-right-color: var(--color-nav-border);
}

.sidebar > nav,
.nav-drawer-content > nav {
  padding: 1rem;
  flex: 1;
}

.sidebar > .author,
.nav-drawer-content > .author {
  text-align: center;
  text-decoration: none;
  padding: 1rem;
}

.sidebar > .author,
.nav-drawer-content > .author > b {
  font-weight: bold;
}

.sidebar > .author > .author-version,
.nav-drawer-content > .author > .author-version {
  display: block;
  font-size: 0.7rem;
  opacity: 0.6;
}

.mobile-nav {
  display: none;
  margin-left: 1rem;
}

.mobile-nav .toggle {
  font-size: 2.625rem;
  border: none;
  padding: 0;
  margin: 0;
  background: none;
  width: 40px;
  height: 40px;
  cursor: pointer;
}

.toggle > .bar1,
.toggle > .bar2,
.toggle > .bar3 {
  width: 30px;
  height: 4px;
  margin: 6px 0;
  transition: 0.4s;
}

/* Rotate first bar */
.change .bar1 {
  transform: rotate(-45deg) translate(-8px, 8px);
}

/* Fade out the second bar */
.change .bar2 {
  opacity: 0;
}

/* Rotate last bar */
.change .bar3 {
  transform: rotate(45deg) translate(-8px, -8px);
}

@media screen and (max-width: 1280px) {
  .main-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "article";
  }

  .mobile-nav {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    display: none;
  }
}

main {
  padding: 1rem;
  overflow-y: auto;
}

/* Breadcrumb Navigation */
nav.breadcrumb {
  max-width: var(--main-width);
  color: color-mix(in srgb, var(--color-text), white 35%);
  margin: 0 auto;
  margin-bottom: var(--element-gap);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.9rem;
}

nav.breadcrumb a {
  color: color-mix(in srgb, var(--color-text), white 35%);
  text-decoration: none;
}

nav.breadcrumb a:hover {
  color: var(--color-brand);
  text-decoration: underline;
}

nav.breadcrumb .breadcrumb-separator {
  margin: 0 4px;
}

nav.breadcrumb .breadcrumb-empty {
  font-style: italic;
}

nav.breadcrumb .breadcrumb-current {
  font-weight: 500;
}

nav.breadcrumb .breadcrumb-home,
nav.breadcrumb .breadcrumb-current {
  text-decoration: none;
}

article {
  max-width: var(--main-width);
  margin: 0 auto;
  grid-area: article;
}

header {
  display: flex;
  grid-area: header;
  margin: 0;
  padding: 0;
  align-items: center;
  z-index: 1001;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 1px 4px;
}

.branding {
  text-decoration: none;
  display: flex;
  padding: 1rem;
  align-items: center;
}

.custom-links-menu {
  padding: 1rem;
  flex: 1;
  display: flex;
  justify-content: flex-end;
  position: relative;
}

.custom-links-menu .links-menu {
  align-items: center;
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
}

#custom-links-header {
  display: flex;
}

#custom-links-footer {
  display: none;
}

#custom-links-footer ul,
#custom-links-footer li {
  list-style: none;
}

#custom-links-footer a {
  display: flex;
  flex-wrap: nowrap;
  text-decoration: none;
}

#custom-links-footer a .label {
  flex: 1;
  text-align: left;
  white-space: nowrap;
}

#custom-links-footer a .icon {
  margin-right: 0.5rem;
}

#custom-links-footer > .links-item {
  border-radius: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--color-nav-border);
  background: var(--color-nav);
  flex: 1;
}

#custom-links-footer .links-sub-menu {
  margin-left: 1.5rem;
}

@media (max-width: 960px) {
  #custom-links-header {
    display: none;
  }

  #custom-links-footer {
    display: flex;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-nav-border);
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

.custom-links-menu .links-menu li:hover .links-sub-menu {
  display: block;
}

.custom-links-menu .links-item {
  box-sizing: border-box;
  font-size: 1rem;
  font-weight: 700;
  position: relative;
  border: 1px solid transparent;
  min-width: 80px;
  text-align: center;
  border-radius: 0.25rem;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: max-content;
}

.custom-links-menu .links-item.sub::after {
  color: var(--color-brand-text);
  content: "\25BC";
  margin-right: 0.5rem;
}

.custom-links-menu .links-item:hover {
  border: 1px solid var(--color-brand-text);
}

.custom-links-menu .links-sub-menu .links-item {
  font-weight: normal;
}

.custom-links-menu .links-sub-menu .links-item a {
  color: var(--color-text);
}

.custom-links-menu .links-sub-menu .links-item:hover {
  border: 1px solid transparent;
  text-decoration: underline;
}

.custom-links-menu a {
  display: flex;
  width: max-content;
  text-decoration: none;
  padding: 0.5rem;
  color: var(--color-brand-text);
  cursor: pointer;
}

.custom-links-menu a .label {
  flex: 1;
  text-align: left;
}

.custom-links-menu a .icon {
  margin-right: 0.5rem;
}

.custom-links-menu .links-sub-menu .links-item:hover .icon {
  text-decoration: none;
}

.custom-links-menu .links-sub-menu {
  display: none;
  position: absolute;
  left: 50%;
  top: 54px;
  transform: translateX(-50%);
  background-color: var(--color-nav);
  width: max-content;
  border: 1px solid var(--color-nav-border);
  border-radius: 0.25rem;
}

.custom-links-menu .links-sub-menu::before {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-80%);
  width: 80px;
  height: 40px;
}

.branding .logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.625rem;
  height: 2.5rem;
  width: auto;
  min-width: 2.5rem;
}

.branding .logo img {
  width: auto;
  height: 100%;
}

.branding .name {
  font-family: hyperbook-heading, sans-serif;
  font-size: 1.1rem;
  font-weight: bold;
}

.jump-container {
  display: flex;
  max-width: var(--main-width);
  margin: 0 auto;
  margin-top: 2.5rem;
  clear: both;
}

.flex {
  flex: 1;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  border-top-style: solid;
  border-top-width: 1px;
  margin: 0 auto;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  max-width: var(--main-width);
}

.meta .edit-github {
  text-decoration: none;
  display: block;
  flex: 1;
}

.meta .vercel {
  text-align: center;
  flex: 1;
}

.meta .copyright {
  text-align: right;
  flex: 1;
}

.section ul,
.virtual-section ul,
nav > ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

nav li + li {
  margin-top: 0px;
}

.section,
.virtual-section {
  display: flex;
  flex-direction: column;
}

.section {
  margin-top: 4px;
}

.section summary.name {
  display: flex;
  text-decoration: none;
  padding: 0.65rem;
  border-width: 1px;
  border-style: solid;
  width: 100%;
  user-select: none;
  cursor: pointer;
  list-style: none;
}

.section summary.name::-webkit-details-marker {
  display: none;
}

.section summary.name::marker {
  display: none;
}

.section summary.name > .label {
  flex: 1;
  text-decoration: none;
}

/* The row always toggles the section, so it always looks clickable. Only the
   title tells the two kinds of section apart: a section without its own page
   is set in italics and is not a link.

   Both rules are scoped with child combinators. Sections nest, so a descendant
   selector would style a subsection according to its parent — a subsection with
   content sitting inside an empty section came out italic. */
.section.empty > summary.name > .label {
  font-style: italic;
}

/* A section that has its own page: the title is a real link and behaves like
   one, while clicking elsewhere in the row just expands the section. */
.section:not(.empty) > summary.name > .label:hover {
  text-decoration: underline;
}

.section summary.name:after {
  content: "\002B";
  width: 1.2rem;
  color: var(--color-text);
  font-weight: bold;
  text-align: right;
  margin-left: 0.25rem;
}

.section[open] > summary.name:after {
  content: "\2212";
}

.section .section {
  margin-left: 1rem;
  margin-bottom: 0px;
}

.page {
  display: block;
  padding: 0.65rem;
  text-decoration: none;
}

.section > .links {
  border-left-width: 1px;
  border-left-style: solid;
}

.pages {
  margin-top: 1.5rem;
}

.border {
  border-radius: 0.25rem;
  border-style: solid;
  border-width: 1px;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: none;
  font-size: 2rem;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

nav.toc li {
  margin-bottom: 0.5rem;
}

nav.toc li > a {
  color: var(--color-text);
  text-decoration: none;
}

nav.toc li > a:hover {
  color: var(--color-brand);
}

nav.toc li.level-1 {
  padding-left: 0px;
}

nav.toc li.level-2 {
  padding-left: 0.5rem;
}

nav.toc li.level-3 {
  padding-left: 1rem;
}

nav.toc li.level-3 {
  padding-left: 1.5rem;
}

.reset-icon {
  display: inline-block;
  background-color: var(--color-brand);
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  margin-right: 1rem;
  mask-repeat: no-repeat;
  cursor: pointer;
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWNvb2tpbmctcG90Ij48cGF0aCBkPSJNMiAxMmgyMCIvPjxwYXRoIGQ9Ik0yMCAxMnY4YTIgMiAwIDAgMS0yIDJINmEyIDIgMCAwIDEtMi0ydi04Ii8+PHBhdGggZD0ibTQgOCAxNi00Ii8+PHBhdGggZD0ibTguODYgNi43OC0uNDUtMS44MWEyIDIgMCAwIDEgMS40NS0yLjQzbDEuOTQtLjQ4YTIgMiAwIDAgMSAyLjQzIDEuNDZsLjQ1IDEuOCIvPjwvc3ZnPg==");
}

.export-icon {
  display: inline-block;
  background-color: var(--color-brand);
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  margin-right: 1rem;
  mask-repeat: no-repeat;
  cursor: pointer;
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWRvd25sb2FkIj48cGF0aCBkPSJNMjEgMTV2NGEyIDIgMCAwIDEtMiAySDVhMiAyIDAgMCAxLTItMnYtNCIvPjxwb2x5bGluZSBwb2ludHM9IjcgMTAgMTIgMTUgMTcgMTAiLz48bGluZSB4MT0iMTIiIHgyPSIxMiIgeTE9IjE1IiB5Mj0iMyIvPjwvc3ZnPg==");
}

.import-icon {
  display: inline-block;
  background-color: var(--color-brand);
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  margin-right: 1rem;
  mask-repeat: no-repeat;
  cursor: pointer;
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLXVwbG9hZCI+PHBhdGggZD0iTTIxIDE1djRhMiAyIDAgMCAxLTIgMkg1YTIgMiAwIDAgMS0yLTJ2LTQiLz48cG9seWxpbmUgcG9pbnRzPSIxNyA4IDEyIDMgNyA4Ii8+PGxpbmUgeDE9IjEyIiB4Mj0iMTIiIHkxPSIzIiB5Mj0iMTUiLz48L3N2Zz4=");
}

.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  padding: 1em;
  /* small margin around edges */
  box-sizing: border-box;
}

.lightbox-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  max-height: 100%;
  height: 100vh;
  /* Ensure full height usage */
  box-sizing: border-box;
}

.lightbox-image-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 1;
  /* Take up remaining space after caption */
  min-height: 0;
  /* Allow flexbox shrinking */
}

.lightbox-image-container img {
  width: calc(100vw - 1em);
  /* Forces image to grow to this width */
  height: 100%;
  /* Use all available height in the flex container */
  max-width: calc(100vw - 1em);
  /* Prevents overflow */
  max-height: 100%;
  /* Prevents overflow */
  object-fit: contain;
  /* Maintains aspect ratio while filling the space */
  cursor: zoom-out;
}

.lightbox-content .caption {
  color: white;
  font-family: hyperbook-body, sans-serif;
  text-align: center;
  font-size: 1em;
  margin-top: 0.5em;
  margin-bottom: 0.5em;
  /* Add bottom margin for spacing */
  max-width: 90vw;
  word-wrap: break-word;
  flex-shrink: 0;
  /* Prevent caption from shrinking */
}

/* Wide layout: full width content with drawer-only navigation */
.main-grid.layout-wide {
  grid-template-columns: 1fr;
  grid-template-areas:
    "header"
    "article";
  --main-width: 1800px;
}

.main-grid.layout-wide .sidebar {
  display: none;
}

.main-grid.layout-wide .mobile-nav {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Standalone layout: content only, no navigation or header (for iframe embedding) */
.main-grid.layout-standalone {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "article";

  --main-width: 1800px;

  #toc-toggle {
    top: inherit;
  }

  #qrcode-open {
    top: 90px;
  }
}

.main-grid.layout-standalone header,
.main-grid.layout-standalone .floating-buttons-container {
  display: none;
}
.main-grid.layout-standalone .sidebar {
  display: none;
}

.main-grid.layout-standalone .jump-container,
.main-grid.layout-standalone .meta,
.main-grid.layout-standalone #custom-links-footer {
  display: none;
}

.main-grid.layout-standalone .breadcrumb {
  display: none;
}

/* User Authentication UI */
#user-toggle {
  margin-right: 8px;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-icon {
  position: relative;
  width: 24px;
  height: 24px;
}

/* The person glyph. Constant across every state — what changes is the badge. */
.user-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: var(--color-brand-text);
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z"/></svg>');
  opacity: 0.5;
}

.user-icon:not([data-state="not-logged-in"])::before {
  opacity: 1;
}

/*
 * The sync badge.
 *
 * Each state gets its own shape, not merely its own colour: this icon is the
 * only ambient sync indicator in the shell, and amber-vs-green at 24px is
 * indistinguishable to a red-green colour blind reader (WCAG 1.4.1). The disc
 * is drawn with fill-rule="evenodd" so the glyph is punched out of it, and the
 * drop-shadow ring keeps it legible over the person glyph beneath.
 */
.user-icon::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 13px;
  height: 13px;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  filter: drop-shadow(0 0 1.5px var(--color-background))
    drop-shadow(0 0 1.5px var(--color-background));
}

/* No badge until there is a session whose sync state means anything. */
.user-icon[data-state="not-logged-in"]::after,
.user-icon[data-state="logged-in"]::after {
  content: none;
}

/* pending: unsent changes are waiting */
.user-icon[data-state="pending"]::after {
  background-color: var(--color-sync-pending);
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a11 11 0 100 22 11 11 0 000-22zM7 10.6a1.6 1.6 0 100 3.2 1.6 1.6 0 100-3.2zm5 0a1.6 1.6 0 100 3.2 1.6 1.6 0 100-3.2zm5 0a1.6 1.6 0 100 3.2 1.6 1.6 0 100-3.2z"/></svg>');
}

/* syncing: a save is in flight */
.user-icon[data-state="syncing"]::after {
  background-color: var(--color-sync-active);
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a11 11 0 100 22 11 11 0 000-22zM9 5.2l4 4.2h-2.8v4.2H7.8V9.4H5zm6 13.6l-4-4.2h2.8v-4.2h2.4v4.2H19z"/></svg>');
}

/* synced: everything is on the server */
.user-icon[data-state="synced"]::after {
  background-color: var(--color-sync-ok);
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a11 11 0 100 22 11 11 0 000-22zM17.1 8.4l-1.6-1.6-4.8 4.8-2.2-2.2-1.6 1.6 3.8 3.8z"/></svg>');
}

/* error: the last save failed */
.user-icon[data-state="error"]::after {
  background-color: var(--color-sync-error);
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a11 11 0 100 22 11 11 0 000-22zM10.8 5.6h2.4v7.2h-2.4zm0 8.8h2.4v2.4h-2.4z"/></svg>');
}

/* offline: no connection */
.user-icon[data-state="offline"]::after {
  background-color: var(--color-sync-idle);
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a11 11 0 100 22 11 11 0 000-22zM6.6 5.1l12.3 12.3-1.5 1.5L5.1 6.6z"/></svg>');
}

/* readonly: impersonation, no writes */
.user-icon[data-state="readonly"]::after {
  background-color: var(--color-sync-readonly);
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 1a11 11 0 100 22 11 11 0 000-22zM12 7.2c-3 0-5.4 2-6.3 4.8.9 2.8 3.3 4.8 6.3 4.8s5.4-2 6.3-4.8c-.9-2.8-3.3-4.8-6.3-4.8zm0 8a3.2 3.2 0 110-6.4 3.2 3.2 0 010 6.4z"/></svg>');
}

.user-icon[data-state="syncing"]::after {
  animation: user-icon-pulse 1s ease-in-out infinite;
}

@keyframes user-icon-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* The badge shape already carries the state; motion is decoration. */
@media (prefers-reduced-motion: reduce) {
  .user-icon[data-state="syncing"]::after {
    animation: none;
  }
}

#user-drawer {
  background: var(--color-background);
  border-left: 1px solid var(--color-nav-border);
}

.user-drawer-content {
  padding: 20px;
  width: 100%;
  max-width: 400px;
}

.user-form,
.user-info {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.user-form h3,
.user-info h3 {
  margin: 0 0 10px 0;
  color: var(--color-text);
}

.user-form input {
  padding: 10px;
  border: 1px solid var(--color-nav-border);
  border-radius: 4px;
  background: var(--color-background);
  color: var(--color-text);
  font-size: 14px;
}

.user-form button,
.user-info button {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  background: var(--color-brand);
  color: var(--color-brand-text);
}

.user-form button:hover,
.user-info button:hover {
  opacity: 0.9;
}

.user-info .logout-btn {
  background: #e74c3c;
  color: white;
}

.user-info .logout-btn:hover {
  background: #c0392b;
}

.user-error {
  color: #e74c3c;
  font-size: 14px;
  min-height: 20px;
}

.user-info p {
  margin: 5px 0;
  color: var(--color-text);
}

#user-save-status {
  font-weight: normal;
}

#user-save-status.unsaved,
#user-save-status.offline-queued {
  color: var(--color-sync-pending);
}

#user-save-status.saving {
  color: var(--color-sync-active);
}

#user-save-status.saved {
  color: var(--color-sync-ok);
}

#user-save-status.error {
  color: var(--color-sync-error);
}

#user-save-status.offline {
  color: var(--color-sync-idle);
}

#user-save-status.readonly {
  color: var(--color-sync-readonly);
  font-weight: bold;
}

/*
 * Ambient sync notice.
 *
 * Only shown for states the reader can act on — offline, a failed save, a
 * merge. The status line it complements lives inside the user drawer, which
 * most readers never open.
 */
#cloud-sync-notice {
  font-family: hyperbook-body, sans-serif;
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  max-width: min(28rem, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid currentColor;
  background: var(--color-background);
  box-shadow: 0 4px 16px rgb(0 0 0 / 18%);
  font-size: 0.9rem;
  line-height: 1.4;
}

#cloud-sync-notice > span {
  color: var(--color-text);
}

#cloud-sync-notice.error {
  color: var(--color-sync-error);
}

#cloud-sync-notice.warning {
  color: var(--color-sync-pending);
}

#cloud-sync-notice.info {
  color: var(--color-sync-active);
}

#cloud-sync-notice button {
  flex: none;
  font: inherit;
  font-weight: bold;
  cursor: pointer;
  color: inherit;
  background: none;
  border: 1px solid currentColor;
  border-radius: 5px;
  padding: 4px 10px;
}

#cloud-sync-notice button:hover,
#cloud-sync-notice button:focus-visible {
  /* A tint rather than a fill: inverting would resolve `currentColor` against
     the overridden colour and paint the button its own background. */
  background: color-mix(in srgb, currentColor 15%, transparent);
}

@media (max-width: 40rem) {
  #cloud-sync-notice {
    left: 16px;
    right: 16px;
    max-width: none;
  }
}

#impersonation-banner {
  font-family: hyperbook-body, sans-serif;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: #e67e22;
  color: white;
  padding: 8px 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  font-size: 1rem;
}

#impersonation-banner a {
  color: white;
  font-weight: bold;
  text-decoration: underline;
}

#impersonation-banner a:hover {
  opacity: 0.8;
}

#impersonation-banner + * {
  margin-top: 36px;
}

.hidden {
  display: none !important;
}
