:root {
  --paper: #f6f1e7;
  --paper-deep: #eee5d5;
  --surface: #fffdf8;
  --surface-muted: #f7f2e9;
  --ink: #2b2021;
  --ink-soft: #65595a;
  --vermilion: #742f3f;
  --vermilion-dark: #57212e;
  --gold: #9b711b;
  --gold-pale: #ead9a7;
  --line: #d9cebd;
  --success: #286347;
  --warning: #8a5a13;
  --danger: #a02e35;
  --focus: #1769aa;
  --shadow: 0 18px 48px rgba(55, 37, 30, 0.1);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 4%, rgba(155, 113, 27, 0.1), transparent 24rem),
    linear-gradient(180deg, var(--paper) 0, #faf7f0 40rem, var(--paper) 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.65;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.68; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 50;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--ink);
  color: white;
}
.skip-link:focus { top: 1rem; }

.site-header {
  border-bottom: 1px solid rgba(116, 47, 63, 0.17);
  background: rgba(255, 253, 248, 0.88);
  backdrop-filter: blur(14px);
}
.header-inner {
  width: min(1280px, calc(100% - 2rem));
  min-height: 88px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.9rem; }
.brand-seal {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 2px solid var(--vermilion);
  border-radius: 12px 12px 16px 12px;
  color: var(--vermilion);
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 1.75rem;
  font-weight: 700;
  transform: rotate(-2deg);
}
.brand h1, .intro-copy h2, .result-toolbar h2, .panel-title {
  margin: 0;
  font-family: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  letter-spacing: 0.04em;
}
.brand h1 { font-size: clamp(1.25rem, 3vw, 1.65rem); }
.eyebrow, .section-kicker {
  margin: 0;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}
.engine-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--surface);
  font-size: 0.85rem;
  white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(40, 99, 71, 0.13); }

