/* Pip — book-native reader. Kindle-first baseline, modern browsers get @supports enhancements. */

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  height: 100%;
  background: #f5f0e6;
}

body {
  margin: 0;
  min-height: 100%;
  background: #f5f0e6;
  color: #1e1b18;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 1rem;
  line-height: 1.55;
}

::selection {
  background: rgba(49, 41, 32, 0.18);
  color: #1e1b18;
}

a {
  color: inherit;
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.16em;
}

a:hover {
  text-decoration-thickness: 0.1em;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  font-size: 0.94em;
}

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

/* --- layout shell (Kindle baseline) --- */

.shell {
  width: 100%;
  max-width: 52rem;
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
  padding-top: 1.25rem;
  padding-bottom: 2rem;
}

.shell--home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.shell--home > * {
  margin-top: 1.2rem;
}
.shell--home > *:first-child {
  margin-top: 0;
}

.shell--page,
.shell--book {
  display: flex;
  flex-direction: column;
}

.shell--page > * + *,
.shell--book > * + * {
  margin-top: 1.75rem;
}

.shell--narrow {
  max-width: 44rem;
}

/* --- stack rhythm (gap fallback via margin) --- */

.stack {
  display: flex;
  flex-direction: column;
}

.stack > * + * {
  margin-top: 1rem;
}

.stack--tight > * + * {
  margin-top: 0.5rem;
}

.hero {
  width: 100%;
  max-width: 42rem;
}

/* --- typography (book-coded, serif throughout) --- */

.kicker,
.eyebrow,
.source-line,
.status-line,
.footer-strip,
.aux-link,
.examples-line,
.page-intro,
.muted {
  color: #5d5449;
}

.kicker,
.eyebrow,
.source-line {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 0.76rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-variant: small-caps;
  font-feature-settings: "smcp" 1;
}

.wordmark,
.page-title,
.book-title,
.panel-title {
  margin: 0;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.wordmark {
  font-family: "Fraunces", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 2.8rem;
  line-height: 0.98;
  font-weight: 600;
  font-style: normal;
  font-variation-settings: "SOFT" 50, "opsz" 144;
}

.lede,
.page-intro {
  margin: 0;
  max-width: 38rem;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-style: italic;
  font-size: 1.18rem;
  line-height: 1.55;
  color: #3a342c;
}

.epigraph {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 0.94rem;
  font-style: italic;
  color: #5d5449;
  opacity: 0.78;
}

.epigraph span {
  font-style: normal;
  opacity: 0.8;
}

.status-line,
.resume-line,
.examples-line,
.aux-link,
.footer-strip p,
.message {
  margin: 0;
}

.status-line,
.resume-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.status-line > * + *,
.resume-line > * + * {
  margin-left: 0.55rem;
}

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: rgba(30, 27, 24, 0.28);
  display: inline-block;
  flex: 0 0 auto;
}

.status-dot--live {
  background: rgba(30, 27, 24, 0.88);
}

.examples-block {
  width: 100%;
  max-width: 34rem;
}

.examples-line {
  display: flex;
  flex-wrap: wrap;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-style: italic;
  font-size: 1rem;
}

.examples-line > * {
  margin-right: 0.55rem;
}

.examples-line span {
  opacity: 0.5;
  font-style: normal;
}

.examples-inline-form {
  display: inline;
  margin: 0;
}

.link-button {
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.16em;
}

.link-button:hover {
  text-decoration-thickness: 0.1em;
}

.page-head {
  width: 100%;
  max-width: 46rem;
}

/* --- panel (flat by default, frosted on modern browsers) --- */

.panel {
  width: 100%;
  max-width: 46rem;
  padding: 1.25rem;
  border: 1px solid rgba(30, 27, 24, 0.12);
  border-radius: 18px;
  background: rgba(247, 242, 233, 0.72);
}

.panel-title {
  font-family: "Fraunces", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 1.55rem;
  font-weight: 600;
}

.book {
  width: 100%;
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}

.book-head {
  padding-top: 0.3rem;
}

.book-title {
  font-family: "Fraunces", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 2.4rem;
  line-height: 1.02;
  font-weight: 600;
}

.prose {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 1.22rem;
  line-height: 1.78;
}

html[data-text-size="lg"] .prose {
  font-size: 1.34rem;
  line-height: 1.88;
}

.prose p {
  margin: 0 0 1.15em;
}

