:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --surface: #111722;
  --surface-raised: #171f2c;
  --surface-soft: #0e141e;
  --line: #2b3443;
  --line-bright: #445167;
  --text: #f1eadb;
  --muted: #a9afba;
  --gold: #d4a84e;
  --gold-bright: #f2cc76;
  --gold-soft: rgba(212, 168, 78, 0.14);
  --green: #8abf70;
  --red: #e06c62;
  --blue: #6ea4c9;
  --purple: #a98bc7;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 0%, rgba(47, 74, 104, 0.2), transparent 34rem),
    radial-gradient(circle at 85% 8%, rgba(139, 100, 36, 0.13), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

.app-header,
.tabs,
main {
  width: min(1440px, calc(100% - 40px));
  margin-inline: auto;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 38px 0 24px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-family: Georgia, "SimSun", serif; font-size: clamp(1.8rem, 3vw, 2.8rem); font-weight: 500; letter-spacing: 0.04em; }
h2 { margin-bottom: 0; font-size: 1.2rem; font-weight: 600; }
h3 { margin-bottom: 12px; font-size: 1rem; }

.eyebrow,
.section-kicker {
  margin-bottom: 5px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.subtitle, .helper { margin-bottom: 0; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 14px; }
.save-state { color: var(--muted); font-size: 0.85rem; }

.button,
.tab,
.segment {
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.button:hover, .tab:hover, .segment:hover { border-color: var(--gold); }
.button:active, .tab:active, .segment:active { transform: translateY(1px); }
.button:focus-visible, .tab:focus-visible, .segment:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(242, 204, 118, 0.45); outline-offset: 2px; }
.button { min-height: 42px; padding: 8px 16px; }
.button-primary { border-color: var(--gold); background: linear-gradient(180deg, var(--gold-bright), var(--gold)); color: #211706; font-weight: 700; }
.button-quiet { background: transparent; }

.tabs {
  display: flex;
  gap: 8px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.tab { padding: 9px 18px; background: transparent; color: var(--muted); }
.tab.is-active { border-color: var(--gold); background: var(--gold-soft); color: var(--gold-bright); }

main { padding: 24px 0 48px; }
.tab-panel:not(.is-active) { display: none; }
.layout-grid { display: grid; grid-template-columns: minmax(300px, 0.85fr) minmax(520px, 1.65fr); gap: 18px; }
.cards-layout, .data-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.workflow-guide {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}
.workflow-guide li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(17, 23, 34, 0.72);
  padding: 11px 13px;
}
.workflow-guide li > span {
  grid-row: 1 / 3;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(212, 168, 78, 0.45);
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold-bright);
  font-weight: 700;
}
.workflow-guide strong { font-size: 0.9rem; }
.workflow-guide small { color: var(--muted); font-size: 0.75rem; }
.workflow-panel { margin-top: 18px; }
.workflow-stack { display: grid; gap: 18px; }
.state-panel .field-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.opening-guide {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  border: 1px solid rgba(242, 204, 118, 0.42);
  border-radius: 10px;
  background: linear-gradient(115deg, rgba(242, 204, 118, 0.14), rgba(242, 204, 118, 0.04));
  padding: 13px 15px;
}
.opening-guide[hidden] { display: none; }
.opening-guide-step { color: var(--gold-bright); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.08em; }
.opening-guide strong { color: var(--text); }
.opening-guide p { margin: 4px 0 0; color: var(--muted); font-size: 0.82rem; }
.opening-guide.is-complete { border-color: rgba(138, 191, 112, 0.45); background: rgba(138, 191, 112, 0.09); }
.opening-field input { border-color: rgba(242, 204, 118, 0.48); background: rgba(242, 204, 118, 0.045); }

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(23, 31, 44, 0.96), rgba(14, 20, 30, 0.98));
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.market-heading { align-items: flex-end; }
.badge { display: inline-flex; align-items: center; min-height: 30px; padding: 3px 11px; border: 1px solid rgba(212, 168, 78, 0.45); border-radius: 99px; background: var(--gold-soft); color: var(--gold-bright); font-size: 0.82rem; white-space: nowrap; }
.badge-good { border-color: rgba(138, 191, 112, 0.45); background: rgba(138, 191, 112, 0.12); color: #b7df9f; }
.badge-warn { border-color: rgba(224, 108, 98, 0.42); background: rgba(224, 108, 98, 0.1); color: #f0a39c; }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; color: var(--muted); font-size: 0.86rem; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 8px 10px;
}

.mode-note, .warning-note { margin-top: 16px; border-left: 3px solid var(--gold); background: var(--gold-soft); padding: 10px 12px; color: var(--muted); font-size: 0.88rem; }
.current-buffs { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.current-buffs h3 { margin-bottom: 8px; }
.buff-list { display: flex; flex-wrap: wrap; gap: 7px; }
.buff-chip { display: inline-flex; padding: 4px 9px; border-radius: 99px; background: rgba(110, 164, 201, 0.12); color: #add2eb; font-size: 0.8rem; }
.buff-chip.persistent { background: rgba(169, 139, 199, 0.14); color: #d1b8e8; }
.buff-empty { color: var(--muted); font-size: 0.86rem; }
.progress-copy { display: flex; justify-content: space-between; gap: 12px; margin-top: 20px; color: var(--muted); }
.progress-track { height: 8px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: rgba(255, 255, 255, 0.07); }
.progress-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-bright)); transition: width 200ms ease; }
.numbers { font-variant-numeric: tabular-nums; }

.inventory-section { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.inventory-section summary { cursor: pointer; color: var(--gold-bright); }
.inventory-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.inventory-field { display: grid; grid-template-columns: minmax(120px, 1fr) 76px 100px; align-items: end; gap: 8px; color: var(--muted); font-size: 0.8rem; }
.inventory-field label { display: grid; gap: 3px; }
.inventory-field small { color: var(--muted); }
.inventory-field input { min-height: 36px; }
.hypothesis-note { margin: 14px 0 0; border: 1px solid rgba(242, 204, 118, 0.35); border-radius: 8px; background: rgba(242, 204, 118, 0.08); padding: 10px 12px; color: var(--muted); font-size: 0.82rem; }
.hypothesis-note strong { color: var(--gold-bright); }

.segmented { display: flex; gap: 6px; }
.segment { min-height: 38px; padding: 7px 13px; background: transparent; color: var(--muted); }
.segment.is-active { border-color: var(--gold); background: var(--gold-soft); color: var(--gold-bright); }
.market-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 22px; align-items: start; }
.market-editor { min-width: 0; }
.market-editor > .helper { margin: -8px 0 18px; font-size: 0.86rem; }
.market-rows { display: grid; gap: 10px; }
.market-advice {
  position: sticky;
  top: 18px;
  border: 1px solid rgba(212, 168, 78, 0.32);
  border-radius: 11px;
  background: rgba(212, 168, 78, 0.07);
  padding: 16px;
}
.market-advice h3 { margin-bottom: 6px; color: var(--gold-bright); }
.market-advice-list { display: grid; gap: 9px; margin: 15px 0 0; padding: 0; list-style: none; }
.market-advice-list li { display: grid; gap: 3px; border-top: 1px solid var(--line); padding-top: 9px; }
.market-advice-list strong { font-size: 0.9rem; }
.market-advice-list span { color: var(--muted); font-size: 0.78rem; }
.market-next-button { width: 100%; margin-top: 16px; border-color: rgba(212, 168, 78, 0.55); background: var(--gold-soft); color: var(--gold-bright); }

.market-row {
  display: grid;
  grid-template-columns: minmax(190px, 1.4fr) repeat(3, minmax(90px, 0.7fr)) minmax(115px, 0.8fr);
  gap: 12px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.market-row:first-child { border-top: 0; padding-top: 0; }
.goods-title { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.goods-mark { width: 10px; height: 36px; border-radius: 4px; background: var(--blue); }
.goods-mark.rare { background: var(--purple); }
.goods-mark.luxury { background: var(--gold); }
.goods-name { display: grid; }
.goods-name small { color: var(--muted); }
.compact-field span { font-size: 0.76rem; }
.trade-toggle { display: flex; align-items: center; justify-content: center; min-height: 42px; gap: 7px; color: var(--muted); }
.trade-toggle input { width: 18px; min-height: 18px; accent-color: var(--gold); }

.recommendation { margin-top: 18px; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.summary-item { border-left: 2px solid var(--line-bright); padding: 8px 14px; }
.summary-item span, .summary-item small { display: block; color: var(--muted); }
.summary-item strong { display: block; margin: 2px 0; font-size: clamp(1.35rem, 2vw, 1.9rem); font-weight: 600; }
.summary-item small.positive, .positive { color: var(--green); }
.summary-item small.negative, .negative { color: var(--red); }
.recommendation-body { display: grid; grid-template-columns: 1.25fr 0.75fr; gap: 28px; margin-top: 24px; border-top: 1px solid var(--line); padding-top: 20px; }
.action-list, .reason-box ul, .rule-list { margin: 0; padding-left: 22px; }
.action-list li, .reason-box li, .rule-list li { margin: 8px 0; }
.action-list strong { color: var(--gold-bright); }
.execution-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.execution-row div { display: grid; gap: 3px; }
.execution-row span, .execution-row small { color: var(--muted); }
.execution-control { display: grid; gap: 4px; color: var(--muted); font-size: 0.78rem; }
.execution-control input, .execution-control select { min-height: 38px; }
.execution-card-control { min-width: 210px; }
.reason-box { border-left: 1px solid var(--line); padding-left: 24px; color: var(--muted); }
.recommendation-actions { display: flex; gap: 10px; margin-top: 22px; }

.station-strategy { margin-top: 18px; }
.route-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.route-branches { display: grid; gap: 10px; margin-top: 18px; }
.route-branch { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.route-branch strong { color: var(--gold-bright); }
.route-branch span { color: var(--muted); }
.card-selectors { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card-ranking { display: grid; gap: 10px; margin-top: 20px; }
.ranked-card { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 12px; align-items: center; border-top: 1px solid var(--line); padding-top: 12px; }
.rank-number { color: var(--gold); font-family: Georgia, serif; font-size: 1.4rem; }
.ranked-card p { margin-bottom: 2px; }
.ranked-card small { color: var(--muted); }
.trigger-certain { color: var(--green); }
.trigger-impossible { color: var(--red); }
.trigger-branch { color: var(--gold-bright); }

table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; }
th { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
td:last-child, th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.rule-list { color: var(--muted); }
.rule-list strong { color: var(--text); }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: min(360px, calc(100% - 40px)); transform: translateY(16px); opacity: 0; pointer-events: none; border: 1px solid var(--line-bright); border-radius: 9px; background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow); padding: 11px 15px; transition: opacity 160ms ease, transform 160ms ease; }
.toast.is-visible { transform: translateY(0); opacity: 1; }

.arrival-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  background: rgba(5, 8, 12, 0.92);
  backdrop-filter: blur(8px);
  padding: 32px 20px;
}
.arrival-page {
  width: min(760px, 100%);
  margin: 5vh auto;
  border: 1px solid var(--line-bright);
  border-radius: 16px;
  background: linear-gradient(145deg, #171f2c, #0e141e);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
  padding: 28px;
}
.arrival-grid { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 16px; margin-top: 22px; }
.arrival-card { display: grid; gap: 4px; border-left: 2px solid var(--gold); padding: 8px 14px; }
.arrival-card span, .arrival-card small { color: var(--muted); }
.arrival-card strong { color: var(--gold-bright); font-size: 1.12rem; }
.trigger-check { display: flex; align-items: flex-start; gap: 12px; margin-top: 20px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); padding: 14px; cursor: pointer; }
.trigger-check input { width: 20px; min-height: 20px; accent-color: var(--gold); }
.trigger-check span { display: grid; gap: 2px; }
.trigger-check small { color: var(--muted); }
.arrival-effect { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 18px; }
.arrival-effect ul { margin: 0; padding-left: 22px; color: var(--muted); }
.arrival-effect li { margin: 7px 0; }
.form-error { min-height: 24px; margin: 14px 0 0; color: var(--red); }

@media (max-width: 960px) {
  .layout-grid, .cards-layout, .data-layout { grid-template-columns: 1fr; }
  .workflow-guide, .state-panel .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .market-workspace { grid-template-columns: 1fr; }
  .market-advice { position: static; }
  .inventory-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .market-row { grid-template-columns: minmax(170px, 1.2fr) repeat(3, minmax(82px, 0.7fr)) 100px; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-header, .tabs, main { width: min(100% - 24px, 1440px); }
  .app-header { align-items: flex-start; flex-direction: column; padding-top: 24px; }
  .header-actions { width: 100%; justify-content: space-between; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
  .panel { padding: 17px; }
  .workflow-guide { grid-template-columns: 1fr; }
  .opening-guide { grid-template-columns: 1fr; }
  .market-heading { align-items: flex-start; flex-direction: column; }
  .market-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .goods-title { grid-column: 1 / -1; }
  .trade-toggle { justify-content: flex-start; }
  .summary-grid { grid-template-columns: 1fr; }
  .recommendation-body { grid-template-columns: 1fr; }
  .execution-row { grid-template-columns: 1fr; }
  .execution-card-control { min-width: 0; }
  .reason-box { border-left: 0; border-top: 1px solid var(--line); padding: 18px 0 0; }
  .arrival-overlay { padding: 12px; }
  .arrival-page { margin: 0 auto; padding: 18px; }
  .arrival-grid { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .field-grid, .state-panel .field-grid, .route-fields, .inventory-grid, .card-selectors { grid-template-columns: 1fr; }
  .panel-heading { align-items: flex-start; }
  .segmented { width: 100%; }
  .segment { flex: 1; }
  .recommendation-actions { flex-direction: column; }
  .button { width: 100%; }
  .save-state { display: none; }
}

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