:root {
  --paper: #fbfaf7;
  --ink: #000;
  --ink-2: #57534b;
  --ink-3: #8d887d;
  --red: #a3141c;
  --gilt: #b08d3c;
  --rule: #e4e0d6;
  --field: #fff;
  --serif-zh: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "Kaiti", var(--serif-zh);
  --serif-en: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17140f;
    --ink: #efe9dc;
    --ink-2: #b9b1a1;
    --ink-3: #807868;
    --red: #e4645a;
    --gilt: #c9a54a;
    --rule: #312b22;
    --field: #201c15;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif-zh);
  line-height: 1.7;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 3.5rem 1rem 4rem;
  border-left: 3px solid var(--gilt);
  min-height: 100vh;
}

@media (min-width: 46rem) {
  main { padding-left: 2.5rem; padding-right: 2.5rem; }
}

header h1 {
  font-family: var(--kai);
  font-weight: 400;
  font-size: 2.25rem;
  line-height: 1.2;
  margin: 0;
  letter-spacing: 0.08em;
}

header p {
  margin: 0.5rem 0 0;
  color: var(--ink-2);
  font-size: 0.95rem;
}

form {
  display: flex;
  gap: 0.5rem;
  margin: 2.25rem 0 0;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-family: var(--kai);
  font-size: 1.25rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule);
  background: var(--field);
  color: var(--ink);
  border-radius: 2px;
}

button {
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 2px;
}

/* same face, size and rules as the input, so the two read as one line; red like the answer */
.primary {
  font-family: var(--kai);
  font-size: 1.25rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--red);
}

.primary:disabled { color: var(--ink-3); cursor: progress; }

.quiet {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-2);
}

.quiet:hover { color: var(--ink); border-color: var(--ink-3); }

:focus-visible { outline: 2px solid var(--gilt); outline-offset: 2px; }

/* the caret is enough to show where you're typing */
input[type="text"]:focus-visible { outline: none; }

/* one line under the input: the loading bar, or a message */
.line {
  min-height: 1.75rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-3);
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.loading[hidden] { display: none; }

.loading .track {
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.loading .fill {
  width: 0;
  height: 2px;
  margin-top: -0.5px;
  background: var(--gilt);
}

.loading .label {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#status { margin: 0; }

/* The answer: the fragment is the red letters, its reference set like a citation. */
#answer { margin-top: 2.75rem; }

#answer[hidden] { display: none; }

.said {
  font-size: clamp(1.6rem, 5.5vw, 2.3rem);
  line-height: 1.45;
  color: var(--red);
  margin: 0;
  text-wrap: balance;
}

.said.en { font-family: var(--serif-en); }

.ref {
  margin: 0.6rem 0 0;
  font-size: 1.05rem;
  color: var(--ink);
}

.context {
  margin: 1.75rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-3);
  font-size: 1rem;
}

.context mark {
  background: none;
  color: var(--red);
}

.context .other {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--serif-en);
  font-size: 0.95rem;
}

.context .other:lang(zh) { font-family: var(--serif-zh); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.more { margin-top: 2.5rem; }

.more h2 {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--ink-3);
  margin: 0 0 0.5rem;
}

.more ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.more li button {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 1.05rem;
  padding: 0.45rem 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  color: var(--ink);
}

.more li button:hover .t { color: var(--red); }

.more li button[aria-current="true"] .t { color: var(--red); }

.more .r {
  color: var(--ink-3);
  font-size: 0.85rem;
  margin-left: 0.5rem;
  white-space: nowrap;
}

.more .en { font-family: var(--serif-en); }

@media (prefers-reduced-motion: no-preference) {
  .said.fresh { animation: ink 420ms ease-out; }
  @keyframes ink {
    from { opacity: 0; filter: blur(2px); }
    to { opacity: 1; filter: none; }
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
