:root {
  --paper: #fffdf7;
  --paper-warm: #fff7e8;
  --surface: #ffffff;
  --ink: #26344c;
  --muted: #68758a;
  --line: #e6dfd3;
  --line-strong: #d7c9b6;
  --orange: #e97d32;
  --orange-dark: #bc5421;
  --gold: #f4c453;
  --teal: #2b988b;
  --teal-soft: #e3f5f1;
  --blue: #5574ca;
  --shadow: 0 22px 60px rgba(92, 66, 34, .13);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 4%, rgba(244, 196, 83, .2), transparent 24rem),
    radial-gradient(circle at 92% 16%, rgba(43, 152, 139, .12), transparent 28rem),
    linear-gradient(180deg, #fffdf9 0%, #f7f3eb 100%);
  line-height: 1.55;
}

button { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin-top: 0; }

.site-topbar {
  border-bottom-color: rgba(125, 99, 68, .13);
  color: var(--ink);
  background: rgba(255, 253, 247, .9);
}

.site-brand { color: var(--ink); }
.site-mark {
  border-color: rgba(233, 125, 50, .3);
  color: #753612;
  background: linear-gradient(145deg, #ffe39a, #f7b65b);
  box-shadow: 0 8px 20px rgba(199, 112, 35, .16);
}
.site-links a { color: #667184; }
.site-links a:hover,
.site-links a.active {
  border-color: #e5d7c5;
  color: #7a3b17;
  background: #fff3df;
}

.fraction-page {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.tool-heading {
  padding: 30px 0 18px;
  text-align: center;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--orange-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
}

.tool-heading h1 {
  margin-bottom: 9px;
  color: #253149;
  font-size: clamp(32px, 4.3vw, 50px);
  line-height: 1.12;
  letter-spacing: -.025em;
}

.lead {
  max-width: 760px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
}

.chips {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.chip {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border: 1px solid #e7ddce;
  border-radius: 999px;
  color: #625747;
  background: rgba(255, 255, 255, .72);
  font-size: 11px;
  font-weight: 850;
}

.fraction-lab {
  overflow: hidden;
  border: 1px solid rgba(185, 150, 105, .25);
  border-radius: 28px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow);
}

.lab-toolbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 18px;
  border-bottom: 1px solid #eadfce;
  background: linear-gradient(90deg, #fffaf0, #f8fffd);
}

.lab-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}

.lab-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 5px rgba(43, 152, 139, .12);
}

.phase-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-align: right;
}

.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 330px);
  gap: 0;
}

.visual-stage {
  min-width: 0;
  padding: 18px;
  border-right: 1px solid #eadfce;
  background:
    radial-gradient(circle at 14% 22%, rgba(244, 196, 83, .16), transparent 17rem),
    radial-gradient(circle at 92% 76%, rgba(43, 152, 139, .1), transparent 18rem),
    #fffaf1;
}

.equation-band {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 15px;
  border: 1px solid #eadcc8;
  border-radius: 15px;
  color: #65594c;
  background: rgba(255, 255, 255, .82);
}

.equation-band span {
  font-size: 13px;
  font-weight: 800;
}

.equation-band strong {
  color: #253149;
  font-size: clamp(25px, 3vw, 34px);
  line-height: 1;
  white-space: nowrap;
}

.distribution-scene {
  min-height: 330px;
  display: grid;
  grid-template-columns: minmax(210px, .8fr) 54px minmax(300px, 1.2fr);
  align-items: stretch;
  gap: 12px;
  padding: 14px 0;
}

.source-zone,
.recipient-zone {
  min-width: 0;
  padding: 13px;
  border: 1px dashed rgba(160, 124, 82, .3);
  border-radius: 18px;
  background: rgba(255, 255, 255, .58);
}

.zone-heading {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #746758;
  font-size: 12px;
  font-weight: 850;
}

.zone-heading strong {
  color: var(--orange-dark);
  font-size: 13px;
}

.mooncake-row {
  min-height: 244px;
  display: flex;
  align-content: center;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
  padding: 12px 0;
}

.mooncake {
  width: clamp(58px, 6vw, 78px);
  aspect-ratio: 1;
  flex: 0 0 auto;
  border-radius: 50%;
  filter: drop-shadow(0 9px 9px rgba(123, 71, 24, .16));
  transform-origin: 50% 50%;
}

.mooncake-svg,
.share-disk svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
  border-radius: 50%;
}

.mooncake-sector {
  fill: var(--sector-color);
  stroke: rgba(113, 64, 27, .38);
  stroke-width: 1.25;
  transition: fill .45s ease, stroke .45s ease, transform .45s ease;
}

[data-tool-state="ready"] .mooncake-sector {
  fill: #f5c868;
  stroke: transparent;
}

.mooncake-ring {
  fill: none;
  stroke: rgba(111, 61, 21, .42);
  stroke-width: 2.4;
}

.mooncake-flower {
  fill: none;
  stroke: rgba(255, 248, 219, .78);
  stroke-width: 1.6;
  stroke-dasharray: 3 4;
  opacity: .9;
}