.prose p:last-child {
  margin-bottom: 0;
}

/* --- forms --- */

.field {
  display: flex;
  flex-direction: column;
}

.field > * + * {
  margin-top: 0.45rem;
}

.field-label,
.legend-label,
.fieldset-inline legend {
  font-size: 0.92rem;
  font-weight: 600;
  color: #1e1b18;
}

input[type="text"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 0.82rem 0.95rem;
  border: 1px solid rgba(30, 27, 24, 0.2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.74);
  outline: none;
}

input[type="file"] {
  padding: 0.65rem 0.75rem;
}

textarea {
  resize: vertical;
  min-height: 7rem;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(30, 27, 24, 0.45);
  box-shadow: 0 0 0 3px rgba(30, 27, 24, 0.08);
}

.fieldset-inline {
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-row,
.actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.choice-row > * + *,
.actions-row > * + * {
  margin-left: 0.75rem;
}

.choice-row > *,
.actions-row > * {
  margin-top: 0.4rem;
}

.choice-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.72rem 0.9rem;
  border: 1px solid rgba(30, 27, 24, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
}

.choice-pill > * + * {
  margin-left: 0.5rem;
}

.choice-pill input {
  width: auto;
  margin: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.9rem;
  padding: 0.75rem 1.2rem;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
}

.button > * + * {
  margin-left: 0.5rem;
}

.button--primary {
  background: #312920;
  color: #f5f0e6;
}

.button--primary:hover {
  background: #1e1b18;
}

.button--primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.button--quiet {
  background: rgba(255, 255, 255, 0.58);
  border-color: rgba(30, 27, 24, 0.2);
}

.button--quiet:hover {
  border-color: rgba(30, 27, 24, 0.4);
}

/* --- composer (static baseline, sticky on modern) --- */

.composer-wrap {
  width: 100%;
  max-width: 46rem;
  margin-left: auto;
  margin-right: auto;
  position: static;
}

.composer {
  padding: 0.85rem;
  border: 1px solid rgba(30, 27, 24, 0.12);
  border-radius: 22px;
  background: rgba(247, 242, 233, 0.96);
}

.composer-row {
  display: flex;
  align-items: flex-end;
}

.composer-row > * + * {
  margin-left: 0.75rem;
}

.composer-main {
  flex: 1 1 auto;
}

.composer-main input,
.composer-main textarea {
  margin: 0;
  background: rgba(255, 255, 255, 0.9);
}

.composer-main textarea {
  min-height: 5.5rem;
}

.composer-cog,
.composer-icon {
  width: 2.9rem;
  height: 2.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(30, 27, 24, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  flex: 0 0 auto;
  color: #1e1b18;
}

.composer-icon:hover {
  border-color: rgba(30, 27, 24, 0.4);
}

.composer-submit {
  flex: 0 0 auto;
}

.aux-link {
  font-size: 0.96rem;
  text-align: center;
}

.footer-strip {
  width: 100%;
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
  padding-top: 0.9rem;
  border-top: 1px solid rgba(30, 27, 24, 0.12);
  font-size: 0.92rem;
  font-style: italic;
  color: #5d5449;
}

.message {
  padding: 0.8rem 0.95rem;
  border-radius: 12px;
  border: 1px solid rgba(30, 27, 24, 0.12);
}

.message--notice {
  background: rgba(49, 41, 32, 0.08);
}

.message--error {
  background: rgba(123, 45, 34, 0.08);
  border-color: rgba(123, 45, 34, 0.18);
  color: #7b2d22;
}

.quiet-link {
  color: inherit;
}

.turn-echo {
  margin: 0;
  font-size: 0.88rem;
  font-style: italic;
  color: #5d5449;
  opacity: 0.72;
}

.turn-marker {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-variant: small-caps;
  color: #5d5449;
  opacity: 0.55;
}

/* --- chat page: brought into the book world --- */

.shell--chat {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 44rem;
  margin-left: auto;
  margin-right: auto;
  padding: 1.25rem 1rem 1.25rem;
}

.chat-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
}

.chat-thread > * + * {
  margin-top: 1.5rem;
}

.chat-message {
  padding: 0;
  background: transparent;
  border: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
}

.chat-message--user,
.chat-message--assistant {
  margin-left: 0;
  margin-right: 0;
  background: transparent;
  border: 0;
}

.chat-message--system {
  background: rgba(49, 41, 32, 0.06);
  border: 1px solid rgba(30, 27, 24, 0.12);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  text-align: center;
  align-self: center;
  max-width: 32rem;
  font-size: 0.92rem;
  font-style: italic;
  color: #5d5449;
}

.chat-role {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-variant: small-caps;
  color: #5d5449;
  margin: 0 0 0.35rem;
  opacity: 0.65;
}

.chat-body {
  font-size: 1.1rem;
  line-height: 1.7;
  color: #1e1b18;
}

.chat-body p {
  margin: 0.4em 0;
}

.chat-body p:first-child {
  margin-top: 0;
}

.chat-body p:last-child {
  margin-bottom: 0;
}

.chat-input-wrap {
  flex: 0 0 auto;
  border-top: 1px solid rgba(30, 27, 24, 0.12);
  padding-top: 0.9rem;
  margin-top: 1rem;
}

.chat-input-form {
  display: flex;
  align-items: flex-end;
}

.chat-input-form > * + * {
  margin-left: 0.5rem;
}

.chat-input-form textarea {
  flex: 1;
  resize: vertical;
  min-height: 2.8rem;
  background: rgba(255, 255, 255, 0.9);
}

.button--small {
  font-size: 0.78rem;
  padding: 0.35rem 0.7rem;
  min-height: 2rem;
}

/* --- stepped responsive: Kindle-safe media queries replacing clamp() --- */

@media (min-width: 600px) {
  .shell {
    padding-left: 1.6rem;
    padding-right: 1.6rem;
    padding-top: 2rem;
    padding-bottom: 2.25rem;
  }
  .shell--page > * + *,
  .shell--book > * + * {
    margin-top: 2.25rem;
  }
  .wordmark {
    font-size: 3.6rem;
  }
  .book-title {
    font-size: 2.8rem;
  }
  .panel {
    padding: 1.5rem;
  }
  .panel-title {
    font-size: 1.7rem;
  }
}

@media (min-width: 900px) {
  .shell {
    padding-left: 2.2rem;
    padding-right: 2.2rem;
    padding-top: 2.5rem;
    padding-bottom: 2.75rem;
  }
  .shell--page > * + *,
  .shell--book > * + * {
    margin-top: 2.75rem;
  }
  .wordmark {
    font-size: 4.5rem;
  }
  .book-title {
    font-size: 3.3rem;
  }
  .panel-title {
    font-size: 1.85rem;
  }
}

/* --- modern enhancement layers (Kindle ignores all @supports blocks) --- */

@supports (background: radial-gradient(red, blue)) {
  body {
    background:
      radial-gradient(circle at top, rgba(255, 255, 255, 0.45), transparent 40%),
      linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 30%),
      #f5f0e6;
  }
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .panel {
    background: rgba(255, 255, 255, 0.58);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.06);
  }
  .composer {
    background: rgba(247, 242, 233, 0.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.08);
  }
}

