/* ============================================
   타전 TAJEON — vintage telegram app
   Olivetti Lettera 32 inspired
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;600;700&family=Noto+Serif+KR:wght@500;700;900&family=Special+Elite&family=Cormorant+Garamond:ital,wght@0,500;0,600;1,500&display=swap');

:root {
  /* Aged paper */
  --paper:        #f1e8d0;
  --paper-dark:   #e4d8b8;
  --paper-darker: #c9bb96;
  --paper-fold:   #b8a878;

  /* Olivetti sage */
  --sage:         #7d9588;
  --sage-dark:    #556b60;
  --sage-light:   #a8bcaf;
  --sage-pale:    #dde5dd;

  /* Ink / type */
  --ink:          #2a241d;
  --ink-soft:     #4a4238;
  --ink-faded:    #6b6358;
  --ink-light:    #948877;

  /* Accents */
  --red-ribbon:   #9c322a;
  --red-key:      #c64a3e;
  --gold:         #a8854a;
  --gold-light:   #d4b87f;
  --gold-dark:    #806038;

  /* Wood (shelf) */
  --wood:         #6e4a30;
  --wood-dark:    #4d321f;
  --wood-light:   #8b6644;

  --shadow-soft:  0 8px 28px rgba(42, 36, 29, 0.10);
  --shadow-paper: 0 1px 1px rgba(42, 36, 29, 0.12),
                  0 4px 14px rgba(42, 36, 29, 0.10),
                  0 18px 40px rgba(42, 36, 29, 0.08);
}

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

html, body, #root {
  height: 100%;
}

body {
  font-family: 'IBM Plex Mono', monospace;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Subtle paper grain on entire bg */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(120,90,40,0.04) 0, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(120,90,40,0.03) 0, transparent 50%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.4  0 0 0 0 0.2  0 0 0 0.08 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-blend-mode: multiply;
  opacity: 0.5;
}

button { font-family: inherit; }
textarea { font-family: inherit; }

/* ============================================
   LAYOUT
   ============================================ */
.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 0 18px 80px;
  display: flex;
  flex-direction: column;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  padding: 22px 4px 14px;
  border-bottom: 1.5px solid var(--ink);
  position: relative;
}
.header::after {
  content: '';
  position: absolute;
  bottom: -4px; left: 0; right: 0;
  height: 1px;
  background: var(--ink);
  opacity: 0.4;
}
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  position: relative;
}
.brand-kr {
  font-family: 'Noto Serif KR', serif;
  font-weight: 900;
  font-size: 30px;
  letter-spacing: 0.08em;
  color: var(--ink);
}
.brand-en {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 14px;
  color: var(--ink-faded);
  letter-spacing: 0.05em;
}
.brand-en::before {
  content: '— ';
  letter-spacing: 0;
}
.brand-dot {
  position: absolute;
  top: -2px; right: -10px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--red-ribbon);
  box-shadow: 0 0 0 2px rgba(156,50,42,0.15);
}
.vol-badge {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--ink-soft);
  border-radius: 1px;
  padding: 4px 8px;
  text-align: right;
  line-height: 1.5;
}
.vol-badge b {
  font-weight: 700;
  letter-spacing: 0.08em;
}
.vol-badge .vol-badge-sub {
  display: block;
  font-size: 8px;
  letter-spacing: 0.25em;
  color: var(--ink-faded);
  margin-top: 1px;
}

/* ============================================
   NAV
   ============================================ */
.nav {
  display: flex;
  border-bottom: 1px solid rgba(42,36,29,0.18);
  padding: 0 2px;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 14px 0 12px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--ink-faded);
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}
.nav-btn:hover { color: var(--ink-soft); }
.nav-btn.active {
  color: var(--ink);
  font-weight: 700;
}
.nav-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 25%; right: 25%;
  height: 2px;
  background: var(--red-ribbon);
}

/* ============================================
   MAIN
   ============================================ */
