/* ================================
   UNSENT LETTERS — Redesign
   A writing surface where nothing is erased
   ================================ */

:root {
  /* Palette */
  --paper: #F4EFE5;
  --paper-deep: #ECE4D4;
  --canvas-bg: #E8E1D2;
  --ink: #1F1B17;
  --ink-soft: #2C2823;
  --muted: #7A7163;
  --faint: #9C9285;
  --rule: #C9BFAE;
  --rule-soft: #D6CDBD;
  --red: #C97862;
  --xout-tint: rgba(201, 120, 98, 0.10);

  /* Typography */
  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --font-ui: 'Inter', system-ui, sans-serif;

  /* Motion */
  --ease-page: cubic-bezier(0.25, 0.1, 0.25, 1.0);
  --duration-micro: 150ms;
  --duration-standard: 400ms;
  --duration-macro: 800ms;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--canvas-bg);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.5;
  min-height: 100vh;
}

/* ================================
   PAPER CARD
   ================================ */
.canvas {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px;
}

.site {
  width: 100%;
  max-width: 960px;
  background: var(--paper);
  border-radius: 4px;
  padding: 80px 96px 56px;
  position: relative;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 24px 60px -32px rgba(31,27,23,0.18);
  opacity: 0;
  animation: fadeIn var(--duration-macro) var(--ease-page) 0.1s forwards;
}

/* ================================
   NAVIGATION
   ================================ */
.margin-nav {
  position: absolute;
  top: 32px;
  left: 36px;
  display: flex;
  gap: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  z-index: 10;
}

.nav-link {
  color: inherit;
  text-decoration: none;
  padding-bottom: 2px;
  border-bottom: 1px solid transparent;
  transition: color var(--duration-micro) var(--ease-page),
              border-color var(--duration-micro) var(--ease-page);
}

.nav-link:hover {
  color: var(--ink);
}

.nav-link.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

/* Top meta (date) */
.top-meta {
  position: absolute;
  top: 32px;
  right: 36px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ================================
   HERO
   ================================ */
.letter-header {
  max-width: 540px;
  margin-bottom: 44px;
  opacity: 0;
  animation: fadeIn var(--duration-macro) var(--ease-page) 0.2s forwards;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 22px;
}

.letter-title {
  font-family: var(--font-serif);
  font-size: 88px;
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.025em;
  margin: 0 0 24px;
  color: var(--ink);
}

.letter-title .dot { color: var(--red); }

.letter-subtitle {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
  line-height: 1.45;
  color: var(--muted);
  margin: 0;
  max-width: 480px;
}

/* ================================
   RULES ROW
   ================================ */
.rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 32px;
  padding: 22px 0;
  border-top: 0.5px solid var(--rule);
  border-bottom: 0.5px solid var(--rule);
  margin-bottom: 56px;
  opacity: 0;
  animation: fadeIn var(--duration-macro) var(--ease-page) 0.3s forwards;
}

.rule .row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.rule .num {
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 10px;
}

.rule .name {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--ink);
}

.rule .desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  padding-left: 30px;
}

.kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--paper-deep);
  border: 0.5px solid var(--rule);
  border-radius: 3px;
  padding: 1px 6px;
  color: var(--ink);
}

.highlight-demo {
  background: var(--xout-tint);
  padding: 1px 5px;
  border-radius: 2px;
}

/* ================================
   WRITING SURFACE
   ================================ */
.letter-wrap {
  display: flex;
  gap: 0;
  margin-bottom: 56px;
  padding-top: 8px;
  position: relative;
  min-height: 50vh;
  opacity: 0;
  animation: fadeIn var(--duration-macro) var(--ease-page) 0.4s forwards;
}

.margin-line {
  width: 1px;
  background: var(--red);
  opacity: 0.55;
  margin: 6px 36px 6px 12px;
  flex-shrink: 0;
}

.paper-body {
  flex: 1;
  position: relative;
}

