.demo-section {
  padding: 1rem clamp(.75rem, 2.5vw, 2rem) 2.25rem;
  background: linear-gradient(180deg, #101c2d 0, #101c2d 7.5rem, var(--paper) 7.5rem);
}

.demo-shell {
  width: min(100%, 92rem);
  height: clamp(500px, calc(100dvh - 6.75rem), 730px);
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: .75rem;
  overflow: hidden;
  box-shadow: 0 20px 48px rgba(16, 28, 45, 0.16);
}

.demo-shell [hidden] { display: none !important; }

/* Top bar */
.demo-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  padding: .5rem 1rem;
  background: var(--ink);
  color: var(--white);
  border-bottom: 1px solid #263950;
}

.demo-topbar-left {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
}

.demo-dot {
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--gold-bright);
  flex-shrink: 0;
}

.demo-topbar h2 {
  font: 600 .88rem/1.3 var(--sans);
  letter-spacing: 0;
  color: var(--white);
}

.demo-topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .9rem;
}

.demo-mode-switch {
  display: inline-flex;
  padding: 2px;
  border-radius: .375rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.mode-btn {
  padding: .22rem .62rem;
  border: 0;
  border-radius: .25rem;
  background: transparent;
  color: #d7dfeb;
  font: 600 .75rem/1.3 var(--sans);
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.mode-btn:hover { color: var(--white); }
.mode-btn.is-active {
  background: var(--gold-bright);
  color: var(--ink);
}

.demo-link {
  color: #d7dfeb;
  font-size: .78rem;
  text-decoration: underline;
  text-underline-offset: .25em;
}
.demo-link:hover { color: var(--white); }

/* Slim Chapter Bar */
.tour-chapters {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .42rem .9rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
  scrollbar-width: none;
}
.tour-chapters::-webkit-scrollbar { display: none; }

.tour-chapter-pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  flex-shrink: 0;
  padding: .22rem .58rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--white);
  color: var(--muted);
  font: 500 .75rem/1.25 var(--sans);
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.tour-chapter-pill:hover {
  border-color: #b7a68b;
  color: var(--ink);
}

.tour-chapter-pill.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
}

.tour-chapter-pill .pill-num {
  font-weight: 700;
  opacity: .75;
}
.tour-chapter-pill.is-active .pill-num {
  color: var(--gold-bright);
  opacity: 1;
}

/* Full-width Workspace Stage */
.demo-stage {
  position: relative;
  overflow: clip;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: #faf4f6;
}

.demo-stage iframe {
  display: block;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #faf4f6;
  transition: filter 180ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .demo-stage iframe { transition: none; }
}

.demo-stage.is-bokeh iframe {
  filter: blur(1px) brightness(0.98);
  pointer-events: none;
}

/* Floating coachmark */
.tour-coachmark {
  position: absolute;
  inset: 0 auto auto 0;
  z-index: 20;
  --coach-normal-width: 420px;
  width: min(var(--coach-width, var(--coach-normal-width)), calc(100% - 20px));
  max-height: min(var(--coach-height, 100%), calc(100% - 20px));
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: .75rem .85rem;
  background: rgba(255, 254, 250, 0.97);
  backdrop-filter: blur(8px);
  border: 1px solid #d5c7b0;
  border-radius: .6rem;
  box-shadow: 0 14px 36px rgba(16, 28, 45, 0.22);
  color: var(--ink);
  display: grid;
  gap: .45rem;
}

.tour-coachmark:has(.coach-action.is-done) {
  --coach-normal-width: 560px;
}

.tour-coachmark.is-collapsed { visibility: hidden; }

.mode-btn.has-coach-toggle {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
  text-decoration: underline;
  text-underline-offset: .18em;
}

