:root {
  color-scheme: light;
  --ink: #17211f;
  --muted: #65716d;
  --paper: #f4f3ed;
  --surface: #fffef9;
  --line: #d9ddd7;
  --accent: #0f766e;
  --accent-strong: #0a5d57;
  --accent-soft: #dff3ee;
  --indigo: #3949ab;
  --danger: #b43a43;
  --shadow: 0 16px 45px rgb(29 46 41 / 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, rgb(15 118 110 / 0.08), transparent 30rem),
    var(--paper);
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 0 3vw;
  color: #f8fffd;
  background: #132b27;
  border-bottom: 1px solid rgb(255 255 255 / 0.1);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  font-weight: 780;
  text-decoration: none;
  letter-spacing: -0.015em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 0.45);
  border-radius: 9px;
  color: #9ce8dc;
  font-family: Georgia, serif;
  font-size: 1.15rem;
}

.topbar nav { display: flex; align-items: center; gap: 0.35rem; }
.topbar nav a {
  padding: 0.55rem 0.78rem;
  border-radius: 8px;
  color: #c9d8d4;
  font-size: 0.89rem;
  text-decoration: none;
}
.topbar nav a:hover, .topbar nav a.active { color: white; background: rgb(255 255 255 / 0.09); }

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.62rem 0.92rem;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 720;
  line-height: 1;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: 0.56; }
