:root {
  color-scheme: light;
  --bg: #eef1f2;
  --page: #fbfbf8;
  --panel: #ffffff;
  --panel-2: #f3f5f5;
  --line: #c8d0d3;
  --line-soft: rgba(88, 104, 112, 0.18);
  --text: #283034;
  --muted: #68757b;
  --dim: #8a969b;
  --blue: #4f6d7a;
  --red: #8f3f42;
  --red-soft: rgba(143, 63, 66, 0.08);
  --shadow: rgba(39, 49, 55, 0.12);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", "Noto Sans SC", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #dde3e5;
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.34;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(41,50,55,0.08) 0 1px, transparent 1px),
    radial-gradient(circle at 72% 64%, rgba(41,50,55,0.045) 0 1px, transparent 1px),
    linear-gradient(rgba(0,0,0,0.025) 50%, transparent 50%);
  background-size: 7px 7px, 11px 11px, 100% 3px;
  z-index: 5;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at center, transparent 0 58%, rgba(80,96,104,0.16) 100%);
  z-index: 4;
}

button, input { font: inherit; }

.app-shell {
  position: relative;
  width: 100%;
  max-width: 430px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(241,244,245,0.98)),
    var(--page);
  border-left: 1px solid rgba(80,96,104,0.12);
  border-right: 1px solid rgba(80,96,104,0.12);
  box-shadow: 0 0 32px rgba(51,61,66,0.14);
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.top-status {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 34px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #7c888d;
  font-size: 11px;
  letter-spacing: 0.08em;
  background: rgba(248,250,250,0.9);
  border-bottom: 1px solid rgba(88,104,112,0.15);
  backdrop-filter: blur(8px);
}

.content {
  padding: 18px 16px 14px;
  animation: pageIn 160ms ease-out;
}

@keyframes pageIn {
  from { opacity: 0.72; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero { padding: 18px 0 8px; }

.kicker {
  color: var(--blue);
  font-size: 12px;
  letter-spacing: 0.18em;
  margin-bottom: 12px;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  color: #263035;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0.03em;
  font-weight: 600;
}

.home-title { animation: titleFlicker 9s infinite steps(1, end); }

@keyframes titleFlicker {
  0%, 96%, 100% { opacity: 1; text-shadow: none; }
  97% { opacity: 0.78; text-shadow: 1px 0 rgba(143,63,66,0.32); }
  98% { opacity: 0.94; }
}

.lead {
  color: #2f3a3f;
  font-size: 18px;
  line-height: 1.7;
  white-space: pre-line;
}

.slogan {
  margin: 18px 0;
  padding-left: 10px;
  border-left: 2px solid var(--red);
  color: #59676d;
  line-height: 1.8;
  background: rgba(143,63,66,0.035);
}

.card, .doc-card, .contact-card, .message-card, .result-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(246,248,248,0.98));
  border: 1px solid var(--line-soft);
  box-shadow: 0 10px 24px rgba(39,49,55,0.07);
}

.card {
  margin: 14px 0;
  padding: 14px;
}

.card h2, .section-title {
  color: #2b353a;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 9px;
}

.card p, .muted, .section-desc {
  color: var(--muted);
  line-height: 1.75;
  font-size: 13px;
}

.notice-list {
  margin: 0;
  padding-left: 18px;
  color: #4f5e65;
  font-size: 13px;
  line-height: 1.9;
}

.tiny-footer {
  margin: 26px 0 8px;
  color: #9aa4a8;
  font-size: 11px;
  text-align: center;
}

.doc-card, .contact-card, .message-card, .result-card {
  width: 100%;
  margin: 12px 0;
  padding: 13px;
}

.doc-card, .contact-card { cursor: pointer; }

