:root {
  color-scheme: light;
  --ink: #2a2320;
  --muted: #7f7068;
  --paper: #f7eee8;
  --panel: #fffaf6;
  --line: #e2d4cb;
  --accent: #c45b58;
  --accent-dark: #8f3838;
  --iris: #596f92;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 15% 8%, rgba(196, 91, 88, 0.18), transparent 28rem),
    radial-gradient(circle at 90% 20%, rgba(89, 111, 146, 0.16), transparent 24rem),
    linear-gradient(145deg, #f7eee8 0%, #eef1f0 52%, #f5ede5 100%);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100dvh;
}

.login-view {
  min-height: 100dvh;
  padding: max(22px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}

.login-card {
  width: min(100%, 390px);
  display: grid;
  gap: 18px;
}

.login-avatar {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 32%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 50px rgba(42, 35, 32, 0.22);
}

.login-copy {
  display: grid;
  gap: 7px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.login-copy h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
}

.login-copy p:last-child {
  margin: 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.login-form input {
  min-width: 0;
  min-height: 48px;
  padding: 0 15px;
  border: 1px solid rgba(226, 212, 203, 0.95);
  border-radius: 8px;
  outline: none;
  background: rgba(255, 250, 246, 0.88);
  color: var(--ink);
}

.login-form button,
.composer button,
.settings button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  color: white;
  background: var(--ink);
}

.shell {
  width: min(100%, 760px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(255, 250, 246, 0.78);
  backdrop-filter: blur(18px);
}

.is-locked .shell {
  display: none;
}

.is-unlocked .login-view {
  display: none;
}

.topbar {
  min-height: 76px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(226, 212, 203, 0.82);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 32%;
}

h1,
h2,
p {
  margin: 0;
}

.topbar h1 {
  font-size: 18px;
  line-height: 1.15;
}

#status {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.icon-button {
  min-width: 52px;
  height: 38px;
  border: 1px solid rgba(226, 212, 203, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
}

.messages {
  overflow-y: auto;
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.bubble {
  max-width: min(82%, 520px);
  padding: 10px 12px;
  border-radius: 18px;
  line-height: 1.45;
  font-size: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 24px rgba(42, 35, 32, 0.07);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--panel);
  border-bottom-left-radius: 6px;
}

.bubble.user {
  align-self: flex-end;
  color: white;
  background: linear-gradient(145deg, var(--accent), var(--accent-dark));
  border-bottom-right-radius: 6px;
}

.bubble.system {
  align-self: center;
  max-width: 92%;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  border: 1px solid rgba(226, 212, 203, 0.85);
  font-size: 14px;
  box-shadow: none;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(226, 212, 203, 0.82);
}

textarea {
  width: 100%;
  min-height: 44px;
  max-height: 132px;
  resize: none;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
}

textarea:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196, 91, 88, 0.16);
}

dialog {
  width: min(calc(100% - 28px), 430px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(42, 35, 32, 0.28);
}

dialog::backdrop {
  background: rgba(42, 35, 32, 0.35);
}

.settings {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.settings h2 {
  font-size: 18px;
}

.settings label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.memory-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.settings input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.settings button {
  padding: 0 10px;
}

.settings button.secondary {
  color: var(--ink);
  background: #eaded5;
}

@media (max-width: 520px) {
  .shell {
    width: 100%;
  }

  .bubble {
    max-width: 86%;
    font-size: 15px;
  }

  .settings-actions {
    grid-template-columns: 1fr;
  }
}