[data-tool-state="cutting"] .mooncake {
  animation: mooncake-cut .7s ease both;
  animation-delay: var(--delay);
}

[data-tool-state="sharing"] .mooncake,
[data-tool-state="result"] .mooncake {
  transform: scale(.94);
}

.flow-arrow {
  display: grid;
  place-content: center;
  gap: 2px;
  color: var(--teal);
  text-align: center;
}

.flow-arrow span {
  color: #778276;
  font-size: 10px;
  font-weight: 850;
  white-space: nowrap;
}

.flow-arrow b {
  font-size: 30px;
  line-height: 1;
  transition: transform .35s ease;
}

[data-tool-state="sharing"] .flow-arrow b {
  animation: arrow-pulse .7s ease-in-out infinite alternate;
}

.recipient-grid {
  min-height: 244px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 8px;
  padding-top: 10px;
}

.recipient {
  min-width: 0;
  min-height: 100px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #e8ddce;
  border-radius: 14px;
  background: rgba(255, 255, 255, .82);
  transition: border-color .3s ease, box-shadow .3s ease, transform .3s ease;
}

[data-tool-state="sharing"] .recipient,
[data-tool-state="result"] .recipient {
  border-color: color-mix(in srgb, var(--recipient-color) 46%, #e8ddce);
  box-shadow: 0 8px 20px color-mix(in srgb, var(--recipient-color) 13%, transparent);
}

.person-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--recipient-color);
  font-size: 12px;
  font-weight: 950;
}

.recipient-main { min-width: 0; }
.recipient-label {
  display: block;
  margin-bottom: 5px;
  color: #6f6254;
  font-size: 10px;
  font-weight: 850;
}

.share-disks {
  min-height: 31px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
}

.share-placeholder {
  color: #9d9489;
  font-size: 10px;
  font-weight: 750;
}

[data-tool-state="sharing"] .share-placeholder,
[data-tool-state="result"] .share-placeholder {
  display: none;
}

.share-disk {
  width: 28px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-20px, -26px) scale(.55);
}

[data-tool-state="sharing"] .share-disk,
[data-tool-state="result"] .share-disk {
  animation: share-arrive .48s cubic-bezier(.2, .8, .25, 1.2) forwards;
  animation-delay: var(--delay);
}

[data-tool-state="result"] .share-disk {
  opacity: 1;
  transform: none;
  animation: none;
}

.result-line {
  min-height: 58px;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 9px 13px;
  padding: 10px 15px;
  border: 1px solid #e2d5c3;
  border-radius: 15px;
  color: #6d6153;
  background: rgba(255, 255, 255, .84);
}

.result-line > span {
  font-size: 12px;
  font-weight: 850;
}

.result-line strong {
  color: var(--orange-dark);
  font-size: 20px;
  white-space: nowrap;
}

.result-line small {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: right;
}

[data-tool-state="result"] .result-line {
  border-color: rgba(43, 152, 139, .4);
  background: var(--teal-soft);
}

.control-deck {
  min-width: 0;
  padding: 20px;
  background: #fff;
}

.control-heading span {
  color: var(--teal);
  font-size: 11px;
  font-weight: 900;
}