.page-shell { width: min(1280px, calc(100% - 2rem)); margin: 2rem auto 4rem; }
.intro-panel {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(260px, 0.7fr) minmax(420px, 1.3fr);
  gap: 2rem;
  padding: clamp(1.5rem, 4vw, 2.75rem);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.intro-panel::before {
  content: "";
  position: absolute;
  right: -100px;
  top: -130px;
  width: 360px;
  height: 360px;
  border: 1px solid rgba(155, 113, 27, 0.16);
  border-radius: 50%;
  box-shadow: 0 0 0 42px rgba(155, 113, 27, 0.035), 0 0 0 86px rgba(116, 47, 63, 0.025);
  pointer-events: none;
}
.intro-copy { position: relative; z-index: 1; padding-top: 0.25rem; }
.intro-copy h2, .result-toolbar h2 { margin-top: 0.35rem; font-size: clamp(1.8rem, 4vw, 2.65rem); }
.intro-copy > p:last-child { max-width: 38rem; color: var(--ink-soft); }
.chart-form { position: relative; z-index: 1; }
.field-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 1.05rem; }
.field-wide { grid-column: auto; }
.field-group { display: flex; flex-direction: column; gap: 0.35rem; }
.field-group label { color: var(--ink); font-weight: 750; }
.optional { color: var(--ink-soft); font-size: 0.82rem; font-weight: 500; }
input, select {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.85rem;
  border: 1px solid #bfb3a2;
  border-radius: 10px;
  background: #fffefa;
  color: var(--ink);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
input:hover, select:hover { border-color: var(--gold); }
input:focus, select:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.13); outline: none; }
.field-help { color: var(--ink-soft); font-size: 0.78rem; line-height: 1.45; }
.advanced-panel { margin-top: 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-muted); }
.advanced-panel summary { min-height: 46px; padding: 0.7rem 0.9rem; font-weight: 700; cursor: pointer; }
.advanced-grid { padding: 0 0.9rem 1rem; grid-template-columns: repeat(3, 1fr); }
.form-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }
.button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.7rem 1.15rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 750;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-primary { color: white; background: var(--vermilion); box-shadow: 0 8px 18px rgba(116, 47, 63, 0.2); }
.button-primary:hover:not(:disabled) { background: var(--vermilion-dark); }
.button-secondary { border-color: #b8aa96; color: var(--ink); background: #fffefa; }
.button-secondary:hover:not(:disabled) { border-color: var(--gold); background: #fbf5e7; }
.button-copy { border-color: var(--gold); color: #5d420b; background: #fff9e8; }
.button-copy:hover:not(:disabled) { background: #f8edca; }
.error-message { margin-top: 1rem; padding: 0.8rem 1rem; border-left: 4px solid var(--danger); border-radius: 6px; background: #fff0f0; color: #7f2026; font-weight: 650; }

.loading-panel {
  min-height: 96px;
  margin-top: 1.25rem;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.loading-panel[hidden] { display: none; }
.loading-panel div { display: flex; flex-direction: column; }
.loading-panel span:not(.spinner) { color: var(--ink-soft); font-size: 0.9rem; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--gold-pale); border-top-color: var(--vermilion); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result-area { margin-top: 2rem; }
.result-area[hidden] { display: none; }
.result-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  background: linear-gradient(180deg, var(--paper) 70%, rgba(246, 241, 231, 0));
}
.result-toolbar h2 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
.result-subtitle { margin: 0.1rem 0 0; color: var(--ink-soft); font-size: 0.9rem; }
.copy-status { min-height: 1.6rem; color: var(--success); text-align: right; font-weight: 700; }

.summary-grid, .panel-grid { display: grid; gap: 1rem; }
.summary-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 1rem; }
.summary-card {
  min-height: 108px;
  padding: 1rem;
  border: 1px solid var(--line);
  border-top: 3px solid var(--gold);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(45, 32, 28, 0.045);
}
.summary-label { display: block; color: var(--ink-soft); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; }
.summary-value { display: block; margin-top: 0.2rem; color: var(--vermilion); font-family: "Noto Serif TC", "Songti TC", serif; font-size: 1.55rem; font-weight: 700; }
.summary-note { display: block; margin-top: 0.15rem; color: var(--ink-soft); font-size: 0.78rem; }
.panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.result-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 9px 24px rgba(55, 37, 30, 0.05);
}
.result-panel.full { grid-column: 1 / -1; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 1rem 1.15rem; border-bottom: 1px solid var(--line); background: var(--surface-muted); }
.panel-title { font-size: 1.12rem; }
.panel-meta { color: var(--ink-soft); font-size: 0.78rem; }
.panel-body { padding: 1rem 1.15rem; }
.definition-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem 1rem; margin: 0; }
.definition-grid > div { padding-bottom: 0.5rem; border-bottom: 1px dashed #ddd1c0; }
.definition-grid dt { color: var(--ink-soft); font-size: 0.78rem; font-weight: 700; }
.definition-grid dd { margin: 0.15rem 0 0; font-weight: 700; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.7rem 0.75rem; border-bottom: 1px solid #e5dccf; text-align: left; white-space: nowrap; }
th { color: #5c4b4d; background: #faf6ee; font-size: 0.78rem; letter-spacing: 0.04em; }
tbody tr:hover { background: #fcf8ef; }
.branch-large { color: var(--vermilion); font-family: "Noto Serif TC", "Songti TC", serif; font-size: 1.18rem; font-weight: 750; }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0.15rem 0.5rem; border-radius: 999px; background: #eee7da; color: #514547; font-size: 0.76rem; font-weight: 750; }
.badge.selected, .badge.valid { background: #e3f3e9; color: #1e6342; }
.badge.matched { background: #fff0c9; color: #77520d; }
.badge.rejected, .badge.void { background: #fbe4e4; color: #8a2730; }
.transmission-flow { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: stretch; gap: 0.65rem; }
.transmission-card { display: grid; place-items: center; min-height: 132px; padding: 0.9rem; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, #fffdf8, #f6efe3); text-align: center; }
.transmission-card strong { color: var(--vermilion); font-family: "Noto Serif TC", serif; font-size: 2rem; }
.transmission-card small { color: var(--ink-soft); }
.flow-arrow { align-self: center; color: var(--gold); font-size: 1.3rem; }
.notice { margin-bottom: 1rem; padding: 0.8rem 1rem; border-radius: 10px; background: #fff5d9; color: #68490d; }
.trace-list { margin: 0; padding: 0; list-style: none; }
.trace-item { display: grid; grid-template-columns: auto minmax(120px, 0.35fr) 1fr; gap: 0.75rem; align-items: start; padding: 0.75rem 0; border-bottom: 1px solid #e8dfd2; }
.trace-item:last-child { border-bottom: 0; }
.trace-rule { font-weight: 750; }
.trace-reason { color: var(--ink-soft); }
.validation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
.validation-item { display: flex; align-items: flex-start; gap: 0.55rem; padding: 0.65rem 0.75rem; border-radius: 9px; background: #edf7f1; color: #23573e; font-size: 0.86rem; }
.validation-check { flex: 0 0 auto; font-weight: 900; }
details.raw-details { border-top: 1px solid var(--line); }
.raw-details summary { min-height: 48px; padding: 0.7rem 1.15rem; cursor: pointer; font-weight: 750; }
pre { max-height: 520px; overflow: auto; margin: 0; padding: 1rem; background: #211c1c; color: #f6eee2; font: 0.78rem/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.site-footer { padding: 1.5rem 1rem 2.5rem; color: var(--ink-soft); text-align: center; font-size: 0.82rem; }
.site-footer p { margin: 0; }

@media (max-width: 1000px) {
  .intro-panel { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .page-shell, .header-inner { width: min(100% - 1.2rem, 1280px); }
  .header-inner { min-height: 76px; }
  .engine-badge { display: none; }
  .intro-panel { padding: 1.2rem; border-radius: 16px; }
  .field-grid, .advanced-grid, .panel-grid { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column-reverse; }
  .button { width: 100%; }
  .result-toolbar { align-items: flex-start; flex-direction: column; }
  .result-toolbar .button { width: 100%; }
  .copy-status { text-align: left; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .definition-grid, .validation-grid { grid-template-columns: 1fr; }
  .transmission-flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); justify-self: center; }
  .trace-item { grid-template-columns: auto 1fr; }
  .trace-reason { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .brand-seal { width: 44px; height: 44px; font-size: 1.4rem; }
  .brand .eyebrow { display: none; }
  .summary-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
