:root {
  --bg: #f5eee8;
  --surface: #fffaf4;
  --surface-soft: #fff0df;
  --text: #241b18;
  --muted: #74655c;
  --line: #decabc;
  --accent: #b4512f;
  --accent-deep: #7f3425;
  --focus: #2f7468;
  --green-soft: #eef6f1;
  --error: #9c2525;
  --shadow: 0 16px 38px rgba(60, 35, 24, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 250, 244, 0.82), transparent 36%),
    linear-gradient(115deg, rgba(238, 246, 241, 0.6), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

.app {
  width: min(100%, 860px);
  height: 100dvh;
  margin: 0 auto;
  padding: 8px 10px 10px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  gap: 6px;
  padding: 6px 8px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(105deg, var(--surface) 0%, #fff2e6 58%, var(--green-soft) 100%);
  box-shadow: 0 8px 24px rgba(60, 35, 24, 0.08);
}

.title-row {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.title-row h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1.42rem;
  font-weight: 650;
  line-height: 1;
  color: #5a2418;
}

.chat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.access {
  padding: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

label {
  color: #6f5d53;
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.access-code,
.prompt {
  width: 100%;
  border: 1px solid #cbb5a5;
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.94);
  font-size: 1rem;
  line-height: 1.35;
}

.access-code {
  min-height: 36px;
  padding: 0 10px;
}

.access-code:focus,
.prompt:focus {
  border-color: var(--focus);
  outline: 3px solid rgba(47, 116, 104, 0.18);
}

.error {
  grid-column: 2;
  margin: -3px 0 0;
  color: var(--error);
  font-weight: 700;
  font-size: 0.94rem;
}

.error:empty {
  display: none;
}

.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.chat[hidden] {
  display: none;
}

.clear {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(180, 81, 47, 0.28);
  border-radius: 8px;
  color: #74331f;
  background: rgba(255, 244, 235, 0.86);
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
}

.clear:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(255, 242, 230, 0.72), rgba(255, 250, 244, 0.92) 34%),
    var(--surface);
}

.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.message {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface-soft);
  border: 1px solid rgba(180, 81, 47, 0.18);
}

.message.error-message {
  align-self: stretch;
  max-width: 100%;
  color: var(--error);
  background: #fff1f1;
  border: 1px solid #efb4b4;
}

.composer {
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: #fff5ec;
}

.prompt {
  min-height: 48px;
  max-height: 144px;
  padding: 12px 14px;
  resize: none;
}

.send {
  min-height: 48px;
  min-width: 88px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(180, 81, 47, 0.2);
}

.send:disabled {
  background: #87938f;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (min-width: 720px) {
  .app {
    padding: 12px 18px 18px;
  }

  .topbar {
    grid-template-columns: auto minmax(320px, 520px);
    align-items: center;
    gap: 16px;
  }

  .title-row h1 {
    font-size: 1.58rem;
  }

  .messages {
    min-height: 52dvh;
  }
}

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

  .access {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
  }

  .error {
    grid-column: 2;
  }

  .title-row h1 {
    font-size: 1.34rem;
  }

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

  .send {
    width: 100%;
  }
}
