:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3345;
  --text: #e8eaef;
  --text-muted: #9aa3b5;
  --primary: #6c8cff;
  --primary-dim: #4a62b3;
  --positive: #3dd68c;
  --negative: #ff6b7a;
  --warning: #ffb020;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --matrix-dynamic-texture: none;
  font-family: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
}

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

body {
  position: relative;
  isolation: isolate;
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    var(--matrix-dynamic-texture),
    url('../assets/matrix-texture.png'),
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 140, 255, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(61, 214, 140, 0.06), transparent);
  background-size:
    512px 384px,
    720px 480px,
    auto,
    auto;
  background-repeat:
    repeat,
    repeat,
    no-repeat,
    no-repeat;
  color: var(--text);
  line-height: 1.6;
}

body::before,
body::after {
  position: fixed;
  inset: -18vmax;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}

body::before {
  content: '';
  background-image:
    repeating-linear-gradient(135deg, transparent 0 23px, #101218 23px 24px),
    repeating-linear-gradient(90deg, transparent 0 53px, #11131a 53px 54px),
    repeating-linear-gradient(0deg, transparent 0 47px, #101217 47px 48px);
  background-size: 180px 180px, 212px 212px, 188px 188px;
}

body::after {
  content:
    'trade\002D ev\002E succ\002E work  MX\002D 0FD4\002D 1893  \611B\7576\6C96\7684\5DE5\7A0B\5E2B  '
    'trade\002D ev\002E succ\002E work  MX\002D 0FD4\002D 1893  \611B\7576\6C96\7684\5DE5\7A0B\5E2B  '
    'trade\002D ev\002E succ\002E work  MX\002D 0FD4\002D 1893  \611B\7576\6C96\7684\5DE5\7A0B\5E2B  '
    'trade\002D ev\002E succ\002E work  MX\002D 0FD4\002D 1893  \611B\7576\6C96\7684\5DE5\7A0B\5E2B  ';
  display: block;
  color: #101218;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  font-weight: 600;
  line-height: 4.8;
  letter-spacing: 0.62em;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  transform: rotate(-18deg) scale(1.18);
  transform-origin: center;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.app-header {
  text-align: center;
  margin-bottom: 2rem;
}

.app-header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.brand-credit {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.85;
}

.brand-credit a,
.site-footer a {
  color: var(--primary);
  text-decoration: none;
}

.brand-credit a:hover,
.site-footer a:hover {
  text-decoration: underline;
}

/* Stepper */
.stepper {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.stepper-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: all 0.2s;
}

.stepper-item.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--text);
}

.stepper-item.done {
  border-color: var(--positive);
  color: var(--positive);
}

.stepper-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 0.75rem;
  font-weight: 600;
}

.stepper-item.active .stepper-num {
  background: var(--primary);
  color: #fff;
}

/* Cards */
.card {
  background: var(--surface);
  background-image:
    repeating-linear-gradient(145deg, transparent 0 31px, #1b1e28 31px 32px),
    repeating-linear-gradient(35deg, transparent 0 67px, #191c26 67px 68px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card h2,
.card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}

.card h4 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.lead {
  color: var(--text-muted);
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
}

.note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 1rem 0 0;
}

/* Matrix preview */
.matrix-preview {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1.25rem 0;
}

.matrix-row {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 0.9rem;
}

.matrix-id {
  font-weight: 700;
  color: var(--primary);
}

.matrix-ev {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.matrix-row--baseline .matrix-ev { color: var(--positive); }
.matrix-row--peak .matrix-ev { color: #7eb8ff; }
.matrix-row--violation .matrix-ev { color: var(--text-muted); }
.matrix-row--bleeding .matrix-ev,
.matrix-row--crash .matrix-ev { color: var(--negative); }

/* Param grid */
.param-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .param-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.param-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  background: var(--surface-2);
}

.param-card header {
  margin-bottom: 0.75rem;
}

.param-id {
  display: inline-block;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.param-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.param-desc {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.param-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.param-fields label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.param-fields input {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
}

.param-ev {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.param-card--bleeding,
.param-card--crash {
  border-color: rgba(255, 107, 122, 0.35);
}

/* Distribution */
.dist-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dist-row {
  display: grid;
  grid-template-columns: 1fr 5rem 3.5rem;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.dist-label {
  font-size: 0.9rem;
}

.dist-row input {
  padding: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
}

.dist-pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.dist-total {
  margin: 1rem 0 0;
  text-align: right;
  font-size: 0.95rem;
}

/* Triggers */
.field-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.field-block textarea {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

/* Stress */
.stress-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.checkbox-row input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--primary);
}

/* Validation */
.validation-panel {
  margin-bottom: 1rem;
}

.validation-item {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.validation-item--error {
  background: rgba(255, 107, 122, 0.12);
  border: 1px solid rgba(255, 107, 122, 0.4);
}

.validation-item--warning {
  background: rgba(255, 176, 32, 0.1);
  border: 1px solid rgba(255, 176, 32, 0.35);
}

.validation-item p {
  margin: 0.25rem 0 0;
}

.validation-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Results */
.result-hero {
  text-align: center;
}

.result-hero--positive {
  border-color: rgba(61, 214, 140, 0.4);
}

.result-hero--negative {
  border-color: rgba(255, 107, 122, 0.4);
}

.ev-display {
  margin: 1rem 0;
}

.ev-value {
  display: block;
  font-size: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.result-hero--positive .ev-value { color: var(--positive); }
.result-hero--negative .ev-value { color: var(--negative); }

.ev-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.ev-compare {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.verdict--pause { border-left: 4px solid var(--negative); }
.verdict--fix { border-left: 4px solid var(--warning); }
.verdict--continue { border-left: 4px solid var(--positive); }
.verdict--hybrid { border-left: 4px solid var(--primary); }

.next-step {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

/* Contrib table */
.contrib-table {
  font-size: 0.85rem;
}

.contrib-header,
.contrib-row {
  display: grid;
  grid-template-columns: 2fr 0.6fr 0.7fr 0.8fr 0.8fr;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.contrib-header {
  color: var(--text-muted);
  font-weight: 600;
}

.text-positive { color: var(--positive); }
.text-negative { color: var(--negative); }

@media (max-width: 560px) {
  .contrib-header,
  .contrib-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
  }

  .contrib-header span:nth-child(n+3),
  .contrib-row span:nth-child(n+3) {
    font-size: 0.8rem;
  }
}

/* Actions */
.action-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.action-item {
  padding: 1rem;
  margin-bottom: 0.75rem;
  border-radius: 8px;
  background: var(--surface-2);
  border-left: 3px solid var(--border);
}

.action-item--critical { border-left-color: var(--negative); }
.action-item--high { border-left-color: var(--warning); }
.action-item--medium { border-left-color: var(--primary); }
.action-item--low { border-left-color: var(--positive); }

.action-item p {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.action-how {
  font-style: italic;
}

.strategy-block {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.strategy-block:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.strategy-ev {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--positive);
}

.psy-check {
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
}

.psy-q {
  margin: 0 0 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.psy-hint {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.psy-hint--warn {
  color: rgba(255, 176, 32, 0.9);
}

.card--warn {
  border-color: rgba(255, 176, 32, 0.35);
}

.card--trigger {
  border-color: rgba(108, 140, 255, 0.35);
}

.card--stress {
  border-color: rgba(61, 214, 140, 0.35);
}

.stress-compare {
  display: grid;
  grid-template-columns: 1fr auto 1fr 1fr;
  gap: 0.75rem;
  align-items: center;
  margin: 1.25rem 0;
}

@media (max-width: 640px) {
  .stress-compare {
    grid-template-columns: 1fr 1fr;
  }

  .stress-compare-arrow {
    display: none;
  }
}

.stress-compare-item {
  padding: 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-align: center;
}

.stress-compare-item--sim {
  border-color: rgba(61, 214, 140, 0.4);
}

.stress-compare-item--baseline {
  border-color: rgba(108, 140, 255, 0.35);
}

.stress-compare-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stress-compare-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stress-compare-arrow {
  font-size: 1.25rem;
  color: var(--text-muted);
  text-align: center;
}

.stress-meta {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.stress-verdict {
  padding: 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  border-left: 3px solid var(--border);
}

.stress-verdict strong {
  display: block;
  margin-bottom: 0.35rem;
}

.stress-verdict p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.stress-verdict--positive { border-left-color: var(--positive); }
.stress-verdict--neutral { border-left-color: var(--primary); }
.stress-verdict--negative { border-left-color: var(--negative); }
.stress-verdict--warn { border-left-color: var(--warning); }

.trigger-entries {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.trigger-entry {
  padding: 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.trigger-entry--filled {
  border-left: 3px solid var(--primary);
}

.trigger-entry--empty {
  border-left: 3px dashed var(--border);
  opacity: 0.85;
}

.trigger-entry h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.trigger-quote {
  margin: 0;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--primary);
  background: rgba(108, 140, 255, 0.08);
  border-radius: 0 6px 6px 0;
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.trigger-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.trigger-corrections-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.trigger-corrections {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.trigger-correction {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.trigger-correction strong {
  display: block;
  margin-bottom: 0.25rem;
}

.trigger-correction-source {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  color: var(--primary);
}

.trigger-correction p {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* Footer */
.app-footer {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.65rem 1.5rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: #5a7aee;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.step-content {
  min-height: 280px;
}

.site-footer {
  position: relative;
  z-index: 1;
  max-width: 880px;
  margin: 2rem auto 0;
  padding: 0 1.25rem 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.site-footer p {
  margin: 0.25rem 0;
}

.site-footer-note {
  font-size: 0.75rem;
  opacity: 0.85;
}

.site-footer code {
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75rem;
}

