/* 格物 · 能源智能体演示 — crayon statechart look */
@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400&family=Ma+Shan+Zheng&family=Noto+Serif+SC:wght@400;600;700&family=ZCOOL+XiaoWei&display=swap');

:root {
  --paper: #e9e3d6;
  --card: #fbf7ec;
  --card-2: #f5f1e8;
  --ink: #2b2622;
  --ink-2: #6b625a;
  --rule: #d6cdbd;
  --navy: #2140d6;
  --navy-d: #16246e;
  --pink: #d6336c;
  --pink-hot: #e8175d;
  --guard: #d81b4a;
  --ok: #178a9a;
  --straw: #f5c935;
  --cream: #fbeccb;
  --sky: #bcd6fb;
  --mint: #9ff0d4;
  --lilac: #a7a2ee;
  --hand: 'ZCOOL XiaoWei', 'Noto Serif SC', 'Kaiti SC', serif;
  --brush: 'Ma Shan Zheng', 'ZCOOL XiaoWei', cursive;
  --serif: 'Noto Serif SC', 'Songti SC', serif;
  --mono: 'Courier Prime', ui-monospace, Menlo, monospace;
  --chapter: 0;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 var(--serif);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--navy); }

/* ---- paper grain ---- */
.grain {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 0;
  opacity: .35;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(60,40,10,.04) 0 1px, transparent 2px),
    radial-gradient(circle at 80% 70%, rgba(60,40,10,.035) 0 1px, transparent 2px),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

/* ---- floating doodles ---- */
.doodles {
  pointer-events: none;
  position: fixed; inset: 0; z-index: 1;
  overflow: hidden;
}
.doodles svg {
  position: absolute;
  opacity: .55;
  animation: floaty 8s ease-in-out infinite;
}
.doodles .d1 { left: 2%; top: 12%; width: 72px; animation-delay: 0s; }
.doodles .d2 { right: 3%; top: 18%; width: 64px; animation-delay: -2s; }
.doodles .d3 { left: 4%; bottom: 14%; width: 58px; animation-delay: -4s; }
.doodles .d4 { right: 5%; bottom: 18%; width: 70px; animation-delay: -1.5s; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}

/* ---- shell ---- */
.app {
  position: relative; z-index: 2;
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 18px 8px;
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 2px 10px;
  border-bottom: 1.5px dashed var(--rule);
}
.brand {
  font-family: var(--hand);
  font-size: 18px;
  color: var(--navy);
  letter-spacing: .02em;
}
.brand em {
  font-style: normal;
  color: var(--pink);
  font-family: var(--mono);
  font-size: 12px;
  margin-left: 8px;
  letter-spacing: 0;
}
.topbar .spacer { flex: 1; }
.icon-btn {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
  font-family: var(--mono);
  font-size: 13px;
  box-shadow: 2px 2px 0 rgba(43,38,34,.08);
}
.icon-btn:hover { background: #fffaf0; }
.icon-btn:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }

/* ---- stage ---- */
.stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.chapter {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateX(28px);
  transition: opacity .35s ease, transform .4s cubic-bezier(.2,.8,.2,1);
  padding: 18px 8px 8px;
  overflow: auto;
}
.chapter.active {
  opacity: 1;
  pointer-events: auto;
  transform: none;
  z-index: 2;
}
.chapter.leave-left { transform: translateX(-28px); opacity: 0; }
.chapter.leave-right { transform: translateX(28px); opacity: 0; }

/* ---- chapter header ---- */
.ch-head {
  margin-bottom: 14px;
  flex-shrink: 0;
}
.ch-series {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  letter-spacing: .04em;
}
.ch-title {
  font-family: var(--hand);
  font-size: clamp(28px, 4.2vw, 42px);
  color: var(--navy);
  margin: 2px 0 0;
  line-height: 1.15;
  letter-spacing: .02em;
}
.ch-sub {
  font-family: var(--serif);
  font-size: clamp(15px, 2vw, 18px);
  color: var(--ink-2);
  margin: 4px 0 0;
}
.ch-tagline {
  display: inline-block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--pink);
  background: rgba(214,51,108,.08);
  border: 1px dashed var(--pink);
  padding: 2px 10px;
  border-radius: 999px;
  transform: rotate(-1.2deg);
}