@supports (position: sticky) {
  .composer-wrap {
    position: sticky;
    bottom: 1rem;
  }
}

@supports (transition: transform 120ms ease) {
  .button {
    transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
  }
  .button:hover {
    transform: translateY(-1px);
  }
  .button--primary:disabled {
    transform: none;
  }
}

/* --- paper texture overlay (modern only, very subtle) --- */

@supports (background-image: url("data:image/svg+xml;utf8,<svg/>")) {
  body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    opacity: 0.035;
    z-index: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.12 0 0 0 0 0.1 0 0 0 0 0.08 0 0 0 1 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  }
  body > * {
    position: relative;
    z-index: 1;
  }
}

/* --- small viewports --- */

@media (max-width: 680px) {
  .shell--home {
    min-height: auto;
    padding-top: 1.2rem;
    padding-bottom: 2rem;
    justify-content: flex-start;
  }
  .composer-row {
    flex-wrap: wrap;
  }
  .composer-cog,
  .composer-submit,
  .button {
    min-width: 0;
  }
  .composer-submit,
  .composer-cog,
  .actions-row > * {
    flex: 1 1 auto;
  }
  .composer-cog {
    max-width: 3.5rem;
  }
  .wordmark {
    font-size: 2.4rem;
  }
}

/* --- print --- */

@media print {
  .composer-wrap,
  .footer-strip,
  .actions-row,
  .aux-link {
    display: none;
  }
  body {
    background: #fff;
  }
  .panel {
    box-shadow: none;
    background: transparent;
  }
}
