:root {
  --paper: #f5f4ed;
  --paper-raise: #faf9f5;
  --warm-sand: #e8e6dc;
  --brand: #1b365d;
  --brand-soft: #e4ecf5;
  --ink: #141413;
  --ink-soft: #504e49;
  --ink-faint: #6b6a64;
  --line: #e8e6dc;
  --line-soft: #e5e3d8;
  --line-strong: #d0dce9;
  --graphite: #30302e;
  --shadow: 0 4px 24px rgba(20, 20, 19, 0.05);
  --radius: 8px;
  --serif: "TsangerJinKai02", "Noto Serif TC", "Noto Serif CJK TC", "Songti TC", "Songti SC", Georgia, serif;
  --mono: "JetBrains Mono", "SF Mono", Consolas, "TsangerJinKai02", "Noto Serif TC", monospace;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(#e8e6dc 1px, transparent 1px),
    linear-gradient(90deg, #e8e6dc 1px, transparent 1px),
    var(--paper);
  background-size: 56px 56px;
  font-family: var(--serif);
}

button {
  font: inherit;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: #f5f4ed;
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow,
.section-label,
.rail__label,
.node-tag {
  margin: 0 0 8px;
  color: var(--ink-faint);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 500;
  line-height: 1.15;
}

h2 {
  font-size: clamp(26px, 3.35vw, 42px);
  font-weight: 500;
  line-height: 1.08;
  max-width: 820px;
}

.topbar__actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button,
.text-button,
.node-chip {
  border: 1px solid var(--line);
  background: var(--paper-raise);
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
}

.text-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink-soft);
}

.icon-button:hover,
.text-button:hover,
.node-chip:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: var(--paper-raise);
  box-shadow: 0 4px 24px rgba(20, 20, 19, 0.05);
}

.workspace {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px 28px 18px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
  flex: 1;
}

.rail {
  border-right: 1px solid var(--line);
  padding-right: 20px;
}

.rail__section + .rail__section {
  margin-top: 24px;
}

.breadcrumb {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breadcrumb button,
.node-chip {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
}

.breadcrumb button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  border-radius: var(--radius);
}

.breadcrumb button[aria-current="page"] {
  background: var(--graphite);
  color: var(--paper-raise);
}

.node-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 280px);
  overflow: auto;
  padding-right: 4px;
}

.node-chip {
  display: grid;
  gap: 4px;
}

.node-chip small {
  color: var(--ink-faint);
}

.node-chip.is-active {
  border-color: var(--brand);
  box-shadow: inset 3px 0 0 var(--brand);
}

.stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raise);
  box-shadow: var(--shadow);
}

.stage-card {
  padding: 18px;
}

.stage-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.canvas-frame {
  position: relative;
  min-height: 440px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(#e8e6dc 1px, transparent 1px),
    linear-gradient(90deg, #e8e6dc 1px, transparent 1px),
    #faf9f5;
  background-size: 56px 56px;
}

.diagram {
  position: absolute;
  inset: 0;
}

.diagram svg {
  width: 100%;
  height: 100%;
  display: block;
}

.logic-flow {
  height: 100%;
  padding: 74px 34px 128px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.diagram:not(.has-drill) .logic-flow {
  padding-bottom: 34px;
}

.logic-flow__label {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
}

.logic-flow__steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px;
}

.logic-step {
  position: relative;
  min-height: 112px;
  padding: 14px 12px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raise);
  box-shadow: var(--shadow);
}

.logic-step__index {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.logic-step strong {
  display: block;
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.25;
}

.logic-step small {
  display: block;
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.35;
}

.hotspots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.drill-panel {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
  z-index: 2;
}

.drill-panel::before {
  content: "延伸探索";
  position: absolute;
  left: 2px;
  top: -22px;
  color: var(--ink-faint);
  font-size: 12px;
  font-weight: 500;
}

.drill-card {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raise);
  box-shadow: 0 4px 24px rgba(20, 20, 19, 0.05);
  color: var(--ink);
  cursor: pointer;
  pointer-events: auto;
  padding: 10px 12px;
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.drill-card:hover,
.drill-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: 0 4px 24px rgba(20, 20, 19, 0.08);
  outline: none;
}

.drill-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
  line-height: 1.25;
}

.drill-card span {
  display: block;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.35;
}

.caption-grid,
.below-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.caption-grid {
  margin-top: 18px;
}

.caption,
.takeaway {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.72;
  font-size: 16px;
}

.takeaway {
  color: var(--ink);
  font-weight: 500;
}

.below-grid .card {
  padding: 18px;
}

.stat-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat {
  border-left: 4px solid var(--stat-color, var(--brand));
  padding: 8px 10px;
  background: var(--paper);
}

.stat b {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.stat span {
  display: block;
  margin-top: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.35;
}

.detail-list {
  margin: 0;
  padding-left: 20px;
  color: var(--ink-soft);
  line-height: 1.65;
}

.detail-list li + li {
  margin-top: 8px;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px 22px;
  color: var(--ink-faint);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--paper-raise);
  background: var(--graphite);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  z-index: 20;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.presenting .topbar,
body.presenting .rail,
body.presenting .footer {
  display: none;
}

body.presenting .workspace {
  grid-template-columns: 1fr;
  width: 100%;
  max-width: none;
  padding: 16px;
}

body.presenting .canvas-frame {
  min-height: 62vh;
}

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

  .rail {
    order: 2;
    border-right: 0;
    padding-right: 0;
  }

  .stage {
    order: 1;
  }

  .breadcrumb,
  .node-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  .node-list {
    max-height: none;
  }

  .caption-grid,
  .below-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 16px;
  }

  .workspace {
    padding: 16px;
  }

  .stage-card__header {
    flex-direction: column;
  }

  .canvas-frame {
    min-height: 520px;
  }

  .diagram[data-diagram-type="hub"] svg {
    opacity: 0.42;
  }

  .diagram[data-diagram-type="hub"]::after {
    content: attr(data-center) "\A 五個壓力點形成一套系統";
    white-space: pre-line;
    position: absolute;
    top: 22px;
    left: 50%;
    width: min(220px, calc(100% - 36px));
    min-height: 96px;
    display: grid;
    place-items: center;
    border: 2px solid var(--brand);
    border-radius: 50%;
    background: var(--paper-raise);
    color: var(--ink);
    text-align: center;
    line-height: 1.5;
    box-shadow: var(--shadow);
    transform: translateX(-50%);
    z-index: 1;
  }

  .logic-flow {
    padding: 24px 12px 228px;
    justify-content: flex-start;
  }

  .diagram:not(.has-drill) .logic-flow {
    padding-bottom: 24px;
  }

  .logic-flow__steps {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .logic-step {
    min-height: auto;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    column-gap: 10px;
    padding: 10px;
  }

  .logic-step strong,
  .logic-step small {
    grid-column: 2;
    margin-top: 0;
  }

  .logic-step small {
    margin-top: 4px;
  }

  .drill-panel {
    left: 12px;
    right: 12px;
    bottom: 12px;
    grid-template-columns: 1fr;
  }

  .drill-card {
    min-height: 54px;
    padding: 8px 10px;
  }

  .footer {
    flex-direction: column;
    padding: 12px 16px 18px;
  }
}
