:root {
  --ink: #1f2937;
  --coal: #ffffff;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --line: rgba(148, 163, 184, 0.28);
  --text: #111827;
  --muted: #64748b;
  --amber: #f3b340;
  --cyan: #14b8a6;
  --green: #16a34a;
  --red: #dc2626;
  --cream: #0f172a;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgba(20, 184, 166, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 184, 166, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 12% 0%, rgba(20, 184, 166, 0.12), transparent 28rem),
    radial-gradient(circle at 88% 14%, rgba(243, 179, 64, 0.12), transparent 24rem),
    linear-gradient(180deg, #f8fbff 0%, #f3f7fb 52%, #eef3f8 100%);
  background-size: 36px 36px, 36px 36px, auto, auto;
  font-family: "Bahnschrift", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 88px;
  padding: 0 4px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--amber);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 0.78rem;
}

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

h1 {
  margin-bottom: 0;
  color: var(--cream);
  font-family: Georgia, "Microsoft YaHei UI", serif;
  font-size: 3.6rem;
  font-weight: 700;
  line-height: 0.95;
}

h2 {
  margin-bottom: 0;
  font-size: 1.48rem;
  font-weight: 700;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.runtime-badge,
.quality-pill,
.sample-count {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  white-space: nowrap;
}

.pulse {
  width: 9px;
  height: 9px;
  margin-right: 9px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 18px var(--cyan);
  animation: pulse 1.8s ease-in-out infinite;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(460px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 246, 220, 0.55), transparent 160px),
    rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
}

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

.panel-head,
.block-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.sample-count {
  color: var(--muted);
  font-size: 0.88rem;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
}

.preset-button,
.ghost-action,
.primary-action {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.preset-button:hover,
.ghost-action:hover {
  transform: translateY(-1px);
  border-color: rgba(20, 184, 166, 0.45);
  background: rgba(20, 184, 166, 0.08);
}

.preset-button.active {
  color: var(--ink);
  border-color: var(--amber);
  background: var(--amber);
}

.solver-form {
  display: grid;
  gap: 16px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.92);
}

fieldset.delivery-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

legend {
  padding: 0 8px;
  color: var(--cyan);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 0.78rem;
}

label {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.84rem;
}

label small {
  position: absolute;
  right: 10px;
  bottom: 10px;
  color: rgba(100, 116, 139, 0.8);
  pointer-events: none;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.14);
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.14);
}

label:has(small) input {
  padding-right: 44px;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 0.38fr 0.38fr;
  gap: 10px;
}

.insight-strip {
  display: grid;
  gap: 10px;
}

.insight-card,
.context-card {
  display: grid;
  gap: 8px;
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
}

.insight-title,
.context-title {
  color: var(--amber);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 0.76rem;
}

.insight-card strong,
.context-card strong {
  color: var(--cream);
  font-size: 1rem;
}

.insight-card small,
.context-card small {
  color: var(--muted);
}

.insight-card.pass {
  border-color: rgba(147, 209, 107, 0.44);
}

.insight-card.warn {
  border-color: rgba(232, 111, 93, 0.54);
}

.insight-card.neutral {
  border-color: rgba(112, 217, 197, 0.28);
}

.advanced-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.92);
}

.advanced-panel summary {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.advanced-panel summary::-webkit-details-marker {
  display: none;
}

.advanced-panel summary span {
  color: var(--cyan);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 0.82rem;
}

.advanced-panel summary small {
  color: var(--muted);
}

.advanced-grid {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
}

.advanced-grid .material-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.advanced-grid .phosphor-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.wide-field {
  grid-column: 1 / -1;
}

.toggle-field {
  display: grid;
  gap: 8px;
}

.toggle-box {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(247, 229, 188, 0.18);
  border-radius: 6px;
  background: rgba(10, 10, 9, 0.5);
}

.toggle-box strong {
  font-size: 0.92rem;
  font-weight: 600;
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--amber);
}

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

.hidden {
  display: none;
}

.primary-action {
  color: var(--ink);
  border-color: var(--amber);
  background: linear-gradient(135deg, var(--amber), #f5d37b);
  font-weight: 700;
}

.primary-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(243, 179, 64, 0.2);
}

.result-hero {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: center;
}

