/* The iPhone app uses the same colours: keep Palette in ios/VisitInterpreter/Views.swift in step. */
:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #5e5e58;
  --line: #dcdad2;
  --accent: #0f6b5c;
  --accent-text: #ffffff;
  --doctor: #1f4f8f;
  --doctor-soft: #e5edf8;
  --mark: #ffe99e;
  --mark-text: #3a2c00;
  --paused-soft: #fff0c4;
  --paused-text: #5c4400;
  /* Red is only for number warnings and failures, so End uses --ink instead. */
  --error: #a32a1e;
  --error-soft: #fbe7e3;
  --warning-fill: #b3261e;
  --warning-text: #ffffff;
  --ink: #1c1c1a;
  --ink-text: #ffffff;

  --font-small: 18px;
  --font-body: 20px;
  --font-heading: 23px;
  --font-translation: 28px;
  --font-title: 34px;
  --font-large: 42px;

  --gutter: 16px;
  --radius: 16px;
  --radius-small: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161614;
    --surface: #22221f;
    --text: #f1f0ea;
    --muted: #b1b0a8;
    --line: #3b3a35;
    --accent: #2f9e8a;
    --accent-text: #08201b;
    --doctor: #8fbbf2;
    --doctor-soft: #1b2a3e;
    --mark: #6a5410;
    --mark-text: #ffeeb8;
    --paused-soft: #47380b;
    --paused-text: #ffe39a;
    --error: #ff9c8f;
    --error-soft: #47201b;
    --warning-fill: #c8352a;
    --ink: #f1f0ea;
    --ink-text: #161614;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: var(--font-body)/1.5 -apple-system, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

.screen {
  max-width: 640px;
  min-height: 100dvh;
  margin: 0 auto;
}

.padded {
  padding: calc(var(--gutter) + env(safe-area-inset-top)) var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom));
}

h1 { font-size: var(--font-title); line-height: 1.2; margin: 12px 0 18px; }
h2 { font-size: var(--font-heading); margin: 32px 0 10px; }
h3 { font-size: var(--font-heading); line-height: 1.3; margin: 0 0 6px; }

.muted { color: var(--muted); font-size: var(--font-small); margin: 4px 0; }

.group {
  padding: 4px var(--gutter);
  border-radius: var(--radius);
  background: var(--surface);
}

label { display: block; margin: 14px 0 6px; color: var(--muted); font-size: var(--font-small); }

input, textarea {
  display: block;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
.fields textarea { margin-bottom: 14px; }

button {
  width: 100%;
  min-height: 64px;
  margin-top: 14px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  touch-action: manipulation;
  transition: transform 0.1s ease-out;
}
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.4; }
.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.mode { position: relative; margin: 0; }
.mode input { position: absolute; inset: 0; margin: 0; opacity: 0; }
.mode span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font-size: var(--font-small);
  font-weight: 600;
  text-align: center;
}
.mode input:checked + span { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.mode input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.stop { background: var(--ink); border-color: var(--ink); color: var(--ink-text); }

button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button.quiet {
  width: auto;
  min-height: 48px;
  margin: 0;
  padding: 6px 16px;
  border-radius: var(--radius-small);
  background: transparent;
  font-size: var(--font-small);
}

button svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }

button.start {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 168px;
  margin: 0 0 16px;
  font-size: var(--font-title);
}
button.start svg { width: 52px; height: 52px; stroke-width: 2; }

#history { border-radius: var(--radius); background: var(--surface); }
#history:empty { display: none; }

button.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  align-items: center;
  min-height: 76px;
  margin: 0;
  padding: 12px var(--gutter);
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-weight: 400;
}
button.history-item + button.history-item { border-top: 1px solid var(--line); }
button.history-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
button.history-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.history-item::after {
  content: "";
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 11px;
  height: 11px;
  border-top: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  transform: rotate(45deg);
}
.history-date { color: var(--muted); font-size: var(--font-small); }
.history-reason { grid-column: 1; overflow-wrap: anywhere; font-weight: 600; }

#visit { display: flex; flex-direction: column; height: 100dvh; min-height: 0; }

.visit-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.visit-bar:has(#status.error) { background: var(--error-soft); }
#visit[data-phase^="paus"] .visit-bar:not(:has(#status.error)) { background: var(--paused-soft); }

#status { flex: 1; min-height: 32px; margin: 0; font-size: var(--font-body); font-weight: 700; }
#status.error { color: var(--error); }
#visit[data-phase^="paus"] #status:not(.error) { color: var(--paused-text); }

/* The dot reports the real state, in the same words as the status text beside it. */
#status::before {
  content: "";
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--muted);
}
#visit[data-phase="listening"] #status::before { background: var(--accent); }
#visit[data-phase^="paus"] #status::before { background: var(--paused-text); }
#status.error::before { background: var(--error); }
#status:empty::before { display: none; }