.paper-texture {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.02;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* Ruled lines (generated by script.js — LINE_HEIGHT = 34px) */
.ruled-lines {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.ruled-line {
  height: 1px;
  background-color: var(--rule-soft);
  opacity: 0.6;
  margin-bottom: 33px; /* 34px line stride - 1px line */
}

/* Contenteditable area */
.letter-content {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 400;
  line-height: 34px; /* matches LINE_HEIGHT in script.js */
  color: var(--ink-soft);
  position: relative;
  z-index: 2;
  min-height: 50vh;
  outline: none;
  caret-color: var(--ink);
  word-wrap: break-word;
  white-space: pre-wrap;
  padding: 0 4px;
}

.letter-content:empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
  pointer-events: none;
}

.letter-content::selection,
.letter-content *::selection {
  background-color: var(--xout-tint);
}

.letter-content:focus { outline: none; }

/* ================================
   CROSSED-OUT TEXT
   ================================ */
.crossed-out {
  position: relative;
  color: var(--faint);
  text-decoration: none;
}

.crossed-out::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  top: 52%;
  height: 1px;
  background-color: var(--ink);
  transform: rotate(-0.3deg);
  pointer-events: none;
}

.crossed-out.variation-1::after {
  transform: rotate(0.3deg);
  height: 1px;
}

.crossed-out.variation-2::after {
  transform: rotate(-0.8deg);
  height: 1.5px;
}

.crossed-out.variation-3::after {
  transform: rotate(0.5deg);
  top: 48%;
}

@keyframes crossOut {
  from { transform: rotate(-0.3deg) scaleX(0); transform-origin: left center; }
  to   { transform: rotate(-0.3deg) scaleX(1); transform-origin: left center; }
}

.crossed-out.animating::after {
  animation: crossOut var(--duration-standard) var(--ease-page) forwards;
}

/* ================================
   ACTION FOOTER
   ================================ */
.letter-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding-top: 28px;
  border-top: 0.5px solid var(--rule);
  opacity: 0;
  animation: fadeIn var(--duration-macro) var(--ease-page) 0.5s forwards;
}

.meta-left,
.meta-right,
.word-count,
.instruction-note {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}

.meta-right,
.instruction-note { text-align: right; }

/* Send button (a.k.a. abyss button) */
.abyss-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 16px 36px;
  border-radius: 999px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.abyss-button:hover {
  background: #000;
  transform: translateY(-1px);
}

.abyss-icon {
  width: 18px;
  height: 18px;
  font-style: normal;
  display: inline-block;
}

.abyss-text { letter-spacing: 0.01em; }

/* ================================
   SIGNATURE
   ================================ */
.sig {
  position: absolute;
  bottom: 22px;
  right: 36px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--faint);
}

/* ================================
   ABOUT SECTION (overlay)
   ================================ */
.about-section {
  position: fixed;
  inset: 0;
  background: var(--paper);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-macro) var(--ease-page);
}

.about-section.active {
  opacity: 1;
  pointer-events: auto;
}

.about-close-x {
  position: absolute;
  top: 32px;
  right: 36px;
  background: transparent;
  border: none;
  font-size: 2rem;
  color: var(--faint);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color var(--duration-micro) var(--ease-page);
}

.about-close-x:hover { color: var(--ink); }

.about-content {
  max-width: 520px;
  padding: 64px 40px;
  text-align: center;
}

.about-title {
  font-family: var(--font-serif);
  font-size: 56px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 56px;
}

.about-line {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: 20px;
  line-height: 1.7;
  color: var(--ink-soft);
  margin-bottom: 32px;
}

.about-line.last {
  margin-bottom: 56px;
  color: var(--muted);
}

.about-close {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  color: var(--paper);
  background: var(--ink);
  border: none;
  padding: 12px 28px;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--duration-standard) var(--ease-page),
              transform 0.2s ease;
}

.about-close:hover {
  background: #000;
  transform: translateY(-1px);
}

