:root {
  --paper: #f1e7bd;
  --paper-deep: #e9daa4;
  --paper-light: #faf4dc;
  --ink: #3f3a2c;
  --ink-soft: #716a52;
  --ink-faint: #9a9070;
  --ochre: #ac8520;
  --ochre-dark: #806114;
  --petal: #d6b543;
  --moss: #687253;
  --rust: #945a3e;
  --line: rgba(76, 67, 42, 0.2);
  --line-strong: rgba(76, 67, 42, 0.38);
  --shadow: 0 16px 55px rgba(79, 64, 23, 0.12);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 17% 8%, rgba(255, 250, 220, 0.82), transparent 35%),
    linear-gradient(135deg, #f4ecc9 0%, var(--paper) 50%, #ebdca6 100%);
  background-color: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
}

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

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--ochre);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

[hidden] {
  display: none !important;
}

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

.paper-grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.43;
  background-image:
    repeating-radial-gradient(circle at 12% 19%, transparent 0 1px, rgba(86, 71, 32, 0.035) 1.6px 2px, transparent 2.4px 5px),
    repeating-linear-gradient(14deg, transparent 0 7px, rgba(255, 255, 255, 0.045) 8px, transparent 9px 14px);
  mix-blend-mode: multiply;
}

.botanical-art {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  filter: saturate(0.52) contrast(0.94) sepia(0.08);
}

.botanical-north {
  top: -210px;
  right: -85px;
  width: min(42vw, 560px);
  opacity: 0.085;
  transform: rotate(2deg);
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
}

.botanical-south {
  left: -90px;
  bottom: -320px;
  width: min(31vw, 430px);
  opacity: 0.11;
  transform: rotate(-3deg);
  -webkit-mask-image: linear-gradient(to top, #000 68%, transparent 100%);
  mask-image: linear-gradient(to top, #000 68%, transparent 100%);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--ochre-dark);
  font-family: Georgia, serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

.login-screen {
  position: relative;
  z-index: 3;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 30px;
}

.login-card {
  position: relative;
  display: grid;
  width: min(910px, 100%);
  min-height: min(610px, calc(100vh - 60px));
  overflow: hidden;
  background: rgba(250, 245, 222, 0.86);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  grid-template-columns: minmax(310px, 0.9fr) minmax(400px, 1.1fr);
}

.login-card::before,
.login-card::after {
  position: absolute;
  width: 42px;
  height: 42px;
  content: "";
  border-color: var(--ochre);
}

.login-art-panel {
  position: relative;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #ded5b5;
  border-right: 1px solid var(--line-strong);
}

.login-art-panel::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background: linear-gradient(120deg, rgba(255, 250, 226, 0.12), transparent 38%, rgba(73, 58, 25, 0.08));
  box-shadow: inset 0 0 70px rgba(70, 55, 22, 0.12);
}

.login-art-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.72) contrast(0.96) sepia(0.06);
  mix-blend-mode: multiply;
}

.login-art-panel figcaption {
  position: absolute;
  right: 20px;
  bottom: 19px;
  z-index: 1;
  display: flex;
  align-items: end;
  flex-direction: column;
  padding: 8px 11px;
  color: var(--ink-soft);
  background: rgba(240, 232, 201, 0.74);
  border: 1px solid rgba(76, 67, 42, 0.2);
  backdrop-filter: blur(4px);
}

.login-art-panel figcaption span {
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: 0.17em;
}

.login-art-panel figcaption small {
  margin-top: 3px;
  font-family: var(--serif);
  font-size: 10px;
  letter-spacing: 0.1em;
}

.login-copy-panel {
  align-self: center;
  padding: 54px clamp(34px, 5vw, 62px) 44px;
  text-align: center;
}

.login-card::before {
  top: 9px;
  left: 9px;
  border-top: 1px solid;
  border-left: 1px solid;
}

.login-card::after {
  right: 9px;
  bottom: 9px;
  border-right: 1px solid;
  border-bottom: 1px solid;
}

