:root {
  color-scheme: light dark;
  --canvas: #edf1ed;
  --paper: #fffefa;
  --thread: #f5f7f3;
  --ink: #1c3028;
  --muted: #476055;
  --primary: #14503d;
  --primary-active: #0d3c2e;
  --on-primary: #fff;
  --tint: #dfede4;
  --line: #b3c3b9;
  --focus: #a54a06;
  --notice: #f8edcf;
  --notice-text: #553909;
  --error: #fae7e0;
  --error-text: #792719;
  --shadow: 0 .5rem 2rem #143c2a14;
  --overlay: #111c17a6;
  font: 106.25% / 1.55 system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #14221c;
    --paper: #1d2e26;
    --thread: #17271f;
    --ink: #edf5ee;
    --muted: #b8cabd;
    --primary: #a6d9bd;
    --primary-active: #c5ebd4;
    --on-primary: #153324;
    --tint: #294837;
    --line: #647e6d;
    --focus: #ffba77;
    --notice: #3e331b;
    --notice-text: #f5d98c;
    --error: #4a2b25;
    --error-text: #ffccc0;
    --shadow: 0 .5rem 2rem #080e0a55;
    --overlay: #030905c9;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
body.chat-open { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.16; text-wrap: balance; }
p { text-wrap: pretty; }
a, summary { color: var(--primary); text-underline-offset: .22em; }
a:hover { text-decoration-thickness: .13em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
button, input, textarea { font: inherit; }
button { min-height: 2.65rem; padding: .55rem .9rem; border-radius: .65rem; border: 1px solid transparent; font-weight: 700; cursor: pointer; text-wrap: balance; }
button:disabled { opacity: .52; cursor: default; }
.primary { background: var(--primary); color: var(--on-primary); }
.primary:hover:not(:disabled) { background: var(--primary-active); }
.secondary { background: var(--paper); border-color: var(--line); color: var(--primary); }
.secondary:hover:not(:disabled) { background: var(--tint); }
label { display: block; font-weight: 700; margin-bottom: .35rem; }
input, textarea { background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: .65rem; min-width: 0; width: 100%; padding: .58rem .72rem; }
input { min-height: 2.65rem; }
textarea { display: block; min-height: 2.65rem; max-height: 7rem; resize: none; line-height: 1.4; }
textarea::placeholder { color: var(--muted); }
:where(.muted, footer) { color: var(--muted); }
.entry { display: flex; align-items: stretch; gap: .55rem; }
.sr-only, .skip:not(:focus) { position: absolute; block-size: 1px; inline-size: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.skip:focus { position: fixed; z-index: 3; inset: .5rem auto auto .5rem; background: var(--paper); padding: .35rem .55rem; }

.page { max-width: 48rem; margin: 0 auto; padding: clamp(1.25rem, 6vw, 3rem) clamp(1rem, 5vw, 2rem) 3rem; }
.page header { margin-bottom: .8rem; font-weight: 650; }
.page h1 { margin-bottom: 1rem; font: 500 clamp(2.1rem, 7vw, 3.6rem) / 1.05 Georgia, serif; letter-spacing: -.035em; }
.page h2 { font-size: 1.35rem; }
.welcome { max-width: 37rem; }
.welcome > p, .welcome footer { margin-top: 1.1rem; }
.welcome form { margin-top: 1.25rem; max-width: 25rem; }
#code-help { margin-top: .35rem; }
footer { border-top: 1px solid var(--line); padding-top: .8rem; }
footer details { margin-top: .5rem; }
.patient-card { background: var(--paper); border: 1px solid var(--line); padding: .9rem; border-radius: .9rem; }
.patient-card, .patient-identity { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.patient-card h2, .patient-identity h1 { font-size: 1.2rem; margin-bottom: .1rem; }
.patient-card p, .patient-identity p { color: var(--muted); line-height: 1.35; }
.avatar { flex: 0 0 auto; display: grid; place-items: center; inline-size: 2.05rem; block-size: 2.05rem; border-radius: 50%; background: var(--tint); color: var(--primary); font-size: .9rem; font-weight: 800; }
.avatar-large { inline-size: 2.65rem; block-size: 2.65rem; background: var(--primary); color: var(--on-primary); }

.chat {
  position: fixed;
  inset-inline: 0;
  top: var(--visual-top, 0px);
  height: var(--visual-height, 100dvh);
  max-width: 64rem;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--thread);
  box-shadow: var(--shadow);
}
.chat-header { background: var(--paper); border-bottom: 1px solid var(--line); padding: .75rem clamp(.9rem, 4vw, 1.5rem); }
.chat-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .45rem; margin-top: .65rem; }
.counter { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
#question-count { font-weight: 800; }
.conversation { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .85rem clamp(.75rem, 4vw, 1.65rem) 1rem; }
#transcript { display: grid; gap: .85rem; margin: 0; padding: 0; list-style: none; }
.message { display: flex; align-items: flex-end; gap: .48rem; overflow-wrap: anywhere; }
.message-content { min-width: 0; max-width: min(85%, 36rem); }
.message strong { display: block; margin: 0 0 .2rem .15rem; line-height: 1.1; font-weight: 700; color: var(--muted); }
.bubble { padding: .58rem .8rem; border: 1px solid var(--line); border-radius: 1rem 1rem 1rem .28rem; background: var(--paper); white-space: pre-wrap; }
.student-message { justify-content: flex-end; }
.student-message strong { margin: 0 .15rem .2rem 0; text-align: right; }
.student-message .bubble { border-radius: 1rem 1rem .28rem 1rem; background: var(--tint); }
.bubble em { color: var(--muted); margin-right: .18rem; }
#typing { margin-top: .85rem; }
.typing-bubble { display: flex; gap: .28rem; align-items: center; min-height: 2.1rem; }
.typing-bubble span { display: block; inline-size: .37rem; block-size: .37rem; border-radius: 50%; background: var(--muted); }
.typing-bubble span:nth-child(2) { animation-delay: .16s; }
.typing-bubble span:nth-child(3) { animation-delay: .32s; }
.composer {
  padding: .65rem clamp(.75rem, 4vw, 1.65rem) max(.65rem, env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.compose-entry { align-items: flex-end; }
.composer-key { display: none; font-size: .95rem; margin-top: .3rem; }
.notice, .error-panel { padding: .55rem .75rem; border-radius: .65rem; }
.notice { background: var(--notice); color: var(--notice-text); }
.composer .notice { margin-bottom: .45rem; }
.notice-dock { max-width: 37rem; margin-inline: auto; }
#main > .notice-dock { padding-inline: 1rem; }
#main > .notice-dock:has(.error-panel:not([hidden])) { margin-top: -2rem; padding-bottom: 1rem; }
.composer .notice-dock { margin: 0 0 .5rem; max-width: none; }
.composer .notice-dock:has(.error-panel[hidden]) { margin: 0; }
.error-panel { display: flex; align-items: center; justify-content: space-between; gap: .6rem; background: var(--error); color: var(--error-text); }
.error-panel button { flex: 0 0 auto; }

.feedback > section, .feedback > details { margin-top: 1.25rem; }
.overview, .next-step { background: var(--tint); border-radius: .8rem; padding: .85rem 1rem; }
.next-step p { margin-top: .45rem; }
.findings { display: grid; gap: .55rem; padding: 0; margin: .6rem 0 0; list-style: none; }
.findings > li { background: var(--paper); border: 1px solid var(--line); border-radius: .72rem; padding: .68rem .82rem; }
.finding-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: .3rem .65rem; }
.badge { font-size: .95rem; font-weight: 700; border-radius: .32rem; padding: .02rem .37rem; color: var(--primary); background: var(--tint); }
.badge.partly, .badge.missed { color: var(--notice-text); background: var(--notice); }
.findings p, .notes p { margin-top: .35rem; }
blockquote { margin: .52rem 0 .15rem; border-left: 3px solid var(--line); padding: 0 0 0 .65rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.notes { margin: .55rem 0 0; padding-left: 1.3rem; }
.notes li + li { margin-top: .55rem; }
.disclosure { border-block-start: 1px solid var(--line); padding-top: .6rem; }
summary { cursor: pointer; font-weight: 680; }
#review[open] #transcript { margin-top: .65rem; }
.report-actions, .dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
#copy-result { margin-top: .45rem; }
dialog { width: min(90vw, 28rem); padding: 1.25rem; border-radius: 1rem; background: var(--paper); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow); }
dialog::backdrop { background: var(--overlay); }
dialog p { margin-top: .6rem; }
dialog h2 { font-size: 1.45rem; }

@media (max-width: 25rem) {
  .counter-unit { position: absolute; clip-path: inset(50%); }
}
@media (min-width: 45rem) {
  .chat-header { display: flex; align-items: center; justify-content: space-between; gap: 1.25rem; }
  .chat-controls { margin-top: 0; gap: .7rem; }
  .composer-key { display: block; }
}
@media (min-width: 67rem) and (min-height: 40rem) {
  .chat { top: calc(var(--visual-top, 0px) + 1.25rem); height: calc(var(--visual-height, 100dvh) - 2.5rem); border-radius: 1rem; border: 1px solid var(--line); overflow: hidden; }
}
@media (max-height: 30rem) {
  .chat-header { padding-block: .4rem; }
  .chat-controls { margin-top: .4rem; }
  .chat-header .avatar-large { inline-size: 2rem; block-size: 2rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .message.new-message { animation: appear .2s ease-out both; }
  .typing-bubble span { animation: typing 1s infinite alternate ease-in-out; }
  @keyframes appear { from { opacity: 0; transform: translateY(.25rem); } }
  @keyframes typing { from { opacity: .35; } to { opacity: 1; } }
}
@media (forced-colors: active) {
  .badge, .avatar, .primary, .secondary { border: 1px solid ButtonText; }
}
