:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-alt: #F1F5F9;
  --ink: #0F172A;
  --ink-muted: #475569;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --accent: #0B57D0;
  --accent-hover: #0842A0;
  --accent-soft: #EBF3FE;
  --danger: #B91C1C;
  --success: #0F766E;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;

  /* Strictly 3 body typography steps (brand wordmark & compact page H1 exempt) */
  --text-heading: 1.25rem;   /* 20px */
  --text-body: 0.9375rem;    /* 15px */
  --text-sm: 0.8125rem;      /* 13px */

  --radius: 10px;
  --radius-sm: 6px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: var(--text-body);
  color: var(--ink);
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(248, 250, 252, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.025em;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--accent);
  position: relative;
  display: inline-block;
}
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  height: 2px;
  background: #FFFFFF;
  border-radius: 2px;
}
.brand-mark::before { top: 7px; }
.brand-mark::after { bottom: 7px; width: 8px; }

.topbar-search {
  flex: 1;
  max-width: 460px;
}

.topbar-search input {
  width: 100%;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.topbar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 87, 208, 0.12);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.lang-switch {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.lang-opt {
  border: none;
  background: transparent;
  padding: 5px 11px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.lang-opt.active {
  background: var(--ink);
  color: #FFFFFF;
}

/* Main Workbench Shell */
.shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 24px 48px;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

.rail {
  position: sticky;
  top: 76px;
}

.rail-intro {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.rail-title {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.rail-sub {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.tool-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease);
}
.nav-item:hover {
  background: var(--surface);
  border-color: var(--border);
}
.nav-item.active {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.nav-item-name {
  font-size: var(--text-body);
  font-weight: 700;
  color: var(--ink);
}
.nav-item.active .nav-item-name { color: var(--accent); }

.nav-item-hint {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-foot {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.rail-note {
  margin: 0 0 10px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

.rail-link {
  display: inline-block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
}

/* Active Tool Stage */
.stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px 30px;
  min-height: 580px;
}

.stage-head {
  padding-bottom: 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.stage-title {
  margin: 0 0 6px;
  font-size: var(--text-heading);
  font-weight: 800;
  letter-spacing: -0.015em;
}

.stage-desc {
  margin: 0;
  font-size: var(--text-body);
  color: var(--ink-muted);
  max-width: 64ch;
}

/* Shared Workspace Layout */
.tool-grid {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 26px;
  align-items: start;
}

.tool-grid.single {
  grid-template-columns: minmax(0, 1fr);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-val {
  color: var(--accent);
  font-weight: 700;
}

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 9px 12px;
  font-size: var(--text-body);
  outline: none;
  transition: border-color 150ms var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
}
.textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.6;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Segmented Control */
.segmented {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 2px;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 7px 10px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
}
.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Color Swatches */
.swatches {
  display: flex;
  gap: 8px;
  align-items: center;
}
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease);
}
.swatch.active {
  border-color: var(--ink);
  transform: scale(1.08);
}

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 18px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-main {
  font-size: var(--text-body);
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 4px;
}
.dropzone-sub {
  font-size: var(--text-sm);
  color: var(--ink-muted);
  margin: 0;
}

/* Primary CTA */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #FFFFFF;
  font-size: var(--text-body);
  font-weight: 700;
  padding: 11px 18px;
  cursor: pointer;
  transition: background-color 150ms var(--ease), transform 120ms var(--ease);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.link-action {
  background: none;
  border: none;
  padding: 4px 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}
.link-action:hover { text-decoration: underline; }

/* Preview Stage */
.preview-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 14px;
}

.preview-box canvas,
.preview-box img {
  max-width: 100%;
  max-height: 520px;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
  background: #FFFFFF;
}

.meta-line {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.meta-strong { color: var(--success); font-weight: 700; }

/* File List (PDF & Stitch) */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}
.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}
.file-row-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.file-row-ops {
  display: flex;
  gap: 8px;
}
.file-row-ops button {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 2px 4px;
}
.file-row-ops button:hover { color: var(--ink); }

/* 9-Grid Preview */
.grid-9 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(390px, 100%);
}
.grid-9 a {
  display: block;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.grid-9 img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  box-shadow: none;
  border-radius: 0;
}

/* Result Panels (Finance & Text) */
.result-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.big-output {
  font-size: var(--text-heading);
  font-weight: 800;
  color: var(--ink);
  word-break: break-all;
  line-height: 1.45;
}
.kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body);
}
.kv-table th, .kv-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.kv-table th {
  color: var(--ink-muted);
  font-weight: 600;
  font-size: var(--text-sm);
}
.kv-table td:last-child {
  text-align: right;
  font-weight: 700;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

/* FAQ Section */
.faq-band {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 44px 24px;
}
.faq-inner {
  max-width: 1320px;
  margin: 0 auto;
}
.faq-heading {
  margin: 0 0 22px;
  font-size: var(--text-heading);
  font-weight: 800;
}
.faq-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
}
.faq-item h3 {
  margin: 0 0 8px;
  font-size: var(--text-body);
  font-weight: 700;
  color: var(--ink);
}
.faq-item p {
  margin: 0;
  font-size: var(--text-body);
  color: var(--ink-muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 22px 24px;
}
.footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}
.footer-links a { color: var(--ink-muted); }
.footer-links a:hover { color: var(--ink); }

/* Mobile & Tablet */
@media (max-width: 980px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 16px 16px 36px;
    gap: 18px;
  }
  .rail, .stage, .workspace, .controls, .preview-box { min-width: 0; max-width: 100%; }
  .rail { position: static; }
  .rail-intro { margin-bottom: 12px; padding-bottom: 12px; }
  .rail-title { font-size: 1.25rem; }
  .tool-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .nav-item {
    flex: 0 0 auto;
    width: auto;
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 8px 13px;
  }
  .nav-item-hint { display: none; }
  .rail-foot { display: none; }
  .stage { padding: 18px 16px 22px; min-height: auto; }
  .tool-grid { grid-template-columns: 1fr; gap: 18px; }
  .preview-box { min-height: 280px; }
  .faq-grid { grid-template-columns: 1fr; gap: 20px; }
}

@media (max-width: 600px) {
  .topbar-inner {
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .topbar-search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }
  .field-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