.main {
  padding: 22px 0 0;
  flex: 1;
}
.fade-up { animation: fadeUp 0.4s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================
   TYPEWRITER (transmit view)
   ============================================ */
.typewriter-stage {
  position: relative;
  margin: 8px -6px 0;
}
.typewriter-img-wrap {
  position: relative;
  width: 100%;
  height: 180px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  overflow: hidden;
}
.typewriter-img {
  width: 320px;
  height: auto;
  margin-bottom: -32px;
  mix-blend-mode: multiply;
  filter: contrast(1.05) saturate(0.9) sepia(0.08);
  user-select: none;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(.2,.8,.2,1);
  transform-origin: 50% 88%;
}
.typewriter-img.is-typing {
  animation: wiggle 0.18s ease;
}
.typewriter-img.is-returning {
  transform: translateX(-12px) rotate(-0.3deg);
}
@keyframes wiggle {
  0% { transform: translate(0, 0); }
  40% { transform: translate(0.5px, -0.5px); }
  100% { transform: translate(0, 0); }
}
/* Carriage indicator (the bar with paper) drawn on top of the photo */
.carriage-paper {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 38px);
  transform: translateX(-50%);
  width: 220px;
  height: 26px;
  background: linear-gradient(to bottom, var(--paper) 60%, var(--paper-dark) 100%);
  border: 1px solid rgba(42,36,29,0.18);
  border-bottom: none;
  border-radius: 2px 2px 0 0;
  box-shadow:
    inset 0 -2px 4px rgba(42,36,29,0.08),
    0 -2px 6px rgba(42,36,29,0.04);
  z-index: 2;
}
.carriage-paper::before {
  content: '';
  position: absolute;
  left: -8px; right: -8px;
  bottom: -2px;
  height: 4px;
  background:
    repeating-linear-gradient(90deg,
      transparent 0, transparent 3px,
      rgba(42,36,29,0.15) 3px, rgba(42,36,29,0.15) 4px);
}
.typing-bell {
  position: absolute;
  top: 8px; right: 24px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--gold-light), var(--gold) 60%, var(--gold-dark));
  box-shadow: 0 2px 4px rgba(42,36,29,0.2);
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 3;
}
.typing-bell.is-ringing {
  opacity: 1;
  animation: ringBell 0.6s ease;
}
@keyframes ringBell {
  0%, 100% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-15deg) scale(1.1); }
  40% { transform: rotate(12deg) scale(1.1); }
  60% { transform: rotate(-8deg) scale(1.05); }
  80% { transform: rotate(5deg) scale(1.02); }
}

/* ============================================
   PAPER (typing surface)
   ============================================ */
