:root {
  --paper: #f7f3ec;
  --ink: #26221d;
  --ink-soft: #6b6255;
  --ink-faint: #9a8f7e;
  --line: #ddd3c2;
  --accent: #9a4a2a;
  --card: #fffdf8;
}

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

html, body {
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  padding: 18px 20px 12px;
  flex: none;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
}

.rule {
  margin-top: 10px;
  height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
}

#scrollback {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 20px 20px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* story lines: roman, serif, full voice */
.story-line {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 19px;
  line-height: 1.6;
  color: var(--ink);
  margin: 10px 0;
  opacity: 0;
  transform: translateY(4px);
  animation: rise 0.35s ease forwards;
}

/* reader lines: italic, quieter, indented like a reply in a manuscript */
.you-line {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.55;
  font-style: italic;
  color: var(--ink-soft);
  margin: 10px 0 10px 14px;
  border-left: 2px solid var(--line);
  padding-left: 12px;
  opacity: 0;
  transform: translateY(4px);
  animation: rise 0.3s ease forwards;
}

.you-line .who {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
  font-weight: 600;
}

.story-line .who {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
  font-weight: 700;
}

@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}

#composer {
  flex: none;
  padding: 10px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--card);
}

.hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 8px;
  line-height: 1.45;
}

#form {
  display: flex;
  gap: 8px;
}

#line {
  flex: 1;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  outline: none;
  min-width: 0;
}

#line:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(154, 74, 42, 0.12);
}

#send {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff8f2;
  font-size: 15px;
  font-weight: 600;
  padding: 0 18px;
  cursor: pointer;
  flex: none;
}

#send:disabled {
  opacity: 0.45;
}

#send:active { transform: scale(0.97); }

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

#counter {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

button.quiet {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line);
  padding: 4px 2px;
}

button.quiet:hover { color: var(--accent); }

/* finale overlay */
.finale {
  position: fixed;
  inset: 0;
  background: rgba(38, 34, 29, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 10;
  overflow-y: auto;
}

.finale.hidden { display: none; }

.sheet {
  background: var(--paper);
  border-radius: 16px;
  max-width: 560px;
  width: 100%;
  padding: 26px 24px 22px;
  max-height: 88dvh;
  overflow-y: auto;
  box-shadow: 0 18px 60px rgba(0,0,0,0.3);
  animation: rise 0.35s ease forwards;
}

.sheet h1 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 26px;
  font-weight: 600;
  margin: 6px 0 14px;
  line-height: 1.25;
}

.final-text {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--ink);
}

.final-text .you {
  color: var(--ink-soft);
  font-style: italic;
}

.finale-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.finale-actions button {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff8f2;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 16px;
  cursor: pointer;
}

.finale-actions button.quiet {
  background: none;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 11px 4px;
}

.copy-note {
  margin-top: 10px;
  font-size: 13px;
  color: var(--accent);
  min-height: 18px;
}
.send-back {
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-soft);
  font-style: italic;
}

#scrollback .note {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  font-style: italic;
  margin: 12px 0 4px;
}

.type-caret::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 0.95em;
  background: var(--ink);
  margin-left: 2px;
  vertical-align: -0.12em;
  animation: blink 0.9s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 380px) {
  .story-line { font-size: 17.5px; }
  .you-line { font-size: 16.5px; }
}
