/* =============================================================================
   制作記録の記事 — a production log sheet laid on the workbench.
   Masthead fields like a spec form, numbered sections hanging in the margin,
   numbered figures, code as a printout, and the same "END OF …" close as the
   works archive. Everything is scoped to .article-view.
   ============================================================================= */
.article-view {
  --a-bg: var(--workbench-black, #070707);
  --a-panel: var(--workbench-panel, #0b0b0b);
  --a-ink: var(--workbench-ink, #e6e6e6);
  --a-text: #c3c3c3;
  --a-muted: var(--workbench-muted, #858585);
  --a-line: var(--workbench-line, rgba(255, 255, 255, 0.12));
  --a-line-soft: var(--workbench-line-soft, rgba(255, 255, 255, 0.065));
  --a-accent: var(--workbench-accent, #bdbdbd);
  --a-bar: 56px;
  --a-gutter: clamp(20px, 4vw, 56px);
  --a-pixel: var(--font-display, 'DotGothic16', monospace);
  --a-body: var(--font-body, 'Noto Sans JP', sans-serif);

  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  background: var(--a-bg);
  color: var(--a-text);
  font-family: var(--a-body);
  /* Stays visible briefly after closing so the exit motion can play. */
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 0.3s;
}
.article-view.active {
  visibility: visible;
  pointer-events: auto;
  transition: none;
}

/* Paper: the same sheet printed out, for long reading in daylight. */
.article-view.is-paper,
.article-paper .article-view {
  --a-bg: #e7e5df;
  --a-panel: #dcd9d1;
  --a-ink: #151515;
  --a-text: #2b2b2a;
  --a-muted: #6a6762;
  --a-line: rgba(0, 0, 0, 0.16);
  --a-line-soft: rgba(0, 0, 0, 0.08);
  --a-accent: #3b3b3a;
}

.article-view .ps2-text { font-family: var(--a-pixel); }
.article-view ::selection { background: var(--a-ink); color: var(--a-bg); }

/* --- Top bar ------------------------------------------------------------- */
.article-bar {
  position: relative;
  flex: 0 0 var(--a-bar);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 28px;
  padding: 0 var(--a-gutter);
  background: var(--a-bg);
  border-bottom: 1px solid var(--a-line);
}
.article-bar-label {
  color: var(--a-muted);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
}
.article-bar-section {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
  color: var(--a-ink);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.2s steps(3, end);
}
.article-view.is-reading .article-bar-section { opacity: 1; }
.article-bar-section b { flex: none; color: var(--a-muted); font-weight: 400; }
.article-bar-section span {
  overflow: hidden;
  font-family: var(--a-body);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.article-bar-actions { display: flex; align-items: center; justify-self: end; gap: 4px; }
.article-bar-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--a-muted);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: color 0.2s ease;
}
.article-bar-btn::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 9px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.3s steps(6, end);
}
.article-bar-btn[aria-pressed="true"],
.article-bar-btn[aria-expanded="true"] { color: var(--a-ink); }
.article-bar-btn[aria-pressed="true"]::after,
.article-bar-btn[aria-expanded="true"]::after { transform: scaleX(1); }
@media (hover: hover) {
  .article-bar-btn:hover { color: var(--a-ink); }
  .article-bar-btn:hover::after { transform: scaleX(1); }
}
.article-bar-btn:focus-visible { outline: 1px solid var(--a-accent); outline-offset: -2px; }
.article-key {
  padding: 1px 5px;
  border: 1px solid var(--a-line);
  color: var(--a-muted);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
}
.article-toc-toggle { display: none; }

/* Reading progress: the bar's own bottom rule fills from the left. */
.article-progress {
  --read: 0;
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--a-ink);
  transform: scaleX(var(--read));
  transform-origin: left center;
  pointer-events: none;
}

/* --- Sheet ---------------------------------------------------------------- */
.article-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-top: 28px;
  scrollbar-color: var(--a-line) transparent;
}
.article-sheet {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: clamp(36px, 6vh, 72px) var(--a-gutter) 0;
}

/* Masthead: the fields of a log sheet, ruled like a form. */
.article-head {
  position: relative;
  padding-bottom: clamp(36px, 5vh, 56px);
}
.article-head::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--a-line);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.article-head.is-ruled::after { transform: scaleX(1); }
.article-fields {
  display: grid;
  grid-template-columns: 0.7fr 1fr 1fr 0.7fr 1.6fr;
  margin: 0 0 clamp(36px, 6vh, 64px);
  border-top: 1px solid var(--a-line);
  border-bottom: 1px solid var(--a-line);
}
.article-fields > div {
  min-width: 0;
  padding: 12px 16px 13px;
  border-left: 1px solid var(--a-line-soft);
}
.article-fields > div:first-child { padding-left: 0; border-left: 0; }
.article-fields dt {
  margin: 0 0 6px;
  color: var(--a-muted);
  font-size: 0.6rem;
  letter-spacing: 0.22em;
}
.article-fields dd {
  margin: 0;
  overflow: hidden;
  color: var(--a-ink);
  font-size: 0.84rem;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.article-title {
  max-width: 22em;
  margin: 0;
  color: var(--a-ink);
  font-family: var(--a-body);
  font-size: clamp(1.7rem, 3.3vw, 2.55rem);
  font-weight: 500;
  line-height: 1.42;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}
.article-title:focus { outline: none; }
.article-lede {
  max-width: 38em;
  margin: 20px 0 0;
  color: var(--a-muted);
  font-size: 0.95rem;
  line-height: 1.9;
}

/* --- Body and index ------------------------------------------------------- */
.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 680px) 210px;
  justify-content: space-between;
  column-gap: 64px;
  padding: clamp(40px, 6vh, 64px) 0 0 76px;
}
.article-content {
  min-width: 0;
  font-size: 1rem;
  line-height: 2;
  letter-spacing: 0.03em;
  overflow-wrap: anywhere;
}
.article-content > * { margin: 0 0 1.6em; }
.article-content > :last-child { margin-bottom: 0; }
.article-content p { color: var(--a-text); }
.article-content strong { color: var(--a-ink); font-weight: 700; }