.paper-stage {
  position: relative;
  margin-top: -8px;
  padding-top: 0;
  z-index: 1;
}
.paper {
  position: relative;
  background:
    linear-gradient(to bottom, var(--paper-dark) 0%, var(--paper) 6%, var(--paper) 100%),
    var(--paper);
  background-blend-mode: multiply;
  border: 1px solid rgba(42,36,29,0.15);
  border-top: 2px solid rgba(42,36,29,0.22);
  box-shadow: var(--shadow-paper);
  padding: 32px 24px 18px;
  border-radius: 1px;
  min-height: 240px;
}
.paper::before {
  /* perforated top edge (just rolled out look) */
  content: '';
  position: absolute;
  top: -3px; left: 0; right: 0; height: 5px;
  background: repeating-linear-gradient(90deg,
    transparent 0, transparent 3px,
    rgba(42,36,29,0.25) 3px, rgba(42,36,29,0.25) 4px);
}
.paper::after {
  /* paper grain */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 90% 10%, rgba(120,90,40,0.06), transparent 35%),
    radial-gradient(circle at 10% 90%, rgba(120,90,40,0.04), transparent 40%);
  mix-blend-mode: multiply;
  border-radius: inherit;
}
.paper-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px dashed rgba(42,36,29,0.25);
}
.paper-header-l, .paper-header-r {
  display: flex; align-items: center; gap: 8px;
  font-size: 9px; letter-spacing: 0.25em;
  color: var(--ink-faded);
  font-weight: 500;
}
.paper-header-title {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.paper-stamp {
  display: inline-block;
  border: 1.5px solid var(--red-ribbon);
  color: var(--red-ribbon);
  font-size: 8px;
  letter-spacing: 0.2em;
  padding: 2px 6px;
  border-radius: 1px;
  transform: rotate(-3deg);
  font-weight: 700;
}
.typing-area {
  position: relative;
  min-height: 130px;
}
.typed-display {
  font-family: 'Special Elite', 'IBM Plex Mono', monospace;
  font-size: 16px;
  line-height: 2.0;
  color: var(--ink);
  letter-spacing: 0.02em;
  word-break: keep-all;
  white-space: pre-wrap;
  min-height: 130px;
  position: relative;
}
.typed-display .ink-char {
  display: inline-block;
  animation: inkOn 0.16s ease-out;
  position: relative;
}
@keyframes inkOn {
  0% { opacity: 0; transform: translateY(-2px) scale(0.95); filter: blur(0.5px); }
  60% { opacity: 1; transform: translateY(0.5px) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
.typed-display .stop-tag {
  color: var(--red-ribbon);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 2px;
}
.cursor-bar {
  display: inline-block;
  width: 12px;
  height: 18px;
  margin-left: 1px;
  background: var(--ink);
  vertical-align: -2px;
  animation: blink 1.1s steps(2) infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
.hidden-input {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 16px;
  caret-color: transparent;
  z-index: 5;
  cursor: text;
}
.placeholder {
  position: absolute;
  top: 4px; left: 0;
  color: var(--ink-light);
  font-family: 'Special Elite', monospace;
  font-size: 16px;
  pointer-events: none;
  letter-spacing: 0.02em;
}

.paper-footer {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed rgba(42,36,29,0.25);
}
.char-bar {
  position: relative;
  height: 3px;
  background: rgba(42,36,29,0.12);
  border-radius: 1px;
  overflow: hidden;
  margin-bottom: 10px;
}
.char-bar-fill {
  height: 100%;
  background: var(--sage-dark);
  transition: width 0.15s, background 0.3s;
}
.char-bar-fill.warn  { background: var(--gold-dark); }
.char-bar-fill.danger { background: var(--red-ribbon); }
.char-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.char-count {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-faded);
}
.char-count.warn   { color: var(--gold-dark); }
.char-count.danger { color: var(--red-ribbon); }
.send-btn {
  background: var(--ink);
  color: var(--paper);
  border: none;
  padding: 9px 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.25em;
  cursor: pointer;
  border-radius: 1px;
  transition: all 0.18s;
  position: relative;
  box-shadow: 0 2px 0 var(--wood-dark);
}
.send-btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 0 var(--wood-dark);
}
.send-btn:not(:disabled):active {
  transform: translateY(1px);
  box-shadow: 0 0 0 var(--wood-dark);
}
.send-btn:disabled {
  background: var(--paper-darker);
  color: var(--ink-light);
  box-shadow: none;
  cursor: not-allowed;
}

/* sent stamp */
.sent-stamp {
  text-align: center;
  margin: 18px 0 8px;
}
.sent-stamp-inner {
  display: inline-block;
  padding: 8px 24px;
  border: 2.5px double var(--red-ribbon);
  color: var(--red-ribbon);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3em;
  transform: rotate(-3deg);
  animation: stampIn 0.5s cubic-bezier(.2,.8,.2,1);
  font-family: 'Cormorant Garamond', serif;
}
@keyframes stampIn {
  0% { opacity: 0; transform: scale(1.6) rotate(-8deg); }
  60% { opacity: 1; transform: scale(0.92) rotate(-3deg); }
  100% { opacity: 1; transform: scale(1) rotate(-3deg); }
}

/* ============================================
   SECTIONS & CARDS
   ============================================ */
.section {
  margin-top: 36px;
}
.section-label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--ink-faded);
  margin-bottom: 14px;
  text-transform: uppercase;
}
.section-label::before,
.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(42,36,29,0.2);
}
.card {
  background: rgba(244, 236, 216, 0.4);
  border: 1px solid rgba(42,36,29,0.15);
  border-left: 3px solid var(--ink-faded);
  border-radius: 1px;
  padding: 12px 14px;
  margin-bottom: 8px;
  animation: slideIn 0.3s ease both;
}
.card.from-me { border-left-color: var(--sage); }
.card.from-other { border-left-color: var(--red-ribbon); }
.card-meta {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--ink-faded);
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
}
.card-meta b { font-weight: 700; color: var(--ink-soft); }
.card-text {
  font-family: 'Special Elite', monospace;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink);
  letter-spacing: 0.02em;
  word-break: keep-all;
}
.card-text .stop-tag {
  color: var(--red-ribbon);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.card-time {
  margin-top: 6px;
  font-size: 9px;
  color: var(--ink-light);
  letter-spacing: 0.06em;
}

/* meeting close button */
.meet-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  margin-top: 36px;
  padding: 18px 0;
  background: transparent;
  border: 1.5px dashed rgba(42,36,29,0.35);
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0.18em;
  cursor: pointer;
  border-radius: 1px;
  transition: all 0.2s;
}
.meet-btn:hover {
  border-color: var(--red-ribbon);
  color: var(--red-ribbon);
  background: rgba(156,50,42,0.04);
}
.meet-btn-icon {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 18px;
}

