:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --ink: #1c1b1a;
  --ink-2: #5c5955;
  --ink-3: #8e8a85;
  --rule: #e6e2dc;
  --bubble: #efece7;
  --accent: #8b2232;
  --accent-ink: #ffffff;
  --accent-soft: rgba(139, 34, 50, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, "Times New Roman", serif;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1d1c1b;
    --ink: #f2efea;
    --ink-2: #b5b0a9;
    --ink-3: #8a857f;
    --rule: #33302d;
    --bubble: #2a2826;
    --accent: #e3848f;
    --accent-ink: #1a0b0e;
    --accent-soft: rgba(227, 132, 143, 0.12);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 680px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 16px calc(180px + env(safe-area-inset-bottom));
}

.masthead { margin: 8px 0 22px; }
.masthead h1 {
  margin: 0;
  font: 600 28px/1.15 var(--serif);
  letter-spacing: -0.01em;
}
.masthead .sub { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }
.byline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  color: var(--ink-2);
  font-size: 13px;
  letter-spacing: 0.01em;
}
.byline img { display: block; width: 28px; height: 28px; border-radius: 6px; }

.frame {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
}
.frame p { margin: 0 0 12px; }
.frame p:last-child { margin-bottom: 0; }
.frame .kicker { font-style: italic; color: var(--accent); }
.frame.closing { margin-top: 28px; }

.note { margin: 14px 4px 0; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
.note a { color: var(--accent); text-decoration: none; }
.note a:hover, .note a:focus-visible { text-decoration: underline; }
.privacy { margin: 10px 4px 0; color: var(--ink-3); font-size: 13px; }

.begin { margin: 22px 0 6px; display: flex; justify-content: center; }

.thread { margin-top: 26px; display: flex; flex-direction: column; gap: 18px; }

.msg { max-width: 100%; }
.msg.clerk {
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 1.58;
  padding-left: 14px;
  border-left: 2px solid var(--accent);
}
.msg.clerk.system { border-left-color: var(--rule); color: var(--ink-2); }
.msg.clerk p { margin: 0 0 10px; }
.msg.clerk p:last-child { margin-bottom: 0; }
.msg.clerk blockquote {
  margin: 8px 0 10px;
  padding: 0 0 0 12px;
  border-left: 2px solid var(--rule);
  color: var(--ink-2);
}
.msg.clerk a { color: var(--accent); }
.msg .who {
  display: block;
  font: 600 11px/1 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 6px;
}
.msg.justice {
  align-self: flex-end;
  max-width: 88%;
  background: var(--bubble);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.justice.final {
  border: 1px solid var(--accent);
  background: var(--accent-soft);
}
.msg.justice .who { color: var(--ink-3); }

.working {
  display: flex; align-items: center; gap: 5px;
  margin: 18px 0 0 16px; color: var(--ink-3); font-size: 14px;
}
.working .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3);
  animation: pulse 1.2s infinite ease-in-out;
}
.working .dot:nth-child(2) { animation-delay: 0.15s; }
.working .dot:nth-child(3) { animation-delay: 0.3s; }
.working-label { margin-left: 6px; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .working .dot { animation: none; opacity: 0.6; } }

.notice { margin: 16px 0 0; color: var(--ink-2); font-size: 15px; text-align: center; }
.notice a { color: var(--accent); }

.choices { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.choices button { flex: 1 1 auto; }
.choices.sendup .msg { flex: 1 0 100%; margin-bottom: 4px; }
@media (max-width: 480px) {
  #background-choices { flex-direction: column; }
  #background-choices button { width: 100%; }
}

button {
  font: 500 16px/1 var(--sans);
  border-radius: 999px;
  padding: 12px 18px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
button:hover { border-color: var(--ink-3); }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { opacity: 0.92; }
button.outline { border-color: var(--accent); color: var(--accent); background: transparent; }
button.quiet { background: transparent; border-color: transparent; color: var(--ink-2); padding-left: 8px; padding-right: 8px; }
button.quiet:hover { color: var(--ink); }

.composer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--rule);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.composer > * { max-width: 680px; margin-left: auto; margin-right: auto; }
.composer textarea {
  display: block;
  width: 100%;
  resize: none;
  font: 17px/1.45 var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 10px 12px;
  max-height: 40vh;
}
.composer.remedy textarea { min-height: 9.5em; border-color: var(--accent); }
.remedy-label { display: block; margin-bottom: 8px; font-size: 14px; color: var(--ink-2); }
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.side-actions, .remedy-actions { display: flex; gap: 6px; flex: 1; }
.send { flex: 0 0 auto; }

.scorecard { margin-top: 28px; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  font-family: var(--serif);
}
.card h2 { margin: 0 0 8px; font: 600 19px/1.25 var(--serif); }
.card h3 {
  margin: 16px 0 6px;
  font: 600 12px/1.2 var(--sans);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.card p { margin: 0 0 10px; }
.card p:last-child { margin-bottom: 0; }
.card.unwritten { border-color: var(--accent); }
.card.unwritten .verdict { font-style: italic; color: var(--accent); }
.break { padding: 10px 0; border-top: 1px solid var(--rule); }
.break:first-of-type { border-top: 0; padding-top: 2px; }
.break .label { font-weight: 600; }
.break .auth { color: var(--ink-2); font-size: 15.5px; }
.inheritor { margin-bottom: 10px; }
.inheritor .label { font: 600 14px/1.3 var(--sans); color: var(--ink-2); display: block; margin-bottom: 2px; }
.dissent { font-size: 16.5px; }

[hidden] { display: none !important; }
