:root {
  --paper: #fbf6f4;
  --paper-warm: #f7f1ec;
  --ink: #1c1816;
  --muted: #766c66;
  --faint: #a89e96;
  --lotus: #7a462a;
  --lotus-soft: #a06c48;
  --connected: #348414;
  --selected: #f0e8e0;
  --bubble: #f2ece7;
  --code: #f4efe8;
  --code-h: #fcf9f6;
  --button: #2b2725;
  --stroke: #e0d8d2;
  --subtitle: #9e8a7a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --header: 78px;
  --sidebar: 292px;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); }
body { padding: var(--safe-t) 0 var(--safe-b); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#splash {
  position: fixed; inset: 0; z-index: 40;
  background: var(--paper);
  display: grid; place-items: center;
  overflow: hidden;
}
#splash img {
  width: 100%; height: 100%; object-fit: cover;
}
.splash-glow {
  position: absolute; width: 55vmin; height: 55vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 220, 150, .28), transparent 70%);
  animation: pulse 2.2s ease-in-out infinite alternate;
  pointer-events: none;
}
.splash-mist {
  position: absolute; width: 80%; height: 30%; bottom: 18%;
  background: radial-gradient(ellipse, rgba(255,255,255,.22), transparent 70%);
  filter: blur(18px);
  animation: drift 3.4s ease-in-out infinite alternate;
  pointer-events: none;
}
.splash-bar-wrap {
  position: absolute; left: 50%; bottom: 16%; transform: translateX(-50%);
  width: min(320px, 30vw); text-align: center;
}
.splash-bar {
  height: 8px; border-radius: 99px;
  background: rgba(90, 70, 55, .45);
  overflow: hidden;
}
.splash-bar i {
  display: block; height: 100%; width: 4%;
  background: #f5eee4;
  border-radius: 99px;
  transition: width .2s linear;
}
.splash-bar-wrap p {
  margin: 10px 0 0;
  font-size: 13px;
  color: rgba(70, 52, 40, .9);
  font-family: system-ui, sans-serif;
}
@keyframes pulse { from { opacity: .45; transform: scale(.96); } to { opacity: 1; transform: scale(1.05); } }
@keyframes drift { from { transform: translateX(-4%); } to { transform: translateX(6%); } }

#app { display: flex; flex-direction: column; height: 100%; min-height: 100dvh; }
#app[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--header);
  padding: 8px 14px 8px 12px;
  background: var(--paper) url("img/mountains.png") right center / 42% no-repeat;
  border-bottom: 1px solid color-mix(in srgb, var(--stroke) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lotus { width: 42px; height: 42px; flex: none; }
.brand h1 {
  margin: 0; font-size: 20px; font-weight: 500; letter-spacing: .28em;
}
.brand p {
  margin: 2px 0 0; font-size: 8px; letter-spacing: .16em;
  color: var(--subtitle); font-family: system-ui, sans-serif;
}
.pills { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(255,255,255,.72);
  border: 1px solid var(--stroke);
  font-family: system-ui, sans-serif; font-size: 12.5px;
}
.model-pill { padding-right: 8px; }
.model-pill select {
  border: 0; background: transparent; max-width: 160px; outline: none;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: orange; }
.dot.on { background: var(--connected); }
.sep { color: var(--faint); }
.sun { color: var(--lotus); }
.icon-btn, .send, .new-dialog, .primary, .side-actions button, .diff-bar button, .row button {
  font-family: system-ui, sans-serif;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 12px;
  border: 1px solid var(--stroke); background: rgba(255,255,255,.72);
}
#install-btn { width: auto; padding: 0 12px; font-size: 12.5px; }
.menu-btn { display: none; }

.shell { display: flex; flex: 1; min-height: 0; }
aside {
  position: relative;
  width: var(--sidebar); flex: none;
  padding: 10px 12px 24px;
  border-right: 1px solid var(--stroke);
  overflow: auto;
  background: var(--paper);
}
.pine {
  position: absolute; left: 0; bottom: 0; width: 100%;
  pointer-events: none; opacity: .95;
}
.new-dialog {
  position: relative; z-index: 1;
  width: 100%; border: 0; border-radius: 999px;
  background: var(--button); color: #fff;
  padding: 10px 14px; font-size: 13.5px;
}
.side-actions { display: flex; gap: 8px; margin: 10px 0; position: relative; z-index: 1; }
.side-actions button, #session-search {
  flex: 1; border: 1px solid var(--stroke); background: rgba(255,255,255,.72);
  border-radius: 999px; padding: 6px 10px; font-size: 12px;
}
#session-search { width: 100%; margin-bottom: 8px; position: relative; z-index: 1; }
aside h2 {
  position: relative; z-index: 1;
  margin: 14px 8px 6px; font-size: 13.5px; font-weight: 600;
  font-family: system-ui, sans-serif;
}
.row-item, .folder {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 10px;
  font-family: system-ui, sans-serif; font-size: 13.5px;
  cursor: pointer;
}
.row-item.active, .row-item:hover { background: var(--selected); }
.row-item span.grow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-item .time { color: var(--faint); font-size: 12px; }
.folder { padding-left: 28px; color: var(--ink); font-size: 13px; }
.lock { color: var(--muted); font-size: 11px; }