/* Section numbers hang in the left margin, as on a ruled log. */
.article-content .article-h2,
.article-content .article-h3 {
  position: relative;
  color: var(--a-ink);
  font-family: var(--a-body);
  font-weight: 500;
  letter-spacing: 0.02em;
  scroll-margin-top: 28px;
}
.article-content .article-h2 {
  margin: 2.9em 0 1.1em;
  padding-top: 1.1em;
  border-top: 1px solid var(--a-line);
  font-size: 1.32rem;
  line-height: 1.6;
}
.article-content > .article-h2:first-child { margin-top: 0; }
.article-content .article-h3 {
  margin: 2.1em 0 0.8em;
  font-size: 1.06rem;
  line-height: 1.7;
}
.article-h-number {
  position: absolute;
  right: calc(100% + 22px);
  color: var(--a-muted);
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.article-h2 .article-h-number { top: calc(1.1em + 0.5em); }
.article-h3 .article-h-number { top: 0.45em; }

.article-content a {
  color: var(--a-ink);
  text-decoration: underline;
  text-decoration-color: var(--a-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: text-decoration-color 0.2s ease;
}
.article-content a.is-external::after {
  content: '↗';
  margin-left: 2px;
  color: var(--a-muted);
  font-size: 0.8em;
}
@media (hover: hover) {
  .article-content a:hover { text-decoration-color: var(--a-ink); }
}

/* Lists: short rules instead of bullets, pixel numerals for steps. */
.article-content ul,
.article-content ol { padding: 0; list-style: none; }
.article-content ol { counter-reset: article-step; }
.article-content li {
  position: relative;
  padding-left: 1.8em;
  color: var(--a-text);
}
.article-content li + li { margin-top: 0.35em; }
.article-content ul > li::before {
  content: '';
  position: absolute;
  left: 0.2em;
  top: 1em;
  width: 0.8em;
  height: 1px;
  background: var(--a-muted);
}
.article-content ol > li { counter-increment: article-step; }
.article-content ol > li::before {
  content: counter(article-step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.15em;
  color: var(--a-muted);
  font-family: var(--a-pixel);
  font-size: 0.74rem;
}

.article-content code {
  padding: 0.1em 0.4em;
  border: 1px solid var(--a-line);
  background: var(--a-panel);
  color: var(--a-ink);
  font-family: var(--a-pixel);
  font-size: 0.86em;
}

/* Code: a printout with its own header and line numbers. */
.article-code {
  margin: 2em 0;
  border: 1px solid var(--a-line);
  background: var(--a-panel);
}
.article-code-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--a-line-soft);
  color: var(--a-muted);
  font-size: 0.6rem;
  letter-spacing: 0.22em;
}
.article-code pre {
  margin: 0;
  padding: 14px 0;
  overflow-x: auto;
  counter-reset: article-line;
}
.article-code pre code {
  display: block;
  min-width: max-content;
  padding: 0;
  border: 0;
  background: none;
  color: var(--a-text);
  font-size: 0.82rem;
  line-height: 1.85;
}
.article-code-line {
  display: block;
  padding-right: 20px;
  counter-increment: article-line;
  white-space: pre;
}
.article-code-line::before {
  content: counter(article-line);
  display: inline-block;
  width: 3.4em;
  margin-right: 1em;
  padding-right: 0.9em;
  border-right: 1px solid var(--a-line-soft);
  color: var(--a-muted);
  text-align: right;
  user-select: none;
  opacity: 0.7;
}

/* Note: a margin remark rather than a quotation box. */
.article-note {
  margin: 2em 0;
  padding: 2px 0 2px 22px;
  border-left: 1px solid var(--a-accent);
  color: var(--a-text);
}
.article-note > p { margin: 0; }
.article-note > p + p { margin-top: 0.8em; }
.article-note-label {
  display: block;
  margin-bottom: 4px;
  color: var(--a-muted);
  font-size: 0.6rem;
  letter-spacing: 0.24em;
}

/* Figures are numbered and captioned; the frame opens the enlarged view. */
.article-figure { margin: 2.6em 0; }
.article-figure-frame {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--a-panel);
  cursor: zoom-in;
}
.article-figure-frame img {
  display: block;
  width: 100%;
  height: auto;
}
.article-figure-frame:focus-visible { outline: 1px solid var(--a-accent); outline-offset: 4px; }
.article-figure figcaption {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-top: 12px;
  color: var(--a-muted);
  font-size: 0.8rem;
  line-height: 1.7;
}
.article-figure figcaption span {
  flex: none;
  color: var(--a-ink);
  font-size: 0.66rem;
  letter-spacing: 0.16em;
}
.article-content p img { max-width: 100%; height: auto; cursor: zoom-in; }