/* ---- caption / typewriter ---- */
.caption {
  margin-top: auto;
  flex-shrink: 0;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 3px 3px 0 rgba(43,38,34,.06);
  min-height: 64px;
}
.caption .tag {
  font-family: var(--mono);
  color: var(--pink);
  white-space:nowrap;
  padding-top: 3px;
  font-size: 13px;
}
.caption .note {
  flex: 1;
  font-family: var(--hand);
  font-size: clamp(18px, 2.4vw, 24px);
  line-height: 1.4;
  color: var(--ink);
}
.caption .note .cursor {
  display: inline-block;
  width: 2px; height: .9em;
  background: var(--pink);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- ticket / state cards ---- */
.ticket {
  position: relative;
  background: var(--card);
  border: 2px solid var(--navy);
  border-radius: 10px;
  padding: 14px 16px 12px;
  box-shadow: 3px 4px 0 rgba(33,64,214,.12);
  transform: rotate(var(--rot, -1deg));
  transition: transform .25s ease, box-shadow .25s, background .25s, border-color .25s;
  cursor: default;
  animation: wobble-card 3.2s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}
.ticket:nth-child(even) { --rot: 1.2deg; }
.ticket:nth-child(3n) { --rot: -.6deg; }
.ticket .pin {
  position: absolute;
  top: -7px; left: 50%;
  width: 14px; height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 18%, var(--pin, var(--pink)) 22% 100%);
  box-shadow: 0 2px 0 rgba(0,0,0,.15), inset 0 -2px 0 rgba(0,0,0,.12);
  z-index: 2;
}
.ticket .tag {
  position: absolute;
  top: 8px; right: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--pink);
  background: #fff0f4;
  border: 1px solid var(--pink);
  padding: 1px 6px;
  border-radius: 4px;
  transform: rotate(3deg);
}
.ticket .label {
  font-family: var(--hand);
  font-size: clamp(16px, 2vw, 20px);
  color: var(--navy);
  line-height: 1.25;
  margin-top: 4px;
}
.ticket .hint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 6px;
}
.ticket.clickable { cursor: pointer; }
.ticket.clickable:hover {
  background: #fffaf0;
  transform: rotate(0deg) translateY(-3px) scale(1.02);
  box-shadow: 4px 8px 0 rgba(33,64,214,.14);
}
.ticket.active, .ticket.on {
  border-color: var(--pink);
  background: #fff5f8;
  box-shadow: 0 0 0 4px rgba(214,51,108,.22), 3px 4px 0 rgba(214,51,108,.15);
  animation: none;
}
.ticket.active::after, .ticket.on::after {
  content: "";
  position: absolute; inset: -6px;
  border: 2.5px solid var(--pink);
  border-radius: 14px;
  pointer-events: none;
  animation: ring-draw .45s ease-out;
}
.ticket.done {
  border-color: var(--ok);
  opacity: .85;
}
.ticket.lit {
  border-color: var(--pink);
  background: #fff5f8;
  box-shadow: 0 0 0 3px rgba(214,51,108,.18);
}
@keyframes wobble-card {
  0%, 100% { transform: rotate(var(--rot, -1deg)); }
  25% { transform: rotate(calc(var(--rot, -1deg) + .6deg)); }
  75% { transform: rotate(calc(var(--rot, -1deg) - .5deg)); }
}
@keyframes ring-draw {
  from { opacity: 0; transform: scale(.92); }
  to { opacity: 1; transform: scale(1); }
}

/* stroke wobble on SVG borders */
@keyframes stroke-boil {
  0%, 100% { stroke-dashoffset: 0; }
  50% { stroke-dashoffset: 3; }
}

/* ---- grids ---- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-content: start;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-content: start;
}
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  align-content: start;
}
@media (max-width: 800px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

/* ---- cover ---- */
.cover-hero {
  flex: 1;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 20px;
  align-items: center;
  min-height: 0;
}
.cover-copy .series {
  font-family: var(--mono);
  color: var(--ink-2);
  font-size: 13px;
}
.cover-copy h1 {
  font-family: var(--hand);
  font-size: clamp(36px, 5.5vw, 56px);
  color: var(--navy);
  margin: 6px 0 0;
  line-height: 1.12;
}
.cover-copy .big-sub {
  font-family: var(--brush);
  font-size: clamp(22px, 3vw, 32px);
  color: var(--ink);
  margin: 10px 0 0;
}
.cover-copy .pill-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 16px;
}
.pill {
  font-family: var(--mono);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--navy);
  background: var(--card);
  color: var(--navy);
}
.pill.pink {
  border-color: var(--pink);
  color: var(--pink);
  background: #fff0f4;
}
.cover-art {
  position: relative;
  height: min(420px, 50vh);
  display: flex; align-items: center; justify-content: center;
}
.cover-art .poster {
  width: 100%;
  max-width: 380px;
  aspect-ratio: 3/4;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 6px 8px 0 rgba(43,38,34,.1);
  position: relative;
  overflow: hidden;
  transform: rotate(1.5deg);
}
.cover-art .poster svg { width: 100%; height: 100%; display: block; }
@media (max-width: 800px) {
  .cover-hero { grid-template-columns: 1fr; }
  .cover-art { height: 240px; }
}

