/* ================= 译笔生花 — ink & paper (画·书) ================= */

:root {
  --paper: #f4eddc;
  --card: #fbf6ea;
  --ink: #26231c;
  --ink-soft: #57534a;
  --ink-faint: #8b8578;
  --line: rgba(38, 35, 28, 0.22);
  --line-soft: rgba(38, 35, 28, 0.12);
  --red: #a8332a;
  --red-deep: #8c2721;
  --red-tint: rgba(168, 51, 42, 0.08);
  --serif-zh: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", var(--serif-zh);
  --serif-en: "EB Garamond", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* the hidden attribute must beat any display: flex/grid on the same element */
[hidden] { display: none !important; }

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

body {
  font-family: var(--serif-zh);
  color: var(--ink);
  background-color: var(--paper);
  /* mottled rice-paper: soft tonal clouds + fine grain */
  background-image:
    radial-gradient(1200px 600px at 15% -5%, rgba(255, 252, 240, 0.9), transparent 60%),
    radial-gradient(900px 500px at 90% 15%, rgba(214, 201, 170, 0.35), transparent 65%),
    radial-gradient(700px 700px at 40% 110%, rgba(214, 201, 170, 0.3), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.2 0 0 0 0 0.18 0 0 0 0 0.12 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  min-height: 100vh;
}

.scroll {
  width: 100%;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 40px) clamp(16px, 3vw, 48px) 40px;
}

/* left: source sheet · right: both translations, separated by a vertical ink stroke */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr);
  gap: clamp(16px, 2vw, 36px);
  align-items: stretch;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(24px, 4vw, 40px);
}

.brand { display: flex; align-items: center; gap: 18px; }

.seal {
  flex: none;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  background: var(--red);
  color: var(--card);
  font-family: var(--kai);
  font-size: 40px;
  line-height: 1;
  border-radius: 14% 9% 15% 10%;
  box-shadow:
    inset 0 0 0 2.5px rgba(251, 246, 234, 0.4),
    inset 0 0 14px rgba(60, 8, 5, 0.35),
    2px 3px 8px rgba(38, 35, 28, 0.25);
  transform: rotate(-3deg);
}

.brand-text h1 {
  font-family: "Ma Shan Zheng", var(--kai);
  font-weight: 400;
  font-size: clamp(2rem, 5vw, 2.9rem);
  letter-spacing: 0.08em;
  line-height: 1.1;
}

.tagline {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}

.motto {
  writing-mode: vertical-rl;
  font-family: var(--kai);
  font-size: 1.05rem;
  letter-spacing: 0.5em;
  color: var(--ink-faint);
  border-right: 1px solid var(--line-soft);
  padding-right: 10px;
  align-self: stretch;
}

/* ---------- paper cards ---------- */

.paper {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    2px 4px 14px rgba(38, 35, 28, 0.08);
  padding: clamp(16px, 3vw, 26px);
  position: relative;
}