.banner {
  margin: 8px 16px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: #f4e6d8;
  border: 1px solid var(--stroke);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  color: var(--lotus);
}
.banner[hidden] { display: none; }
.empty-server {
  margin: 48px 24px;
  text-align: center;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
}

main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.tabs {
  display: flex; gap: 8px; padding: 8px 16px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--stroke) 70%, transparent);
  min-height: 40px; overflow-x: auto;
  font-family: system-ui, sans-serif; font-size: 13px;
}
.tab {
  display: flex; gap: 8px; align-items: center;
  padding: 7px 12px; border-radius: 8px; cursor: pointer;
}
.tab.active { box-shadow: inset 0 -1px 0 rgba(28,24,22,.12); }
.messages { flex: 1; overflow: auto; padding: 18px 22px 12px; }
.msg { margin-bottom: 20px; max-width: 820px; }
.who { display: flex; align-items: center; gap: 8px; font-family: system-ui, sans-serif; font-size: 13.5px; font-weight: 600; }
.who time { font-weight: 400; color: var(--faint); font-size: 12px; }
.avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: #726b66; color: #fff; display: grid; place-items: center; font-size: 11px;
}
.bubble {
  margin: 8px 0 0 30px; padding: 10px 14px; border-radius: 14px;
  background: var(--bubble); font-family: system-ui, sans-serif; font-size: 14.5px; line-height: 1.45;
  white-space: pre-wrap;
}
.plain {
  margin: 8px 0 0 30px; font-family: system-ui, sans-serif; font-size: 14.5px; line-height: 1.5;
  white-space: pre-wrap;
}
pre {
  margin: 8px 0 0 30px; padding: 10px; border-radius: 10px;
  background: var(--code); border: 1px solid var(--stroke);
  overflow: auto; font-size: 12.5px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 30px; }
.chip {
  font-family: system-ui, sans-serif; font-size: 12px;
  padding: 4px 10px; border-radius: 999px;
  background: #fff; border: 1px solid var(--stroke);
}
.code-card {
  margin: 12px 0 0 44px; border: 1px solid var(--stroke); border-radius: 14px; overflow: hidden;
  background: var(--code);
}
.code-card header {
  display: flex; justify-content: space-between; padding: 10px 14px;
  background: var(--code-h); font-family: system-ui, sans-serif; font-size: 13px;
  border-bottom: 1px solid var(--stroke);
}
.code-card pre { margin: 0; border: 0; max-height: 320px; }

.diff-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 8px 22px 10px;
  font-family: system-ui, sans-serif; font-size: 13.5px;
}
.diff-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.diff-bar button, .row button, #check-btn, #download-btn, #close-settings {
  border: 1px solid var(--stroke); background: var(--paper);
  border-radius: 12px; padding: 9px 14px;
}
.primary, .send, .new-dialog {
  background: var(--button); color: #fff; border: 0;
}

.composer { padding: 4px 16px calc(12px + var(--safe-b)); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--stroke); border-radius: 18px;
  padding: 6px 8px; background: #fff;
}
textarea {
  flex: 1; border: 0; resize: none; max-height: 140px;
  font-family: system-ui, sans-serif; font-size: 14.5px; outline: none;
  background: transparent;
}
.send { width: 36px; height: 36px; border-radius: 12px; }

#scrim { display: none; }
dialog {
  border: 1px solid var(--stroke); border-radius: 16px;
  background: var(--paper); padding: 20px; width: min(420px, 92vw);
  font-family: system-ui, sans-serif;
}
dialog h3 { font-family: serif; margin: 0 0 8px; }
dialog p { color: var(--muted); font-size: 13px; }
dialog label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0; }
dialog input { width: 100%; margin-top: 4px; padding: 8px; border-radius: 8px; border: 1px solid var(--stroke); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { font-size: 12px; }
.error { color: #a33; }

@media (max-width: 860px) {
  .brand p, #status-pill span:first-of-type, #status-pill .sep { display: none; }
  .brand h1 { font-size: 15px; letter-spacing: .18em; }
  .lotus { width: 32px; height: 32px; }
  .menu-btn { display: grid; place-items: center; }
  .top { background-size: 70%; }
  aside {
    position: fixed; z-index: 20; top: calc(var(--header) + var(--safe-t)); bottom: 0; left: 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 8px 0 30px rgba(40, 20, 10, .12);
  }
  aside.open { transform: none; }
  #scrim {
    display: block; position: fixed; inset: 0; z-index: 15;
    background: rgba(28, 24, 22, .28);
  }
  #scrim[hidden] { display: none; }
  .messages { padding: 14px 14px 8px; }
  .code-card { margin-left: 8px; }
  .diff-bar { padding: 8px 14px; }
  .diff-actions { margin-left: 0; width: 100%; }
  .diff-actions button { flex: 1; }
}

@media (display-mode: standalone) {
  body { user-select: none; }
  textarea, .bubble, .plain, pre { user-select: text; }
}