.seal {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 27px;
  color: #f5e9ba;
  background: var(--rust);
  border: 1px solid rgba(75, 44, 31, 0.5);
  box-shadow: 0 3px 10px rgba(74, 42, 23, 0.2);
  font-family: var(--serif);
  font-size: 29px;
  place-items: center;
  transform: rotate(-3deg);
}

.login-card h1 {
  margin: 10px 0 12px;
  font-family: var(--serif);
  font-size: clamp(31px, 6vw, 43px);
  font-weight: 500;
  letter-spacing: 0.09em;
}

.login-copy {
  margin: 0 auto 31px;
  color: var(--ink-soft);
  line-height: 1.85;
}

.login-form {
  text-align: left;
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.login-input-row {
  display: flex;
  border: 1px solid var(--line-strong);
  background: rgba(255, 252, 236, 0.75);
}

.login-input-row input {
  min-width: 0;
  flex: 1;
  padding: 13px 15px;
  background: transparent;
  border: 0;
}

.login-input-row button {
  min-width: 82px;
  color: #fff7d9;
  background: var(--ink);
  border: 0;
  letter-spacing: 0.1em;
}

.form-error {
  min-height: 21px;
  margin: 8px 0 0;
  color: var(--rust);
  font-size: 12px;
}

.ornament-rule {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 19px 0 12px;
  color: var(--ochre);
}

.ornament-rule::before,
.ornament-rule::after {
  height: 1px;
  flex: 1;
  content: "";
  background: var(--line);
}

.privacy-note {
  margin: 0;
  color: var(--ink-faint);
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.app-shell {
  position: relative;
  z-index: 2;
  display: grid;
  height: 100vh;
  grid-template-rows: 74px 1fr;
}

.site-header {
  display: grid;
  align-items: center;
  padding: 0 clamp(20px, 3vw, 50px);
  border-bottom: 1px solid var(--line);
  background: rgba(242, 233, 197, 0.78);
  backdrop-filter: blur(18px);
  grid-template-columns: 1fr auto 1fr;
}

.brand {
  display: flex;
  align-items: center;
  justify-self: start;
  gap: 12px;
  padding: 0;
  text-align: left;
  background: transparent;
  border: 0;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  color: var(--paper-light);
  background: var(--rust);
  font-family: var(--serif);
  font-size: 21px;
  place-items: center;
  transform: rotate(-2deg);
}

.brand-words {
  display: flex;
  flex-direction: column;
}

.brand-words strong {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.15em;
}

.brand-words small {
  margin-top: 1px;
  color: var(--ink-faint);
  font-family: Georgia, serif;
  font-size: 8px;
  letter-spacing: 0.18em;
}

.module-nav {
  display: flex;
  align-self: stretch;
  gap: 8px;
}

.module-tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 105px;
  justify-content: center;
  padding: 0 16px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
}

.module-tab::after {
  position: absolute;
  right: 15px;
  bottom: -1px;
  left: 15px;
  height: 2px;
  content: "";
  background: var(--ochre);
  opacity: 0;
  transform: scaleX(0.5);
  transition: 180ms ease;
}

.module-tab svg,
.mobile-rail-button svg,
.icon-button svg,
.send-button svg,
.search-field svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.module-tab.is-active {
  color: var(--ink);
}

.module-tab.is-active::after {
  opacity: 1;
  transform: scaleX(1);
}

.nav-count {
  display: inline-grid;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  color: var(--paper-light);
  background: var(--ochre-dark);
  border-radius: 20px;
  font-size: 10px;
  place-items: center;
}

.quiet-button {
  padding: 9px 15px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--line-strong);
}

.quiet-button:hover {
  color: var(--ink);
  background: rgba(255, 252, 235, 0.45);
}

.logout-button {
  justify-self: end;
}

.main-stage {
  min-height: 0;
  overflow: hidden;
}

.module-view {
  display: none;
  height: 100%;
}

.module-view.is-active {
  display: block;
}

.chat-view.is-active {
  display: grid;
  grid-template-columns: minmax(245px, 290px) 1fr;
}