.empty {
  text-align: center;
  padding: 56px 0;
  color: var(--ink-light);
  font-size: 12px;
  letter-spacing: 0.15em;
}

.notice {
  text-align: center;
  padding: 14px 0;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--ink-faded);
  border-bottom: 1px dashed rgba(42,36,29,0.25);
  margin-bottom: 18px;
}

/* identity switch (demo) */
.identity-switch {
  display: inline-flex;
  font-size: 9px;
  letter-spacing: 0.15em;
  border: 1px solid rgba(42,36,29,0.3);
  border-radius: 1px;
  overflow: hidden;
  margin-top: 8px;
}
.identity-switch button {
  background: transparent;
  border: none;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--ink-faded);
}
.identity-switch button.active {
  background: var(--ink);
  color: var(--paper);
}

/* footer */
.app-footer {
  text-align: center;
  padding: 24px 0 10px;
  font-size: 9px;
  letter-spacing: 0.3em;
  color: var(--ink-light);
}

/* ============================================
   MODAL
   ============================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(42,36,29,0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================
   SHELF (archive)
   ============================================ */
.shelf-wrap {
  margin-top: 8px;
}
.shelf {
  position: relative;
  background:
    linear-gradient(to bottom, var(--wood-light) 0%, var(--wood) 70%, var(--wood-dark) 100%);
  border-radius: 2px;
  padding: 22px 14px 16px;
  margin-bottom: 14px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.12),
    inset 0 -2px 0 rgba(0,0,0,0.3),
    0 6px 14px rgba(42,36,29,0.18);
}
.shelf::before {
  /* wood grain */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg,
      transparent 0, transparent 18px,
      rgba(0,0,0,0.06) 18px, rgba(0,0,0,0.06) 19px),
    repeating-linear-gradient(90deg,
      transparent 0, transparent 42px,
      rgba(255,255,255,0.04) 42px, rgba(255,255,255,0.04) 43px);
  border-radius: inherit;
}
.shelf-board {
  position: absolute;
  bottom: 0; left: -4px; right: -4px;
  height: 14px;
  background: linear-gradient(to bottom, var(--wood-dark), #2c1c10);
  border-radius: 0 0 2px 2px;
  box-shadow: 0 8px 14px rgba(42,36,29,0.3);
}
.shelf-books {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 168px;
  position: relative;
  z-index: 1;
}
.shelf-empty {
  align-self: center;
  width: 100%;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.25em;
  color: rgba(255,255,255,0.6);
}

/* Book spine */
.book {
  flex: 0 0 auto;
  width: 36px;
  height: 100%;
  cursor: pointer;
  position: relative;
  transform-origin: 50% 100%;
  transition: transform 0.3s cubic-bezier(.2,.8,.2,1);
  outline: none;
  border: none;
  padding: 0;
  background: transparent;
}
.book:hover { transform: translateY(-8px) rotate(-1deg); }
.book:focus-visible { transform: translateY(-8px); }
.book-spine {
  width: 100%;
  height: 100%;
  border-radius: 1px 1px 0 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.08),
    inset -3px 0 6px rgba(0,0,0,0.25),
    inset 3px 0 6px rgba(0,0,0,0.1),
    0 1px 0 rgba(0,0,0,0.3);
}
.book-spine::before {
  /* horizontal gilded bands */
  content: '';
  position: absolute;
  left: 4px; right: 4px;
  top: 26px;
  height: 1.5px;
  background: var(--gold);
  box-shadow: 0 60px 0 var(--gold);
}
.book-spine-label {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--gold-light);
  text-align: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  line-height: 1.4;
  margin-top: 6px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}
.book-spine-vol {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--gold-light);
  margin-bottom: 4px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

