/* Tokens follow the "从AI到物理" design system: warm paper, glowing green, warm accents. */
:root {
  --paper: #F4F0E6;
  --paper-raised: #FBF8F1;
  --paper-line: #E3DCCB;
  --ink: #1F1E1B;
  --ink-muted: #6B6558;
  --green: #16A35C;
  --green-ink: #0F8A4A;
  --green-deep: #0B7A40;
  --electron: #3BE38A;
  --channel: #5BEFA0;
  --energized: #E5A23B;
  --clay: #D97757;
  --clay-ink: #B85C3C;
  --stone: #8C7B6B;
  --rose: #D9707F;
  --oxide: #CFE3D8;
  --metal: #8A8F96;
  --contact: #B8902C;
  --copper: #C87533;
  --shadow: #3B33261F;

  --radius-pill: 24px;
  --radius-sm: 8px;
  --radius-part: 6px;

  --sans: "Noto Sans SC", "PingFang SC", -apple-system, sans-serif;
  --num: "Space Grotesk", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in: cubic-bezier(.7, 0, .84, 0);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.7 var(--sans);
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 96px 20px 64px;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--paper-line);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  transition: text-decoration-color .15s;
}
a:hover { text-decoration-color: var(--electron); }

h1 {
  font: 700 2rem/1.15 var(--num);
  letter-spacing: -0.01em;
}
h1::after {
  content: "";
  display: block;
  width: 40px;
  height: 4px;
  margin-top: 14px;
  border-radius: 2px;
  background: var(--green);
}
h2 {
  font: 500 0.8rem/1 var(--num);
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 28px;
}
h3 { font: 700 1.1rem/1.4 var(--num); }

.lede { margin-top: 18px; color: var(--ink-muted); max-width: 600px; }

.links { display: flex; flex-wrap: wrap; gap: 20px; margin-top: 18px; font-size: 0.95rem; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  padding: 4px 14px 4px 10px;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-pill);
  background: var(--paper-raised);
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--electron);
  box-shadow: 0 0 0 2px #3BE38A33, 0 0 10px var(--electron);
  flex: none;
}
.dot.pulse { animation: pulse 2.4s var(--ease-out) infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px #3BE38A33, 0 0 6px var(--electron); }
  50% { box-shadow: 0 0 0 5px #3BE38A22, 0 0 14px var(--electron); }
}

section { margin-top: 88px; }

article + article { margin-top: 64px; }
article p { margin-top: 8px; }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.meta { color: var(--ink-muted); font: 0.875rem var(--num); white-space: nowrap; }
.sub { color: var(--ink-muted); font-size: 0.95rem; }
.tags { color: var(--ink-muted); font-size: 0.85rem; }

/* ---------- Visualization panels ---------- */

.viz {
  margin-top: 20px;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  box-shadow: 0 1px 0 var(--paper-line), 0 12px 32px -20px var(--shadow);
  overflow: hidden;
}
.viz-stage {
  position: relative;
  min-height: 220px;
  font-size: 0.85rem;
}
.viz figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--paper-line);
  color: var(--ink-muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 10px 1px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--paper-line);
  background: var(--paper);
  color: var(--ink);
  font: 500 0.72rem/1.6 var(--num);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge.live { color: var(--green-deep); border-color: #16A35C55; }
.badge.sim::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--stone);
}

/* Shared controls used inside the panels */
.viz-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--paper-line);
}
.viz-bar .spacer { flex: 1; }
.btn {
  appearance: none;
  border: 1px solid var(--paper-line);
  background: var(--paper);
  color: var(--ink);
  font: 500 0.78rem/1 var(--num);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--stone); }
.btn:focus-visible, .viz input:focus-visible, .viz select:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.btn.primary { background: var(--ink); color: var(--paper-raised); border-color: var(--ink); }
.btn.primary:hover { background: #33312c; }
.btn[aria-pressed="true"] { background: var(--oxide); border-color: var(--green); }
.viz select {
  font: 500 0.78rem var(--num);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}
.viz input[type="range"] { accent-color: var(--green); }

.readout { font: 700 1rem/1.2 var(--num); font-variant-numeric: tabular-nums; }
.readout-label { color: var(--ink-muted); font: 500 0.68rem/1.2 var(--num); letter-spacing: 0.1em; text-transform: uppercase; }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-pill);
  background: var(--paper-raised);
  font: 500 0.75rem/1.5 var(--num);
}

canvas.fill { display: block; width: 100%; }