/* Tables: ruled rows, pixel headers. */
.article-table { margin: 2em 0; overflow-x: auto; }
.article-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  line-height: 1.7;
}
.article-table th {
  padding: 0 16px 10px 0;
  border-bottom: 1px solid var(--a-accent);
  color: var(--a-muted);
  font-family: var(--a-pixel);
  font-size: 0.66rem;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-align: left;
  white-space: nowrap;
}
.article-table td {
  padding: 11px 16px 11px 0;
  border-bottom: 1px solid var(--a-line-soft);
  color: var(--a-text);
  vertical-align: top;
}
.article-table td:first-child { color: var(--a-ink); }

.article-content hr {
  height: 1px;
  margin: 3em 0;
  border: 0;
  background: var(--a-line);
}

/* Index: numbers and titles; the section in view carries a short rule. */
.article-toc {
  position: sticky;
  top: 28px;
  align-self: start;
  max-height: calc(100vh - var(--a-bar) - 56px);
  overflow-y: auto;
  scrollbar-width: none;
}
.article-toc::-webkit-scrollbar { display: none; }
.article-toc-label {
  margin: 0 0 14px;
  color: var(--a-muted);
  font-size: 0.6rem;
  letter-spacing: 0.24em;
}
.article-toc ol { margin: 0; padding: 0; list-style: none; border-left: 1px solid var(--a-line-soft); }
.article-toc a {
  position: relative;
  display: grid;
  grid-template-columns: 2.6em minmax(0, 1fr);
  padding: 6px 0 6px 14px;
  color: var(--a-muted);
  font-size: 0.8rem;
  line-height: 1.6;
  text-decoration: none;
  transition: color 0.2s ease;
}
.article-toc a span { font-size: 0.66rem; letter-spacing: 0.06em; line-height: 2; }
.article-toc .is-sub a { padding-left: 26px; font-size: 0.76rem; }
.article-toc a::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 8px;
  bottom: 8px;
  width: 1px;
  background: var(--a-ink);
  transform: scaleY(0);
  transition: transform 0.24s steps(5, end);
}
.article-toc a.is-current { color: var(--a-ink); }
.article-toc a.is-current::before { transform: scaleY(1); }
@media (hover: hover) {
  .article-toc a:hover { color: var(--a-ink); }
}
.article-toc a:focus-visible { outline: 1px solid var(--a-accent); outline-offset: 2px; }