.ratio-dial {
  display: grid;
  place-items: center;
  width: 220px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    conic-gradient(var(--amber) 0deg, var(--amber) var(--yag-deg, 210deg), var(--red) var(--yag-deg, 210deg), var(--red) var(--casn-deg, 300deg), var(--cyan) var(--casn-deg, 300deg), var(--cyan) 360deg);
  box-shadow: inset 0 0 36px rgba(0, 0, 0, 0.45), 0 24px 54px rgba(0, 0, 0, 0.32);
}

.dial-core {
  display: grid;
  place-items: center;
  width: 128px;
  aspect-ratio: 1;
  border: 1px solid rgba(247, 229, 188, 0.2);
  border-radius: 50%;
  background: var(--coal);
}

.dial-core span {
  color: var(--muted);
  font-size: 0.86rem;
}

.dial-core strong {
  color: var(--cream);
  font-size: 1.5rem;
}

.ratio-list {
  display: grid;
  gap: 12px;
  align-content: start;
}

.ratio-item {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(180px, 320px) minmax(120px, 140px);
  gap: 16px;
  align-items: center;
  justify-content: start;
}

.ratio-name {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
  word-break: break-word;
}

.ratio-track {
  width: min(100%, 320px);
  justify-self: start;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(226, 232, 240, 0.95);
}

.ratio-fill {
  display: block;
  width: var(--value);
  height: 100%;
  border-radius: inherit;
  background: var(--color);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
  transition: width 280ms ease;
}

.ratio-value {
  color: var(--cream);
  text-align: right;
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
}

.ratio-row-plain {
  grid-template-columns: minmax(170px, 220px) 1fr;
  align-items: center;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}

.ratio-row-plain .ratio-name {
  color: var(--amber);
  font-weight: 600;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0;
}

.metric {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
}

.metric span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.metric strong {
  color: var(--cream);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 1.18rem;
}

.acceptance-band {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 16px;
  padding: 16px;
  border: 1px solid rgba(112, 217, 197, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(20, 184, 166, 0.10), transparent),
    rgba(255, 255, 255, 0.96);
}

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

.check-item {
  min-height: 62px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(248, 250, 252, 0.98);
}

.check-item strong {
  display: block;
  margin-top: 7px;
  color: var(--cream);
  font-size: 0.9rem;
}

.check-item.pass {
  border-color: rgba(147, 209, 107, 0.44);
}

.check-item.fail {
  border-color: rgba(232, 111, 93, 0.54);
}

.candidate-block {
  margin-top: 18px;
}

.block-title {
  margin-bottom: 10px;
}

.block-title span {
  color: var(--muted);
  font-size: 0.86rem;
}

.candidate-table {
  display: grid;
  gap: 8px;
}

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

.history-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.history-tab {
  position: relative;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.92rem;
  transition: color 160ms ease, background 160ms ease;
}

.history-tab small {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  color: var(--cream);
  background: rgba(148, 163, 184, 0.28);
  font-size: 0.78rem;
}

.history-tab:hover {
  color: var(--text);
  background: rgba(20, 184, 166, 0.06);
}

.history-tab.active {
  color: var(--cream);
  border-color: var(--line);
  border-bottom-color: rgba(255, 255, 255, 0.98);
  background: rgba(255, 255, 255, 0.98);
  font-weight: 700;
}

.history-tab.active small {
  background: var(--amber);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(148, 163, 184, 0.28);
  backdrop-filter: blur(10px);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  width: min(980px, 100%);
  max-height: min(82vh, 920px);
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 246, 220, 0.55), transparent 160px),
    rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.modal-head {
  margin-bottom: 12px;
}

.modal-note {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.modal-close {
  min-width: 88px;
}

.history-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.98);
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.history-delete-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(220, 38, 38, 0.22);
  border-radius: 6px;
  color: var(--red);
  background: rgba(254, 242, 242, 0.95);
}

.history-delete-button:hover {
  border-color: rgba(220, 38, 38, 0.42);
  background: rgba(254, 226, 226, 1);
}

.history-row + .history-row {
  margin-top: 8px;
}

.history-row strong {
  color: var(--cream);
  font-size: 0.95rem;
}

.history-row.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

.history-empty {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(248, 250, 252, 0.9);
}

