/* In Dialogue with Nature — editorial chat app */

:root {
  --paper: #f3ecdd;
  --paper-2: #eae0c9;
  --paper-3: #fffdf6;
  --line: #d8cbae;
  --ink: #241a10;
  --ink-soft: #5f4e39;
  --ox: #8c2b1a;
  --ox-deep: #641c0f;
  --brass: #8f6f1e;
  --ok: #6f9a55;
  --warn: #c98a2e;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --display: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(95, 78, 57, 0.045) 31px 32px),
    radial-gradient(120% 90% at 20% 0%, #f7f1e4 0%, var(--paper) 55%, #ecdfc6 100%);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.mono { font-family: var(--mono); }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--paper-2);
  border: 1px solid var(--line);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* ---------- app shell ---------- */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  background: color-mix(in srgb, var(--paper-3) 55%, transparent);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

/* ---------- topbar ---------- */

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  background: var(--ink);
  color: var(--paper);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--ox);
  color: var(--paper-3);
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(243, 236, 221, 0.15);
}

.brand-text { min-width: 0; }

.brand-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: #c9b998;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #7a6b50;
  flex: 0 0 auto;
}
.status-dot.live {
  background: var(--ok);
  box-shadow: 0 0 8px 0 color-mix(in srgb, var(--ok) 75%, transparent);
  animation: pulse 2.6s infinite;
}
.status-dot.preview { background: var(--warn); }
@keyframes pulse { 50% { opacity: 0.55; } }

.topbar-actions { display: flex; align-items: center; gap: 4px; }

.timer {
  font-size: 13px;
  color: var(--warn);
  margin-right: 4px;
  min-width: 46px;
  text-align: right;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  color: var(--paper);
  border-radius: 9px;
  cursor: pointer;
  opacity: 0.82;
  transition: background 0.14s ease, opacity 0.14s ease;
}
.icon-btn:hover { background: rgba(243, 236, 221, 0.12); opacity: 1; }

/* ---------- chat ---------- */

.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 15px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 16px;
  line-height: 1.5;
  animation: pop 0.22s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.msg-bot {
  align-self: flex-start;
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 0 rgba(36, 26, 16, 0.04);
}

.msg-user {
  align-self: flex-end;
  background: var(--ox);
  color: #f8f1e2;
  border-bottom-right-radius: 4px;
}

.msg-system {
  align-self: center;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  background: var(--paper-2);
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 5px 15px;
  max-width: 92%;
  text-align: center;
}

.msg-divider {
  align-self: stretch;
  text-align: center;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ox);
  margin: 10px 0 3px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.msg-divider::before, .msg-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid color-mix(in srgb, var(--ox) 38%, transparent);
}

.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* first-message intro flourish */
.intro-drop::first-letter {
  font-family: var(--display);
  font-size: 2.6em;
  line-height: 0.8;
  float: left;
  padding: 0.05em 0.1em 0 0;
  color: var(--ox);
  font-weight: 640;
}

/* ---------- chips ---------- */

.chips {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 14px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 12px;
  border: 1px solid var(--ink);
  background: var(--paper-3);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.chip:hover { background: var(--ink); color: var(--paper); }

/* ---------- composer ---------- */

.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 9px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper-3) 70%, transparent);
  border-top: 1px solid var(--line);
}

.composer input {
  flex: 1;
  font-family: var(--serif);
  font-size: 16px;
  padding: 12px 15px;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  background: var(--paper-3);
  color: var(--ink);
}
.composer input:focus { outline: 2px solid var(--ox); outline-offset: 1px; }
.composer input:disabled { opacity: 0.55; }

.composer button {
  width: 48px;
  flex: 0 0 auto;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  background: var(--ox);
  color: var(--paper-3);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.12s ease, transform 0.1s ease;
}
.composer button:hover:not(:disabled) { background: var(--ox-deep); }
.composer button:active:not(:disabled) { transform: scale(0.94); }
.composer button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- sheets (modals) ---------- */

.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(36, 26, 16, 0.5);
  backdrop-filter: blur(2px);
  animation: fade 0.2s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet-card {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(36, 26, 16, 0.28);
  animation: rise 0.26s cubic-bezier(0.2, 0.7, 0.2, 1);
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 21px;
  margin: 0;
}
.sheet-head .icon-btn { color: var(--ink); }
.sheet-head .icon-btn:hover { background: var(--paper-2); }

.sheet-body { padding: 16px 20px 26px; }
.sheet-body p { margin: 0 0 12px; color: var(--ink-soft); }
.sheet-body .lede { font-size: 17px; color: var(--ink); }
.sheet-body .lede em { font-style: italic; color: var(--ox); }
.sheet-body h3 {
  font-family: var(--display);
  font-weight: 640;
  font-size: 16px;
  margin: 20px 0 8px;
  color: var(--ink);
}
.sheet-body strong { color: var(--ink); }

.cmd-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 4px; }
.cmd-list code { font-size: 13px; padding: 8px 12px; border-radius: 8px; }

.rounds { list-style: none; margin: 6px 0; padding: 0; }
.rounds li { display: flex; gap: 12px; margin-bottom: 12px; align-items: flex-start; }
.rounds .r-no {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
}
.rounds li:last-child .r-no { background: var(--ox); }
.rounds div { font-size: 15px; color: var(--ink-soft); }
.rounds b { color: var(--ink); }

.fine { font-size: 13.5px; color: var(--ink-soft); }
.same-system {
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--paper-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  border-radius: 8px;
  font-size: 14px;
}

.sheet-card-small { max-width: 460px; }
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--serif);
  font-size: 16px;
  padding: 13px 15px;
  margin-bottom: 8px;
  background: var(--paper-3);
  border: 1.5px solid var(--ink);
  border-radius: 11px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.menu-item:hover { background: var(--ink); color: var(--paper); }

/* ---------- responsive ---------- */

@media (min-width: 781px) {
  .app { box-shadow: 0 0 60px rgba(36, 26, 16, 0.1); }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .sheet-card, .sheet-backdrop { animation: none; }
  .status-dot.live { animation: none; }
  .chat { scroll-behavior: auto; }
}
