#portal-left-content {
  container-type: inline-size;
  --reading-text: #e2e3eb;
  --reading-muted: #aeb9d0;
  --reading-line: #91a3d13b;
  --reading-width: 57rem;
  --reading-gutter: clamp(1rem, 5.6cqw, 3.65rem);
  --reading-heading-gutter: max(var(--reading-gutter), calc((100cqw - var(--reading-width)) / 2 + var(--reading-gutter)));
  color: var(--reading-text);
  background: #0a111e;
}

.portal-document-surface, .portal-wiki {
  min-height: 100%;
  background: radial-gradient(ellipse at 88% 0, #161c3c, transparent 68%), #0a111e;
}

.portal-document-heading {
  min-height: clamp(13rem, 53cqw, 26rem);
  display: grid;
  align-items: end;
  padding: clamp(1.3rem, 6cqw, 3.6rem) var(--reading-heading-gutter);
  border-bottom: 1px solid var(--reading-line);
  background: linear-gradient(0deg, #080b17c9, transparent 75%), #12121a url('/art/laplace-nocturne.webp') 47% 52% / cover no-repeat;
}

.portal-document-heading .portal-content-title { margin: 0; text-shadow: 0 2px 14px #09090e; }
.portal-document-surface.empty-archive {
  display: flex;
  flex-direction: column;
  justify-content: end;
  padding-block: 2.2rem clamp(2.2rem, 10cqw, 5.5rem);
  background: linear-gradient(0deg, #080b17cc, transparent 65%), #12121a url('/art/laplace-nocturne.webp') 35% center / cover no-repeat;
}
.empty-archive .portal-document-heading, .has-document .portal-document-heading {
  min-height: 0;
  border-bottom: 0;
  background: none;
}
.empty-archive .portal-document-heading { padding-block: 0 .8rem; }
.portal-document-surface.empty-archive .portal-document-body {
  margin: 0;
  padding-block: 0;
  color: #c4c5d3;
  text-shadow: 0 1px 5px #05060d;
}
.has-document .portal-document-heading { padding-block: clamp(1.45rem, 6cqw, 3rem) 0; }
.has-document .portal-document-body { padding-block-start: 1.075rem; }
.portal-wiki-heading {
  padding: clamp(1.5rem, 6.5cqw, 3.75rem) var(--reading-heading-gutter) clamp(1.2rem, 4cqw, 2.2rem);
  border-bottom: 1px solid var(--reading-line);
  background: linear-gradient(124deg, #1d1729, #141b32 70%, #172238);
}
.portal-wiki-label {
  margin: 0 0 .75rem;
  color: #b9a5af;
  letter-spacing: .13em;
  font-size: .875rem;
}
.portal-wiki-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.portal-wiki-meta:not(:empty) { margin-top: .8rem; }
.portal-wiki-category {
  min-height: 1.8rem;
  padding: .15rem .55rem;
  border: 1px solid #81799c87;
  border-radius: 5px;
  background: #34294375;
  color: #dfd1e5;
  font-size: .8125rem;
  overflow-wrap: anywhere;
}
.portal-wiki-category:hover { background: #5b405b80; color: #fff0f7; }
.portal-wiki .portal-content-title::before { display: none; }
.portal-wiki .portal-content-title { margin: 0; }
.portal-wiki-filter {
  min-width: 0;
  width: 100%;
  min-height: 2.5rem;
  font-size: .875rem;
  padding: .45rem .6rem;
  border-radius: 6px;
  border: 1px solid #47546f;
  background: #0c1323;
  color: #dce1ec;
}
.portal-wiki-toc {
  margin-bottom: 1.5rem;
  padding: .65rem .9rem;
  border: 1px solid var(--reading-line);
  border-left: 2px solid #936b87;
  border-radius: 6px;
  background: #21243985;
}
.portal-wiki-toc summary { cursor: pointer; color: #e1d8eb; font-weight: 590; }
.portal-wiki-toc-link { display: block; padding: .3rem 0; text-align: left; color: #c5d1e7; }
.portal-wiki-toc-link:hover { color: #f3f3ff; text-decoration: underline; }

.portal-document-body, .portal-wiki-layout, .portal-voice {
  max-width: var(--reading-width);
  margin-inline: auto;
  padding: clamp(1.1rem, 4.6cqw, 2.8rem) var(--reading-gutter);
}

.portal-content-title {
  color: #f1eef1;
  font-size: clamp(1.65rem, 6.75cqw, 3.4rem);
  font-weight: 590;
  line-height: 1.22;
  letter-spacing: .035em;
  overflow-wrap: anywhere;
}

.portal-content-title::before {
  content: '';
  display: block;
  width: 2rem;
  height: 1px;
  margin: 0 0 .85rem;
  background: #d64d47;
  box-shadow: 0 0 .55rem #d64d476b;
}

.portal-content-status {
  color: var(--reading-muted, #b0bed5);
  font-size: .9375rem;
  margin: 0;
  overflow-wrap: anywhere;
}

.portal-content-button {
  padding: .46rem .8rem;
  min-height: 2.5rem;
  border: 1px solid #a1afd775;
  border-radius: 7px;
  background: linear-gradient(125deg, #272c4d, #171f36);
  color: #e4e9fa;
  font-size: .875rem;
  font-weight: 560;
}

.portal-content-button:hover:not(:disabled) {
  border-color: #969fc4;
  background: #25304b;
}

.portal-content-button:disabled { opacity: .55; }
.portal-content-status + .portal-content-button { margin-top: .9rem; }

.portal-document-list {
  padding: 0;
  margin: 0;
  list-style: none;
  background: linear-gradient(120deg, #192239, #131c2e);
  border: 1px solid var(--reading-line);
  border-radius: 11px;
}

.portal-document-link {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .4rem 1rem;
  width: 100%;
  min-height: 3.35rem;
  padding: .9rem clamp(.8rem, 3cqw, 1.25rem);
  text-align: left;
  color: #e9edff;
  border: 0;
  background: transparent;
  font-size: 1rem;
  font-weight: 570;
  overflow-wrap: anywhere;
}

.portal-document-list li + li { border-top: 1px solid var(--reading-line); }
.portal-document-link:hover { background: #7982cb24; }
.portal-document-list li:first-child > .portal-document-link { border-start-start-radius: 10px; border-start-end-radius: 10px; }
.portal-document-list li:last-child > .portal-document-link { border-end-start-radius: 10px; border-end-end-radius: 10px; }
.portal-content-date { font-size: .8125rem; color: var(--reading-muted); font-variant-numeric: tabular-nums; font-weight: 400; white-space: nowrap; }

.portal-document-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .6rem 1rem;
  margin-bottom: 1.25rem;
}

.portal-markdown {
  max-width: 74ch;
  font-size: 1rem;
  line-height: 1.85;
  overflow-wrap: anywhere;
  color: #d7e1f3;
}

.portal-markdown :is(h1, h2, h3, h4, h5, h6) { color: #f2f5ff; line-height: 1.35; margin: 1.45em 0 .55em; }
.portal-markdown > :first-child { margin-top: 0; }
.portal-markdown a { color: #c8cfff; text-decoration: underline; text-underline-offset: .18em; }
.portal-markdown a:hover { color: #f0ecff; }
.portal-markdown pre { overflow: auto; padding: .95rem; border: 1px solid var(--reading-line, var(--line)); border-radius: 7px; background: #080f1d; }
.portal-markdown code { font-family: ui-monospace, Consolas, monospace; font-size: .88em; }
.portal-markdown :not(pre) > code { border-radius: 3px; background: #1d2940; padding: .11em .28em; }
.portal-markdown blockquote { margin-inline: 0; padding: .05rem .95rem; border-left: 2px solid #947892; background: #221e325c; color: #cec7dd; }
.portal-markdown table { display: block; max-width: 100%; overflow: auto; border-collapse: collapse; }
.portal-markdown :is(th, td) { border: 1px solid #43516a; padding: .45rem .75rem; }
.portal-markdown th { background: #212a41; color: #eeeaf6; }
.portal-markdown tr:nth-child(even) { background: #212a4157; }
.portal-markdown img { max-width: 100%; height: auto; }
.portal-markdown hr { border: 0; border-top: 1px solid #33415a; }
.portal-markdown :is(ol, ul) { padding-inline-start: 1.45rem; }
.portal-markdown li + li { margin-top: .25em; }

.portal-wiki-layout {
  display: grid;
  grid-template-columns: minmax(7.5rem, 11rem) minmax(0, 1fr);
  align-items: start;
  column-gap: clamp(1.1rem, 4cqw, 2rem);
}

.portal-wiki-nav {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding: .6rem;
  max-height: min(59dvh, 36rem);
  overflow: auto;
  scrollbar-width: thin;
  border: 1px solid var(--reading-line);
  border-radius: 8px;
  background: #10192b;
}

.portal-wiki-link {
  min-height: 2.4rem;
  flex-shrink: 0;
  padding: .4rem .6rem;
  text-align: left;
  font-size: .875rem;
  border: 0;
  border-radius: 4px;
  color: var(--reading-muted);
  background: transparent;
  overflow-wrap: anywhere;
}

.portal-wiki-link[aria-current='page'], .portal-wiki-link:hover {
  color: #f0f2ff;
  background: #7982cb26;
}

.portal-wiki-link[aria-current='page'] { box-shadow: inset 2px 0 #d64d47; font-weight: 600; }
.portal-wiki-article { min-width: 0; }
.portal-wiki-nav:is([hidden], :empty) + .portal-wiki-article { grid-column: 1 / -1; }

#portal-left-content:has(> .portal-voice) {
  background: linear-gradient(#090f1e62, #0a101fe6), url('/art/laplace-nocturne.webp') 42% center / cover;
}

.portal-voice {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: .85rem 1rem;
  max-width: 44rem;
  padding-block-start: clamp(2.5rem, 11cqw, 6rem);
}
.portal-voice .portal-content-status { grid-area: 2 / 1; align-self: center; text-shadow: 0 1px 4px #0a1020; }
.portal-voice .portal-content-button { grid-area: 2 / 2; min-width: 5.2rem; }

.portal-voice-message {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 8rem;
  padding: .85rem;
  resize: vertical;
  border-radius: 9px;
  border: 1px solid #a7b5db80;
  background-color: #0c1426d9;
  box-shadow: 0 1rem 2rem #04081363;
  color: #e6ebf4;
  font: inherit;
  font-size: 1rem;
  line-height: 1.55;
}

.portal-voice-message:focus-visible { outline: 2px solid #bbc5f1; outline-offset: 2px; border-color: transparent; }
.portal-voice-message[readonly] { opacity: .75; }

#portal-jpg-content {
  display: flex;
  background: #080e1b;
  overflow: hidden;
}

.portal-gallery {
  isolation: isolate;
  position: relative;
  container: gallery / size;
  width: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  margin: 0;
}

.portal-gallery-image, .portal-gallery-blur {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portal-gallery[data-style='contain'] .portal-gallery-image,
.portal-gallery[data-style='blur'] .portal-gallery-image { object-fit: contain; }

.portal-gallery-blur { display: none; }

.portal-gallery[data-style='blur'] .portal-gallery-blur {
  display: block;
  z-index: -1;
  transform: scale(1.1);
  filter: blur(24px) brightness(.58);
}

.portal-gallery-mosaic {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  grid-template-areas: var(--gallery-landscape);
}

.portal-gallery-mosaic.is-reflected { direction: rtl; }
.portal-gallery-pending {
  background: linear-gradient(145deg, #182337, #0c1322);
}

.portal-gallery-mosaic > .portal-gallery-image {
  position: static;
  display: block;
  min-width: 0;
  min-height: 0;
  object-fit: cover;
  outline: 1px solid #070d2373;
  outline-offset: -1px;
}

.portal-gallery-mosaic > :nth-child(1) { grid-area: a; }
.portal-gallery-mosaic > :nth-child(2) { grid-area: b; }
.portal-gallery-mosaic > :nth-child(3) { grid-area: c; }
.portal-gallery-mosaic > :nth-child(4) { grid-area: d; }
.portal-gallery-mosaic > :nth-child(5) { grid-area: e; }
.portal-gallery-mosaic > :nth-child(6) { grid-area: f; }

.portal-gallery-mosaic[data-count='1'] {
  --gallery-landscape:
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'a a a a a a';
}

.portal-gallery-mosaic[data-count='2'] {
  --gallery-landscape:
    'a a a a b b'
    'a a a a b b'
    'a a a a b b'
    'a a a a b b'
    'a a a a b b'
    'a a a a b b';
  --gallery-portrait:
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'b b b b b b'
    'b b b b b b';
}

.portal-gallery-mosaic[data-count='3'] {
  --gallery-landscape:
    'a a a a b b'
    'a a a a b b'
    'a a a a b b'
    'a a a a c c'
    'a a a a c c'
    'a a a a c c';
  --gallery-portrait:
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'b b b b c c'
    'b b b b c c';
}

.portal-gallery-mosaic[data-count='4'] {
  --gallery-landscape:
    'a a a a b b'
    'a a a a b b'
    'a a a a b b'
    'a a a a c c'
    'd d d d c c'
    'd d d d c c';
  --gallery-portrait:
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'b b b b c c'
    'b b b b c c'
    'd d d d d d';
}

.portal-gallery-mosaic[data-count='5'] {
  --gallery-landscape:
    'a a a a b b'
    'a a a a b b'
    'a a a a c c'
    'a a a a c c'
    'd d d e e e'
    'd d d e e e';
  --gallery-portrait:
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'b b b b c c'
    'd d d e e e'
    'd d d e e e';
}

.portal-gallery-mosaic[data-count='6'] {
  --gallery-landscape:
    'a a a a b b'
    'a a a a b b'
    'a a a a c d'
    'a a a a c d'
    'e e e f f f'
    'e e e f f f';
  --gallery-portrait:
    'a a a a a a'
    'a a a a a a'
    'a a a a a a'
    'b b b b c c'
    'b b b b c c'
    'd d e e f f';
}

@container gallery (aspect-ratio < 1) {
  .portal-gallery-mosaic { grid-template-areas: var(--gallery-portrait, var(--gallery-landscape)); }
}

#portal-right-panel { container: right-pane / size; }

.portal-gallery-trigger[aria-expanded='true'] {
  border-color: #b3b8eea6;
  background: #2b3756;
}

.portal-gallery-settings {
  position: absolute;
  inset-block-start: calc(100% + .45rem);
  inset-inline-end: calc(-1 * (var(--portal-corner-size) + var(--portal-tools-gap)));
  width: min(17rem, calc(100cqw - 2 * var(--portal-tools-inset)));
  max-height: min(16.25rem, calc(100cqh - var(--portal-corner-size) - 2 * var(--portal-tools-inset) - .45rem));
  padding: .85rem;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #6a78a1 transparent;
  scrollbar-width: thin;
  border: 1px solid #9fadd261;
  border-radius: 10px;
  color: #e4eafa;
  background: linear-gradient(145deg, #242b46fa, #131c31fa);
  box-shadow: 0 .8rem 2rem #020613bf;
  backdrop-filter: blur(12px);
}

.portal-gallery-field {
  display: grid;
  gap: .35rem;
  font-size: .875rem;
  color: #c0c9dd;
}

.portal-gallery-field + .portal-gallery-field {
  margin-top: .65rem;
  padding-top: .65rem;
  border-top: 1px solid #8d9cc638;
}

.portal-gallery-field select {
  width: 100%;
  min-width: 0;
  min-height: 2.55rem;
  padding: .4rem .55rem;
  border: 1px solid #8798c07c;
  border-radius: 6px;
  background: #0c1325;
  color: #e2e9fa;
  font: inherit;
}

.portal-gallery-note { font-size: .82rem; margin: .6rem 0 0; color: #d1a6ad; }
.portal-gallery-note:empty { display: none; }

@container right-pane (min-width: 260px) and (max-height: 195px) {
  .portal-gallery-settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .4rem .65rem;
    padding: .45rem .65rem;
  }
  .portal-gallery-field + .portal-gallery-field { margin: 0; padding: 0; border: 0; }
  .portal-gallery-note { grid-column: 1 / -1; margin-top: 0; }
}

@media (pointer: coarse) {
  .portal-wiki-filter,
  .portal-gallery-field select { font-size: 1rem; }
}

@container (max-width: 31rem) {
  .portal-wiki-layout { grid-template-columns: minmax(0, 1fr); row-gap: 1rem; }
  .portal-wiki-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: min(15rem, 37dvh); }
  .portal-wiki-nav .portal-content-status { grid-column: 1 / -1; }
  .portal-wiki-filter:not(:has(+ .portal-wiki-filter)):first-child { grid-column: 1 / -1; }
}