/* ---- statechart board ---- */
.board {
  position: relative;
  flex: 1;
  min-height: 220px;
  background: linear-gradient(180deg, rgba(255,255,255,.25), transparent);
  border: 1.5px dashed var(--rule);
  border-radius: 12px;
  padding: 20px 12px 16px;
  margin-bottom: 12px;
}
.board .nodes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  position: relative;
  z-index: 2;
}
.board .nodes.cols-3 { grid-template-columns: repeat(3, 1fr); }
.board .nodes.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 700px) {
  .board .nodes, .board .nodes.cols-3, .board .nodes.cols-5 {
    grid-template-columns: 1fr 1fr;
  }
}
.board svg.wires {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}
.board svg.wires path {
  fill: none;
  stroke: var(--navy);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 1 0;
  animation: stroke-boil .2s steps(2) infinite;
}
.board svg.wires .bead {
  fill: var(--pink);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.2));
}

/* ---- play controls ---- */
.play-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.play-btn {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--pink);
  color: #fff;
  border: 1.5px solid var(--navy-d);
  border-radius: 8px;
  padding: 8px 16px;
  min-height: 40px;
  box-shadow: 2px 2px 0 rgba(43,38,34,.15);
  letter-spacing: .02em;
}
.play-btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.play-btn.ghost {
  background: var(--card);
  color: var(--ink);
  border-color: var(--ink);
}
.play-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.demo-badge {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  border: 1px dashed var(--ink-2);
  padding: 3px 8px;
  border-radius: 4px;
}

/* ---- chat bubbles ---- */
.chat {
  display: flex; flex-direction: column; gap: 8px;
  max-width: 420px;
}
.bubble {
  align-self: flex-start;
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 14px 14px 14px 4px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
  box-shadow: 2px 2px 0 rgba(43,38,34,.06);
}
.bubble.user {
  align-self: flex-end;
  border-radius: 14px 14px 4px 14px;
  background: #eef2ff;
  border-color: var(--navy);
  color: var(--navy-d);
}
.bubble.agent {
  background: #fff8ec;
}
.bubble:hover {
  transform: translateY(-2px);
  border-color: var(--pink);
  box-shadow: 3px 4px 0 rgba(214,51,108,.12);
}
.bubble.playing {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(214,51,108,.2);
}
.bubble .who {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  margin-bottom: 2px;
}

/* ---- tabs ---- */
.tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px;
}
.tab {
  font-family: var(--mono);
  font-size: 13px;
  padding: 7px 14px;
  background: var(--card-2);
  border: 1.5px solid var(--rule);
  border-radius: 999px;
  color: var(--ink-2);
}
.tab:hover { border-color: var(--ink); color: var(--ink); }
.tab.on {
  background: var(--navy);
  color: var(--card);
  border-color: var(--navy);
}
.tab-panel { display: none; }
.tab-panel.on { display: block; }

/* ---- timeline ---- */
.timeline {
  position: relative;
  padding: 8px 0 8px 28px;
  border-left: 3px solid var(--navy);
  margin: 8px 0 16px 12px;
}
.timeline .step {
  position: relative;
  margin-bottom: 18px;
  padding: 12px 14px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  transform: rotate(-.4deg);
}
.timeline .step:nth-child(even) { transform: rotate(.5deg); }
.timeline .step::before {
  content: "";
  position: absolute;
  left: -37px; top: 16px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--pink);
  border: 2px solid var(--card);
  box-shadow: 0 0 0 2px var(--navy);
}
.timeline .step h3 {
  font-family: var(--hand);
  font-size: 20px;
  color: var(--navy);
  margin: 0 0 4px;
}
.timeline .step p { margin: 0; color: var(--ink-2); font-size: 15px; }
.callout {
  background: #fff0f4;
  border: 1.5px dashed var(--guard);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--ink);
}
.callout strong { color: var(--guard); font-family: var(--hand); }

