/* Base settings */
:root {
  --bg: #efeee9;
  --paper: #f8f7f2;
  --paper-dark: #e2dfd6;
  --ink: #171717;
  --muted: #6a6964;
  --line: #c9c4b8;
  --line-dark: #8d877b;
  --red: #7a171d;
  --red-dark: #4f0f13;
  --shadow: 0 22px 60px rgba(20, 18, 16, 0.08);
  --max: 1120px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.025) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
    var(--bg);
  background-size: 42px 42px, 42px 42px, auto;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.85;
  letter-spacing: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 10%, transparent 0, rgba(0, 0, 0, 0.08) 100%);
  opacity: 0.55;
  z-index: -2;
}

a {
  color: inherit;
  text-decoration-color: rgba(122, 23, 29, 0.45);
  text-underline-offset: 0.22em;
}

a:hover {
  color: var(--red);
}

img,
svg {
  max-width: 100%;
}

button,
input {
  font: inherit;
}

/* Subtle paper texture overlay */
.page-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.22;
  background-image:
    repeating-radial-gradient(circle at 12% 18%, rgba(0, 0, 0, 0.09) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(103deg, rgba(255, 255, 255, 0.18) 0 1px, transparent 1px 5px);
  mix-blend-mode: multiply;
}

.stray-note {
  position: fixed;
  right: clamp(12px, 3vw, 42px);
  bottom: 42%;
  writing-mode: vertical-rl;
  color: rgba(79, 15, 19, 0.28);
  font-family: "Courier New", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* Shared layout */
.site-header {
  width: min(var(--max), calc(100% - 32px));
  margin: 24px auto 0;
  padding: 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.site-logo {
  font-weight: 700;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  text-decoration: none;
  letter-spacing: 0.03em;
}

.misalign {
  display: inline-block;
  transform: translateY(2px) rotate(-1.5deg);
  color: var(--red-dark);
}

.global-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

.global-nav a {
  position: relative;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.global-nav a:hover {
  text-shadow: 1px 0 rgba(122, 23, 29, 0.38), -1px 0 rgba(0, 0, 0, 0.18);
}

.global-nav a.is-current {
  color: var(--red-dark);
}

.section {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(44px, 8vw, 82px) 0;
  min-width: 0;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.section-kicker {
  margin: 0 0 8px;
  color: var(--red);
  font-family: "Courier New", monospace;
  font-size: 0.76rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.35;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 600;
  overflow-wrap: anywhere;
}

h1 {
  font-size: clamp(2.3rem, 9vw, 6.4rem);
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
}

h3 {
  font-size: 1.2rem;
}

p {
  margin: 0;
}

.lead {
  margin-top: 14px;
  font-size: clamp(1.08rem, 2.6vw, 1.5rem);
  color: #2a2927;
}

.button {
  min-height: 48px;
  padding: 10px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--red-dark);
  text-decoration: none;
  font-weight: 700;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button--primary {
  color: #f8f7f2;
  background: var(--red-dark);
}

.button--ghost {
  color: var(--red-dark);
  background: rgba(248, 247, 242, 0.54);
}

/* Top page */
.hero {
  min-height: calc(100vh - 92px);
  display: grid;
  align-content: center;
  position: relative;
}

.hero::after {
  content: "record copied / original location unknown";
  position: absolute;
  right: 0;
  bottom: 38px;
  max-width: 100%;
  color: rgba(23, 23, 23, 0.28);
  font-family: "Courier New", monospace;
  font-size: 0.72rem;
  overflow-wrap: anywhere;
}

.hero__meta {
  width: fit-content;
  margin-bottom: 22px;
  padding: 5px 10px;
  color: var(--red-dark);
  background: rgba(122, 23, 29, 0.08);
  border: 1px solid rgba(122, 23, 29, 0.22);
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
}

.hero__title {
  white-space: nowrap;
  font-size: clamp(2.35rem, 7.1vw, 5.8rem);
}

.hero__text {
  max-width: 720px;
  margin-top: 28px;
  color: #33312e;
}

.hero__actions {
  margin-top: 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.recovery-console {
  width: min(760px, 100%);
  max-width: 100%;
  margin-top: 32px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: rgba(248, 247, 242, 0.62);
  font-family: "Courier New", monospace;
  font-size: 0.78rem;
  overflow: hidden;
}

.recovery-console span {
  min-width: 0;
  min-height: 42px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  color: #45423c;
  border-right: 1px solid var(--line);
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.recovery-console span:first-child {
  color: var(--red-dark);
}

.recovery-console span:last-child {
  border-right: 0;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(300px, 0.78fr);
  gap: clamp(24px, 4vw, 56px);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.intro-panel__title {
  white-space: nowrap;
  font-size: clamp(1.28rem, 2.85vw, 2.12rem);
}

.split-section {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: clamp(28px, 6vw, 72px);
  align-items: start;
}

/* Cards and record lists */
.card-grid,
.archive-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.archive-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.record-card {
  position: relative;
  min-height: 260px;
  padding: 22px;
  background: rgba(248, 247, 242, 0.78);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-wrap: break-word;
}

.record-card:nth-child(even) {
  transform: translateY(7px);
}

.record-card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(141, 135, 123, 0.28);
  pointer-events: none;
}

.record-card__top,
.record-card__meta,
.story-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.record-card__top {
  justify-content: space-between;
  margin-bottom: 18px;
}

.record-card h2,
.record-card h3 {
  margin-bottom: 14px;
  font-size: clamp(1.1rem, 2.6vw, 1.28rem);
}

.record-card p {
  color: #3f3d39;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.record-card__meta {
  margin-top: 22px;
  justify-content: space-between;
}

.record-number,
.ghost-number {
  font-family: "Courier New", monospace;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.status {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 2px 9px;
  border: 1px solid currentColor;
  font-size: 0.78rem;
  line-height: 1.4;
}

.status--watch {
  color: #534f48;
}

.status--review {
  color: #7a171d;
}

.status--danger {
  color: #f8f7f2;
  background: var(--red-dark);
}

.status--copy {
  color: #5b5550;
  background: rgba(23, 23, 23, 0.06);
}

.tag-row,
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-row span,
.tag-cloud a {
  padding: 4px 10px;
  color: #45423c;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.tag-cloud a:hover {
  border-color: var(--red);
  transform: translateY(1px) rotate(-0.4deg);
}

.thin-list {
  border-top: 1px solid var(--line);
}

.thin-list a {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}

.thin-list span {
  color: var(--red);
  font-family: "Courier New", monospace;
}

/* Archive controls */
.page-title {
  padding-bottom: 24px;
}

.page-title p:last-child {
  max-width: 680px;
  margin-top: 18px;
  color: #3f3d39;
}

.filter-box {
  padding-top: 10px;
  padding-bottom: 22px;
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: end;
}

.search-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.search-field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  color: var(--ink);
  background: rgba(248, 247, 242, 0.8);
  border: 1px solid var(--line-dark);
  outline: none;
}

.search-field input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(122, 23, 29, 0.12);
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-button {
  min-height: 40px;
  padding: 7px 12px;
  color: #383632;
  background: rgba(248, 247, 242, 0.68);
  border: 1px solid var(--line);
  cursor: pointer;
  border-radius: 0;
}

.filter-button:hover,
.filter-button.is-active {
  color: #f8f7f2;
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.empty-message {
  margin-top: 26px;
  padding: 18px;
  color: var(--red-dark);
  border: 1px dashed var(--red);
  background: rgba(248, 247, 242, 0.62);
}

.loading-message {
  color: var(--muted);
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
}

/* Story page */
.story-article {
  width: min(840px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(52px, 8vw, 96px) 0 28px;
}

.story-header {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.story-header h1 {
  margin-bottom: 22px;
  font-size: clamp(2.1rem, 7vw, 4.6rem);
}

.story-header .tag-row {
  margin-top: 18px;
}

.story-body {
  padding: clamp(38px, 7vw, 76px) 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(1.05rem, 2vw, 1.17rem);
  line-height: 2.05;
  overflow-wrap: break-word;
}

.story-body > * + *,
.mini-story p + p {
  margin-top: 1.65em;
}

.story-body a {
  color: var(--red-dark);
}

.story-body blockquote {
  margin: 2em 0;
  padding-left: 18px;
  border-left: 2px solid var(--line-dark);
  color: #3f3d39;
}

.story-pagination {
  padding-top: 28px;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.page-numbers {
  min-width: 40px;
  min-height: 40px;
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: rgba(248, 247, 242, 0.68);
  text-decoration: none;
}

.page-numbers.current {
  color: #f8f7f2;
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.last-line {
  margin-top: clamp(54px, 10vw, 110px) !important;
  padding-left: 18px;
  border-left: 2px solid var(--red);
  color: #161413;
  font-size: clamp(1.1rem, 2.4vw, 1.32rem);
  line-height: 2;
}

.after-note,
.document-panel,
.not-found__box {
  padding: clamp(24px, 5vw, 42px);
  background: rgba(248, 247, 242, 0.76);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-wrap: break-word;
}

.after-note h2,
.document-panel h2 {
  margin-bottom: 14px;
  font-size: clamp(1.25rem, 3vw, 1.7rem);
}

.sample-stories {
  width: min(840px, calc(100% - 32px));
}

.mini-story {
  padding: 28px 0;
  border-bottom: 1px solid var(--line);
}

.mini-story:first-of-type {
  border-top: 1px solid var(--line);
}

.mini-story h3 {
  margin-bottom: 18px;
}

.story-nav {
  width: min(840px, calc(100% - 32px));
  padding-top: 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
}

/* About page */
.document-panel {
  width: min(860px, calc(100% - 32px));
}

.document-panel p + p {
  margin-top: 18px;
}

.document-panel ul,
.document-panel ol {
  padding-left: 1.4em;
}

.document-panel--offset {
  transform: translateX(28px);
}

/* Subtle restore failure effect for short interface copy only */
.corrupt-text {
  position: relative;
}

.corrupt-char {
  display: inline-block;
  min-width: 0.55em;
  transition: color 420ms ease, opacity 420ms ease, transform 420ms ease, text-shadow 420ms ease;
}

.corrupt-char.is-faded {
  color: rgba(69, 66, 60, 0.34);
  opacity: 0.9;
  transform: translateY(0.5px);
  text-shadow:
    0.8px 0 rgba(248, 247, 242, 0.75),
    -0.8px 0 rgba(141, 135, 123, 0.16);
}

.corrupt-char.is-erased {
  color: transparent;
  opacity: 0.86;
  background:
    linear-gradient(180deg, transparent 0 42%, rgba(141, 135, 123, 0.18) 42% 58%, transparent 58%),
    radial-gradient(ellipse at 35% 56%, rgba(122, 23, 29, 0.12) 0 18%, transparent 19%),
    radial-gradient(ellipse at 72% 48%, rgba(141, 135, 123, 0.16) 0 16%, transparent 17%);
  background-size: 100% 100%, 0.72em 0.34em, 0.58em 0.28em;
  background-position: center, center, center;
  background-repeat: no-repeat;
  text-shadow: none;
}

.corrupt-text.is-restored .corrupt-char {
  color: inherit;
  opacity: 1;
  transform: none;
  background: transparent;
  text-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .corrupt-char {
    transition: none;
  }
}

/* 404 page */
.not-found {
  min-height: calc(100vh - 220px);
  display: grid;
  place-items: center;
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 64px 0;
}

.not-found__box {
  position: relative;
  width: 100%;
  text-align: center;
}

.not-found__box::before {
  content: "NOT FOUND";
  position: absolute;
  inset: 8px auto auto 12px;
  color: rgba(122, 23, 29, 0.12);
  font-family: "Courier New", monospace;
  font-size: clamp(2rem, 10vw, 6rem);
  line-height: 1;
  pointer-events: none;
}

.not-found__box h1 {
  margin: 18px 0;
  font-size: clamp(2rem, 7vw, 4.8rem);
}

.not-found__box p:not(.ghost-number) {
  max-width: 560px;
  margin: 0 auto 28px;
}

.ghost-number {
  color: rgba(79, 15, 19, 0.55);
}

/* Footer */
.site-footer {
  width: min(var(--max), calc(100% - 32px));
  margin: 40px auto 0;
  padding: 28px 0 36px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.site-footer p {
  color: #383632;
}

.site-footer small {
  display: block;
  margin-top: 8px;
  font-family: "Courier New", monospace;
}

/* Responsive adjustments */
@media (max-width: 820px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .global-nav {
    justify-content: flex-start;
    gap: 6px 14px;
  }

  h1 {
    font-size: clamp(2rem, 10vw, 4.4rem);
  }

  .hero {
    min-height: auto;
    padding-top: 72px;
  }

  .hero::after {
    position: static;
    display: block;
    margin-top: 18px;
    text-align: left;
  }

  .hero__title {
    font-size: clamp(2.1rem, 9.2vw, 4.25rem);
  }

  .intro-panel__title {
    white-space: normal;
    font-size: clamp(1.12rem, 4.8vw, 1.65rem);
    overflow-wrap: anywhere;
  }

  .intro-panel,
  .split-section,
  .filter-box {
    grid-template-columns: 1fr;
  }

  .card-grid,
  .archive-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .record-card:nth-child(even),
  .document-panel--offset {
    transform: none;
  }

  .story-nav {
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .stray-note {
    display: none;
  }

  .section,
  .site-header,
  .site-footer,
  .story-article,
  .sample-stories,
  .story-nav,
  .document-panel,
  .not-found {
    width: min(100% - 24px, var(--max));
  }

  .site-header {
    margin-top: 14px;
    padding: 12px 0;
  }

  .site-logo {
    font-size: 1.02rem;
  }

  .global-nav {
    width: 100%;
    gap: 4px 10px;
    font-size: 0.84rem;
  }

  .global-nav a {
    min-height: 38px;
  }

  .section {
    padding: 40px 0;
  }

  h1 {
    font-size: clamp(2rem, 12vw, 3.35rem);
  }

  h2 {
    font-size: clamp(1.35rem, 7vw, 1.85rem);
  }

  .lead {
    font-size: 1.05rem;
  }

  .hero__text {
    margin-top: 20px;
  }

  .hero__title {
    max-width: 100%;
    font-size: clamp(1.82rem, 9vw, 3.35rem);
  }

  .hero__meta,
  .button {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .recovery-console {
    grid-template-columns: 1fr;
  }

  .recovery-console span {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .recovery-console span:last-child {
    border-bottom: 0;
  }

  .intro-panel__title {
    white-space: normal;
    font-size: clamp(1.08rem, 5vw, 1.38rem);
    overflow-wrap: anywhere;
  }

  .record-card {
    padding: 18px;
    min-height: auto;
  }

  .record-card__top,
  .record-card__meta,
  .story-meta {
    gap: 7px 10px;
    font-size: 0.78rem;
  }

  .record-card p {
    -webkit-line-clamp: 5;
  }

  .tag-row span,
  .tag-cloud a {
    font-size: 0.78rem;
  }

  .filter-box {
    gap: 12px;
  }

  .search-field input {
    min-height: 46px;
  }

  .filter-button {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 0.82rem;
  }

  .story-article {
    padding-top: 46px;
  }

  .story-header h1 {
    font-size: clamp(2rem, 11vw, 3.2rem);
  }

  .story-body {
    padding: 36px 0 52px;
    font-size: 1.04rem;
    line-height: 2;
  }

  .last-line {
    margin-top: 64px !important;
    padding-left: 14px;
    font-size: 1.12rem;
  }

  .after-note,
  .document-panel,
  .not-found__box {
    padding: 22px 18px;
  }

  .thin-list a {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .button {
    width: 100%;
  }

}
