:root {
  --bg: #f5f8fc;
  --panel: rgba(255, 255, 255, 0.92);
  --text: #172033;
  --muted: #64748b;
  --line: #dbe5f2;
  --blue: #1f5eff;
  --blue-dark: #1748c7;
  --blue-soft: #e9f0ff;
  --green: #0f9f6e;
  --amber: #b7791f;
  --shadow: 0 18px 45px rgba(30, 64, 116, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(31, 94, 255, 0.13), transparent 32rem),
    radial-gradient(circle at 90% 12%, rgba(71, 134, 255, 0.12), transparent 28rem),
    var(--bg);
}

button,
select,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 56px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  align-items: stretch;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.06;
  letter-spacing: -0.04em;
}

.hero-copy {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.8;
}

.hero-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 20px;
  border: 1px solid rgba(31, 94, 255, 0.16);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(255,255,255,0.96), rgba(232,240,255,0.8));
  box-shadow: var(--shadow);
}

.hero-card span {
  display: grid;
  place-items: center;
  min-height: 74px;
  padding: 14px;
  border-radius: 18px;
  color: #1c376b;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(31, 94, 255, 0.12);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 24px;
  margin-bottom: 24px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.input-panel,
.insight-panel,
.result-panel {
  padding: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.panel-header h2,
.insight-panel h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.example-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.example-chip,
.ghost-button,
.secondary-button,
.primary-button {
  border: 0;
  border-radius: 999px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.example-chip,
.ghost-button {
  padding: 9px 14px;
  color: #1e3a66;
  background: var(--blue-soft);
  font-weight: 600;
}

.example-chip:hover,
.ghost-button:hover,
.secondary-button:hover,
.primary-button:hover {
  transform: translateY(-1px);
}

.upload-card {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px dashed rgba(31, 94, 255, 0.45);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(237, 244, 255, 0.82), rgba(255, 255, 255, 0.9));
}

.upload-card.dragover {
  border-color: var(--blue);
  background: #edf4ff;
}

.upload-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-card label {
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.upload-card strong {
  color: #183a76;
  font-size: 16px;
}

.upload-card span,
.upload-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

textarea {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--text);
  background: #fbfdff;
  outline: none;
  line-height: 1.7;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(31, 94, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(31, 94, 255, 0.1);
}

input[type="text"],
input[type="search"] {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.link-area {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(237, 244, 255, 0.72), rgba(255, 255, 255, 0.9));
  border: 1px dashed rgba(31, 94, 255, 0.38);
}

.link-area .link-field {
  min-width: 0;
}

.link-area .link-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.link-area .link-field input:focus {
  border-color: rgba(31, 94, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(31, 94, 255, 0.1);
}

.link-area button.secondary-button {
  justify-self: start;
}

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

.link-chip {
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  color: #1e3a66;
  background: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(31, 94, 255, 0.12);
  transition: transform 0.16s ease, background 0.16s ease;
}

.link-chip:hover {
  transform: translateY(-1px);
  background: #fff;
}

.link-area > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.link-progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e8ecf4;
  overflow: hidden;
  display: none;
}

.link-progress.visible {
  display: block;
}

.link-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--blue);
  transition: width 0.3s ease;
}

.shortcut-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.link-mode-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.link-mode-row input {
  flex: 1;
}

#batchLinkInput {
  width: 100%;
  min-height: 100px;
  margin-top: 8px;
}

#batchLinkInput.hidden {
  display: none;
}