/* book color variants */
.book.cover-sage     .book-spine { background: linear-gradient(to right, #4d6357 0%, #6b8577 50%, #4d6357 100%); }
.book.cover-burgundy .book-spine { background: linear-gradient(to right, #5c2118 0%, #8b3327 50%, #5c2118 100%); }
.book.cover-sand     .book-spine { background: linear-gradient(to right, #806038 0%, #ad8a5a 50%, #806038 100%); }
.book.cover-navy     .book-spine { background: linear-gradient(to right, #1e2a3a 0%, #344862 50%, #1e2a3a 100%); }
.book.cover-charcoal .book-spine { background: linear-gradient(to right, #1f1c18 0%, #3a3530 50%, #1f1c18 100%); }

/* random heights per book to feel hand-arranged */
.book[data-h="0"] { height: 96%; }
.book[data-h="1"] { height: 100%; }
.book[data-h="2"] { height: 93%; }
.book[data-h="3"] { height: 98%; }
.book[data-h="4"] { height: 95%; }

/* ============================================
   BOOK OPEN (archive detail)
   ============================================ */
.book-stage {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(20,16,12,0.72);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}
.book-stage-top {
  display: flex;
  justify-content: space-between;
  padding: 18px 22px;
  color: var(--paper);
  font-size: 11px;
  letter-spacing: 0.2em;
}
.book-stage-top button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: var(--paper);
  padding: 6px 14px;
  cursor: pointer;
  border-radius: 1px;
  font-size: 11px;
  letter-spacing: 0.2em;
}
.book-stage-top button:hover { border-color: white; }

.book-open {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px 30px;
  perspective: 1500px;
}
.book-inner {
  position: relative;
  max-width: 380px;
  width: 100%;
  background:
    linear-gradient(to right, var(--paper-darker) 0%, var(--paper) 6%, var(--paper) 100%),
    var(--paper);
  background-blend-mode: multiply;
  border-radius: 2px;
  padding: 40px 30px 32px;
  box-shadow:
    0 30px 60px rgba(0,0,0,0.4),
    0 0 0 1px rgba(42,36,29,0.15);
  animation: bookOpen 0.5s cubic-bezier(.2,.8,.2,1) both;
  min-height: 60vh;
  max-height: 80vh;
  overflow-y: auto;
}
@keyframes bookOpen {
  from { opacity: 0; transform: rotateY(-20deg) scale(0.9); }
  to { opacity: 1; transform: rotateY(0) scale(1); }
}
.book-inner::-webkit-scrollbar { width: 4px; }
.book-inner::-webkit-scrollbar-thumb { background: var(--paper-darker); }

.book-title-page {
  text-align: center;
  padding: 14px 0 28px;
  border-bottom: 1px solid rgba(42,36,29,0.2);
  margin-bottom: 24px;
  position: relative;
}
.book-title-page::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 30%; right: 30%;
  border-bottom: 3px double rgba(42,36,29,0.4);
  height: 4px;
}
.book-title-vol {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 32px;
  letter-spacing: 0.15em;
  color: var(--ink);
  margin-bottom: 6px;
}
.book-title-name {
  font-family: 'Noto Serif KR', serif;
  font-weight: 700;
  font-size: 20px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  margin-bottom: 14px;
}
.book-title-period {
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--ink-faded);
  margin-bottom: 4px;
}
.book-title-count {
  font-size: 10px;
  letter-spacing: 0.25em;
  color: var(--ink-light);
}

.book-page-tg {
  border-bottom: 1px dashed rgba(42,36,29,0.18);
  padding: 14px 0;
}
.book-page-tg:last-child { border-bottom: none; }
.book-page-from {
  font-size: 9px;
  letter-spacing: 0.25em;
  color: var(--ink-faded);
  font-weight: 700;
  margin-bottom: 6px;
}
.book-page-from.me { color: var(--sage-dark); }
.book-page-from.other { color: var(--red-ribbon); }
.book-page-text {
  font-family: 'Special Elite', monospace;
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink);
  letter-spacing: 0.01em;
  word-break: keep-all;
}
.book-page-text .stop-tag { color: var(--red-ribbon); font-weight: 700; letter-spacing: 0.08em; }
.book-page-time {
  font-size: 9px;
  color: var(--ink-light);
  letter-spacing: 0.1em;
  margin-top: 6px;
}

.book-end-stamp {
  margin-top: 36px;
  text-align: center;
}
.book-end-stamp-inner {
  display: inline-block;
  padding: 6px 18px;
  border: 1.5px solid var(--ink-faded);
  font-size: 9px;
  letter-spacing: 0.4em;
  color: var(--ink-faded);
  font-family: 'Cormorant Garamond', serif;
  transform: rotate(-1.5deg);
}

/* ============================================
   RITUAL (closing ceremony)
   ============================================ */
.ritual-stage {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(15,12,8,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.4s ease;
}
.ritual-card {
  max-width: 380px;
  width: 100%;
  background: var(--paper);
  padding: 36px 30px 28px;
  border-radius: 1px;
  text-align: center;
  position: relative;
  box-shadow: 0 30px 70px rgba(0,0,0,0.5);
}
.ritual-card::before {
  content: '';
  position: absolute;
  top: -3px; left: 0; right: 0; height: 5px;
  background: repeating-linear-gradient(90deg,
    transparent 0, transparent 3px,
    rgba(42,36,29,0.25) 3px, rgba(42,36,29,0.25) 4px);
}
.ritual-step-label {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 13px;
  color: var(--red-ribbon);
  letter-spacing: 0.2em;
  margin-bottom: 14px;
}
.ritual-title {
  font-family: 'Noto Serif KR', serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}
.ritual-sub {
  font-size: 12px;
  color: var(--ink-faded);
  letter-spacing: 0.06em;
  line-height: 1.7;
  margin-bottom: 22px;
}
.ritual-meta {
  display: flex;
  justify-content: space-around;
  padding: 14px 0;
  margin-bottom: 22px;
  border-top: 1px dashed rgba(42,36,29,0.25);
  border-bottom: 1px dashed rgba(42,36,29,0.25);
}
.ritual-meta-item { text-align: center; }
.ritual-meta-num {
  font-family: 'Cormorant Garamond', serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
}
.ritual-meta-label {
  font-size: 9px;
  letter-spacing: 0.25em;
  color: var(--ink-faded);
  text-transform: uppercase;
  margin-top: 2px;
}
.ritual-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--ink-faded);
  font-family: 'Noto Serif KR', serif;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  padding: 8px 0;
  color: var(--ink);
  outline: none;
  margin-bottom: 18px;
}
.ritual-input:focus { border-color: var(--red-ribbon); }
.ritual-covers {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
}
.cover-swatch {
  width: 40px; height: 56px;
  border: none;
  cursor: pointer;
  border-radius: 1px;
  position: relative;
  transition: transform 0.18s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.cover-swatch:hover { transform: translateY(-2px); }
.cover-swatch.active::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
}
.cover-swatch.sage     { background: linear-gradient(to right, #4d6357, #6b8577, #4d6357); }
.cover-swatch.burgundy { background: linear-gradient(to right, #5c2118, #8b3327, #5c2118); }
.cover-swatch.sand     { background: linear-gradient(to right, #806038, #ad8a5a, #806038); }
.cover-swatch.navy     { background: linear-gradient(to right, #1e2a3a, #344862, #1e2a3a); }
.cover-swatch.charcoal { background: linear-gradient(to right, #1f1c18, #3a3530, #1f1c18); }

.ritual-btns {
  display: flex;
  gap: 10px;
}
.ritual-btn {
  flex: 1;
  padding: 12px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.25em;
  cursor: pointer;
  border: none;
  border-radius: 1px;
  transition: all 0.18s;
}
.ritual-btn.primary {
  background: var(--ink);
  color: var(--paper);
}
.ritual-btn.primary:hover { background: var(--red-ribbon); }
.ritual-btn.ghost {
  background: transparent;
  color: var(--ink-faded);
  border: 1px solid var(--ink-faded);
}
.ritual-btn.ghost:hover { color: var(--ink); border-color: var(--ink); }

/* Binding animation */
.binding-stage {
  width: 100%;
  max-width: 380px;
  height: 60vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.binding-status {
  position: absolute;
  bottom: 20px;
  width: 100%;
  text-align: center;
  color: var(--paper);
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 16px;
  letter-spacing: 0.15em;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
.binding-pages {
  position: relative;
  width: 180px;
  height: 240px;
  transform-style: preserve-3d;
}
.binding-page {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border: 1px solid rgba(42,36,29,0.15);
  transform-origin: 50% 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.binding-cover-front,
.binding-cover-back {
  position: absolute;
  inset: -4px;
  border-radius: 2px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  transform-origin: left center;
}
.binding-gold-stamp {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 0.15em;
  color: var(--gold-light);
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
  opacity: 0;
  z-index: 10;
}

/* Confetti / sparks */
.sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.spark {
  position: absolute;
  top: 50%; left: 50%;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--gold-light);
  box-shadow: 0 0 8px var(--gold-light);
}

/* tweaks panel for demo identity toggle */
.demo-note {
  font-size: 9px;
  letter-spacing: 0.15em;
  color: var(--ink-light);
  margin-top: 8px;
  text-transform: uppercase;
}