.candidate-row {
  display: grid;
  grid-template-columns: 42px 1fr 1fr 1fr 92px 74px;
  gap: 8px;
  align-items: center;
  min-height: 54px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
}

.candidate-row.header {
  min-height: 38px;
  color: var(--muted);
  background: rgba(248, 250, 252, 0.55);
}

.candidate-row:not(.header) {
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
}

.candidate-row-selectable {
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.candidate-row-selectable:hover {
  border-color: rgba(20, 184, 166, 0.55);
  background: rgba(20, 184, 166, 0.08);
}

.candidate-row-selectable.selected {
  border-color: var(--amber);
  background: rgba(243, 179, 64, 0.16);
  box-shadow: 0 6px 18px rgba(243, 179, 64, 0.18);
}

.record-trigger {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(20, 184, 166, 0.55);
  border-radius: 8px;
  color: var(--cyan);
  background: rgba(20, 184, 166, 0.1);
  font-size: 0.86rem;
  transition: background 140ms ease, color 140ms ease;
}

.record-trigger:hover {
  background: rgba(20, 184, 166, 0.22);
  color: var(--text);
}

.candidate-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
  padding: 4px 4px 0;
}

.candidate-actions button {
  min-height: 40px;
  padding: 0 18px;
}

.candidate-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.candidate-actions small {
  color: var(--muted);
  font-size: 0.84rem;
}

.record-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.95);
}

.record-panel.hidden {
  display: none;
}

.record-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.record-panel-head strong {
  color: var(--cream);
}

.verify-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.verify-label {
  color: var(--muted);
  font-size: 0.86rem;
}

.verify-btn {
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}

.verify-btn:hover {
  border-color: rgba(20, 184, 166, 0.5);
  color: var(--text);
}

.verify-btn.passed {
  border-color: var(--green);
  color: var(--green);
  background: rgba(147, 209, 107, 0.16);
  font-weight: 700;
}

.verify-btn.failed {
  border-color: var(--red);
  color: var(--red);
  background: rgba(232, 111, 93, 0.16);
  font-weight: 700;
}

.record-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.record-section-title {
  margin: 14px 0 8px;
  color: var(--cyan);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 0.82rem;
}

.record-fields label {
  display: grid;
  gap: 6px;
}

.record-fields span {
  color: var(--muted);
  font-size: 0.82rem;
}

.record-actions {
  display: flex;
  gap: 12px;
}

.record-actions .primary-action {
  min-height: 40px;
  padding: 0 22px;
}

.record-actions .primary-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.history-item-recorded {
  border-left: 3px solid var(--green);
}

.history-formula {
  color: var(--cream);
  font-family: "Cascadia Code", "Microsoft YaHei UI", monospace;
  font-size: 0.86rem;
}

.candidate-row .ok {
  color: var(--green);
  font-weight: 700;
}

.candidate-row .warn {
  color: var(--red);
  font-weight: 700;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

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

  .advanced-grid .phosphor-row,
  .lock-model-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .topbar,
  .panel-head,
  .block-title {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 2.35rem;
  }

  .preset-row,
  fieldset,
  .metric-grid,
  .check-list,
  .advanced-grid,
  .lock-model-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-actions {
    grid-template-columns: 1fr 1fr;
  }

  .result-hero,
  .acceptance-band {
    grid-template-columns: 1fr;
  }

  .ratio-dial {
    width: min(220px, 100%);
    justify-self: center;
  }

  .ratio-item {
    grid-template-columns: minmax(140px, 1fr) minmax(140px, 260px) minmax(96px, 120px);
    gap: 12px;
  }

  .candidate-row {
    grid-template-columns: 34px 1fr 1fr;
    min-height: auto;
    padding: 12px;
  }

  .candidate-row span:nth-child(5),
  .candidate-row span:nth-child(6) {
    grid-column: span 1;
  }
}

@media (max-width: 520px) {
  .preset-row,
  fieldset,
  .metric-grid,
  .check-list,
  .form-actions,
  .advanced-grid .material-row,
  .advanced-grid .phosphor-row,
  .lock-model-grid {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .candidate-row {
    grid-template-columns: 1fr 1fr;
  }

  .ratio-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .ratio-track,
  .ratio-value {
    width: 100%;
    text-align: left;
  }

  .candidate-row span:first-child {
    grid-column: span 2;
  }
}
