:root {
  --bg: #edf2f7;
  --panel: rgba(255, 255, 255, 0.96);
  --surface: #f5f8fc;
  --surface-strong: #eaf0f7;
  --border: #d5dfeb;
  --border-strong: #bccbdd;
  --text: #182433;
  --subtle: #637286;
  --accent: #1268e8;
  --accent-dark: #084dac;
  --accent-soft: #e8f1ff;
  --teal: #087f72;
  --metal: #dc2626;
  --dielectric: #2563eb;
  --warn: #c93838;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(43, 61, 82, 0.08);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 12% 0%, rgba(18, 104, 232, 0.08), transparent 24rem),
    linear-gradient(145deg, #f4f7fa 0%, var(--bg) 55%, #e8eef5 100%);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.page-shell { min-height: 100vh; }

.topbar {
  height: 64px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 8px 18px;
  background: rgba(250, 252, 255, 0.94);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 18px rgba(36, 52, 71, 0.05);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 10;
}

.brand-block, .token-row, .top-nav, .panel-heading > div,
.color-legend, .file-row {
  display: flex;
  align-items: center;
}

.brand-block { gap: 10px; white-space: nowrap; }

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(145deg, #1675ff, #084dac);
  box-shadow: 0 8px 18px rgba(18, 104, 232, 0.25);
}

.brand-text { display: block; }
.brand-mini { color: #74849a; font-size: 8px; font-weight: 700; letter-spacing: 0.13em; }
.brand-text h1 { margin: 1px 0 0; font-size: 18px; line-height: 1.1; letter-spacing: 0.02em; }

.edition-tag, .scope-tag, .auto-fill-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  white-space: nowrap;
}

.edition-tag {
  padding: 4px 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid #cfe0fb;
  font-size: 11px;
  font-weight: 700;
}

.top-nav { justify-content: center; gap: 4px; }

.nav-btn {
  border: 0;
  border-radius: 9px;
  padding: 8px 13px;
  color: var(--subtle);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: color 160ms ease, background 160ms ease;
}

.nav-btn:hover { color: var(--text); background: var(--surface-strong); }
.nav-btn.active { color: #fff; background: var(--text); }
.token-row { gap: 8px; }
.token-row input { width: 150px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 7px 9px;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(18, 104, 232, 0.11);
}

input[type="file"] { min-width: 0; padding: 5px 7px; color: var(--subtle); font-size: 11px; }
input[type="file"]::file-selector-button {
  margin-right: 7px;
  border: 0;
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  cursor: pointer;
}

.btn {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.btn-light { color: var(--accent-dark); background: #fff; }
.btn-light:hover { border-color: #9ebce8; background: var(--accent-soft); }
.btn-primary {
  color: #fff;
  border-color: var(--accent);
  background: linear-gradient(135deg, #1976f3, #0755c1);
  box-shadow: 0 8px 18px rgba(18, 104, 232, 0.22);
}
.btn-primary:hover { filter: brightness(1.05); }

.workspace-shell {
  display: block;
  width: 100%;
  max-width: none;
  height: calc(100vh - 64px);
  padding: 12px;
}
.main-shell, .section-view.active, .workbench-grid { height: 100%; min-width: 0; }
.section-view { display: none; }
.section-view.active { display: block; overflow: auto; }
#section-workbench.active { overflow: hidden; }
.workbench-grid {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(320px, 0.82fr) minmax(500px, 1.18fr) minmax(440px, 1fr);
  gap: 12px;
}

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

.dashboard-card { min-width: 0; min-height: 0; padding: 14px; overflow: hidden; }
.panel-heading {
  min-height: 34px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: -14px -14px 12px;
  padding: 11px 14px;
  border-bottom: 1px solid #c8d6e7;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(90deg, #f0f5fb, #fbfdff);
}
.panel-heading > div { gap: 8px; }

.step-tag {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 900;
}

.group-title, .card-title { color: var(--text); font-size: 15px; font-weight: 800; }
.grid-size-field {
  display: grid;
  grid-template-columns: auto 64px;
  align-items: center;
  gap: 7px;
  color: var(--subtle);
  font-size: 11px;
}
.grid-size-field input { height: 30px; padding: 4px 7px; }

.structure-card { display: flex; flex-direction: column; }
.import-stack { display: grid; gap: 7px; }
.file-row { gap: 7px; }
.file-row input { flex: 1; }
.file-row .btn { width: 82px; }

.preview-stage {
  flex: 1;
  min-height: 250px;
  display: grid;
  place-items: center;
  margin-top: 10px;
  padding: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background:
    linear-gradient(90deg, rgba(188, 203, 221, 0.2) 1px, transparent 1px),
    linear-gradient(rgba(188, 203, 221, 0.2) 1px, transparent 1px),
    #f7f9fc;
  background-size: 20px 20px;
}

#forwardMatrixCanvas {
  width: 100%;
  height: 100%;
  max-height: 430px;
  display: block;
  object-fit: contain;
  border-radius: 8px;
}

.preview-footer { min-height: 52px; padding-top: 9px; }
.color-legend { gap: 14px; color: var(--subtle); font-size: 11px; }
.color-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; display: inline-block; border: 1px solid var(--border-strong); border-radius: 3px; }
.swatch-metal { background: var(--metal); }
.swatch-diel { background: var(--dielectric); }
.swatch-blank { background: #fff; }
.inline-status { margin-top: 7px; color: var(--subtle); font-size: 11px; line-height: 1.35; }
.inline-status.error { color: var(--warn); }

.parameter-card { overflow-y: auto; scrollbar-width: thin; }
.auto-fill-tag, .scope-tag { padding: 4px 8px; font-size: 10px; font-weight: 800; }
.auto-fill-tag { color: var(--teal); background: #e5f7f3; }
.scope-tag { color: var(--accent-dark); background: var(--accent-soft); }

.material-grid, .control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 8px;
}

.param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 8px;
}

.material-grid label, .control-grid label, .param-field {
  min-width: 0;
  display: grid;
  gap: 3px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
}

.material-grid select, .control-grid select, .control-grid input, .param-field input {
  height: 28px;
  min-width: 0;
  padding: 4px 7px;
  font-size: 11px;
}

.parameter-section-title { margin: 8px 0 5px; color: #44556a; font-size: 11px; font-weight: 800; letter-spacing: 0.03em; }
.run-button {
  width: 100%;
  min-height: 46px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 11px;
}
.run-button span { font-size: 15px; }
.run-button small { font-size: 10px; font-weight: 500; opacity: 0.78; }

.result-card { display: flex; flex-direction: column; }
.result-heading { flex: 0 0 auto; }
.chart-box {
  flex: 1;
  min-height: 300px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #f8fafc;
}
.chart-box svg { width: 100%; height: 100%; display: block; }

.empty-state { display: grid; justify-items: center; gap: 7px; color: #8a99aa; text-align: center; }
.empty-state::before {
  content: "";
  width: 54px;
  height: 30px;
  border-left: 2px solid #aec0d4;
  border-bottom: 2px solid #aec0d4;
  background: linear-gradient(155deg, transparent 48%, #6f9fe3 49% 52%, transparent 53%);
}
.empty-state strong { color: #607189; font-size: 14px; }
.empty-state span { font-size: 11px; }

.result-summary { flex: 0 0 120px; min-height: 0; margin-top: 9px; }
.result-summary-title { margin-bottom: 5px; color: #44556a; font-size: 11px; font-weight: 800; }
.detail-box {
  width: 100%;
  height: calc(100% - 19px);
  min-height: 0;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--subtle);
  font: 10px/1.45 "Consolas", "Microsoft YaHei", monospace;
  white-space: pre-wrap;
}

.resource-details { flex: 0 0 auto; margin-top: 8px; color: var(--subtle); font-size: 10px; }
.resource-details summary { cursor: pointer; font-weight: 700; }
.resource-lines { display: grid; gap: 3px; margin-top: 6px; padding: 7px; border-radius: 7px; background: var(--surface); line-height: 1.35; }

/* Information pages */
.section-view:not(#section-workbench) {
  width: 100%;
  max-width: none;
  padding: 16px;
}
.tab-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.tab-caption { margin-bottom: 3px; color: var(--subtle); font-size: 11px; }
.tab-header h2 { margin: 0; font-size: 24px; }
.tab-note, .hint, .para, .side-list { color: var(--subtle); }
.info-grid, .case-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 16px;
}
.case-grid { grid-template-columns: repeat(3, minmax(280px, 1fr)); }
.info-grid .group-box, .case-grid .group-box { padding: 16px; }
.para { margin: 10px 0 0; line-height: 1.65; font-size: 13px; }
.side-list { margin: 10px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.7; }

.case-art {
  height: 210px;
  margin-top: 14px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, #f8fbff, #edf4ff);
}

.ring-art::before, .ring-art::after, .cross-art::before, .cross-art::after,
.inverse-disabled-art::before, .inverse-disabled-art::after { content: ""; position: absolute; }
.ring-art::before { inset: 22px; border: 22px solid #2563eb; }
.ring-art::after { left: 50%; top: 50%; width: 74px; height: 74px; transform: translate(-50%, -50%); border: 18px solid #c99847; border-radius: 50%; }
.cross-art::before { left: 50%; top: 30px; width: 36px; height: 148px; transform: translateX(-50%); background: #2563eb; }
.cross-art::after { left: 50%; top: 50%; width: 160px; height: 34px; transform: translate(-50%, -50%); background: #2563eb; box-shadow: 0 -56px 0 -8px #2563eb, 0 56px 0 -8px #2563eb; }
.inverse-disabled-art::before {
  inset: 22px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, transparent 0 46%, rgba(201, 56, 56, 0.78) 46% 54%, transparent 54%),
    linear-gradient(180deg, rgba(18, 104, 232, 0.12), rgba(8, 127, 114, 0.09));
}
.inverse-disabled-art::after { inset: 38px; border: 2px dashed rgba(201, 56, 56, 0.42); border-radius: 12px; }

@media (max-width: 1180px) {
  body { overflow: auto; }
  .topbar { grid-template-columns: auto 1fr; height: auto; }
  .token-row { display: none; }
  .workspace-shell { height: auto; min-height: calc(100vh - 64px); }
  #section-workbench.active { overflow: visible; }
  .workbench-grid { height: auto; grid-template-columns: minmax(300px, 0.85fr) minmax(430px, 1.15fr); }
  .result-card { grid-column: 1 / -1; min-height: 620px; }
  .parameter-card { max-height: 700px; }
}

@media (max-width: 760px) {
  .topbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .brand-mini, .edition-tag { display: none; }
  .top-nav { width: 100%; justify-content: flex-start; overflow-x: auto; }
  .workspace-shell { padding: 8px; }
  .workbench-grid, .info-grid, .case-grid { grid-template-columns: 1fr; }
  .result-card { grid-column: auto; }
  .material-grid, .control-grid, .param-grid { grid-template-columns: 1fr; }
  .structure-card, .parameter-card, .result-card { min-height: 620px; }
}
