:root {
  color-scheme: light;
  --bg: #f7f0e7;
  --panel: #fffaf3;
  --text: #173f2d;
  --muted: #766d63;
  --line: #e5d6c4;
  --soft: #f2e8dc;
  --user-bubble: #f1e8d8;
  --accent: #86bd9d;
  --accent-strong: #5f9f7a;
  --danger: #b94b4b;
  --avatar-border: #e5d6c4;
  --chat-font-size: 18px;
  --shadow: 0 22px 80px rgba(45, 35, 25, 0.12);
  font-family: ui-serif, Georgia, "Times New Roman", "Songti SC", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100%;
}

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}

.screen-active {
  display: flex;
}

.entry-panel,
.end-panel {
  width: min(760px, calc(100% - 32px));
  margin: auto;
  padding: 34px;
  background: rgba(255, 250, 243, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.condition-panel {
  width: min(900px, calc(100% - 32px));
}

.entry-panel h1 {
  margin-bottom: 28px;
}

.intake-panel {
  width: min(860px, calc(100% - 32px));
  margin-block: 32px;
}

.profile-panel {
  width: min(620px, calc(100% - 32px));
}

.form-intro {
  margin: -10px 0 26px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.75;
}

.end-avatar {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 36px;
  line-height: 1.15;
}

.entry-form {
  display: grid;
  gap: 20px;
}

.condition-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.condition-card {
  display: grid;
  gap: 8px;
  align-content: center;
  min-height: 132px;
  padding: 22px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.condition-card:hover,
.condition-card:focus-visible {
  border-color: var(--accent-strong);
  box-shadow: 0 10px 32px rgba(45, 35, 25, 0.1);
  transform: translateY(-2px);
  outline: none;
}

.condition-card span {
  font-size: 26px;
  line-height: 1;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

.field input,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #2d271f;
  outline: none;
}

.field textarea {
  min-height: 104px;
  resize: vertical;
  line-height: 1.6;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(134, 189, 157, 0.24);
}

.field textarea[aria-invalid="true"] {
  border-color: #8b8176;
  box-shadow: 0 0 0 3px rgba(139, 129, 118, 0.14);
}

.field-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.4;
}

.choice-field {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 26px;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

.choice-field legend {
  width: 100%;
  margin-bottom: 10px;
}

.choice-error {
  flex-basis: 100%;
}

.choice-field label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: #2d271f;
}

.choice-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-strong);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.split-actions {
  justify-content: space-between;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 46px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
}

.primary-button {
  padding: 0 22px;
  background: var(--text);
  color: #fffaf3;
}

.secondary-button {
  padding: 0 22px;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.ghost-button {
  padding: 0 16px;
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.form-error,
.chat-error {
  min-height: 20px;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.form-error {
  color: var(--danger);
}

.chat-error {
  color: #5f5a52;
}

.chat-screen.screen-active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100vh;
  min-height: 100dvh;
  width: min(1220px, 100%);
  margin: 0 auto;
  background: var(--bg);
  padding: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 14px clamp(18px, 4vw, 42px) 0;
}

.turn-counter {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1;
}

.turn-counter strong {
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.chat-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 0;
  overflow-y: auto;
  padding: 26px clamp(18px, 5vw, 58px) 24px;
}

.message {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 16px;
  max-width: 1040px;
}

.message.user {
  grid-template-columns: minmax(0, auto);
  align-self: end;
  width: min(780px, calc(100% - 66px));
  justify-content: end;
}

.message-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--avatar-border);
  background: #fff;
}

.message.user .bubble {
  grid-row: 1;
}

.bubble {
  align-self: start;
  color: var(--text);
  font-size: var(--chat-font-size);
  line-height: 1.6;
  font-weight: 600;
  white-space: pre-wrap;
}

.message.user .bubble {
  padding: 14px 18px;
  background: var(--user-bubble);
  border: 0;
  border-radius: 28px;
  color: var(--text);
  font-family: ui-serif, Georgia, "Times New Roman", "Songti SC", serif;
  font-size: var(--chat-font-size);
  line-height: 1.6;
  font-weight: 600;
}

.message-actions {
  grid-column: 2;
  height: 28px;
  color: #786f65;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.composer-wrap {
  padding: 0 clamp(18px, 5vw, 58px) 14px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 56px;
  align-items: end;
  gap: 12px;
  width: 100%;
  min-height: 86px;
  padding: 12px 12px 12px 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 28px;
}

.composer textarea {
  width: 100%;
  max-height: 160px;
  min-height: 58px;
  resize: none;
  border: 0;
  outline: none;
  color: #2d271f;
  background: transparent;
  font-size: 17px;
  line-height: 1.45;
  font-weight: 500;
}

.composer textarea::placeholder {
  color: #b9ad9e;
}

.send-button {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.send-button svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.disclaimer {
  margin: 14px 0 0;
  text-align: center;
  color: #6f665d;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 27, 22, 0.32);
}

.modal-backdrop[hidden] {
  display: none;
}

.completion-modal {
  width: min(440px, 100%);
  padding: 30px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.completion-modal h2 {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 30px;
  line-height: 1.2;
}

.completion-modal p {
  margin: 0 0 22px;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

.end-panel {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 12px;
}

.end-panel p {
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
}

@media (max-width: 700px) {
  .screen {
    padding: 10px;
  }

  .entry-panel,
  .end-panel {
    width: min(100%, 560px);
    padding: 24px 18px;
  }

  .intake-panel {
    margin-block: 10px;
  }

  h1 {
    font-size: 28px;
  }

  .condition-options {
    grid-template-columns: 1fr;
  }

  .condition-card {
    min-height: 92px;
    padding: 18px;
  }

  .form-intro {
    font-size: 14px;
  }

  .form-actions .primary-button,
  .form-actions .secondary-button {
    min-width: 110px;
  }

  .chat-header {
    gap: 12px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .turn-counter {
    gap: 6px;
    font-size: 13px;
  }

  .turn-counter strong {
    font-size: 15px;
  }

  .ghost-button {
    min-height: 40px;
    padding: 0 12px;
    font-size: 14px;
  }

  .chat-body {
    gap: 22px;
    padding: 22px 14px 18px;
  }

  .message {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 12px;
    width: 100%;
  }

  .message.user {
    grid-template-columns: minmax(0, auto);
    width: min(100%, calc(100% - 46px));
  }

  .message-avatar {
    width: 42px;
    height: 42px;
  }

  .composer {
    grid-template-columns: 1fr 48px;
    min-height: 72px;
    padding: 10px 10px 10px 16px;
    border-radius: 24px;
  }

  .composer textarea {
    min-height: 46px;
    font-size: 16px;
  }

  .send-button {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 420px) {
  .entry-panel,
  .end-panel,
  .completion-modal {
    padding: 20px 14px;
  }

  .condition-card span {
    font-size: 28px;
  }

  .message {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
  }

  .message-avatar {
    width: 38px;
    height: 38px;
  }

  .bubble {
    font-size: 16px;
    line-height: 1.55;
  }

  .message.user {
    width: min(100%, calc(100% - 38px));
  }

  .message.user .bubble {
    border-radius: 22px;
  }

  .composer-wrap {
    padding: 0 10px 10px;
  }

  .disclaimer {
    font-size: 13px;
  }
}
