:root {
    --kraft: #c4ab7c;
    --kraft-dark: #a88d5c;
    --paper: #ece4cf;
    --ink: #221f1a;
    --stamp-red: #b3261e;
    --stamp-violet: #4b3f78;
    --serif: "PT Serif", Georgia, "Times New Roman", serif;
    --mono: "PT Mono", "Courier New", monospace;
    --stamp: "Oswald", "Arial Narrow", Impact, sans-serif;
  }
  * { box-sizing: border-box; }
  html { background: var(--kraft-dark); }
  body {
    margin: 0;
    color: var(--ink);
    font: 1.1rem/1.7 var(--serif);
    background: var(--kraft-dark);
  }
  a { color: var(--stamp-violet); }
  a:focus-visible, button:focus-visible { outline: 3px solid var(--stamp-red); outline-offset: 3px; }

  /* ---------- Folder cover (hero) ---------- */
  .folder {
    position: relative;
    max-width: 80rem;
    margin: 2.5rem auto 0;
    padding: 3rem clamp(1.5rem, 5vw, 4rem) 4rem;
    background:
      radial-gradient(ellipse at 20% 10%, rgba(255,255,255,.18), transparent 60%),
      radial-gradient(ellipse at 80% 90%, rgba(80,50,10,.18), transparent 55%),
      var(--kraft);
    border-radius: 2px 14px 2px 2px;
    box-shadow: 0 1px 0 #d8c298 inset, 0 18px 40px rgba(40,25,5,.35);
    overflow: hidden;
    container-type: inline-size;
  }
  .folder::before { /* folder tab */
    content: "";
    position: absolute; top: 0; right: 0;
    width: 30%; height: 10px;
    background: var(--kraft-dark);
    opacity: .5;
  }
  .folder-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
    font-family: var(--mono); font-size: .95rem;
    border-bottom: 2px solid var(--ink);
    padding-bottom: .6rem;
  }
  .folder h1 {
    font-family: var(--stamp);
    font-weight: 700;
    font-size: min(8rem, 14cqi);
    line-height: 1.05;
    letter-spacing: .02em;
    margin: 2.5rem 0 1.5rem;
  }
  .folder .lede {
    max-width: 40rem;
    font-size: 1.25rem;
    margin: 0;
  }
  .fields {
    margin-top: 2.5rem;
    font-family: var(--mono);
    font-size: .95rem;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .4rem 1rem;
    max-width: 30rem;
  }
  .fields dd { margin: 0; border-bottom: 1px solid rgba(34,31,26,.5); }

  .stamp {
    position: absolute;
    right: clamp(1rem, 6vw, 4rem);
    top: 10.5rem;
    transform: rotate(-11deg);
    font-family: var(--stamp);
    font-weight: 700;
    font-size: clamp(1.1rem, 3.4vw, 2rem);
    line-height: 1.1;
    text-align: center;
    color: var(--stamp-red);
    border: 5px double var(--stamp-red);
    padding: .5rem 1rem;
    opacity: .85;
    mix-blend-mode: multiply;
    -webkit-mask-image: repeating-radial-gradient(circle at 30% 40%, #000 0 2px, rgba(0,0,0,.72) 3px 4px);
            mask-image: repeating-radial-gradient(circle at 30% 40%, #000 0 2px, rgba(0,0,0,.72) 3px 4px);
  }

  /* ---------- Paper sheets ---------- */
  .sheet {
    max-width: 76rem;
    margin: -1.2rem auto 0;
    position: relative;
    background: var(--paper);
    padding: 3rem clamp(1.5rem, 5vw, 4rem);
    box-shadow: 0 10px 30px rgba(40,25,5,.3);
  }
  .sheet + .sheet { margin-top: 1.5rem; }
  .sheet h2 {
    font-family: var(--serif);
    font-size: 1.6rem;
    margin: 0 0 1rem;
  }
  .sheet p { max-width: 44rem; }

  .redact {
    background: var(--ink);
    color: transparent;
    border: 0;
    font: inherit;
    padding: 0 .15em;
    cursor: pointer;
    transition: background .3s, color .3s;
  }
  .redact[aria-pressed="true"] { background: rgba(179,38,30,.15); color: var(--ink); }

  .violet-stamp {
    display: inline-block;
    font-family: var(--mono);
    font-size: .85rem;
    color: var(--stamp-violet);
    border: 2px solid var(--stamp-violet);
    border-radius: 50%;
    padding: 1.2rem 1rem;
    transform: rotate(6deg);
    text-align: center;
    line-height: 1.3;
    opacity: .75;
    float: right;
    margin: 0 0 1rem 1.5rem;
  }

  /* ---------- Register table ---------- */
  .register-wrap { overflow-x: auto; }
  table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: .95rem;
    min-width: 36rem;
  }
  th, td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid rgba(34,31,26,.35); vertical-align: top; }
  thead th { border-bottom: 2px solid var(--ink); font-weight: 400; }
  td:first-child { white-space: nowrap; }
  td .subject { font-family: var(--serif); font-size: 1.05rem; display: block; }
  td .note { color: #5a5245; }
  .status { color: var(--stamp-red); white-space: nowrap; }

  footer {
    max-width: 76rem;
    margin: 0 auto;
    padding: 2rem clamp(1.5rem, 5vw, 4rem) 3rem;
    font-family: var(--mono);
    font-size: .9rem;
    color: #2e2618;
  }

  .folder h1.long-title { font-size: min(6.5rem, 11cqi); }
  @media (min-width: 56.01rem) {
    .folder h1 { max-width: 64%; } /* long titles wrap beside the stamp */
  }
  @media (max-width: 56rem) { /* stamp stays at the top-right, beside the title; overlapping is fine */
    .stamp { top: 7rem; right: 1.4rem; margin: 0; }
  }
  @media (max-width: 40rem) {
    .folder { margin-top: 0; border-radius: 0; }
    .violet-stamp { float: none; margin: 0 0 1rem; }
    .fields { grid-template-columns: 1fr; gap: 0; }
    .fields dt { margin-top: .6rem; }
  }

  /* ---------- Site navigation (folder tabs) ---------- */
  .tabs {
    max-width: 80rem;
    margin: 1.5rem auto 0;
    padding: 0 clamp(1rem, 4vw, 2rem);
    display: flex; flex-wrap: wrap; align-items: flex-end;
    font-family: var(--mono); font-size: .95rem;
  }
  .tab-links { display: flex; gap: .4rem; flex-wrap: wrap; }
  .tabs a {
    white-space: nowrap;
    color: var(--ink);
    text-decoration: none;
    background: #b39a6a;
    padding: .5rem 1.1rem .4rem;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -2px 6px rgba(40,25,5,.2);
  }
  .tabs a:hover { background: #bda476; }
  .tabs a[aria-current="page"] { background: var(--kraft); }
  .tabs + .folder { margin-top: 0; }

  .sheet figure { margin: 1.5rem 0 0; }
  .sheet figcaption { font-family: var(--mono); font-size: .9rem; color: #5a5245; margin-top: .5rem; }
  .map-svg { width: 100%; max-width: 48rem; height: auto; display: block; background: #e3d9bd; border: 1px solid rgba(34,31,26,.4); }
  .card-list { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
  .card-list li {
    background: #f6f1e2;
    border: 1px solid rgba(34,31,26,.35);
    padding: 1rem 1.1rem;
    font-size: 1rem;
    position: relative;
  }
  .card-list li::before { /* catalogue card punch hole */
    content: ""; position: absolute; bottom: .5rem; left: 50%; width: .7rem; height: .7rem;
    margin-left: -.35rem; border-radius: 50%; background: var(--paper); border: 1px solid rgba(34,31,26,.35);
  }
  .card-list .call { font-family: var(--mono); font-size: .85rem; color: var(--stamp-violet); display: block; }
  .card-list strong { display: block; margin: .2rem 0 .3rem; }
  .card-list p { margin: 0 0 1rem; }
  @media (max-width: 40rem) { .tabs { margin-top: .5rem; } }

  /* ---------- References ---------- */
  sup.ref { font-family: var(--mono); font-size: .7em; line-height: 0; }
  sup.ref a { text-decoration: none; }
  .refs { font-size: .95rem; padding-left: 1.6rem; max-width: 52rem; }
  .refs li { margin-bottom: .6rem; overflow-wrap: anywhere; }
  .refs li:target { background: rgba(75,63,120,.12); }

  /* ---------- Hand correction on the home title (drawn by script) ---------- */
  .correction { position: relative; display: inline-block; }
  .correction .scribble {
    position: absolute; left: -5%; top: 0;
    width: 110%; height: 100%;
    overflow: visible; pointer-events: none;
  }
  .correction .handwriting {
    position: absolute; left: 28%; bottom: 74%; /* squeezed in above the word; takes no layout space */
    height: .48em; width: auto;
    overflow: visible; pointer-events: none;
    transform-origin: left bottom;
  }

  /* ---------- Stamps are artwork, not text to copy ---------- */
  .stamp, .violet-stamp, .folder h1,
  .correction, .correction .handwriting, .correction .scribble {
    -webkit-user-select: none;
    user-select: none;
    cursor: default;
  }
  /* the lettering is drawn by CSS, so it is never part of the page text */
  .correction .ru::before, .folder h1[data-text]::before { content: attr(data-text); }
  .stamp::before, .violet-stamp::before {
    content: attr(data-stamp);
    white-space: pre-line;
  }

  /* ---------- Warning label beside the tabs ---------- */
  .tabs .warning {
    margin-left: auto;
    align-self: center;
    position: relative; top: -.75rem; /* even space above and below; doesn't move anything else */
    font-family: var(--stamp);
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: .06em;
    color: var(--stamp-red);
    border: 2px solid var(--stamp-red);
    padding: .15rem .6rem;
    -webkit-user-select: none;
    user-select: none;
    cursor: default;
  }
  .tabs .warning::before { content: attr(data-stamp); }
  @media (max-width: 75rem) { /* not enough room beside the six tabs: own line above them, still on the right */
    .tabs .warning { order: -1; top: 0; margin: .4rem 0 .7rem auto; }
    .tab-links { flex-basis: 100%; }
  }
  @media (max-width: 40rem) {
    .tabs .warning { margin: .4rem 0 .6rem; font-size: .8rem; max-width: 100%; }
  }

  /* ---------- Footer: contact on the left, note on the right ---------- */
  footer {
    display: flex; justify-content: space-between; align-items: baseline;
    flex-wrap: wrap; gap: 0 2rem;
  }
  footer p { margin: .3rem 0; }
  footer a { color: inherit; }
  .footer-note { text-align: right; }
  @media (max-width: 40rem) {
    footer { display: block; }
    .footer-note { text-align: left; margin-top: 1rem; }
  }


  /* ---------- Logo: СЕКРЕТНО drawn as an embedded SVG after Soviet map lettering (style Рн-342) ---------- */
  .logo {
    display: inline-block;
    color: var(--ink);
    line-height: 0;
    -webkit-user-select: none;
    user-select: none;
    cursor: default;
  }
  .logo-mark { display: block; height: .95rem; width: auto; }


  /* ---------- Phones ---------- */
  @media (max-width: 40rem) {
    /* tabs: one compact row that scrolls sideways */
    .tabs { margin-top: .25rem; }
    .tab-links {
      position: relative;
      flex-wrap: nowrap; gap: .3rem;
      overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .tab-links::-webkit-scrollbar { display: none; }
    .tab-links.more-right { -webkit-mask-image: linear-gradient(to right, #000 82%, transparent); mask-image: linear-gradient(to right, #000 82%, transparent); }
    .tab-links.more-left { -webkit-mask-image: linear-gradient(to left, #000 82%, transparent); mask-image: linear-gradient(to left, #000 82%, transparent); }
    .tab-links.more-left.more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 14%, #000 86%, transparent); mask-image: linear-gradient(to right, transparent, #000 14%, #000 86%, transparent); }
    .tabs a { flex: none; font-size: .82rem; padding: .45rem .8rem .35rem; }
    .tabs .warning { font-size: .7rem; padding: .1rem .5rem; margin: .45rem auto .55rem; } /* centred */

    /* folder header: smaller and tighter */
    .folder { padding: 1.3rem 1.25rem 2rem; }
    .folder-head { font-size: .78rem; gap: .3rem 1rem; padding-bottom: .5rem; }
    .logo-mark { height: .8rem; }
    .folder h1 { margin: 1.3rem 0 .8rem; }
    .folder .lede { font-size: 1.08rem; }
    .fields { margin-top: 1.4rem; }

    /* stamp: smaller, bottom-right of the folder */
    .stamp { font-size: .85rem; padding: .3rem .55rem; border-width: 4px; top: 4.4rem; right: .9rem; }
    .violet-stamp { float: right; margin: 0 0 .6rem .8rem; font-size: .68rem; padding: .8rem .65rem; }
  }

  /* sub-headings inside a section, e.g. map scales */
  .sheet h3 {
    font-family: var(--mono);
    font-weight: 400;
    font-size: 1.05rem;
    letter-spacing: .02em;
    margin: 1.8rem 0 .3rem;
    padding-bottom: .2rem;
    border-bottom: 1px solid rgba(34,31,26,.35);
    max-width: 44rem;
  }

  /* photographs of original documents */
  .doc-photo { max-width: 44rem; margin: 1.2rem 0 .4rem; }
  .doc-photo img { display: block; width: 100%; height: auto; border: 1px solid rgba(34,31,26,.35); box-shadow: 0 4px 14px rgba(40,25,5,.18); }
  .doc-photo a { display: block; cursor: zoom-in; }

  /* embedded videos: 16:9, same width as text */
  .video { max-width: 44rem; aspect-ratio: 16 / 9; margin: 1rem 0 .4rem; border: 1px solid rgba(34,31,26,.35); box-shadow: 0 4px 14px rgba(40,25,5,.18); background: #1a1814; }
  .video iframe { display: block; width: 100%; height: 100%; border: 0; }

  /* lists inside sections */
  .sheet ul { max-width: 44rem; margin: -.4rem 0 1rem; padding-left: 1.3rem; }
  .sheet ul li { margin-bottom: .35rem; }
  .sheet ul li::marker { color: var(--stamp-red); }

  /* ---------- Source popups: hover or keyboard focus on [n] shows the source (CSS only) ---------- */
  sup.ref { position: relative; }
  .ref-pop { display: none; }
  @media (hover: hover) {
    sup.ref:hover .ref-pop,
    sup.ref:focus-within .ref-pop {
      display: block;
      position: absolute;
      z-index: 20;
      bottom: 100%;
      left: -1rem;
      width: max-content;
      max-width: min(24rem, calc(100vw - 3rem));
      margin-bottom: .45rem;
      padding: .6rem .75rem;
      background: #fbf7ec;
      border: 1px solid rgba(34,31,26,.35);
      box-shadow: 0 6px 18px rgba(40,25,5,.22);
      font-family: var(--serif);
      font-size: .85rem;
      line-height: 1.45;
      font-weight: 400;
      color: var(--ink);
      text-align: left;
      white-space: normal;
      overflow-wrap: anywhere;
    }
    /* invisible bridge so the pointer can move from [n] into the popup without it closing */
    sup.ref:hover .ref-pop::after,
    sup.ref:focus-within .ref-pop::after {
      content: ""; position: absolute; left: 0; right: 0; top: 100%; height: .6rem;
    }
    .ref-pop .ref-num { font-family: var(--mono); color: var(--stamp-violet); margin-right: .2rem; }
    .ref-pop a { color: var(--stamp-violet); }
  }