/* ---- expand cards ---- */
.expand-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .35s ease, opacity .3s;
  opacity: 0;
}
.ticket.open .expand-body {
  max-height: 120px;
  opacity: 1;
  margin-top: 8px;
}
.ticket.open { --rot: 0deg; border-color: var(--pink); }

/* ---- CTA ---- */
.cta-stack {
  display: flex; flex-direction: column; gap: 12px;
  align-items: flex-start;
  margin-top: 8px;
}
.cta-big {
  font-family: var(--hand);
  font-size: clamp(22px, 3vw, 30px);
  background: var(--pink);
  color: #fff;
  border: 2px solid var(--navy-d);
  border-radius: 12px;
  padding: 14px 28px;
  box-shadow: 4px 5px 0 rgba(43,38,34,.18);
  letter-spacing: .03em;
}
.cta-big:hover { transform: translateY(-2px); filter: brightness(1.05); }
.check-list {
  list-style: none; padding: 0; margin: 0;
}
.check-list li {
  position: relative;
  padding: 8px 0 8px 28px;
  font-size: 17px;
  border-bottom: 1px dashed var(--rule);
}
.check-list li::before {
  content: "○";
  position: absolute; left: 0; color: var(--pink);
  font-family: var(--mono);
}

/* ---- bottom nav ---- */
.bottom {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px 4px;
  border-top: 1.5px dashed var(--rule);
  flex-shrink: 0;
}
.nav-btn {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  min-height: 40px;
  min-width: 40px;
  box-shadow: 2px 2px 0 rgba(43,38,34,.08);
}
.nav-btn:hover:not(:disabled) { background: #fffaf0; }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.dots {
  flex: 1;
  display: flex; justify-content: center; gap: 7px;
  flex-wrap: wrap;
}
.dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: transparent;
  padding: 0;
  transition: background .2s, transform .2s, border-color .2s;
}
.dot:hover { transform: scale(1.25); }
.dot.on {
  background: var(--pink);
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(214,51,108,.2);
}
.dot.visited { background: var(--navy); border-color: var(--navy); }
.page-num {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
  min-width: 48px;
  text-align: right;
}

/* ---- drawer ---- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(43,38,34,.35);
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity .25s;
}
.drawer-backdrop.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(340px, 92vw);
  background: var(--card);
  border-left: 2px solid var(--ink);
  z-index: 50;
  padding: 20px 16px;
  transform: translateX(105%);
  transition: transform .3s cubic-bezier(.2,.8,.2,1);
  overflow: auto;
  box-shadow: -8px 0 24px rgba(0,0,0,.12);
}
.drawer.on { transform: none; }
.drawer h2 {
  font-family: var(--hand);
  font-size: 24px;
  color: var(--navy);
  margin: 0 0 12px;
}
.drawer ol { list-style: none; padding: 0; margin: 0; }
.drawer li {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1.5px solid transparent;
}
.drawer li:hover { background: rgba(255,255,255,.6); }
.drawer li.on {
  background: #fff;
  border-color: var(--pink);
  box-shadow: inset 3px 0 0 var(--pink);
}
.drawer li .num { font-family: var(--mono); color: var(--pink); font-size: 13px; padding-top: 3px; }
.drawer li .t { font-family: var(--hand); font-size: 17px; color: var(--navy); }
.drawer .keys {
  margin-top: 20px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  line-height: 1.7;
}

/* ---- result table (case A) ---- */
.result-panel {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .35s, transform .35s;
  max-height: 180px;
  overflow: auto;
}
.result-panel.show {
  opacity: 1;
  transform: none;
}
.result-panel table {
  width: 100%;
  border-collapse: collapse;
}
.result-panel th, .result-panel td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px dashed var(--rule);
}
.result-panel th { color: var(--navy); }
.result-panel .hint-row {
  color: var(--ink-2);
  font-size: 11px;
  margin-top: 6px;
}

/* ---- split layouts ---- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  flex: 1;
  min-height: 0;
  align-items: start;
}
@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; }
}

/* ---- kb flow icons ---- */
.flow-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  justify-content: center;
  margin: 12px 0;
}
.flow-arrow {
  font-family: var(--mono);
  color: var(--navy);
  font-size: 22px;
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .ticket { animation: none; }
  .doodles svg { animation: none; }
  .board svg.wires path { animation: none; }
  .chapter { transition: none; }
}

/* projector / fullscreen friendly */
@media (min-height: 900px) {
  .ch-title { font-size: 46px; }
  .caption .note { font-size: 26px; }
}
