:root {
  color-scheme: light;
  font-family: Inter, "SF Pro Display", "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #292521;
  background: #f4efe8;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { width: 100%; height: 100%; overflow: hidden; background: #f4efe8; }
body { width: 100%; height: 100%; overflow: hidden; margin: 0; background: linear-gradient(155deg, #f9f5ef 0%, #eee7df 58%, #e9e2dc 100%); }
button, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.shell {
  display: grid;
  grid-template-rows: auto minmax(340px, 1fr) auto;
  gap: 16px;
  width: min(100%, 620px);
  height: 100svh;
  max-height: 100dvh;
  overflow: hidden;
  margin: auto;
  padding: max(22px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

.topbar { display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; align-items: center; padding: 0 4px; }
.brand { min-width: 0; }
.nav-button, .close-button { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; color: #655c56; background: rgba(255,255,255,.58); box-shadow: 0 6px 18px rgba(82,63,52,.08); cursor: pointer; }
.eyebrow { color: #a27b70; font-size: 10px; font-weight: 700; letter-spacing: .2em; }
h1, h2 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-weight: 600; letter-spacing: -.02em; }
h1 { font-size: 25px; }
h2 { font-size: 23px; }
.connection { display: flex; align-items: center; gap: 7px; color: #777068; font-size: 12px; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: #d59676; box-shadow: 0 0 0 4px rgba(213,150,118,.12); }
.connection.online i { background: #4eac7b; box-shadow: 0 0 0 4px rgba(78,172,123,.12); }

.paper {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(112,87,72,.1);
  border-radius: 26px;
  background:
    linear-gradient(rgba(255,255,255,.83), rgba(255,255,255,.83)),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(91,109,126,.055) 31px 32px);
  box-shadow: 0 20px 55px rgba(89,72,60,.12), inset 0 1px 0 white;
}

.paper-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 20px 15px; border-bottom: 1px solid rgba(112,87,72,.08); }
.paper-head div { display: grid; gap: 3px; min-width: 0; }
.caption { color: #aaa097; font-size: 10px; letter-spacing: .12em; }
.paper-head strong { overflow: hidden; color: #504943; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: #f1ece7; filter: grayscale(1); opacity: .55; cursor: pointer; }
.icon-button.active { background: #f6e4df; filter: none; opacity: 1; }

.messages { display: flex; flex-direction: column; gap: 18px; min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 22px 20px; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.scroll-bottom { position: absolute; z-index: 3; right: 22px; bottom: 82px; display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid rgba(123,91,80,.13); border-radius: 50%; color: white; background: rgba(151,100,90,.94); box-shadow: 0 8px 22px rgba(89,57,51,.2); cursor: pointer; }
.scroll-bottom[hidden] { display: none; }
.welcome { margin: auto; max-width: 310px; color: #958a81; text-align: center; line-height: 1.7; }
.welcome span { display: block; margin-bottom: 8px; color: #c48678; font-size: 23px; }
.welcome p { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 15px; }
.message { max-width: 88%; animation: enter .24s ease both; }
.message .who { display: block; margin-bottom: 5px; color: #a39a91; font-size: 10px; letter-spacing: .1em; }
.message-content { line-height: 1.78; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 .72em; }
.message.user { align-self: flex-end; }
.message.user .who { text-align: right; }
.message.user .message-content { padding: 11px 14px; border-radius: 18px 18px 5px 18px; color: #fff; background: linear-gradient(145deg, #b37b70, #98675e); box-shadow: 0 8px 18px rgba(134,82,72,.16); white-space: pre-wrap; }
.message.assistant { align-self: flex-start; width: 100%; }
.message.assistant .message-content { font-family: Georgia, "Songti SC", "Microsoft YaHei", serif; color: #3f3934; font-size: 17px; overflow-wrap: anywhere; }
.message.assistant h3, .message.assistant h4, .message.assistant h5, .message.assistant h6 { margin: 1.2em 0 .55em; color: #312c28; line-height: 1.4; }
.message.assistant h3 { font-size: 1.2em; }
.message.assistant h4 { font-size: 1.12em; }
.message.assistant .md-list { padding-left: .3em; margin: .38em 0; }
.message.assistant blockquote { margin: .9em 0; padding: .2em 0 .2em .9em; border-left: 3px solid #c58b7d; color: #71665f; }
.message.assistant code { padding: .12em .32em; border-radius: 5px; color: #8d5149; background: #f1e8e3; font-family: "Cascadia Code", Consolas, monospace; font-size: .88em; }
.message.assistant pre { max-width: 100%; overflow-x: auto; margin: .9em 0; padding: 13px 14px; border: 1px solid rgba(114,89,77,.1); border-radius: 12px; color: #413b37; background: #f4f0eb; font-family: "Cascadia Code", Consolas, monospace; font-size: 13px; line-height: 1.62; white-space: pre; }
.message.assistant pre code { padding: 0; color: inherit; background: transparent; }
.message small { display: block; margin-top: 6px; color: #a0958d; font-size: 10px; }

.image-preview { display: flex; gap: 8px; overflow-x: auto; padding: 8px 15px 0; }
.image-preview div { position: relative; flex: 0 0 58px; }
.image-preview img { width: 58px; height: 58px; border-radius: 13px; object-fit: cover; }
.image-preview button { position: absolute; top: -5px; right: -5px; width: 20px; height: 20px; border: 0; border-radius: 50%; color: white; background: #7c625c; }
.composer { display: grid; grid-template-columns: auto 1fr auto; gap: 9px; align-items: end; margin: 0 14px 14px; padding: 10px; border: 1px solid rgba(112,87,72,.1); border-radius: 19px; background: rgba(248,244,239,.93); }
.add-button { width: 39px; height: 39px; border: 0; border-radius: 50%; color: #8f776e; background: #eee6df; font-size: 24px; cursor: pointer; }
textarea { width: 100%; max-height: 120px; resize: none; border: 0; outline: 0; color: #3e3833; background: transparent; line-height: 1.5; }
textarea::placeholder { color: #b2a8a0; }
#sendButton { width: 39px; height: 39px; border: 0; border-radius: 50%; color: white; background: #9d6d63; font-size: 21px; cursor: pointer; transition: transform .18s ease, background .18s ease; }
#sendButton.busy { background: #c94f55; font-size: 14px; box-shadow: 0 0 0 5px rgba(201,79,85,.12); animation: busyPulse 1.5s ease-in-out infinite; }
#sendButton:disabled { opacity: .55; cursor: wait; }

.hint { margin: 0; color: #aaa098; text-align: center; font-size: 10px; }

.backdrop { position: fixed; z-index: 10; inset: 0; background: rgba(38,31,28,.28); backdrop-filter: blur(2px); }
.drawer { position: fixed; z-index: 11; top: 0; bottom: 0; left: 0; display: grid; grid-template-rows: auto auto minmax(0,1fr); gap: 18px; width: min(88vw, 390px); padding: max(24px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom)); background: #f9f5ef; box-shadow: 20px 0 70px rgba(55,42,35,.18); transform: translateX(-105%); transition: transform .25s ease; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.close-button { font-size: 25px; box-shadow: none; background: #eee7e0; }
.drawer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.new-session, .pair-device { display: flex; align-items: center; gap: 9px; width: 100%; padding: 13px 12px; border: 0; border-radius: 16px; text-align: left; cursor: pointer; }
.new-session { color: white; background: linear-gradient(145deg, #a8756b, #8b5f57); box-shadow: 0 10px 24px rgba(129,83,73,.16); }
.pair-device { color: #79665e; background: #eee5de; }
.new-session span, .pair-device span { font-size: 20px; }
.pair-code-card { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 13px 15px; border: 1px solid rgba(157,109,99,.15); border-radius: 15px; background: white; }
.pair-code-card small { grid-column: 1 / 3; color: #a0958d; font-size: 10px; }
.pair-code-card strong { color: #8f5e55; font-size: 21px; letter-spacing: .16em; }
.pair-code-card button { border: 0; border-radius: 999px; color: #806b63; background: #f0e9e3; font-size: 11px; }
.session-list { overflow-y: auto; padding-right: 3px; }
.session-list h3 { margin: 18px 4px 9px; color: #a0877e; font-size: 11px; letter-spacing: .12em; }
.session-card { display: grid; grid-template-columns: minmax(0,1fr) 35px; align-items: center; width: 100%; margin-bottom: 8px; border: 1px solid transparent; border-radius: 16px; color: #4a423d; background: transparent; }
.session-card:hover, .session-card.active, .session-card.pinned { border-color: rgba(157,109,99,.15); background: #fff; box-shadow: 0 8px 22px rgba(81,61,50,.07); }
.session-open { min-width: 0; padding: 13px 7px 13px 14px; border: 0; color: inherit; background: transparent; text-align: left; cursor: pointer; }
.session-pin { width: 30px; height: 30px; border: 0; border-radius: 50%; color: #baa39b; background: transparent; cursor: pointer; }
.session-card.pinned .session-pin { color: #a4675c; background: #f6e8e3; }
.session-card strong, .session-card p, .session-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-card strong { font-size: 14px; }
.session-card p { margin: 5px 0; color: #8d837c; font-size: 11px; }
.session-card small, .loading { color: #afa49c; font-size: 10px; }
.loading { padding: 24px 8px; text-align: center; }

.dialog { width: min(calc(100% - 32px), 420px); border: 0; border-radius: 24px; color: #3d3733; background: #fbf7f2; box-shadow: 0 28px 80px rgba(45,34,29,.25); }
.dialog::backdrop { background: rgba(44,35,31,.34); backdrop-filter: blur(3px); }
.dialog form { padding: 12px 8px 6px; }
.project-choices { display: grid; gap: 8px; margin: 20px 0; }
.project-choice { padding: 13px 15px; border: 1px solid rgba(117,89,77,.1); border-radius: 14px; color: #665b54; background: white; text-align: left; cursor: pointer; }
.project-choice.selected { border-color: #a8756b; color: #8e5e55; background: #f8e9e4; }
.name-field { display: grid; gap: 7px; color: #93877f; font-size: 11px; }
.name-field input { padding: 12px 13px; border: 1px solid rgba(117,89,77,.12); border-radius: 13px; outline: 0; color: #4c443f; background: white; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.dialog-actions button { padding: 10px 17px; border: 0; border-radius: 999px; cursor: pointer; }
.dialog-actions .secondary { color: #81766e; background: #eee8e2; }
.dialog-actions .primary { color: white; background: #95675e; }
.pair-dialog p { color: #8d8179; line-height: 1.65; }
.pair-dialog input { font-size: 22px; font-weight: 700; letter-spacing: .22em; text-align: center; }
.pair-dialog .dialog-actions .primary { width: 100%; padding: 13px 18px; }
.pair-error { min-height: 20px; margin: 9px 0 0; color: #ae655e !important; font-size: 11px; text-align: center; }

@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
@keyframes pulse { 50% { transform: scale(1.04); opacity: .25; } }
@keyframes float { 50% { transform: translateY(-3px); } }
@keyframes busyPulse { 50% { transform: scale(.94); box-shadow: 0 0 0 9px rgba(201,79,85,.05); } }

@media (max-width: 420px) {
  .shell { gap: 10px; padding-top: max(12px, env(safe-area-inset-top)); padding-left: 12px; padding-right: 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 44px; }
  h1 { font-size: 22px; }
  .paper { border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