.button-primary { color: white; background: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.button-secondary { color: var(--accent-strong); background: var(--accent-soft); border-color: #b7dfd6; }
.button-quiet { color: #38534d; background: white; border-color: var(--line); }
.button.small { min-height: 32px; padding: 0.42rem 0.68rem; font-size: 0.82rem; }

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 820;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.demo-shell { width: min(1760px, 100%); margin: 0 auto; padding: 2rem 2.2vw 3rem; }
.demo-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.25rem;
}
.demo-intro h1 { max-width: 780px; margin: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(2rem, 3vw, 3.3rem); font-weight: 500; letter-spacing: -0.035em; }
.demo-intro p:not(.eyebrow) { max-width: 780px; margin: 0.7rem 0 0; color: var(--muted); line-height: 1.7; }
.demo-intro code, .principles-grid code { padding: 0.08rem 0.28rem; color: var(--accent-strong); background: var(--accent-soft); border-radius: 5px; }
.flow { flex: 0 0 auto; display: flex; align-items: center; gap: 0.45rem; padding: 0.7rem; border: 1px solid var(--line); border-radius: 12px; background: rgb(255 254 249 / 0.76); }
.flow span { padding: 0.38rem 0.5rem; color: #39504a; font-size: 0.75rem; font-weight: 740; white-space: nowrap; }
.flow b { color: #9aa6a2; font-weight: 500; }

.workspace {
  display: grid;
  grid-template-columns: minmax(210px, 0.64fr) minmax(500px, 1.75fr) minmax(320px, 1.05fr);
  align-items: start;
  gap: 1rem;
}
.control-panel, .editor-panel, .xml-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.control-panel, .xml-panel { position: sticky; top: 1rem; padding: 1rem; }
.editor-panel { min-height: 620px; padding: 1rem; }
.panel-heading { margin-bottom: 0.9rem; }
.panel-heading h2 { margin: 0; font-size: 1.05rem; }
.preview-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.button-stack { display: grid; gap: 0.5rem; margin-top: 0.9rem; }

.field { display: grid; gap: 0.32rem; min-width: 0; }
.field > span { color: #596963; font-size: 0.75rem; font-weight: 760; letter-spacing: 0.025em; }
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 40px;
  padding: 0.55rem 0.68rem;
  border: 1px solid #cbd2ce;
  border-radius: 8px;
  color: var(--ink);
  background: white;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(15 118 110 / 0.12); }
.field input[readonly] { color: #52615c; background: #edf1ee; }
.field input[data-x-invalid] { border-color: var(--danger); box-shadow: 0 0 0 3px rgb(180 58 67 / 0.1); }
.grow { flex: 1 1 220px; }
.xst-field-error { color: var(--danger); font-size: 0.72rem; font-weight: 680; }

.connection-meta { margin: 1rem 0 0; padding: 0.8rem 0 0; border-top: 1px solid var(--line); }
.connection-meta div { display: grid; grid-template-columns: 1fr; gap: 0.15rem; margin-bottom: 0.7rem; }
.connection-meta dt { color: #7b8883; font-size: 0.7rem; font-weight: 760; text-transform: uppercase; }
.connection-meta dd { margin: 0; overflow-wrap: anywhere; color: #344b45; font-size: 0.77rem; }
.connection-meta code { font-size: 0.72rem; }
.status { margin-top: 0.8rem; padding: 0.68rem 0.72rem; border-radius: 8px; color: #40534e; background: #edf1ef; font-size: 0.78rem; line-height: 1.45; }
.status[data-kind="success"] { color: #116149; background: #e2f4eb; }
.status[data-kind="error"] { color: #8d2931; background: #fae8e9; }

.editor-mount[aria-busy="true"] { min-height: 560px; display: grid; place-items: center; color: var(--muted); }
.editor-mount[aria-busy="true"]::before { content: "正在展開 XML templates…"; }
.library-card { display: grid; gap: 0.9rem; }
.library-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 0.35rem 0.25rem 0.8rem; border-bottom: 1px solid var(--line); }
.library-heading > div { flex: 1; }
.field-title input { min-height: 48px; border: 0; border-bottom: 1px solid #b8c3be; border-radius: 0; padding-left: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 1.75rem; }
.metadata { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.55fr); gap: 0.7rem; padding: 0.78rem; border: 1px dashed #c8d3ce; border-radius: 11px; background: #f7f8f4; }
.shelf-list { display: grid; gap: 0.8rem; }
.shelf-card { padding: 0.85rem; border: 1px solid #cbd4d0; border-left: 4px solid var(--accent); border-radius: 12px; background: #fbfcf8; }
.fragment-heading { display: flex; align-items: end; gap: 0.7rem; margin-bottom: 0.75rem; }
.fragment-actions { display: flex; gap: 0.3rem; }
.icon-button { width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0; border: 1px solid #cbd3d0; border-radius: 7px; color: #425650; background: white; cursor: pointer; font-weight: 800; }
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.icon-button.danger:hover { border-color: var(--danger); color: var(--danger); }
.book-list { display: grid; gap: 0.48rem; }
.book-card { display: flex; align-items: end; gap: 0.55rem; padding: 0.62rem; border: 1px solid #dfe3df; border-radius: 9px; background: white; }
.book-fields { min-width: 0; flex: 1; display: flex; align-items: start; gap: 0.55rem; }
.book-fields .isbn-field { flex: 0 1 155px; }
.book-actions { flex: 0 0 auto; padding-bottom: 0.02rem; }
.shelf-card > .button { margin-top: 0.62rem; }
[data-x-ref], [x\:ref], [_REF] { display: none !important; }

.xml-panel pre {
  max-width: 100%;
  min-height: 530px;
  max-height: calc(100vh - 230px);
  margin: 0;
  padding: 0.9rem;
  overflow: auto;
  border-radius: 10px;
  color: #d7ece6;
  background: #122520;
  font: 0.73rem/1.62 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  tab-size: 2;
  white-space: pre;
}

.landing-page { background: #f3f1e8; }
.landing-shell { width: min(1380px, 92vw); margin: 0 auto; padding: clamp(3rem, 8vw, 8rem) 0 5rem; }
.hero-section { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(420px, 0.9fr); align-items: center; gap: clamp(2rem, 6vw, 7rem); }
.hero-copy h1 { max-width: 780px; margin: 0; font: 500 clamp(3rem, 6vw, 6.2rem)/0.98 Georgia, "Noto Serif TC", serif; letter-spacing: -0.055em; }
.hero-lead { max-width: 720px; margin: 1.5rem 0 0; color: #53615d; font-size: clamp(1rem, 1.4vw, 1.25rem); line-height: 1.8; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1.8rem; }
.architecture-card { display: grid; gap: 0.6rem; padding: 1.2rem; border: 1px solid #cbd4ce; border-radius: 24px; background: rgb(255 254 249 / 0.78); box-shadow: var(--shadow); }
.architecture-card > div { display: grid; grid-template-columns: 46px 1fr; gap: 0 0.7rem; align-items: center; padding: 0.8rem; border: 1px solid #dde2dd; border-radius: 13px; background: white; }
.architecture-card > div.accent { border-color: #8fc9bc; background: var(--accent-soft); }
.architecture-card small { grid-row: 1 / span 2; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: white; background: #28453e; font: 700 1rem Georgia, serif; }
.architecture-card strong { font-size: 0.94rem; }
.architecture-card span { color: var(--muted); font-size: 0.78rem; }
.architecture-card > b { justify-self: center; color: #8d9a95; font-weight: 500; }
.principles-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; margin-top: clamp(4rem, 8vw, 8rem); }
.principles-grid article { padding: 1.2rem; border-top: 1px solid #9caaa4; }
.principles-grid .number { color: var(--accent); font: 600 0.76rem Georgia, serif; }
.principles-grid h2 { margin: 1.5rem 0 0.55rem; font: 500 1.35rem Georgia, serif; }
.principles-grid p { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.65; }

@media (max-width: 1250px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr); }
  .xml-panel { position: static; grid-column: 1 / -1; }
  .xml-panel pre { min-height: 320px; max-height: 520px; }
  .hero-section { grid-template-columns: 1fr; }
  .architecture-card { grid-template-columns: repeat(7, auto); align-items: center; }
  .architecture-card > b { transform: rotate(-90deg); }
}

@media (max-width: 780px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 0.5rem; padding: 0.85rem 1rem; }
  .topbar nav { max-width: 100%; overflow-x: auto; }
  .demo-shell { padding: 1.25rem 0.75rem 2rem; }
  .demo-intro { align-items: stretch; flex-direction: column; }
  .flow { overflow-x: auto; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .control-panel { position: static; }
  .xml-panel { grid-column: auto; }
  .metadata { grid-template-columns: 1fr; }
  .book-card, .book-fields { align-items: stretch; flex-direction: column; }
  .book-fields .grow { flex: 0 0 auto; }
  .book-fields .isbn-field { flex-basis: auto; }
  .book-actions { align-self: end; }
  .landing-shell { width: min(92vw, 700px); padding-top: 3rem; }
  .hero-section { grid-template-columns: 1fr; }
  .hero-copy h1 { font-size: clamp(2.75rem, 14vw, 5rem); }
  .architecture-card { grid-template-columns: 1fr; }
  .architecture-card > b { transform: none; }
  .principles-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .principles-grid { grid-template-columns: 1fr; }
  .library-heading { align-items: stretch; flex-direction: column; }
  .fragment-heading { align-items: stretch; flex-direction: column; }
  .fragment-heading .grow { flex: 0 0 auto; }
  .fragment-actions { align-self: end; }
}
