:root {
  --paper: #f6f1e6;
  --paper-soft: #fbf7ee;
  --card: #fffdf8;
  --ink: #23262a;
  --ink-soft: #4c5250;
  --muted: #7d8079;
  --line: #e4dbc9;
  --line-strong: #d4c7ae;
  --accent: #ac4429;
  --accent-soft: #f4e2d9;
  --accent-ink: #8c3520;
  --jade: #2e6a5c;
  --shadow: 0 18px 44px rgba(72, 56, 34, 0.08);
  --radius: 18px;
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1100px 600px at 12% -8%, #fdf8ec 0%, rgba(253, 248, 236, 0) 60%),
    radial-gradient(900px 500px at 92% 4%, #f7eade 0%, rgba(247, 234, 222, 0) 62%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image:
    repeating-linear-gradient(0deg, rgba(120, 96, 61, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(120, 96, 61, 0.025) 0 1px, transparent 1px 4px);
  mix-blend-mode: multiply;
}

.site-header,
.layout,
.site-footer {
  position: relative;
  z-index: 1;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 28px 10px;
}

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

.seal {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff8ee;
  font-family: var(--serif);
  font-size: 24px;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28), 0 8px 20px rgba(172, 68, 41, 0.24);
  transform: rotate(-3deg);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 3px;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.6px;
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 46vw;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.8);
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--jade);
  box-shadow: 0 0 0 3px rgba(46, 106, 92, 0.12);
  flex: none;
}

.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 28px 40px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 24px 22px 20px;
  position: sticky;
  top: 18px;
}

form .field {
  margin-bottom: 18px;
  border: 0;
  padding: 0;
}

fieldset.field legend,
label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-bottom: 8px;
  padding: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
}

.hint-inline {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.count {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

input[type="text"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fffefb;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: #b3ab9a;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(172, 68, 41, 0.1);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.seg {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-soft);
}

.seg-sm {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn {
  padding: 8px 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.seg-btn:hover {
  background: rgba(172, 68, 41, 0.06);
}

.seg-btn.is-active {
  background: var(--accent);
  color: #fff8ee;
  box-shadow: 0 4px 12px rgba(172, 68, 41, 0.2);
}

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

.chip {
  padding: 6px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fffefb;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.16s ease;
}

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

.chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}

[hidden],
.is-hidden {
  display: none !important;
}

.submit {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #b74a2d, #9a3a22);
  color: #fff8ee;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(154, 58, 34, 0.24);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(154, 58, 34, 0.28);
}

.submit:disabled {
  cursor: progress;
  filter: saturate(0.7) brightness(1.02);
  transform: none;
  box-shadow: 0 8px 18px rgba(154, 58, 34, 0.18);
}

.submit-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 248, 238, 0.45);
  border-top-color: #fff8ee;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.submit.is-loading .submit-spinner {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.form-tip {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
  text-align: center;
}

.result-panel {
  padding: 24px 26px 22px;
  min-height: 620px;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--line);
}

.result-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 2px;
}

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

.result-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.ghost-btn {
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ghost-btn:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 16px;
  color: var(--ink-soft);
  font-size: 12.5px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-line.is-done .status-dot {
  background: var(--jade);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.85); }
}

.alert {
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid #e7c3b6;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: #fdf1ec;
  color: var(--accent-ink);
  font-size: 13px;
}

.stream-box {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(250, 246, 236, 0.85);
  max-height: 190px;
  overflow: auto;
}

.stream-label {
  position: sticky;
  top: 0;
  padding-bottom: 6px;
  background: linear-gradient(180deg, rgba(250, 246, 236, 0.98) 70%, rgba(250, 246, 236, 0));
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
}

.stream-text {
  margin: 0;
  color: #5c5f57;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px 20px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(120% 90% at 100% 0%, #fbf3e4 0%, rgba(251, 243, 228, 0) 55%),
    #fffdf8;
  animation: rise 0.5s cubic-bezier(0.22, 0.72, 0.24, 1) both;
  overflow: hidden;
}

.card::after {
  content: "";
  position: absolute;
  right: -28px;
  bottom: -34px;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 1px solid rgba(172, 68, 41, 0.12);
  background: rgba(172, 68, 41, 0.04);
  pointer-events: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-index {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 1px;
}

.card-name {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: 5px;
  line-height: 1.25;
  color: var(--ink);
}

.card-pinyin {
  margin: -4px 0 0;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: lowercase;
}

.card-meaning {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.95;
  text-align: justify;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}

.tag {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11px;
}

.card-copy {
  align-self: flex-start;
  padding: 3px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

.card-copy:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.card.is-placeholder {
  justify-content: center;
  align-items: center;
  min-height: 190px;
  border-style: dashed;
  background: rgba(255, 253, 248, 0.6);
  color: var(--muted);
  font-size: 12.5px;
  animation: none;
}

.card.is-placeholder::after {
  display: none;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px 46px;
  text-align: center;
  color: var(--muted);
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 30px;
  opacity: 0.8;
}

.empty p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 1.5px;
  line-height: 2;
}

.empty span {
  font-size: 12px;
  color: var(--muted);
}

.history-block {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.history-head h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 2px;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

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

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-soft);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.history-item:hover {
  border-color: var(--accent);
  background: #fff8f0;
}

.history-main {
  min-width: 0;
  flex: 1;
}

.history-names {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-del {
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.history-del:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 34px;
  color: var(--muted);
  font-size: 11.5px;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .form-panel {
    position: static;
  }

  .site-header {
    padding-top: 24px;
  }

  .result-panel {
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  .site-header,
  .layout,
  .site-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .brand-text h1 {
    font-size: 22px;
  }

  .brand-text p {
    display: none;
  }

  .seg {
    grid-template-columns: repeat(3, 1fr);
  }

  .seg-btn {
    font-size: 12px;
  }

  .card-name {
    font-size: 30px;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}