/* ================================
   ABYSS OVERLAY & ANIMATION
   ================================ */
.abyss-overlay {
  position: fixed;
  inset: 0;
  background: var(--ink);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.abyss-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.abyss-letter-container {
  position: relative;
  width: 80%;
  max-width: 600px;
  perspective: 1000px;
}

.abyss-letter {
  background: var(--paper);
  padding: 40px;
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  max-height: 60vh;
  overflow: hidden;
  position: relative;
  transform-origin: center center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.abyss-letter.tearing {
  animation: tearPaper 2s ease-in-out forwards;
}

@keyframes tearPaper {
  0%   { transform: rotateX(0) rotateY(0) scale(1); opacity: 1;
         clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
  20%  { transform: rotateX(-5deg) rotateY(3deg) scale(1);
         clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
  40%  { transform: rotateX(-10deg) rotateY(-5deg) scale(0.95);
         clip-path: polygon(0 0, 52% 0, 48% 100%, 0 100%); }
  60%  { transform: rotateX(-20deg) rotateY(10deg) scale(0.85);
         clip-path: polygon(5% 5%, 30% 0, 25% 100%, 0 95%); }
  80%  { transform: rotateX(-40deg) rotateY(-15deg) scale(0.6); opacity: 0.6;
         clip-path: polygon(10% 10%, 20% 5%, 15% 90%, 5% 85%); }
  100% { transform: rotateX(-60deg) rotateY(20deg) scale(0.1); opacity: 0;
         clip-path: polygon(45% 45%, 55% 45%, 55% 55%, 45% 55%); }
}

.abyss-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.particle { position: absolute; pointer-events: none; }

.particle.paper-scrap {
  width: 20px;
  height: 15px;
  background: var(--paper);
  animation: floatScrap 2s ease-out forwards;
}

@keyframes floatScrap {
  0%   { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(200px) translateX(var(--drift-x, 100px))
                  rotate(var(--rotation, 180deg)) scale(0.5); opacity: 0; }
}

.abyss-message {
  position: absolute;
  color: var(--paper);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
  opacity: 0;
  animation: fadeInMessage 1s ease-out 2.5s forwards;
  text-align: center;
}

@keyframes fadeInMessage {
  0%   { opacity: 0; transform: translateY(20px); }
  100% { opacity: 0.85; transform: translateY(0); }
}

/* ================================
   ANIMATIONS
   ================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 768px) {
  .canvas { padding: 16px 12px; }
  .site { padding: 72px 28px 80px; }
  .margin-nav { top: 24px; left: 24px; gap: 16px; }
  .top-meta { top: 24px; right: 24px; }
  .letter-title { font-size: 56px; }
  .letter-subtitle { font-size: 18px; }
  .rules { grid-template-columns: 1fr; gap: 18px; padding: 18px 0; }
  .rule .desc { padding-left: 30px; }
  .margin-line { margin: 6px 18px 6px 4px; }
  .letter-footer {
    grid-template-columns: 1fr;
    gap: 16px;
    text-align: center;
  }
  .meta-right, .instruction-note { text-align: center; }
  .abyss-button { justify-self: center; }
  .sig { position: static; display: block; text-align: right; margin-top: 24px; }
  .about-title { font-size: 40px; }
  .about-line { font-size: 17px; }
}

@media (max-width: 480px) {
  .site { padding: 64px 20px 72px; }
  .letter-title { font-size: 44px; }
  .letter-content { font-size: 15px; }
  .margin-nav { font-size: 10px; }
}

/* ================================
   PRINT
   ================================ */
@media print {
  .margin-nav,
  .top-meta,
  .rules,
  .letter-footer,
  .sig,
  .abyss-overlay,
  .about-section { display: none; }
  body, .canvas, .site {
    background: #fff;
    box-shadow: none;
    padding: 0;
  }
  .letter-content { min-height: auto; }
  .crossed-out { color: inherit; }
}