/* --- Loading and errors -------------------------------------------------- */
.article-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  color: var(--a-muted);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
}
.article-status i {
  width: 0.6em;
  height: 1.1em;
  background: var(--a-muted);
  animation: article-cursor 1s steps(1, end) infinite;
}
@keyframes article-cursor { 50% { opacity: 0; } }
.article-status.is-error { display: block; letter-spacing: 0; }
.article-status.is-error span { display: block; margin-bottom: 8px; color: var(--a-ink); font-size: 0.7rem; letter-spacing: 0.22em; }
.article-status.is-error p { margin: 0; color: var(--a-text); font-family: var(--a-body); font-size: 0.95rem; }
.article-status-detail { margin-top: 6px !important; color: var(--a-muted) !important; font-size: 0.8rem !important; }

/* --- End of record -------------------------------------------------------- */
/* Laid out on the body's grid, so it lines up with the text column exactly. */
.article-end {
  display: grid;
  grid-template-columns: minmax(0, 680px) 210px;
  justify-content: space-between;
  column-gap: 64px;
  padding: clamp(64px, 10vh, 112px) 0 clamp(64px, 12vh, 120px) 76px;
}
.article-end > * { grid-column: 1; }
.article-end:empty { display: none; }
.article-end-mark {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
  color: var(--a-muted);
  font-size: 0.66rem;
  letter-spacing: 0.2em;
}
.article-end-mark i { width: 48px; height: 1px; background: var(--a-accent); }
.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 24px 0 0;
  color: var(--a-muted);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
}
/* Works made in this record, then the post on X and the page for sharing. */
.article-related {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 22px;
  margin: 28px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--a-line);
}
.article-related span { width: 100%; color: var(--a-muted); font-size: 0.64rem; letter-spacing: 0.2em; }
.article-links { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 18px 0 0; }
.article-related a,
.article-links a {
  color: var(--a-ink);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-decoration: underline;
  text-decoration-color: var(--a-line);
  text-underline-offset: 5px;
  transition: text-decoration-color 0.25s ease;
}
.article-related a { font-size: 0.86rem; letter-spacing: 0.02em; }
@media (hover: hover) {
  .article-related a:hover,
  .article-links a:hover { text-decoration-color: currentColor; }
}
.article-related a:focus-visible,
.article-links a:focus-visible { outline: 1px solid var(--a-accent); outline-offset: 3px; }
.article-pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 24px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--a-line);
}
.article-pager-link {
  display: grid;
  gap: 6px;
  padding: 6px 0;
  border: 0;
  background: none;
  color: var(--a-text);
  font-family: var(--a-body);
  text-align: left;
  cursor: pointer;
}
.article-pager-link.is-next { text-align: right; }
.article-pager-link span.ps2-text { color: var(--a-muted); font-size: 0.64rem; letter-spacing: 0.2em; }
.article-pager-link.is-prev span.ps2-text::before { content: '← '; }
.article-pager-link.is-next span.ps2-text::after { content: ' →'; }
.article-pager-title { font-size: 0.9rem; line-height: 1.6; }
.article-pager-back {
  align-self: center;
  padding: 10px 16px;
  border: 1px solid var(--a-line);
  background: none;
  color: var(--a-muted);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
@media (hover: hover) {
  .article-pager-link:hover .article-pager-title { color: var(--a-ink); }
  .article-pager-back:hover { color: var(--a-ink); border-color: var(--a-accent); }
}
.article-pager-link:focus-visible,
.article-pager-back:focus-visible { outline: 1px solid var(--a-accent); outline-offset: 3px; }

/* --- Narrow screens -------------------------------------------------------- */
@media (max-width: 1024px) {
  .article-layout { grid-template-columns: minmax(0, 1fr); padding-left: 0; }
  .article-end { grid-template-columns: minmax(0, 1fr); padding-left: 0; }
  .article-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .article-fields > div:nth-child(5) {
    grid-column: 1 / -1;
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--a-line-soft);
  }
  /* Section numbers move inline, before the heading. */
  .article-h-number {
    position: static;
    display: block;
    margin-bottom: 4px;
  }
  .article-toc-toggle:not([hidden]) { display: inline-flex; }
  /* The index opens from the bar as a sheet of its own. */
  .article-toc {
    position: absolute;
    top: var(--a-bar);
    left: 0;
    right: 0;
    z-index: 2;
    max-height: min(62vh, 520px);
    padding: 18px var(--a-gutter) 22px;
    background: var(--a-bg);
    border-bottom: 1px solid var(--a-line);
    visibility: hidden;
    clip-path: inset(0 0 100% 0);
    transition: clip-path 0.26s steps(8, end), visibility 0s linear 0.26s;
  }
  .article-view.toc-open .article-toc {
    visibility: visible;
    clip-path: inset(0 0 0% 0);
    transition: clip-path 0.26s steps(8, end);
  }
}
@media (max-width: 640px) {
  .article-view { --a-bar: 52px; }
  .article-bar { grid-template-columns: auto minmax(0, 1fr); column-gap: 12px; padding-right: 8px; }
  .article-bar-section { display: none; }
  .article-bar-btn { padding: 0 9px; letter-spacing: 0.08em; }
  .article-key { display: none; }
  .article-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .article-fields > div:nth-child(3) { padding-left: 0; border-left: 0; }
  .article-fields > div:nth-child(n + 3) { border-top: 1px solid var(--a-line-soft); }
  .article-content { font-size: 0.95rem; line-height: 1.95; }
  .article-content .article-h2 { font-size: 1.18rem; }
  .article-pager { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .article-pager-back { grid-column: 1 / -1; grid-row: 2; justify-self: start; }
}

/* --- Shared page (records/<id>/) ---------------------------------------- */
/* The same sheet as a page of its own: the document scrolls and the bar stays on top. */
.article-page body { margin: 0; background: #070707; }
.article-page.article-paper body { background: #e7e5df; }
.article-view.is-static,
.article-view.is-static *,
.article-view.is-static *::before,
.article-view.is-static *::after { box-sizing: border-box; }
.article-view.is-static {
  position: static;
  min-height: 100vh;
  visibility: visible;
  pointer-events: auto;
  transition: none;
}
.article-view.is-static .article-bar { position: sticky; top: 0; z-index: 3; }
.article-view.is-static .article-scroll { flex: none; overflow: visible; }
.article-view.is-static .article-toc { top: calc(var(--a-bar) + 28px); }
.article-view.is-static .article-content .article-h2,
.article-view.is-static .article-content .article-h3 { scroll-margin-top: calc(var(--a-bar) + 28px); }
.article-view.is-static .article-bar-label,
.article-view.is-static .article-bar-btn,
.article-view.is-static .article-pager-link,
.article-view.is-static .article-pager-back { text-decoration: none; }
.article-view.is-static .article-bar-label { color: var(--a-muted); }
@media (hover: hover) {
  .article-view.is-static .article-bar-label:hover { color: var(--a-ink); }
}
@media (max-width: 1024px) {
  /* No bar menu here: the index sits above the text. */
  .article-view.is-static .article-toc {
    position: static;
    order: -1;
    max-height: none;
    margin-bottom: 40px;
    padding: 0;
    border: 0;
    background: none;
    visibility: visible;
    clip-path: none;
    transition: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .article-view,
  .article-head::after,
  .article-bar-btn::after,
  .article-bar-section,
  .article-toc,
  .article-toc a::before { transition: none !important; }
  .article-status i { animation: none; }
}