.tiny-button {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  color: #1d3768;
  background: #edf4ff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: 18px;
  background: #f8fbff;
  border: 1px solid var(--line);
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: #1d3768;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}

.field {
  min-width: 170px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.secondary-button,
.primary-button {
  min-height: 44px;
  padding: 0 18px;
  font-weight: 700;
}

.secondary-button {
  color: #1d3768;
  background: #edf4ff;
  border: 1px solid rgba(31, 94, 255, 0.12);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  box-shadow: 0 10px 18px rgba(31, 94, 255, 0.22);
}

.insight-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.status-card {
  padding: 16px;
  border-radius: 18px;
  background: #f8fbff;
  border: 1px solid var(--line);
}

.status-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.status-card strong {
  color: #143369;
  font-size: 22px;
}

.mini-section {
  margin-top: 4px;
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, #f8fbff, #ffffff);
  border: 1px solid var(--line);
}

.mini-section h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.mini-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.mini-header h3 {
  margin-bottom: 0;
}

.mini-section ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.7;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.result-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.result-tools span {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.result-box {
  min-height: 230px;
  padding: 22px;
  border-radius: 20px;
  background: #fbfdff;
  border: 1px solid var(--line);
  line-height: 1.85;
}

.result-box ol,
.result-box ul {
  margin: 0;
  padding-left: 24px;
}

.result-box li {
  margin-bottom: 12px;
}

.result-list li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.result-list li .ref-content {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.ref-actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}

.ref-action-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.ref-action-btn:hover {
  transform: translateY(-1px);
  background: var(--blue-soft);
  border-color: var(--blue);
}

body.dark .ref-action-btn {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}

body.dark .ref-action-btn:hover {
  background: rgba(31, 94, 255, 0.2);
  border-color: var(--blue);
}

.ref-source-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
  white-space: nowrap;
}

body.dark .ref-source-tag {
  background: rgba(31, 94, 255, 0.2);
  color: #8ab4ff;
}

.highlight {
  background: #fef08a;
  color: #713f12;
  border-radius: 3px;
  padding: 0 2px;
}

body.dark .highlight {
  background: #a16207;
  color: #fef9c3;
}

.placeholder {
  margin: 0;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 40px 0;
}

.empty-state .secondary-button {
  margin-top: 16px;
}

.warning {
  color: var(--amber);
}

.success {
  color: var(--green);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-list p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.history-item {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: #fff;
  text-align: left;
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
  color: #16366e;
  font-size: 14px;
}

.history-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.result-box li.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.style-preview {
  margin-top: 16px;
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #fbfdff;
}

.style-preview h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.preview-card {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.preview-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.preview-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

body.dark {
  --bg: #0a0e1a;
  --panel: rgba(20, 28, 45, 0.95);
  --text: #e8f0f9;
  --muted: #a0aec0;
  --line: #2a3752;
  --blue-soft: rgba(31, 94, 255, 0.16);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.5);
}

#darkToggle {
  position: fixed;
  right: 24px;
  top: 24px;
  width: 44px;
  height: 44px;
  line-height: 42px;
  padding: 0;
  text-align: center;
  border-radius: 50%;
}

@media (max-width: 640px) {
  #darkToggle {
    position: static;
    margin-left: auto;
  }
}

.upgrade-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-top: 24px;
}

.upgrade-grid article {
  padding: 20px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
}

.upgrade-grid span {
  display: inline-flex;
  margin-bottom: 14px;
  color: var(--blue);
  font-weight: 800;
}

.upgrade-grid h3 {
  margin-bottom: 8px;
  font-size: 17px;
}

.upgrade-grid p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 18px);
  padding: 12px 18px;
  border-radius: 999px;
  color: white;
  background: rgba(17, 32, 62, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 960px) {
  .hero,
  .workspace-grid,
  .upgrade-grid {
    grid-template-columns: 1fr;
  }

  .hero-card {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 24px;
  }

  .input-panel,
  .insight-panel,
  .result-panel {
    padding: 18px;
  }

  .panel-header {
    flex-direction: column;
  }

  .hero-card,
  .upgrade-grid {
    grid-template-columns: 1fr;
  }

  .tool-row > *,
  .settings-grid,
  .settings-grid > *,
  .result-tools,
  .result-tools > *,
  .result-actions,
  .result-actions button {
    width: 100%;
  }
}

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

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--muted);
}

.loading-state .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

body.dark .loading-state .spinner {
  border-color: rgba(255, 255, 255, 0.15);
  border-top-color: var(--blue);
}