.conversation-rail {
  position: relative;
  z-index: 3;
  display: grid;
  min-height: 0;
  padding: 30px 20px 19px clamp(20px, 3vw, 44px);
  background: rgba(229, 216, 167, 0.38);
  border-right: 1px solid var(--line);
  grid-template-rows: auto 1fr auto;
}

.rail-heading,
.card-heading,
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rail-heading h2,
.card-heading h2,
.dialog-heading h2,
.library-toolbar h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.icon-button,
.mobile-rail-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--ink-soft);
  background: rgba(250, 245, 222, 0.55);
  border: 1px solid var(--line);
  place-items: center;
}

.icon-button:hover,
.mobile-rail-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.conversation-list {
  min-height: 0;
  margin-top: 24px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.conversation-item {
  position: relative;
  width: 100%;
  margin: 0 0 7px;
  padding: 13px 36px 13px 13px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  transition: 150ms ease;
}

.conversation-open {
  display: block;
  width: 100%;
  padding: 0;
  text-align: left;
  background: transparent;
  border: 0;
}

.conversation-item:hover,
.conversation-item.is-active {
  background: rgba(253, 248, 226, 0.62);
  border-color: var(--line);
}

.conversation-item.is-active::before {
  position: absolute;
  top: 11px;
  bottom: 11px;
  left: -1px;
  width: 2px;
  content: "";
  background: var(--ochre);
}

.conversation-item strong,
.conversation-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item strong {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
}

.conversation-item span {
  margin-top: 5px;
  color: var(--ink-faint);
  font-size: 11px;
}

.conversation-delete {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 27px;
  height: 27px;
  padding: 0;
  color: var(--ink-faint);
  background: transparent;
  border: 0;
  opacity: 0;
  transform: translateY(-50%);
}

.conversation-item:hover .conversation-delete,
.conversation-item:focus-within .conversation-delete {
  opacity: 1;
}

.rail-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 15px;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.model-dot {
  width: 7px;
  height: 7px;
  background: var(--moss);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(104, 114, 83, 0.13);
}

.model-dot.is-offline {
  background: var(--rust);
}

.chat-panel {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  background: rgba(249, 244, 222, 0.25);
  grid-template-rows: auto 1fr auto;
}

.chat-topbar {
  display: flex;
  align-items: center;
  min-height: 77px;
  padding: 14px clamp(20px, 4vw, 62px);
  border-bottom: 1px solid var(--line);
}

.mobile-rail-button {
  display: none;
  margin-right: 12px;
}

.chat-title-wrap {
  min-width: 0;
}

.chat-kicker {
  margin: 0 0 4px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.chat-title-wrap h2 {
  max-width: min(48vw, 520px);
  margin: 0;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.memory-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 8px 12px;
  color: var(--ink-soft);
  background: rgba(234, 217, 155, 0.33);
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 11px;
}

.memory-status strong {
  color: var(--ink);
}

.memory-status-flower {
  color: var(--ochre);
  font-size: 16px;
}

.messages {
  min-height: 0;
  padding: 36px clamp(24px, 8vw, 140px) 24px;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.empty-chat {
  display: grid;
  width: min(820px, 100%);
  min-height: 100%;
  margin: auto;
  align-items: center;
  text-align: left;
  grid-template-columns: minmax(230px, 290px) minmax(250px, 1fr);
  gap: clamp(34px, 6vw, 78px);
  place-content: center;
}

.empty-botanical {
  width: min(290px, 100%);
  aspect-ratio: 2 / 3;
  margin: 0 auto 22px;
  overflow: hidden;
  opacity: 0.82;
  border: 1px solid rgba(76, 67, 42, 0.18);
  box-shadow: 0 14px 38px rgba(79, 64, 23, 0.08);
  mix-blend-mode: multiply;
}

.empty-botanical img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  filter: saturate(0.76) contrast(0.99) sepia(0.05);
}

.empty-copy h3 {
  margin: 4px 0 10px;
  font-family: var(--serif);
  font-size: clamp(23px, 3.2vw, 34px);
  font-weight: 500;
  letter-spacing: 0.06em;
}

.empty-copy > p:last-child {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.8;
}

.message {
  display: grid;
  margin: 0 auto 25px;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  max-width: 880px;
  animation: message-in 220ms ease both;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.message-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  color: var(--paper-light);
  background: var(--moss);
  font-family: var(--serif);
  font-size: 15px;
  place-items: center;
}

.message.user .message-avatar {
  background: var(--rust);
  grid-column: 2;
  grid-row: 1;
}

.message-body {
  min-width: 0;
}

.message.user .message-body {
  justify-self: end;
  grid-column: 1;
  grid-row: 1;
}

.message-meta {
  display: flex;
  gap: 8px;
  margin: 0 0 7px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.message.user .message-meta {
  justify-content: flex-end;
}

.message-content {
  max-width: min(100%, 760px);
  padding: 15px 17px;
  line-height: 1.82;
  overflow-wrap: anywhere;
  background: rgba(252, 248, 229, 0.67);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(88, 69, 22, 0.035);
}

.message.user .message-content {
  background: rgba(219, 193, 104, 0.24);
  border-color: rgba(128, 97, 20, 0.24);
}

.message.is-incomplete .message-content {
  border-style: dashed;
}

.message-content p {
  margin: 0 0 0.8em;
}

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

.message-content pre {
  max-width: 100%;
  padding: 14px;
  overflow-x: auto;
  color: #eee5c6;
  background: #403d31;
  border-left: 3px solid var(--petal);
  font-size: 12px;
  line-height: 1.55;
}

.message-content code {
  padding: 0.12em 0.32em;
  background: rgba(95, 82, 43, 0.1);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
}

.message-content pre code {
  padding: 0;
  background: transparent;
}

.typing-caret::after {
  display: inline-block;
  width: 5px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -0.12em;
  content: "";
  background: var(--ochre-dark);
  animation: blink 0.85s step-end infinite;
}

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

.composer {
  padding: 14px clamp(24px, 8vw, 140px) 23px;
  background: linear-gradient(transparent, rgba(241, 231, 189, 0.85) 28%);
}

.composer-paper {
  width: min(880px, 100%);
  margin: auto;
  background: rgba(253, 249, 230, 0.86);
  border: 1px solid var(--line-strong);
  box-shadow: 0 12px 38px rgba(75, 61, 24, 0.09);
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 190px;
  min-height: 54px;
  padding: 16px 18px 8px;
  resize: none;
  line-height: 1.6;
  background: transparent;
  border: 0;
}

.composer textarea::placeholder,
.import-card textarea::placeholder,
.edit-dialog textarea::placeholder {
  color: var(--ink-faint);
}

.composer-actions {
  display: flex;
  align-items: center;
  min-height: 50px;
  padding: 6px 8px 8px 17px;
}

.composer-hint {
  color: var(--ink-faint);
  font-size: 10px;
}

.send-button,
.stop-button,
.primary-button {
  min-height: 38px;
  margin-left: auto;
  padding: 0 16px;
  color: #fbf4d7;
  background: var(--ink);
  border: 1px solid var(--ink);
}

.send-button {
  display: flex;
  align-items: center;
  gap: 8px;
}

.send-button svg {
  width: 16px;
}

.send-button:hover,
.primary-button:hover {
  background: #29271f;
}

.stop-button {
  background: var(--rust);
  border-color: var(--rust);
}

.rail-scrim {
  display: none;
}

.memory-view {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.memory-page {
  width: min(1260px, calc(100% - 48px));
  margin: 0 auto;
  padding: clamp(42px, 6vw, 78px) 0 90px;
}

.memory-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 50px;
  padding: 0 clamp(0px, 2vw, 24px) 40px;
  border-bottom: 1px solid var(--line-strong);
}

.memory-hero > div:first-child {
  max-width: 680px;
}

.memory-hero h1 {
  margin: 4px 0 15px;
  font-family: var(--serif);
  font-size: clamp(38px, 6vw, 68px);
  font-weight: 400;
  letter-spacing: 0.1em;
}

.memory-hero p:last-child {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.9;
}

.memory-stats {
  display: flex;
  flex: 0 0 auto;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.memory-stats div {
  display: flex;
  width: 90px;
  min-height: 82px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: rgba(249, 244, 222, 0.76);
}

.memory-stats strong {
  font-family: Georgia, serif;
  font-size: 24px;
  font-weight: 400;
}

.memory-stats span {
  margin-top: 5px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.memory-workbench {
  display: grid;
  margin-top: 34px;
  background: rgba(249, 244, 222, 0.44);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
}

.import-card,
.preview-card {
  min-width: 0;
  padding: clamp(25px, 3vw, 39px);
}

.preview-card {
  background: rgba(224, 207, 145, 0.18);
  border-left: 1px solid var(--line);
}

.card-heading {
  justify-content: flex-start;
  gap: 17px;
}

.section-number {
  color: var(--ochre);
  font-family: Georgia, serif;
  font-size: 28px;
  font-style: italic;
}

.card-copy {
  margin: 21px 0 14px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.75;
}

.import-card textarea,
.edit-dialog textarea {
  width: 100%;
  padding: 17px;
  resize: vertical;
  line-height: 1.75;
  background:
    linear-gradient(rgba(255, 252, 237, 0.82), rgba(255, 252, 237, 0.82)),
    repeating-linear-gradient(transparent 0 29px, rgba(78, 66, 33, 0.12) 30px);
  border: 1px solid var(--line-strong);
}

.import-actions {
  display: flex;
  align-items: center;
  margin-top: 13px;
}

.parse-indicator {
  color: var(--ink-faint);
  font-size: 11px;
}

.parse-indicator.is-ready {
  color: var(--moss);
}

.primary-button {
  min-height: 42px;
}

.preview-list {
  display: grid;
  max-height: 340px;
  margin-top: 24px;
  overflow: auto;
  gap: 9px;
  scrollbar-width: thin;
}

.preview-empty {
  display: grid;
  min-height: 180px;
  color: var(--ink-faint);
  place-content: center;
  text-align: center;
}

.preview-empty span {
  font-family: Georgia, serif;
  font-size: 35px;
  font-style: italic;
}

.preview-empty p {
  max-width: 250px;
  line-height: 1.7;
}

.preview-item {
  display: grid;
  padding: 13px 15px;
  background: rgba(252, 248, 229, 0.58);
  border: 1px solid var(--line);
  grid-template-columns: 34px 1fr;
  gap: 10px;
}

.preview-index {
  color: var(--ochre-dark);
  font-family: Georgia, serif;
  font-size: 17px;
  font-style: italic;
}

.preview-item p {
  margin: 0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.memory-library {
  margin-top: 52px;
}

.prompt-card {
  display: grid;
  margin-top: 34px;
  padding: clamp(25px, 3vw, 39px);
  background: rgba(249, 244, 222, 0.5);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  grid-template-columns: minmax(230px, 0.72fr) minmax(0, 1.28fr);
  gap: clamp(28px, 5vw, 70px);
}

.prompt-card-copy > p {
  margin: 22px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.8;
}

.prompt-order {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.prompt-order span {
  padding: 7px 10px;
  background: rgba(224, 207, 145, 0.2);
  border: 1px solid var(--line);
}

.prompt-order b {
  color: var(--ochre-dark);
  font-weight: 400;
}

.prompt-form label {
  display: block;
  margin-bottom: 9px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.prompt-form textarea {
  width: 100%;
  min-height: 220px;
  padding: 17px;
  resize: vertical;
  line-height: 1.75;
  background:
    linear-gradient(rgba(255, 252, 237, 0.84), rgba(255, 252, 237, 0.84)),
    repeating-linear-gradient(transparent 0 29px, rgba(78, 66, 33, 0.12) 30px);
  border: 1px solid var(--line-strong);
}

.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 13px;
}

.prompt-actions span {
  color: var(--ink-faint);
  font-size: 11px;
}

.prompt-actions span.is-dirty {
  color: var(--ochre-dark);
}

.library-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.search-field {
  display: flex;
  width: min(320px, 42vw);
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  background: rgba(251, 247, 227, 0.55);
  border-bottom: 1px solid var(--line-strong);
}

.search-field svg {
  width: 16px;
  color: var(--ink-faint);
}

.search-field input {
  width: 100%;
  padding: 10px 0;
  background: transparent;
  border: 0;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.memory-card {
  position: relative;
  display: grid;
  min-height: 190px;
  padding: 19px;
  background: rgba(250, 246, 226, 0.61);
  border: 1px solid var(--line);
  grid-template-rows: auto 1fr auto;
  transition: 160ms ease;
}

.memory-card:hover {
  background: rgba(253, 250, 233, 0.82);
  border-color: var(--line-strong);
  transform: translateY(-2px);
}

.memory-card.is-disabled {
  opacity: 0.57;
}

.memory-card-head,
.memory-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.memory-card-index {
  color: var(--ochre-dark);
  font-family: Georgia, serif;
  font-size: 12px;
  font-style: italic;
  letter-spacing: 0.08em;
}

.memory-toggle {
  position: relative;
  width: 37px;
  height: 20px;
  padding: 0;
  background: rgba(89, 83, 61, 0.18);
  border: 1px solid var(--line-strong);
  border-radius: 30px;
}

.memory-toggle::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  content: "";
  background: var(--paper-light);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  transition: 160ms ease;
}

.memory-toggle.is-on {
  background: var(--moss);
}

.memory-toggle.is-on::after {
  left: 19px;
}

.memory-card-content {
  margin: 18px 0;
  display: -webkit-box;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.72;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.memory-date {
  color: var(--ink-faint);
  font-family: Georgia, serif;
  font-size: 9px;
  letter-spacing: 0.07em;
}

.memory-actions {
  display: flex;
  gap: 4px;
}

.memory-actions button {
  padding: 5px 7px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  font-size: 11px;
}

.memory-actions button:hover {
  color: var(--ink);
  background: rgba(118, 98, 39, 0.08);
}

.memory-actions .delete-memory:hover {
  color: var(--rust);
}

.memory-empty {
  padding: 70px 20px;
  text-align: center;
  color: var(--ink-soft);
  border: 1px dashed var(--line-strong);
}

.memory-empty .empty-index {
  color: var(--ochre);
  font-family: Georgia, serif;
  font-size: 16px;
}

.memory-empty h3 {
  margin: 12px 0 8px;
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 500;
}

.memory-empty p {
  margin: 0;
  font-size: 12px;
}

.edit-dialog {
  width: min(580px, calc(100% - 30px));
  padding: 0;
  color: var(--ink);
  background: var(--paper-light);
  border: 1px solid var(--line-strong);
  box-shadow: 0 25px 90px rgba(42, 36, 20, 0.3);
}

.edit-dialog::backdrop {
  background: rgba(50, 44, 29, 0.43);
  backdrop-filter: blur(3px);
}

.edit-dialog form {
  padding: 28px;
}

.edit-dialog textarea {
  margin-top: 23px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 15px;
}

.dialog-actions .primary-button {
  margin-left: 0;
}

.toast-region {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  display: grid;
  width: min(340px, calc(100% - 44px));
  gap: 8px;
}

.toast {
  padding: 12px 15px;
  color: #fbf4d7;
  background: rgba(63, 58, 44, 0.95);
  border-left: 3px solid var(--petal);
  box-shadow: 0 8px 30px rgba(50, 42, 19, 0.23);
  font-size: 12px;
  line-height: 1.55;
  animation: toast-in 180ms ease both;
}

.toast.error {
  border-left-color: #d48060;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(7px); }
}

@media (max-width: 980px) {
  .chat-view.is-active {
    grid-template-columns: 230px 1fr;
  }

  .conversation-rail {
    padding-left: 20px;
  }

  .messages,
  .composer {
    padding-right: 38px;
    padding-left: 38px;
  }

  .memory-workbench {
    grid-template-columns: 1fr;
  }

  .prompt-card {
    grid-template-columns: 1fr;
  }

  .preview-card {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .memory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .botanical-art {
    opacity: 0.07;
  }

  .botanical-north {
    top: -70px;
    width: 62vw;
  }

  .login-screen {
    min-height: 100dvh;
    padding: 14px;
    overflow-y: auto;
  }

  .login-card {
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: 190px auto;
  }

  .login-art-panel {
    min-height: 190px;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }

  .login-art-panel img {
    object-position: 50% 31%;
  }

  .login-art-panel figcaption {
    top: 12px;
    right: 12px;
    bottom: auto;
  }

  .login-copy-panel {
    padding: 42px 25px 32px;
  }

  .login-copy-panel .seal {
    position: relative;
    z-index: 2;
    margin-top: -72px;
  }

  .app-shell {
    height: 100dvh;
    grid-template-rows: 62px 1fr;
  }

  .site-header {
    padding: 0 14px;
    grid-template-columns: 1fr auto;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-words strong {
    font-size: 17px;
  }

  .brand-words small,
  .logout-button {
    display: none;
  }

  .module-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 11;
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 0 18px env(safe-area-inset-bottom);
    justify-content: space-around;
    background: rgba(244, 235, 201, 0.94);
    border-top: 1px solid var(--line-strong);
    backdrop-filter: blur(15px);
  }

  .module-tab {
    min-width: 115px;
    height: 64px;
  }

  .module-tab::after {
    top: 0;
    bottom: auto;
  }

  .main-stage {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .chat-view.is-active {
    display: block;
  }

  .conversation-rail {
    position: fixed;
    top: 62px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 0;
    z-index: 13;
    width: min(82vw, 310px);
    padding: 25px 18px 17px;
    background: rgba(239, 228, 186, 0.98);
    box-shadow: 20px 0 50px rgba(47, 40, 21, 0.18);
    transform: translateX(-105%);
    transition: 210ms ease;
  }

  .conversation-rail.is-open {
    transform: translateX(0);
  }

  .rail-scrim {
    position: fixed;
    inset: 62px 0 calc(64px + env(safe-area-inset-bottom));
    z-index: 12;
    display: block;
    width: 100%;
    padding: 0;
    background: rgba(47, 41, 25, 0.33);
    border: 0;
    opacity: 0;
    pointer-events: none;
    transition: 180ms ease;
  }

  .rail-scrim.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-panel {
    height: 100%;
  }

  .chat-topbar {
    min-height: 65px;
    padding: 10px 14px;
  }

  .mobile-rail-button {
    display: grid;
  }

  .chat-kicker {
    display: none;
  }

  .chat-title-wrap h2 {
    max-width: 34vw;
    font-size: 16px;
  }

  .memory-status {
    max-width: 43vw;
    padding: 7px 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .memory-status-flower {
    display: none;
  }

  .messages {
    padding: 25px 14px 15px;
  }

  .empty-chat {
    width: 100%;
    min-height: 100%;
    padding: 18px 0 28px;
    text-align: center;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .empty-botanical {
    width: min(220px, 58vw);
    margin-bottom: 0;
    justify-self: center;
  }

  .message,
  .message.user {
    grid-template-columns: 29px minmax(0, 1fr);
    gap: 9px;
  }

  .message.user .message-avatar {
    grid-column: 1;
  }

  .message.user .message-body {
    width: 100%;
    grid-column: 2;
  }

  .message.user .message-meta {
    justify-content: flex-start;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .message-content {
    padding: 12px 13px;
    font-size: 14px;
    line-height: 1.72;
  }

  .composer {
    padding: 9px 10px 12px;
  }

  .composer-hint {
    display: none;
  }

  .composer-actions {
    padding-left: 8px;
  }

  .memory-page {
    width: calc(100% - 28px);
    padding: 34px 0 60px;
  }

  .memory-hero {
    align-items: stretch;
    flex-direction: column;
    gap: 26px;
    padding-bottom: 29px;
  }

  .memory-hero h1 {
    font-size: 43px;
  }

  .memory-stats {
    width: 100%;
  }

  .memory-stats div {
    width: auto;
    flex: 1;
  }

  .import-card,
  .preview-card,
  .prompt-card {
    padding: 23px 18px;
  }

  .prompt-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .library-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-field {
    width: 100%;
  }

  .memory-grid {
    grid-template-columns: 1fr;
  }

  .memory-card {
    min-height: 165px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