.control-heading h2 {
  margin: 3px 0 13px;
  font-size: 23px;
  line-height: 1.2;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.case-button {
  min-height: 57px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  padding: 9px 10px;
  border: 1px solid #e1d7c9;
  border-radius: 12px;
  color: #4b5568;
  background: #fffaf2;
}

.case-button strong { font-size: 16px; }
.case-button span {
  color: #908476;
  font-size: 9px;
  font-weight: 800;
}

.case-button:hover,
.case-button:focus-visible {
  border-color: var(--orange);
  background: #fff5e6;
}

.case-button[aria-checked="true"] {
  border-color: #da7732;
  color: #713513;
  background: linear-gradient(145deg, #fff0ce, #ffe4bd);
  box-shadow: inset 0 0 0 1px rgba(218, 119, 50, .14);
}

.case-button:disabled { cursor: wait; opacity: .7; }

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
  margin-top: 12px;
}

.primary-action,
.reset-button {
  min-height: 48px;
  border-radius: 12px;
  font-weight: 900;
}

.primary-action {
  border: 1px solid var(--orange-dark);
  color: #fff;
  background: linear-gradient(135deg, #e8742a, #c95822);
  box-shadow: 0 12px 24px rgba(199, 88, 34, .2);
}

.primary-action:hover:not(:disabled) { transform: translateY(-1px); }
.primary-action:disabled { cursor: wait; opacity: .68; }

.reset-button {
  border: 1px solid #d9cfc0;
  color: #5d6573;
  background: #fff;
}

.reset-button:hover { border-color: var(--teal); color: #246d65; }

.step-line {
  display: grid;
  gap: 6px;
  margin: 15px 0 0;
  padding: 0;
  list-style: none;
}

.step-line li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8a8278;
  font-size: 11px;
  font-weight: 800;
  transition: color .25s ease;
}

.step-line li span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid #ddd3c5;
  border-radius: 50%;
  background: #fffaf2;
  font-size: 10px;
}

[data-tool-state="cutting"] [data-step="cut"],
[data-tool-state="sharing"] [data-step="cut"],
[data-tool-state="sharing"] [data-step="share"],
[data-tool-state="result"] .step-line li {
  color: #216f66;
}

[data-tool-state="cutting"] [data-step="cut"] span,
[data-tool-state="sharing"] [data-step="cut"] span,
[data-tool-state="sharing"] [data-step="share"] span,
[data-tool-state="result"] .step-line li span {
  border-color: #68b8ad;
  color: #fff;
  background: var(--teal);
}

.truth-note {
  margin: 15px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  border-radius: 9px;
  color: #685328;
  background: #fff8e5;
  font-size: 11px;
  font-weight: 850;
}

:where(.case-button, .primary-action, .reset-button):focus-visible {
  outline: 3px solid rgba(85, 116, 202, .3);
  outline-offset: 3px;
}

.resource-strip {
  border-color: rgba(185, 150, 105, .26);
  border-radius: 18px;
  box-shadow: 0 14px 36px rgba(92, 66, 34, .09);
}

.trial-pill { color: #6c3214; background: #ffe7bd; }
.strip-button.primary { border-color: var(--teal); background: var(--teal); }

@keyframes mooncake-cut {
  0% { transform: scale(1); }
  45% { transform: scale(1.08) rotate(2deg); }
  100% { transform: scale(.98); }
}

@keyframes arrow-pulse {
  from { transform: translateX(-4px); }
  to { transform: translateX(5px); }
}

@keyframes share-arrive {
  to { opacity: 1; transform: translate(0, 0) scale(1); }
}

@media (max-width: 980px) {
  .lab-grid { grid-template-columns: 1fr; }
  .visual-stage { border-right: 0; border-bottom: 1px solid #eadfce; }
  .control-deck { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px 18px; }
  .control-heading { grid-row: span 2; }
  .preset-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .action-row { margin-top: 0; grid-template-columns: minmax(0, 1fr) 84px; }
  .step-line { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); margin-top: 0; }
  .truth-note { grid-column: 1 / -1; margin-top: 0; }
}

@media (max-width: 720px) {
  .fraction-page { width: calc(100% - 28px); }
  .tool-heading { padding: 22px 0 14px; }
  .tool-heading h1 { font-size: clamp(29px, 8vw, 40px); }
  .lead { font-size: 14px; }
  .lab-toolbar { align-items: flex-start; flex-direction: column; gap: 3px; }
  .phase-copy { text-align: left; }
  .distribution-scene { grid-template-columns: 1fr; min-height: 0; }
  .mooncake-row { min-height: 132px; }
  .flow-arrow { transform: rotate(90deg); }
  .flow-arrow span { display: none; }
  .recipient-grid { min-height: 0; }
  .control-deck { display: block; }
  .preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-row { margin-top: 12px; }
  .step-line { grid-template-columns: 1fr; margin-top: 14px; }
  .truth-note { margin-top: 14px; }
}

@media (max-width: 430px) {
  .site-nav { gap: 6px; }
  .site-links a { font-size: 12px; }
  .tool-heading { padding-top: 17px; }
  .tool-heading h1 { margin-bottom: 6px; font-size: 29px; }
  .lead { font-size: 13px; }
  .chips { margin-top: 9px; }
  .chip { min-height: 25px; font-size: 10px; }
  .fraction-lab { border-radius: 20px; }
  .lab-toolbar { min-height: 52px; padding: 10px 12px; }
  .lab-title { font-size: 14px; }
  .phase-copy { font-size: 11px; }
  .visual-stage { padding: 11px; }
  .equation-band { min-height: 52px; padding: 8px 10px; }
  .equation-band span { font-size: 11px; }
  .equation-band strong { font-size: 24px; }
  .distribution-scene { padding: 10px 0; gap: 7px; }
  .source-zone, .recipient-zone { padding: 9px; border-radius: 14px; }
  .mooncake-row { min-height: 105px; gap: 6px; padding: 6px 0; }
  .mooncake { width: 55px; }
  .recipient-grid { gap: 6px; padding-top: 7px; }
  .recipient { min-height: 80px; grid-template-columns: 27px minmax(0, 1fr); gap: 5px; padding: 6px; }
  .person-mark { width: 26px; height: 26px; font-size: 10px; }
  .share-disk { width: 23px; }
  .result-line { grid-template-columns: auto auto; min-height: 56px; gap: 3px 9px; padding: 8px 10px; }
  .result-line strong { font-size: 18px; }
  .result-line small { grid-column: 1 / -1; text-align: left; }
  .control-deck { padding: 14px; }
  .control-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
  .control-heading h2 { margin-bottom: 10px; font-size: 19px; }
  .control-heading span { font-size: 9px; }
  .case-button { min-height: 50px; }
  .step-line { display: flex; justify-content: space-between; gap: 4px; }
  .step-line li { gap: 4px; font-size: 9px; }
  .step-line li span { width: 19px; height: 19px; }
  .truth-note { padding: 8px 9px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