#sound { flex: none; }
#sound[aria-pressed="false"] { color: var(--muted); }
.meter { flex: none; width: 96px; height: 10px; overflow: hidden; border-radius: 5px; background: var(--line); }
#visit:not([data-phase="listening"]) .meter { display: none; }
#level { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; }

/* The note scrolls with the conversation, so it gives its room back to the translations. */
.visit-scroll {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 12px var(--gutter);
  overflow-y: auto;
  overscroll-behavior: contain;
}


.empty {
  margin: auto 0;
  padding: 24px var(--gutter);
  text-align: center;
  color: var(--muted);
  font-size: var(--font-heading);
  line-height: 1.45;
}

#turns { display: flex; flex-direction: column; gap: 12px; }
#turns:empty { display: none; }

.turn {
  padding: 12px var(--gutter) 14px;
  border-radius: var(--radius);
  background: var(--surface);
  overflow-wrap: anywhere;
  scroll-margin-bottom: 12px;
}
.turn.doctor { background: var(--doctor-soft); }
.turn p { margin: 0; }
.who { color: var(--muted); font-size: var(--font-small); font-weight: 700; }
.turn.doctor .who { color: var(--doctor); }
.source { margin-top: 2px !important; color: var(--muted); font-size: var(--font-small); line-height: 1.4; }
.translation { margin-top: 6px !important; font-size: var(--font-translation); line-height: 1.38; font-weight: 700; }
.source:empty, .translation:empty { display: none; }

.number-warning {
  margin-top: 12px;
  padding: 12px 14px 14px;
  border-radius: var(--radius-small);
  background: var(--warning-fill);
  color: var(--warning-text);
  font-size: var(--font-small);
  font-weight: 600;
  line-height: 1.35;
}
.warning-title { display: block; font-size: var(--font-body); font-weight: 700; text-wrap: balance; }
.warning-values { display: flex; flex-wrap: wrap; gap: 2px 20px; margin-top: 8px; }
.warning-value { flex: 1 1 max-content; font-size: var(--font-heading); font-weight: 700; }

.turn-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.turn-actions:not(:has(button:not([hidden]))) { display: none; }
.turn.doctor .turn-actions button { border-color: var(--doctor); color: var(--doctor); }

strong { white-space: nowrap; padding: 0 4px; border-radius: 5px; background: var(--mark); color: var(--mark-text); font-weight: 700; }

.control-bar {
  display: grid;
  flex: none;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.control-bar button { min-height: 80px; margin: 0; padding: 12px 6px; font-size: var(--font-heading); white-space: nowrap; }
#visit[data-phase="paused"] #pause { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

button.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: -8px;
  padding: 6px 12px 6px 4px;
  border: 0;
  color: var(--accent);
  font-size: var(--font-body);
}
button.back svg { width: 26px; height: 26px; stroke-width: 2.4; }

#summary-state { margin: 14px 0 0; font-weight: 600; }
#summary-state:empty { display: none; }
/* Both buttons stay hidden only while the summary is being written. */
#result:has(#retry-summary[hidden]):has(#share[hidden]) #summary-state:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 10px;
  vertical-align: -3px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.summary-reason { margin: 16px 0 0; font-size: var(--font-translation); line-height: 1.35; font-weight: 700; }

.summary-section {
  margin-top: 12px;
  padding: 14px var(--gutter);
  border-radius: var(--radius);
  background: var(--surface);
}
.summary-section.urgent { background: var(--error-soft); }
.summary-section.urgent h3 { color: var(--error); }
.summary-section ul { margin: 0; padding-left: 22px; }
.summary-section li { margin: 6px 0; overflow-wrap: anywhere; }

details { margin-top: 12px; padding: 0 var(--gutter); }
summary { display: flex; align-items: center; min-height: 64px; font-weight: 600; }
#dialogue { margin: 0; padding: 0 0 8px; list-style: none; }
#dialogue li { padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
#dialogue p { margin: 0; }
.dialogue-translation { color: var(--muted); }

#delete-visit { display: block; margin: 16px auto 0; border: 0; color: var(--error); }

#large {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: calc(24px + env(safe-area-inset-top)) var(--gutter) calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--surface);
}
#large-text { width: 100%; margin: auto 0; font-size: var(--font-large); line-height: 1.3; font-weight: 700; overflow-wrap: anywhere; }
#large.flipped { transform: rotate(180deg); }

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  button:active:not(:disabled) { transform: none; }
  #result:has(#retry-summary[hidden]):has(#share[hidden]) #summary-state:not(:empty)::before { animation: none; }
}
