:root {
  color-scheme: light;
  --paper: #f4f6f3;
  --ink: #20231f;
  --muted: #66705f;
  --line: #d4d8d0;
  --olive: #3e5a2c;
  --moss: #dfe8c6;
  --clay: #b96b47;
  --white: #ffffff;
  --shadow: 0 18px 50px rgb(41 49 33 / 16%);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: linear-gradient(145deg, #f4f6f3 0%, #e8edf0 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--olive);
  color: var(--white);
  cursor: pointer;
  font-weight: 700;
  padding: 0 16px;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ghost-button {
  border: 1px solid var(--line);
  background: rgb(255 254 250 / 70%);
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
  padding: 14px;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 6px 0 14px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.1rem;
}

.conversation {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0;
}

.message {
  max-width: min(88%, 680px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 254 250 / 82%);
  box-shadow: 0 8px 24px rgb(41 49 33 / 7%);
  padding: 12px 13px;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.message.user {
  align-self: flex-end;
  border-color: transparent;
  background: var(--olive);
  color: var(--white);
}

.message.system {
  align-self: center;
  border-style: dashed;
  background: rgb(223 232 198 / 62%);
  color: #35432d;
  font-size: 0.92rem;
}

.meta {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.message.user .meta {
  color: rgb(255 254 250 / 78%);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 254 250 / 88%);
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 46px;
  max-height: 150px;
  resize: none;
  padding: 12px;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

textarea:focus,
input:focus {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px rgb(185 107 71 / 16%);
}

.token-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(32 35 31 / 46%);
  padding: 18px;
}

.token-panel[hidden] {
  display: none;
}

.token-card {
  width: min(100%, 420px);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
  padding: 18px;
}

.token-card label {
  display: block;
  margin: 18px 0 7px;
  color: var(--muted);
  font-weight: 700;
}

.token-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 520px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .topbar-actions button {
    flex: 1;
    padding: 0 10px;
  }

  h1 {
    font-size: 1.35rem;
  }

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

  .message {
    max-width: 94%;
  }
}