/* red seal-corner on every sheet */
.paper::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  background: var(--red);
  opacity: 0.55;
  border-radius: 20% 35% 25% 40%;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title {
  font-family: var(--kai);
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: 0.1em;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.card-title .en {
  font-family: var(--serif-en);
  font-weight: 400;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
  align-self: center;
  margin-right: 2px;
}

.result[data-engine="deepseek"] .dot { background: var(--red); }

.count {
  font-family: var(--serif-en);
  font-size: 0.82rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* ---------- input ---------- */

.input-card { display: flex; flex-direction: column; }

.input-card textarea { flex: 1; }

textarea {
  width: 100%;
  border: none;
  background:
    repeating-linear-gradient(transparent, transparent 2.05em, var(--line-soft) 2.05em, var(--line-soft) calc(2.05em + 1px));
  color: var(--ink);
  font-family: var(--kai);
  font-size: 1.18rem;
  line-height: 2.05em;
  resize: vertical;
  min-height: 11em;
  outline: none;
}

textarea::placeholder { color: var(--ink-faint); opacity: 0.75; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  font-family: var(--serif-zh);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip i {
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin-left: 2px;
}

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

.chip.active {
  border-color: var(--red);
  color: var(--red-deep);
  background: var(--red-tint);
}
.chip.active i { color: var(--red); }

.actions { display: flex; align-items: center; gap: 10px; }

.ghost-btn {
  font-family: var(--serif-zh);
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 4px 2px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.ghost-btn:hover { color: var(--red-deep); border-bottom-color: var(--red-deep); }

.ghost-btn i {
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 0.8rem;
}

.seal-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--red);
  color: #fbf6ea;
  border: none;
  border-radius: 4px;
  padding: 10px 18px 10px 12px;
  font-family: var(--serif-zh);
  font-size: 1rem;
  letter-spacing: 0.14em;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1.5px rgba(251, 246, 234, 0.35),
    inset 0 -8px 16px rgba(60, 8, 5, 0.25),
    1px 2px 6px rgba(38, 35, 28, 0.3);
  transition: transform 0.12s ease, background 0.15s ease;
}

.seal-btn:hover { background: var(--red-deep); }
.seal-btn:active { transform: translateY(1px) scale(0.99); }
.seal-btn:disabled { opacity: 0.55; cursor: wait; transform: none; }

.seal-btn-glyph {
  font-family: var(--kai);
  font-size: 1.25rem;
  line-height: 1;
  border: 1px solid rgba(251, 246, 234, 0.55);
  border-radius: 3px;
  padding: 3px 5px;
}

.hint {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}

/* ---------- input tools & pinyin IME ---------- */

.input-tools { display: flex; align-items: center; gap: 12px; }

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 9px 3px 4px;
  cursor: pointer;
  font-family: var(--serif-zh);
  font-size: 0.82rem;
  color: var(--ink-soft);
  letter-spacing: 0.05em;
  transition: all 0.15s ease;
}

.tool-chip .glyph {
  font-family: var(--kai);
  font-size: 0.95rem;
  line-height: 1;
  padding: 3px 4px;
  border-radius: 3px;
  border: 1px solid var(--line);
  transition: all 0.15s ease;
}

.tool-chip i { font-style: normal; }

.tool-chip:hover { border-color: var(--ink); color: var(--ink); }

.tool-chip:disabled { opacity: 0.6; cursor: wait; }

.tool-chip.active {
  border-color: var(--red);
  color: var(--red-deep);
  background: var(--red-tint);
}

.tool-chip.active .glyph {
  background: var(--red);
  border-color: var(--red);
  color: #fbf6ea;
}

.tool-chip.listening {
  border-color: var(--red);
  background: var(--red);
  color: #fbf6ea;
  animation: pulse 1.2s ease-in-out infinite;
}

.tool-chip.listening .glyph { border-color: rgba(251, 246, 234, 0.6); background: transparent; color: #fbf6ea; }

@keyframes pulse { 50% { opacity: 0.65; } }

.ime-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 7px 12px;
  background: rgba(168, 51, 42, 0.04);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  border-radius: 3px;
}

.ime-pinyin {
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 1rem;
  color: var(--red-deep);
  letter-spacing: 0.06em;
  border-bottom: 1px dashed var(--red);
  white-space: nowrap;
}

.ime-cands {
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 2px 4px;
  flex-wrap: wrap;
}

.ime-cands li {
  cursor: pointer;
  font-family: var(--serif-zh);
  font-size: 1.12rem;
  padding: 1px 7px;
  border-radius: 3px;
  transition: background 0.12s ease;
}

.ime-cands li i {
  font-style: normal;
  font-family: var(--serif-en);
  font-size: 0.75rem;
  color: var(--ink-faint);
  margin-right: 3px;
}

.ime-cands li:hover { background: var(--red-tint); }

.ime-cands li.first { color: var(--red-deep); }

.ime-nav { display: flex; gap: 2px; margin-left: auto; }

.ime-nav button {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 4px 6px;
}

.ime-nav button:hover:not(:disabled) { color: var(--red-deep); }
.ime-nav button:disabled { opacity: 0.3; cursor: default; }

/* ---------- ink divider (vertical, between the columns) ---------- */

.ink-divider-v { align-self: stretch; }

.ink-divider-v svg { display: block; width: 18px; height: 100%; min-height: 240px; }

.ink-divider-v path { fill: var(--ink); opacity: 0.75; }

/* ---------- results ---------- */

.results {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2vw, 24px);
}

.results .result { flex: 1; display: flex; flex-direction: column; }

.results .output { flex: 1; }

.output {
  font-family: var(--serif-en);
  font-size: 1.12rem;
  line-height: 1.75;
  min-height: 6.5em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.output .placeholder {
  color: var(--ink-faint);
  font-family: var(--kai);
  font-size: 1rem;
  letter-spacing: 0.08em;
}

.output.streaming::after {
  content: "▍";
  color: var(--red);
  animation: blink 0.9s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.output.error {
  color: var(--red-deep);
  font-family: var(--serif-zh);
  font-size: 0.95rem;
}

.model-note { font-style: normal; }

/* ---------- history ---------- */

.history { margin-top: clamp(26px, 4vw, 40px); }

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 6px;
  margin-bottom: 10px;
}

.history-head h3 {
  font-family: var(--kai);
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 1.02rem;
}

.history-head .en {
  font-family: var(--serif-en);
  font-style: italic;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--ink-faint);
  margin-left: 6px;
}

#historyList { list-style: none; }

#historyList li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 7px 4px;
  border-bottom: 1px dashed var(--line-soft);
  cursor: pointer;
  transition: background 0.15s ease;
}

#historyList li:hover { background: var(--red-tint); }

#historyList .snippet {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

#historyList .when {
  font-family: var(--serif-en);
  font-size: 0.78rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* ---------- footer ---------- */

footer {
  margin-top: clamp(30px, 5vw, 48px);
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

/* ---------- responsive ---------- */

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .ink-divider-v { display: none; }
  .motto { display: none; }
}

@media (max-width: 600px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .actions { justify-content: flex-end; }
}