/* ---------- More projects ---------- */

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px 28px;
  margin-top: 56px;
}
.grid article + article { margin-top: 0; }
.grid h3 { font-size: 1rem; }
.grid article > p { font-size: 0.92rem; color: var(--ink-muted); }
/* Cards in a row share a height and their panels line up at the bottom. */
.grid article { display: flex; flex-direction: column; }
.grid .viz { margin-top: auto; }
.grid article > p { margin-bottom: 14px; }
.grid .viz-stage { min-height: 0; height: 330px; overflow: hidden; }
/* Badge above the text so every caption is the same two lines. */
.grid .viz figcaption { flex-direction: column; align-items: flex-start; gap: 4px; }
/* Canvas MCP and Subway Surf share the game's 16:9 frame. */
.grid .viz[data-viz="canvasmcp"] .viz-stage,
.grid .viz[data-viz="subway"] .viz-stage { height: auto; aspect-ratio: 16 / 9; }

footer {
  margin-top: 96px;
  padding-top: 24px;
  border-top: 1px solid var(--paper-line);
  color: var(--ink-muted);
  font-size: 0.875rem;
}

@media (max-width: 640px) {
  main { padding: 56px 16px 48px; }
  .row { flex-direction: column; gap: 0; }
  .grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .dot.pulse { animation: none; }
}

.viz figcaption code { font: 0.78rem var(--mono); color: var(--ink); }

/* ---- Chat assistant ---- */
.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--paper-raised);
  font: 500 0.9rem/1 var(--num);
  box-shadow: 0 6px 24px var(--shadow);
  cursor: pointer;
  transition: transform .2s var(--ease-out);
}
.chat-launcher:hover { transform: translateY(-2px); }
.chat-launcher .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--electron);
  box-shadow: 0 0 8px var(--electron);
}
.chat-launcher.open { display: none; }

.chat-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 51;
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  background: var(--paper-raised);
  border: 1px solid var(--paper-line);
  border-radius: 16px;
  box-shadow: 0 16px 48px var(--shadow);
  overflow: hidden;
  animation: chat-in .25s var(--ease-out);
}
.chat-panel[hidden] { display: none; }
@keyframes chat-in {
  from { opacity: 0; transform: translateY(12px); }
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--paper-line);
}
.chat-head strong { display: block; font: 700 1rem/1.3 var(--num); }
.chat-head span { font-size: 0.75rem; color: var(--ink-muted); }
.chat-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.chat-close:hover { background: var(--paper); color: var(--ink); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.92rem;
  line-height: 1.6;
}
.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  overflow-wrap: anywhere;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper-raised);
  border-bottom-right-radius: 4px;
}
.chat-msg.user a { color: inherit; }
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--paper);
  border-bottom-left-radius: 4px;
}
.chat-msg.error { color: var(--clay-ink); }
.chat-msg p + p, .chat-msg p + ul, .chat-msg ul + p, .chat-msg p + ol, .chat-msg ol + p { margin-top: 8px; }
.chat-msg ul, .chat-msg ol { padding-left: 20px; }
.chat-msg code {
  font: 0.85em var(--mono);
  background: var(--paper-line);
  padding: 1px 5px;
  border-radius: 4px;
}
.chat-status {
  align-self: flex-start;
  font-size: 0.78rem;
  color: var(--green-ink);
}

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--stone);
  animation: typing 1s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: .3; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
}
.chat-suggestions[hidden] { display: none; }
.chat-suggestions button {
  padding: 6px 12px;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  font: 0.8rem/1.3 var(--sans);
  cursor: pointer;
}
.chat-suggestions button:hover { border-color: var(--green); color: var(--green-ink); }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--paper-line);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--paper-line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
}
.chat-form textarea:focus, .chat-draft input:focus, .chat-draft textarea:focus {
  outline: 2px solid var(--green);
  outline-offset: -1px;
}
.chat-send {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font: 700 1.1rem/1 var(--num);
  cursor: pointer;
}
.chat-send:disabled { opacity: .4; cursor: default; }

.chat-draft {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--green);
  border-radius: 12px;
  background: var(--paper-raised);
}
.chat-draft-title { font: 500 0.75rem/1.3 var(--num); color: var(--green-ink); text-transform: uppercase; letter-spacing: .08em; }
.chat-draft label { display: flex; flex-direction: column; gap: 2px; font-size: 0.75rem; color: var(--ink-muted); }
.chat-draft input, .chat-draft textarea {
  padding: 6px 8px;
  border: 1px solid var(--paper-line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 var(--sans);
  resize: vertical;
}
.chat-draft-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-draft-actions button {
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--green);
  color: #fff;
  font: 500 0.85rem/1 var(--num);
  cursor: pointer;
}
.chat-draft-actions button:disabled { opacity: .5; }
.chat-draft-status { font-size: 0.8rem; color: var(--ink-muted); }
.chat-draft.sent { border-color: var(--paper-line); }
.chat-draft.sent .chat-draft-status { color: var(--green-ink); }
.chat-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

@media (max-width: 640px) {
  .chat-launcher { right: 16px; bottom: 16px; }
  .chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .chat-panel, .typing i { animation: none; }
}