.doc-head, .contact-head, .message-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.doc-title, .contact-name, .sender {
  font-size: 15px;
  color: #263035;
  font-weight: 600;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.badge {
  display: inline-flex;
  border: 1px solid rgba(79,109,122,0.25);
  color: #61747c;
  background: #f5f7f7;
  padding: 2px 6px;
  font-size: 10px;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge.red { border-color: rgba(143,63,66,0.34); color: #8f3f42; background: #fff8f8; }
.badge.read { color: #8c989d; border-color: rgba(110,122,127,0.22); background: #fafafa; }

.doc-body, .auto-reply {
  margin-top: 12px;
  color: #4f5d63;
  font-size: 13px;
  line-height: 1.75;
  border-top: 1px solid rgba(88,104,112,0.13);
  padding-top: 12px;
  white-space: pre-line;
}

.search-row {
  display: flex;
  gap: 8px;
  margin: 16px 0 10px;
}

.search-input {
  min-width: 0;
  flex: 1;
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid rgba(88,104,112,0.28);
  outline: none;
}

.search-input:focus {
  border-color: rgba(79,109,122,0.55);
  box-shadow: 0 0 0 2px rgba(79,109,122,0.08);
}

.primary-btn, .modal-btn {
  min-height: 42px;
  padding: 0 14px;
  color: #2f3a3f;
  background: #eef2f3;
  border: 1px solid rgba(88,104,112,0.28);
  cursor: pointer;
}

.primary-btn:active, .modal-btn:active { transform: translateY(1px); }

.result-title {
  color: #273238;
  font-size: 17px;
  margin-bottom: 6px;
}

.result-subtitle {
  color: #6b7b82;
  font-size: 12px;
  margin-bottom: 12px;
}

.result-body {
  color: #4c5a60;
  white-space: pre-line;
  line-height: 1.75;
  font-size: 13px;
}

.delayed-text {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(143,63,66,0.22);
  color: #354147;
  white-space: pre-line;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.history-chip {
  border: 1px solid rgba(88,104,112,0.18);
  color: #617078;
  background: #fafbfb;
  padding: 6px 9px;
  font-size: 12px;
}

.contact-desc, .message-time {
  color: var(--dim);
  font-size: 12px;
  line-height: 1.65;
}

.message-card { cursor: default; }

.message-content {
  margin-top: 8px;
  color: #445157;
  line-height: 1.65;
  font-size: 13px;
}

.empty-note {
  margin-top: 20px;
  color: #8f9ba0;
  font-size: 13px;
  text-align: center;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: calc(68px + env(safe-area-inset-bottom));
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: rgba(250,251,251,0.96);
  border-top: 1px solid rgba(88,104,112,0.18);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.nav-item {
  position: relative;
  border: 0;
  background: transparent;
  color: #7d8a90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  cursor: pointer;
}

.nav-icon { font-size: 16px; line-height: 1; }

.nav-item.active {
  color: #263035;
  background: rgba(79,109,122,0.08);
  box-shadow: inset 0 0 0 1px rgba(79,109,122,0.15);
}

.unread-dot {
  display: none;
  position: absolute;
  top: 10px;
  right: 18px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #a83d43;
  box-shadow: 0 0 9px rgba(168,61,67,0.45);
}

.unread-dot.show { display: block; }

.nav-item.pulse { animation: navPulse 600ms ease-out; }

@keyframes navPulse {
  0% { transform: translateX(0); }
  20% { transform: translateX(-1px); color: #9d454a; }
  40% { transform: translateX(1px); }
  65% { transform: translateX(-1px); }
  100% { transform: translateX(0); }
}

.reset-entry {
  display: block;
  margin: 18px auto 0;
  border: 0;
  background: transparent;
  color: #a0aaae;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(37,45,50,0.42);
}

.modal-layer.open { display: flex; }

.modal-card {
  width: min(100%, 360px);
  background: #ffffff;
  border: 1px solid rgba(79,109,122,0.34);
  box-shadow: 0 24px 80px rgba(44,54,60,0.24);
  padding: 17px;
}

.modal-card h2 {
  color: #263035;
  font-size: 17px;
  margin-bottom: 12px;
}

.modal-card p {
  color: #526066;
  line-height: 1.75;
  font-size: 13px;
  white-space: pre-line;
}

.modal-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-btn.danger {
  border-color: rgba(143,63,66,0.38);
  color: #8f3f42;
  background: #fff7f7;
}

.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  background: rgba(255,255,255,0.96);
  opacity: 0;
}

.screen-flash.on { animation: flashWhite 150ms ease-out; }

@keyframes flashWhite {
  0% { opacity: 0; }
  35% { opacity: 1; }
  100% { opacity: 0; }
}

@media (min-width: 431px) {
  .app-shell { margin: 0 auto; }
}

/* Stage 2 additions */
.history-chip.injected {
  color: #5f5456;
  border-color: rgba(143,63,66,0.18);
  background: rgba(143,63,66,0.035);
  animation: injectedBlink 1.1s ease-out 1;
}

@keyframes injectedBlink {
  0%, 100% { opacity: 0.72; }
  35% { opacity: 0.28; }
  65% { opacity: 0.86; }
}

.highlight-contact {
  animation: contactGlow 1.2s ease-out 1;
  border-color: rgba(143,63,66,0.35);
}

@keyframes contactGlow {
  0% { transform: translateY(0); box-shadow: 0 0 0 rgba(143,63,66,0); }
  30% { transform: translateY(-1px); box-shadow: 0 0 0 3px rgba(143,63,66,0.08); }
  100% { transform: translateY(0); box-shadow: 0 10px 24px rgba(39,49,55,0.07); }
}

.black-flash {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #d8d8d8;
  font-size: 12px;
  letter-spacing: 0.12em;
  pointer-events: none;
}

.toast-stack {
  position: fixed;
  z-index: 35;
  left: 50%;
  top: 48px;
  transform: translateX(-50%);
  width: min(360px, calc(100vw - 28px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.sys-toast {
  align-self: flex-end;
  max-width: 92%;
  padding: 9px 11px;
  color: #344248;
  background: rgba(255,255,255,0.94);
  border: 1px solid rgba(143,63,66,0.22);
  box-shadow: 0 12px 30px rgba(39,49,55,0.13);
  font-size: 12px;
  animation: toastInOut 1s ease-in-out forwards;
}

@keyframes toastInOut {
  0% { opacity: 0; transform: translateY(-5px); }
  18%, 78% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-3px); }
}

.cursor-line::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  background: #4d5a60;
  animation: cursorBlink 0.7s steps(1, end) infinite;
}

@keyframes cursorBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.ghost-input {
  color: #8f3f42 !important;
  background: #fff8f8 !important;
}

.bad-title {
  color: #8f3f42 !important;
}

/* Stage 2 rework: article library + chat system */
.article-summary {
  margin-top: 5px;
  color: #6c777c;
  font-size: 12px;
  line-height: 1.55;
  font-weight: 400;
}

.article-card.open {
  background: #fff;
}

.article-body {
  user-select: text;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-item {
  width: 100%;
  border: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(246,248,248,0.98));
  box-shadow: 0 10px 24px rgba(39,49,55,0.06);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.chat-main {
  min-width: 0;
  flex: 1;
}

.chat-name {
  color: #263035;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 5px;
}

.chat-preview {
  color: #707d82;
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-meta {
  min-width: 42px;
  color: #9aa4a8;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.chat-unread {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #9b2f35;
  color: #fff;
  font-size: 10px;
  font-style: normal;
  padding: 0 5px;
}

.chat-detail {
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
}

.chat-top {
  position: sticky;
  top: 34px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -4px -2px 10px;
  padding: 8px 0 10px;
  background: rgba(249,251,251,0.92);
  border-bottom: 1px solid rgba(88,104,112,0.12);
  backdrop-filter: blur(8px);
}

.chat-top h1 {
  margin: 0;
  font-size: 18px;
}

.back-btn {
  border: 1px solid rgba(88,104,112,0.22);
  background: #fff;
  color: #4f5e65;
  height: 32px;
  padding: 0 9px;
  cursor: pointer;
}

.chat-messages {
  flex: 1;
  overflow: auto;
  padding: 5px 0 82px;
}

.bubble-row {
  display: flex;
  margin: 8px 0;
}

.bubble-row.left { justify-content: flex-start; }
.bubble-row.right { justify-content: flex-end; }

.bubble {
  max-width: 78%;
  padding: 9px 11px;
  border: 1px solid rgba(88,104,112,0.16);
  background: #fff;
  color: #39464b;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-line;
  box-shadow: 0 6px 18px rgba(39,49,55,0.05);
}

.bubble-row.right .bubble {
  background: #eef3f4;
  border-color: rgba(79,109,122,0.20);
}

.blank-bubble {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input-row {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(430px, 100vw);
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(248,250,250,0.94);
  border-top: 1px solid rgba(88,104,112,0.15);
  z-index: 3;
}

.chat-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 11px;
  color: var(--text);
  background: #fff;
  border: 1px solid rgba(88,104,112,0.28);
  outline: none;
}

.message-notice {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: 10px;
  transform: translate(-50%, -140%);
  width: min(396px, calc(100vw - 28px));
  padding: 9px 11px;
  color: #d7dddd;
  background: rgba(32,38,41,0.96);
  border: 1px solid rgba(216,226,229,0.22);
  box-shadow: 0 12px 28px rgba(0,0,0,0.24);
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0.03em;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
  opacity: 0;
}

.message-notice.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.message-notice.in-chat {
  animation: noticeBlink 300ms ease-out 1;
}

@keyframes noticeBlink {
  0%, 100% { filter: none; }
  45% { filter: brightness(1.45); }
}

/* Stage 3: article pages, red dialogs, deletion event */
.article-page {
  background: linear-gradient(180deg, rgba(255,255,255,0.99), rgba(246,248,248,0.98));
  border: 1px solid rgba(88,104,112,0.16);
  padding: 13px;
  box-shadow: 0 10px 26px rgba(39,49,55,0.07);
}

.article-back {
  margin-bottom: 14px;
}

.article-title {
  margin: 4px 0 10px;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.article-meta {
  display: grid;
  gap: 5px;
  padding: 9px 0 12px;
  margin-bottom: 12px;
  border-top: 1px solid rgba(88,104,112,0.12);
  border-bottom: 1px solid rgba(88,104,112,0.12);
  color: #6f7d83;
  font-size: 11px;
}

.article-page-body {
  min-height: 42vh;
  color: #39464b;
  font-size: 13px;
  line-height: 1.95;
  letter-spacing: 0.01em;
  user-select: text;
}

.article-updated {
  margin-top: 5px;
  color: #96a0a4;
  font-size: 11px;
}

.unstable-line {
  color: #8f3f42;
  opacity: 0.75;
}

.deleted-note {
  margin: 14px 2px 0;
  color: #8f3f42;
  opacity: 0.72;
  font-size: 11px;
  text-align: center;
}

.chat-item.recycle-flash {
  animation: recycleFlash 0.45s steps(1, end) 3;
}

@keyframes recycleFlash {
  0%, 100% { background: #fff; border-color: rgba(88,104,112,0.16); }
  50% { background: rgba(143, 20, 28, 0.16); border-color: rgba(143, 20, 28, 0.55); color: #7d1f26; }
}

.modal-layer.red-modal .modal-card {
  color: #f2d7d7;
  background: linear-gradient(180deg, rgba(45, 7, 10, 0.98), rgba(22, 3, 5, 0.98));
  border-color: rgba(209, 44, 51, 0.58);
  box-shadow: 0 0 0 1px rgba(255, 95, 101, 0.08), 0 22px 60px rgba(55, 0, 8, 0.58);
}

.modal-layer.red-modal .modal-card h2 {
  color: #ffb4b8;
  font-size: 20px;
  text-shadow: 1px 0 rgba(255,0,0,0.35);
}

.modal-layer.red-modal .modal-card p {
  color: #ffd6d8;
  font-size: 16px;
  line-height: 1.7;
}

.modal-layer.red-modal .modal-btn.danger {
  color: #ffe3e3;
  background: #5c1118;
  border-color: rgba(255, 101, 108, 0.5);
}

.message-notice.danger {
  color: #ffd6d8;
  background: rgba(54, 5, 9, 0.97);
  border-color: rgba(212, 40, 48, 0.62);
  box-shadow: 0 12px 32px rgba(92, 0, 10, 0.36);
}

.message-notice.cold {
  color: #dbe3e4;
  background: rgba(39, 46, 50, 0.97);
  border-color: rgba(172, 190, 196, 0.34);
}

.screen-shake .app-shell,
.screen-shake .modal-card {
  animation: tinyShake 0.22s linear 1;
}

@keyframes tinyShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-1px); }
  50% { transform: translateX(1px); }
  75% { transform: translateX(-1px); }
}

.red-wash .app-shell {
  animation: redWash 1s ease-out 1;
}

@keyframes redWash {
  0%, 100% { filter: none; }
  30% { filter: sepia(0.25) saturate(1.4) hue-rotate(305deg); background-color: rgba(143, 32, 39, 0.08); }
}

.bad-title {
  color: #8f3f42;
}

/* Stage 3.5: restricted archive, message board, hidden contact traces */
.article-page-body strong,
.result-body strong,
.delayed-text strong,
.bubble strong,
.board-text strong {
  color: #eef2f2;
  background: rgba(88, 28, 34, 0.18);
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 700;
  text-decoration: none;
}

.home-card-button {
  width: 100%;
  margin: 12px 0;
  padding: 14px;
  border: 1px solid rgba(88,104,112,0.16);
  background: rgba(255,255,255,0.93);
  color: #344147;
  text-align: left;
  box-shadow: 0 10px 24px rgba(39,49,55,0.06);
}
.home-card-button strong { display:block; margin-bottom:7px; font-size:16px; color:#35444a; }
.home-card-button span { display:block; font-size:12px; line-height:1.7; color:#7a878c; }

.restricted-card { border-color: rgba(123, 45, 52, 0.28); background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(248,244,244,.96)); }
.damaged-strip { margin-top: 10px; color:#8d5559; font-size: 11px; letter-spacing:.03em; }
.black-block { display:inline-block; width:58px; height:11px; vertical-align:-1px; background:#15191b; box-shadow: inset 0 0 0 1px rgba(255,255,255,.05); }
.restricted-page .subtle { color:#8d666a; font-size:12px; }
.code-result { min-height:22px; margin: 10px 0 14px; color:#8d5559; font-size:12px; }
.archive-list { display:grid; gap:10px; }
.archive-doc { padding:12px; border:1px solid rgba(88,104,112,.16); background:#fff; color:#344147; text-align:left; }
.archive-doc span { display:block; margin-top:5px; font-size:11px; color:#9a555d; }

.board-page { display:flex; flex-direction:column; min-height: calc(100vh - 150px); }
.board-posts { display:grid; gap:10px; max-height: 52vh; overflow:auto; padding: 2px 1px 12px; }
.board-post { border:1px solid rgba(88,104,112,.16); background: rgba(255,255,255,.94); padding:10px; box-shadow:0 6px 18px rgba(39,49,55,.05); }
.board-post.system { background: rgba(244,247,247,.94); }
.board-author { font-size:11px; color:#879399; margin-bottom:5px; }
.board-text { white-space:normal; line-height:1.7; color:#3e4a4f; font-size:13px; }
.board-form { margin-top:auto; }
.board-post.flash-red { animation: boardFlash .8s linear 1; }
@keyframes boardFlash { 0%,100%{border-color:rgba(88,104,112,.16)} 50%{border-color:rgba(168,35,43,.72); background:rgba(126,18,26,.1)} }

.ghost-contact-line { min-height:18px; margin-top: 12px; text-align:center; font-size:10px; color:rgba(127,50,55,.62); transition: opacity .4s; }
.system-footer { position: fixed; left: 50%; bottom: 4px; transform: translateX(-50%); width:min(430px,100vw); pointer-events:none; text-align:center; font-size:9px; letter-spacing:.08em; color:rgba(112,125,131,.42); z-index: 20; }

/* Stage 4: final review and one-run endings */
.final-review-card { border-color: rgba(114, 34, 42, .35); background: linear-gradient(180deg, rgba(255,255,255,.97), rgba(250,244,245,.97)); }
.final-review-card em { display:inline-block; margin-top:9px; font-size:11px; color:#8b353d; font-style:normal; letter-spacing:.08em; }
.final-review-card.done { opacity:.78; }
.final-page, .ending-page { min-height: calc(100vh - 140px); display:flex; flex-direction:column; gap:12px; }
.final-body, .ending-body { border:1px solid rgba(88,104,112,.16); background:rgba(255,255,255,.94); padding:14px; color:#3b484e; line-height:1.75; font-size:13px; white-space:normal; box-shadow:0 10px 24px rgba(39,49,55,.06); }
.final-body p { margin:0 0 11px; }
.final-system { margin-top:12px; padding:10px; border-left:2px solid rgba(138,43,51,.55); background:rgba(121,35,43,.06); color:#5f4549; font-size:12px; line-height:1.8; }
.final-reply { margin-top:12px; padding:10px; border:1px solid rgba(88,104,112,.12); background:rgba(244,247,247,.92); color:#59686e; font-size:12px; line-height:1.8; }
.final-form { margin-top:auto; }
.primary-btn.wide { width:100%; justify-content:center; text-align:center; }
.reveal-page .final-body strong, .appointed-page strong, .ending-body strong { color:#eef2f2; background:rgba(91,26,34,.22); border-radius:3px; padding:0 2px; }
.nav-hidden { opacity:0; pointer-events:none; transform:translateY(12px); transition:.2s; }
.nav-item.disabled-flash { filter:grayscale(1); opacity:.45; }
.appointment-screen { position:fixed; inset:0; z-index:95; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px; background:#2b0609; color:#f2e7e8; font-size:13px; letter-spacing:.05em; animation: appointFade 2.5s ease both; }
.appointment-screen p { margin:0; opacity:0; animation: lineReveal .5s ease forwards; }
.appointment-screen p:nth-child(2){animation-delay:.35s}.appointment-screen p:nth-child(3){animation-delay:.7s}.appointment-screen p:nth-child(4){animation-delay:1.05s}.appointment-screen p:nth-child(5){animation-delay:1.4s}
@keyframes lineReveal { from{opacity:0; transform:translateY(5px)} to{opacity:1; transform:none} }
@keyframes appointFade { 0%{background:#000} 25%,85%{background:#2b0609} 100%{opacity:0} }
.ending-page h1 { margin:0 0 8px; font-size:24px; letter-spacing:.08em; }
.ending-body { white-space:normal; min-height:55vh; }
.normal-ending .ending-body { background:rgba(255,255,255,.96); }
.good-ending .ending-body { background:linear-gradient(180deg, rgba(255,255,255,.96), rgba(244,247,247,.96)); }
.bad-ending { color:#d8e8f4; }
.bad-ending h1 { color:#d8e8f4; }
.bad-ending .ending-body { border-color:rgba(94,144,178,.28); background:linear-gradient(180deg, rgba(8,15,23,.96), rgba(4,9,15,.97)); color:#d8e8f4; box-shadow:0 0 24px rgba(51,113,156,.18); }
.bad-ending .primary-btn { background:#d8e8f4; color:#081018; }
.cold-takeover .app-shell { background:linear-gradient(180deg,#071018,#101a22); }
.cold-takeover .top-status { color:#9ebbd0; border-color:rgba(126,170,205,.24); }
.cold-takeover .message-notice { display:none; }
.cold-ending { background:linear-gradient(180deg, rgba(9,17,26,.96), rgba(14,24,34,.96)); color:#d7e7f4; }

/* Stage 4 calibration revision */
.reset-entry { z-index: 70; }
.modal-layer { z-index: 120; }
.red-dialog-active .app-shell { filter: brightness(.72) saturate(.82); }
.modal-layer.red-sequence .modal-card { animation: redModalFade .18s ease both; transform:none !important; }
.modal-layer.red-modal { background: rgba(4,0,1,.68); }
.modal-layer.red-modal .modal-card { background:#090607; border:1px solid rgba(139,28,39,.72); box-shadow:0 0 0 1px rgba(60,0,0,.4), 0 18px 70px rgba(0,0,0,.62), 0 0 24px rgba(126,13,25,.16); color:#d8d1d2; }
.modal-layer.red-modal h2 { color:#b84c57; text-shadow:0 0 10px rgba(181,31,45,.22); }
.modal-layer.red-modal p { color:#d8d1d2; }
.modal-layer.red-modal .modal-btn.danger { background:#140708; border-color:#8e2d37; color:#e2c4c7; }
.modal-layer.red-modal .modal-btn.danger:disabled { opacity:.38; }
@keyframes redModalFade { from{opacity:0; filter:brightness(.7)} to{opacity:1; filter:brightness(1)} }
.forced-final-overlay { position:fixed; inset:0; z-index:95; display:flex; align-items:center; justify-content:center; padding:28px; background:radial-gradient(circle at center, rgba(98,10,18,.38), rgba(8,0,2,.94) 62%); color:#f2e8e8; text-align:center; letter-spacing:.04em; }
.forced-final-text { max-width:340px; border:1px solid rgba(160,33,45,.45); background:rgba(8,3,5,.76); padding:18px 16px; line-height:1.9; font-size:13px; box-shadow:0 0 28px rgba(110,15,24,.25); }
.forced-final-text strong { display:block; margin-top:14px; font-size:36px; color:#cf4b57; }
.forced-final .final-body { border-color:rgba(110,28,39,.18); }
.final-audit .red-line { color:#9d2330; font-weight:700; text-shadow:0 0 8px rgba(151,23,36,.25); }
.memory-flicker { margin-top:18px; min-height:52px; display:grid; place-items:center; border:1px solid rgba(125,35,45,.18); background:rgba(100,10,22,.04); color:#4b3538; }
.memory-flicker span { grid-area:1/1; opacity:0; animation: memoryBlink 1.2s ease-in-out 3; }
.memory-flicker span:nth-child(2) { animation-delay:.6s; color:#962a35; }
@keyframes memoryBlink { 0%,100%{opacity:0} 35%,72%{opacity:1} }
.confidential-title { margin:0; padding:10px 12px; background:#100b0d; color:#d8d0d0; border:1px solid rgba(95,36,43,.36); font-size:14px; letter-spacing:.08em; }
.classified-card { border:1px solid rgba(88,50,55,.25); background:linear-gradient(180deg, rgba(255,255,255,.95), rgba(246,242,240,.95)); padding:13px; box-shadow:0 10px 24px rgba(45,35,36,.06); }
.classified-card h3 { margin:0 0 8px; color:#5d2029; font-size:14px; letter-spacing:.08em; }
.classified-card p { margin:0; color:#3d4446; line-height:1.75; font-size:13px; }
.calibration-box { border:1px solid rgba(110,28,39,.28); background:linear-gradient(180deg, rgba(255,255,255,.96), rgba(249,244,245,.96)); padding:14px; box-shadow:0 12px 30px rgba(65,28,36,.08); }
.calibration-box h2 { margin:0 0 8px; font-size:18px; color:#56202a; }
.calibration-box p { margin:0 0 9px; line-height:1.7; color:#4d5659; font-size:13px; }
.calibration-message { margin-top:10px; white-space:normal; color:#78313a; line-height:1.75; font-size:12px; }
.appointment-screen.enhanced { background:linear-gradient(180deg,#000,#2a0509 18%,#190306); }
.appointment-screen.enhanced h2 { margin:0 0 14px; color:#d34755; font-size:15px; letter-spacing:.08em; }
.appointment-screen.enhanced p { opacity:0; transform:translateY(4px); color:#eadedf; }
.appointment-screen.enhanced p.on { opacity:1; transform:none; transition:.18s; text-shadow:0 0 8px rgba(216,51,67,.24); }
.rewrite-lines { margin-bottom:18px; padding:12px; border:1px solid rgba(88,104,112,.14); background:rgba(248,248,247,.84); }
.rewrite-lines p { display:grid; gap:4px; margin:0 0 10px; }
.rewrite-lines span { color:#7d3d45; text-decoration:line-through; opacity:.65; animation: fadeStrike .8s ease both; }
.rewrite-lines b { color:#39474c; font-weight:600; animation: lineReveal .8s ease both; }
@keyframes fadeStrike { from{opacity:1} to{opacity:.42} }
.forget-list { margin:10px 0 18px; padding:12px; border:1px solid rgba(88,104,112,.14); background:rgba(246,247,247,.88); }
.forget-list p { margin:0 0 6px; color:#778287; filter:grayscale(1); }
.forget-list .remember { color:#64232c; filter:none; font-weight:700; }
.reset-inline { margin-top:10px; width:100%; border:1px solid rgba(88,104,112,.2); background:rgba(255,255,255,.8); color:#5f6a6f; border-radius:10px; padding:11px; font-size:13px; }
.bad-ending .reset-inline { background:rgba(10,20,30,.72); color:#d8e8f4; border-color:rgba(94,144,178,.28); }

/* Reset modal must remain usable after every ending, including bad ending takeover. */
.modal-layer.reset-modal.open { display:flex !important; }
.modal-layer.reset-modal { z-index: 220; background: rgba(0,0,0,.64); }
.modal-layer.reset-modal .modal-card { border-color: rgba(120,42,52,.42); box-shadow:0 18px 70px rgba(0,0,0,.42); }


/* Fix click-blocking overlays: hidden layers must never capture taps. */
.modal-layer { pointer-events: none; visibility: hidden; }
.modal-layer.open { pointer-events: auto; visibility: visible; }
.toast-stack, .sys-toast, .message-notice, .screen-flash, .black-flash { pointer-events: none !important; }
.forced-final-overlay, .appointment-screen { pointer-events: auto; }
.forced-final-overlay[aria-hidden="true"], .appointment-screen[aria-hidden="true"] { pointer-events: none; visibility: hidden; display: none; }


.reset-entry[hidden] { display: none !important; }

/* === STAGE5 TRUE ENDING START === */
.stage5-screen {
  min-height: calc(100vh - 24px);
  padding: 28px 18px 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: #f4eeee;
  background: #090707;
  border-radius: 18px;
  box-shadow: inset 0 0 80px rgba(145, 0, 16, .18);
}
.stage5-red {
  background: radial-gradient(circle at 50% 35%, rgba(110,0,18,.36), #090707 64%);
}
.stage5-quiet, .stage5-black {
  background: #030303;
}
.stage5-lines p,
.stage5-monologue p,
.stage5-collapse p {
  margin: 12px 0;
  letter-spacing: .04em;
  white-space: pre-wrap;
}
.stage5-lines {
  font-size: 18px;
  text-align: center;
}
.stage5-auto-search {
  min-height: 48px;
  margin: 28px auto 0;
  width: min(100%, 330px);
  padding: 14px 16px;
  border: 1px solid rgba(180, 30, 48, .55);
  border-radius: 12px;
  color: #ffccd2;
  background: rgba(20,0,4,.62);
  box-shadow: 0 0 22px rgba(160,0,20,.26);
  font-size: 16px;
}
.stage5-monologue {
  max-width: 330px;
  margin: 0 auto;
  color: #eee;
  line-height: 1.82;
}
.stage5-monologue p:last-child {
  color: #ffb8c0;
  font-size: 20px;
  text-align: center;
  margin-top: 28px;
}
.stage5-collapse {
  text-align: center;
  color: #ffd6dc;
}
.stage5-collapse h2 {
  margin: 28px 0 12px;
  font-size: 18px;
  color: #fff;
}
#stage5Progress {
  font-size: 24px;
  color: #ff4b5e;
  margin-top: 12px;
}
#stage5Last {
  min-height: 28px;
  margin-top: 20px;
  color: #fff;
}
.stage5-disconnect {
  text-align: center;
  font-size: 18px;
  letter-spacing: .08em;
}
.stage5-blank {
  min-height: calc(100vh - 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c7073;
  background: #f0f0ec;
  border-radius: 18px;
}
.stage5-freedom {
  min-height: calc(100vh - 24px);
  padding: 48px 24px 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  text-align: center;
  color: #30373a;
  background: linear-gradient(180deg, #fbfaf5, #eef1ee);
  border-radius: 18px;
}
.stage5-free-text {
  line-height: 1.85;
  font-size: 15px;
}
.stage5-free-text p { margin: 0 0 18px; }
.stage5-freedom .reset-inline,
.stage5-reset-fixed {
  border: 1px solid rgba(80, 96, 104, .28);
  border-radius: 999px;
  background: rgba(255,255,255,.78);
  color: #657075;
  padding: 10px 16px;
  font-size: 12px;
}
.stage5-reset-fixed {
  position: fixed;
  right: max(12px, calc((100vw - 430px) / 2 + 12px));
  top: calc(56px + env(safe-area-inset-top));
  bottom: auto;
  z-index: 120;
  background: rgba(18, 18, 18, .62);
  color: #d8d8d8;
  border-color: rgba(255,255,255,.18);
}
.stage5-screen + .reset-entry,
.stage5-freedom + .reset-entry { display: none !important; }
/* === STAGE5 TRUE ENDING END === */

/* === FINAL REVIEW PACING FIX 4.2 START === */
.final-ready-card { border-color: rgba(114, 34, 42, .42); background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(249,244,245,.98)); }
.final-ready-card .section-desc { margin: 0 0 8px; color: #8b353d; }
.final-checklist { margin: 12px 0 0; padding-left: 0; list-style: none; line-height: 1.9; color: #4d5659; }
.final-clues { margin: 12px 0; padding: 12px; border: 1px solid rgba(88,104,112,.16); background: rgba(255,255,255,.92); box-shadow: 0 10px 24px rgba(39,49,55,.05); }
.final-clues h2 { margin: 0 0 10px; font-size: 16px; color: #4a555a; }
.final-clue-row { display: grid; gap: 4px; margin: 0 0 10px; padding-bottom: 9px; border-bottom: 1px dashed rgba(88,104,112,.16); color: #3f4a50; font-size: 12px; line-height: 1.65; }
.final-clue-row:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.final-clue-row strong { color: #6b2730; }
.final-clue-row.muted { color: #9aa3a8; }
.debug-panel { position: fixed; left: max(8px, calc((100vw - 430px) / 2 + 8px)); top: 8px; z-index: 300; max-width: min(410px, calc(100vw - 16px)); padding: 8px; background: rgba(8,10,12,.86); color: #d7f7d7; border: 1px solid rgba(150,255,150,.25); border-radius: 8px; font-size: 10px; line-height: 1.35; white-space: pre-wrap; pointer-events: none; }
/* === FINAL REVIEW PACING FIX 4.2 END === */

/* Final calibration mobile alignment fix */
.calibration-box .final-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: 100%;
  margin: 14px 0 10px;
}

.calibration-box .final-form .search-input,
.calibration-box .final-form .primary-btn {
  width: 100%;
  box-sizing: border-box;
}

.calibration-box .final-form .primary-btn {
  justify-content: center;
  text-align: center;
}

/* UX polish patch */
.progress-nudge,
.ending-gallery,
.second-run-hint,
.appointment-result {
  border: 1px solid rgba(88,104,112,.16);
  background: rgba(255,255,255,.94);
  padding: 13px;
  box-shadow: 0 10px 24px rgba(39,49,55,.05);
}
.progress-nudge h2,
.ending-gallery h2 { margin: 0 0 9px; font-size: 15px; color: #5d2029; }
.progress-nudge p { margin: 0 0 6px; color: #68757a; font-size: 12px; line-height: 1.65; }
.system-whisper { color: #8b303b !important; letter-spacing: .08em; }
.ending-gallery { margin-top: 12px; }
.ending-gallery-row { display: grid; gap: 3px; padding: 9px 0; border-bottom: 1px dashed rgba(88,104,112,.14); font-size: 12px; line-height: 1.55; }
.ending-gallery-row:last-child { border-bottom: 0; }
.ending-gallery-row strong { color: #4b555a; }
.ending-gallery-row.seen strong { color: #6b2730; }
.ending-gallery-row.locked { opacity: .56; }
.ending-gallery-row span { color: #6c777b; }
.calibration-ritual {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at center, rgba(84,18,27,.34), rgba(6,2,3,.92) 62%);
  color: #eee4e5;
}
.calibration-ritual-card {
  width: min(360px, 100%);
  border: 1px solid rgba(168,45,58,.42);
  background: rgba(12,4,6,.84);
  padding: 18px 16px;
  box-shadow: 0 18px 70px rgba(0,0,0,.52), 0 0 26px rgba(130,20,32,.18);
}
.calibration-ritual-card h2 { margin: 0 0 12px; font-size: 15px; color: #d04f5d; letter-spacing: .08em; }
.calibration-ritual-card p { margin: 8px 0; opacity: 0; transform: translateY(5px); transition: .18s ease; font-size: 13px; line-height: 1.65; }
.calibration-ritual-card p.on { opacity: 1; transform: none; }
.appointment-result { min-height: calc(100vh - 170px); display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.appointment-result h1 { margin: 0; color: #5d2029; font-size: 20px; }
.appointment-result .ending-body p { margin: 0 0 10px; }

/* Puzzle gating discovery patch */
.puzzle-progress {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid rgba(88,104,112,0.18);
  background: rgba(255,255,255,0.62);
}
.puzzle-progress h2,
.suggested-terms h2 {
  margin: 0 0 10px;
  font-size: 15px;
  color: #39474d;
}
.puzzle-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}
.puzzle-step {
  padding: 8px 5px;
  text-align: center;
  border: 1px solid rgba(88,104,112,0.16);
  background: rgba(238,242,243,0.72);
  color: #7f8a8f;
  font-size: 10px;
}
.puzzle-step strong,
.puzzle-step span { display: block; }
.puzzle-step strong { margin-bottom: 3px; font-size: 9px; font-weight: 600; }
.puzzle-step.on {
  color: #5d2029;
  border-color: rgba(139,48,59,0.28);
  background: rgba(238,228,229,0.88);
}
.suggested-terms {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px dashed rgba(88,104,112,0.22);
  background: rgba(255,255,255,0.58);
}
.term-chip {
  margin: 0 7px 7px 0;
  padding: 7px 10px;
  border: 1px solid rgba(88,104,112,0.22);
  background: #f4f6f6;
  color: #39474d;
  font-size: 12px;
}
.puzzle-discovery-toast {
  position: fixed;
  left: 50%;
  bottom: 82px;
  z-index: 240;
  width: min(360px, calc(100vw - 28px));
  transform: translate(-50%, 12px);
  opacity: 0;
  padding: 11px 13px;
  border: 1px solid rgba(93,32,41,0.24);
  background: rgba(250,247,247,0.96);
  box-shadow: 0 10px 28px rgba(37,45,49,0.14);
  color: #39474d;
  transition: opacity .24s ease, transform .24s ease;
  pointer-events: none;
}
.puzzle-discovery-toast.show { opacity: 1; transform: translate(-50%, 0); }
.puzzle-discovery-toast strong,
.puzzle-discovery-toast span { display: block; }
.puzzle-discovery-toast strong { margin-bottom: 3px; color: #6b2730; font-size: 13px; }
.puzzle-discovery-toast span { font-size: 11px; color: #657075; }
.puzzle-home-hint { border-style: dashed; }
@media (max-width: 390px) {
  .puzzle-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* No-spoiler fix: never show explicit search-term chips in the puzzle flow. */
.suggested-terms,
.puzzle-home-hint {
  display: none !important;
}


/* Hotfix 2026-06-08: keep modal truly viewport-centered on mobile.
   Do not let page centering or screen-shake animation offset the dialog. */
.modal-layer {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  min-height: 100vh;
  min-height: 100dvh;
  display: none;
  place-items: center !important;
  align-items: center !important;
  justify-content: center !important;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom)) !important;
  box-sizing: border-box;
}
.modal-layer.open { display: grid !important; }
.modal-card {
  width: min(360px, calc(100vw - 36px)) !important;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  margin: 0 !important;
  transform: none !important;
}
.screen-shake .modal-card { animation: none !important; }
.screen-shake .modal-layer.red-modal .modal-card { animation: redModalFade .18s ease both !important; }

/* SR pack launcher return entry */
.pack-home-link{
  display:inline-flex;
  align-items:center;
  gap:4px;
  color:inherit;
  text-decoration:none;
  font-size:12px;
  letter-spacing:.02em;
  padding:6px 9px;
  margin-right:8px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.07);
  backdrop-filter:blur(10px);
  transition:background .16s ease,border-color .16s ease,transform .16s ease;
}
.pack-home-link:hover{
  background:rgba(255,255,255,.13);
  border-color:rgba(255,255,255,.3);
  transform:translateY(-1px);
}
@media (max-width:430px){
  .pack-home-link{font-size:11px;padding:5px 7px;margin-right:4px;}
}