.coach-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.coach-meta {
  color: var(--gold);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.coach-title {
  font: 400 1.3rem/1.1 var(--serif);
  color: var(--ink);
}
.coach-title:lang(ja), .coach-title:lang(zh) {
  font-size: clamp(1rem, 5vw, 1.15rem);
}
.coach-title:focus { outline: none; }

.coach-problem {
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.42;
}

.coach-action {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: .6rem .72rem;
  border-radius: .45rem;
  background: var(--gold-soft);
  border: 1px solid #e3cfa8;
  border-left: 3px solid #b88430;
  display: grid;
  gap: .4rem;
}

.coach-action.is-done {
  background: #edf5ef;
  border-color: #bfd9c7;
  border-left-color: #3f7d58;
}

.coach-action-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.coach-action-head strong {
  color: var(--ink);
  font-size: .78rem;
  font-weight: 700;
}

.coach-step-count {
  font-size: .7rem;
  font-weight: 600;
  color: var(--gold);
}
.coach-action.is-done .coach-step-count { color: #326647; }

#tour-prompt {
  color: var(--ink);
  font-size: .84rem;
  line-height: 1.44;
}
#tour-prompt:focus { outline: none; }

#tour-status:empty { display: none; }
#tour-status {
  color: var(--gold);
  font-size: .78rem;
  font-weight: 600;
}

#tour-sample {
  display: grid;
  gap: .4rem;
}

.tour-sample-action {
  justify-self: start;
  padding: .34rem .62rem;
  border: 1.5px solid #b88430;
  border-radius: .35rem;
  background: var(--white);
  color: var(--ink);
  font: 600 .78rem/1.3 var(--sans);
  cursor: pointer;
}
.tour-sample-action:hover:not(:disabled) { background: #fbf6ec; }
.tour-sample-action:disabled { opacity: .5; cursor: default; }

#tour-example summary {
  width: fit-content;
  padding: .28rem .55rem;
  color: var(--ink);
  background: var(--white);
  border: 1.5px solid #be8d3d;
  border-radius: .32rem;
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
}
#tour-example[open] p {
  margin-top: .45rem;
  font-size: .8rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.coach-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem;
  padding-top: .15rem;
}

.coach-footer-left,
.coach-footer-right {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.coach-footer-left { justify-content: flex-start; }

.tour-btn {
  white-space: nowrap;
  min-height: 1.9rem;
  padding: .26rem .65rem;
  border: 1px solid #cbbda7;
  border-radius: .35rem;
  background: var(--white);
  color: var(--ink);
  font: 600 .78rem/1.3 var(--sans);
  cursor: pointer;
}
.tour-btn:hover:not(:disabled) { background: #f2ece1; }
.tour-btn:disabled { opacity: .4; cursor: default; }

.tour-btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.tour-btn-ghost:hover:not(:disabled) {
  background: #ebe4d7;
  color: var(--ink);
}

.tour-btn-primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--white);
}
.tour-btn-primary:hover:not(:disabled) {
  background: #233750;
}

.tour-coachmark.is-complete .coach-action-head { display: none; }

@media (max-width: 48rem) {
  .demo-shell {
    height: auto;
    grid-template-rows: auto auto auto;
  }
  .demo-stage { height: auto; }
  .demo-stage iframe {
    flex: 0 0 auto;
    height: max(520px, 65svh);
  }
  .tour-btn { white-space: normal; }
}

@media (max-width: 48rem) { .site-header { position: relative; } .demo-stage iframe { scroll-margin-top: 12px; } }

.tour-shortcut-hint { font-size: 10px; opacity: .7; white-space: nowrap; }


.tour-coachmark.is-compact {
  grid-template-rows: minmax(0, 1fr) auto;
  padding: .35rem .45rem;
  gap: .25rem;
}

.tour-coachmark.is-compact :is(.coach-head, .coach-title) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.tour-coachmark.is-compact .coach-action { padding: .4rem .48rem; }
.tour-coachmark.is-compact .coach-footer { gap: .2rem; }
.tour-coachmark.is-compact .tour-btn { padding-inline: .45rem; }

@media (hover: none) and (pointer: coarse) {
  .tour-shortcut-hint { display: none; }
}

.tour-coachmark.is-toolbar {
  padding: .23rem .38rem;
  gap: .16rem;
  box-shadow: none;
}
.tour-coachmark.is-toolbar .coach-action { padding: .16rem .4rem; gap: .16rem; }
.tour-coachmark.is-toolbar .coach-action-head { display: none; }
.tour-coachmark.is-toolbar #tour-prompt { font-size: .78rem; line-height: 1.25; }
.tour-coachmark.is-toolbar .coach-footer { padding-top: 0; }
.tour-coachmark.is-toolbar .coach-footer :is(.coach-footer-left, .coach-footer-right) { gap: .06rem; flex-wrap: nowrap; }
.tour-coachmark.is-toolbar .tour-shortcut-hint { display: none; }
