:root {
  color-scheme: light;
  --surface: #f5f0e6;
  --panel: #fff9ef;
  --panel-soft: #e9ddcc;
  --ink: #2e2118;
  --ink-soft: #5a3727;
  --muted: #8b7866;
  --line: #d9cbb8;
  --accent: #b87555;
  --accent-dark: #8f543d;
  --danger: #b85d4b;
  --shade: rgba(46, 33, 24, 0.38);
  --shadow: 0 18px 36px rgba(46, 33, 24, 0.16);
  --soft-shadow: 0 10px 24px rgba(46, 33, 24, 0.10);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
  background:
    radial-gradient(circle at 24% 12%, rgba(255, 249, 239, 0.92), transparent 26%),
    linear-gradient(180deg, #e5ded2 0%, #d7d1c7 100%);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button[hidden],
.modal[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100vw, 390px);
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 12%, rgba(184, 117, 85, 0.08), transparent 18%),
    radial-gradient(circle at 82% 28%, rgba(90, 55, 39, 0.06), transparent 20%);
}

.topbar {
  height: 88px;
  padding: 16px 14px 10px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(245, 240, 230, 0.94);
  border-bottom: 1px solid rgba(217, 203, 184, 0.72);
  backdrop-filter: blur(12px);
}

.title-block {
  min-width: 0;
}

.topbar.is-chat .title-block {
  text-align: center;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: 23px;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.topbar.is-chat h1 {
  font-size: 24px;
}

h2 {
  margin: 18px 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 24px;
  line-height: 1;
}

.icon-btn.home-logo {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.menu-btn {
  gap: 5px;
  align-content: center;
}

.menu-btn span {
  width: 18px;
  height: 2px;
  display: block;
  border-radius: 999px;
  background: var(--ink-soft);
}

main {
  height: calc(100% - 88px);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.page {
  display: none;
  height: 100%;
  padding: 10px 20px 24px;
  overflow-y: auto;
}

.page.is-active {
  display: block;
}

.status-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.status-pill,
.role-pill {
  min-width: 0;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--ink-soft);
  padding: 8px 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.role-pill {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
}

.status-pill.is-ok {
  color: var(--panel);
  background: var(--accent);
}

.visual-strip {
  min-height: 154px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 94px;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--soft-shadow);
}

.visual-strip img {
  order: 2;
  width: 94px;
  height: 104px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
}

.visual-copy {
  order: 1;
  min-width: 0;
}

.visual-copy strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: 22px;
  line-height: 1.15;
}

.visual-copy span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.primary-actions {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.action-btn,
.primary-btn,
.secondary-btn,
.small-btn,
.send-btn,
.icon-mini-btn {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.action-btn,
.primary-btn,
.secondary-btn,
.send-btn {
  min-height: 50px;
  padding: 10px 14px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.action-btn::after {
  content: "›";
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
}

.action-main,
.primary-btn,
.send-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--panel);
}

.action-main {
  justify-content: center;
  border-radius: 999px;
}

.action-main::after {
  content: "";
}

.secondary-btn {
  background: var(--panel);
  color: var(--ink-soft);
}

.small-btn {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--ink-soft);
}

.drop-zone {
  height: 142px;
  display: grid;
  place-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 18px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.drop-zone::before {
  content: "☕";
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
}

.drop-zone.is-over {
  border-color: var(--accent);
  background: #f2e6d8;
}

.drop-zone input {
  display: none;
}

.drop-zone p {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
}

.drop-zone span,
.callout small,
.range-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.info-band,
.callout,
.range-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.info-band {
  background: var(--panel-soft);
  border: 0;
}

.info-band span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.info-band strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: 22px;
  overflow-wrap: anywhere;
}

.info-band p,
.callout {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.form-flow {
  display: grid;
  gap: 12px;
}

.form-flow::before {
  content: "";
  display: none;
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-weight: 800;
}

label span {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 900;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: var(--panel);
  color: var(--ink);
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 117, 85, 0.16);
}

.range-card {
  display: grid;
  gap: 12px;
}

.range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.range-row span,
.range-row strong {
  font-size: 14px;
  font-weight: 900;
}

.range-row strong {
  color: var(--accent);
}

input[type="range"] {
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chat-page {
  display: none;
  height: 100%;
  padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
}

.chat-page.is-active {
  display: grid;
}

.messages {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.empty-chat {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  text-align: center;
  line-height: 1.55;
}

.message {
  max-width: 86%;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user {
  margin-left: auto;
  background: var(--accent);
  color: var(--panel);
}

.message.assistant {
  margin-right: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}

.message.loading {
  color: var(--muted);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  align-items: stretch;
  gap: 10px;
  min-height: 94px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--soft-shadow);
}

.composer textarea {
  min-height: 68px;
  height: 100%;
  max-height: none;
  resize: none;
  padding: 12px 14px;
  background: var(--surface);
}

.send-btn {
  height: 100%;
  border-radius: 14px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  background: var(--shade);
}

.drawer.is-open {
  display: block;
}

.drawer-panel {
  position: absolute;
  top: 82px;
  right: max(18px, calc((100vw - 390px) / 2 + 18px));
  width: min(280px, calc(100vw - 36px));
  height: min(680px, calc(100dvh - 132px));
  padding: 18px 14px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 18px 36px rgba(46, 33, 24, 0.30);
}

.drawer-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.drawer-title strong {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: 22px;
}

.model-status {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 16px;
  background: var(--panel-soft);
}

.model-status span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.model-status strong {
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.drawer-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 2px 6px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 117, 85, 0.45) transparent;
}

.drawer-scroll::-webkit-scrollbar {
  width: 6px;
}

.drawer-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(184, 117, 85, 0.45);
}

.list {
  display: grid;
  gap: 8px;
}

.list-card {
  min-height: 64px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.list-card.is-empty {
  min-height: 96px;
}

.character-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-record {
  cursor: pointer;
}

.list-card.is-selected {
  border-color: var(--accent);
  background: var(--panel);
}

.card-title {
  display: block;
  min-width: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.card-meta,
.card-preview,
.list-card p {
  display: block;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.icon-mini-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--panel);
  color: var(--accent);
}

.icon-mini-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-mini-btn.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--panel);
}

.icon-mini-btn.danger {
  color: var(--accent);
  border-color: var(--line);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(46, 33, 24, 0.72);
}

.modal-card {
  width: min(100%, 338px);
  max-height: 90dvh;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 18px 36px rgba(46, 33, 24, 0.30);
}

.modal-card-compact {
  width: min(100%, 330px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-head strong {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: 22px;
}

.picker-card {
  width: 100%;
  min-height: 68px;
  display: grid;
  gap: 5px;
  text-align: left;
  align-content: center;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 60;
  width: min(88%, 278px);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
  font-weight: 800;
  line-height: 1.45;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.94);
  transition: transform 160ms ease, opacity 160ms ease;
}

.toast.is-show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (min-width: 720px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px 0;
  }

  .app-shell {
    width: 390px;
    height: min(844px, calc(100vh - 48px));
    min-height: min(844px, calc(100vh - 48px));
    max-height: calc(100vh - 48px);
    border: 1px solid var(--line);
    border-radius: 28px;
  }
}

@media (max-width: 420px) {
  .drawer-panel {
    right: 18px;
  }
}
