/* The "play by code" demonstration. Color tokens and fonts come from site.css. */

.demo { padding-block: clamp(64px, 9vw, 120px); background: var(--bg-deep); color: var(--text); overflow-x: clip; }
.demo-inner { max-width: 1200px; margin-inline: auto; padding-inline: var(--gutter); }

.demo-head { max-width: none; }
.demo-head .lead { max-width: 720px; }

/* Stage */

.demo-stage {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 156px minmax(0, 1fr);
  align-items: stretch; margin-bottom: 24px;
}
.demo-stage[hidden] { display: none; }
.demo-flow { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; image-rendering: pixelated; z-index: 0; }

.demo-hub { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px; text-align: center; pointer-events: none; }
.demo-hub-node {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 10px; border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--panel); transition: border-color 0.3s, box-shadow 0.3s;
}
.demo-hub-node .ew-flame { width: 32px; height: 32px; }
.demo-hub.is-live .demo-hub-node { border-color: var(--accent); box-shadow: 0 0 22px rgba(255, 122, 47, 0.45); }
.demo-hub-name { margin: 0 0 2px; padding: 0 4px; background: var(--bg-deep); font-size: 13px; font-weight: 800; }
.demo-hub-note { margin: 0; padding: 0 4px; background: var(--bg-deep); color: var(--text-2); font-size: 13px; font-weight: 600; line-height: 1.35; }

/* The current step, on narrow screens only. */
.demo-now { display: none; }

/* Launcher windows */

.ew { position: relative; z-index: 1; display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); overflow: hidden; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35); }
.ew-flame { display: block; width: 14px; height: 14px; flex: none; fill: var(--accent); }
.ew-bar { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 12px; background: var(--bg-deep); border-bottom: 1px solid var(--line); }
.ew-name { font: 700 11px 'Unbounded Variable', 'Segoe UI', sans-serif; letter-spacing: 0.08em; }
.ew-who { margin-left: auto; color: var(--text-3); font-size: 12px; white-space: nowrap; }

.ew-game { position: relative; aspect-ratio: 16 / 6.4; min-height: 172px; background: var(--bg-deep); overflow: hidden; }
.ew-game canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.ew-tag {
  position: absolute; top: 0; left: 0; z-index: 1; visibility: hidden; padding: 1px 6px; border-radius: 4px; background: rgba(15, 12, 10, 0.82);
  color: var(--text); font-size: 11px; font-weight: 700; line-height: 1.4; white-space: nowrap;
}

/* Game menus are drawn in the brand's style. */
.ew-menu {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 10px;
  background: var(--bg); transition: opacity 0.25s, visibility 0.25s;
}
.ew-menu.is-off { opacity: 0; visibility: hidden; }
.ew-menu-title { margin: 0 0 2px; font: 700 12px 'Unbounded Variable', 'Segoe UI', sans-serif; }
.ew-gbtn { min-width: 170px; padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel-2); color: var(--text-2); font-size: 13px; font-weight: 700; text-align: center; }
.ew-gbtn-main { border-color: var(--accent); color: var(--text); transition: transform 0.1s, background-color 0.1s; }
.ew-gbtn-main.is-pressed { transform: translateY(1px) scale(0.98); background: var(--accent); color: var(--accent-text); }

.ew-list { display: grid; width: min(250px, 100%); min-height: 50px; }
.ew-list > * { grid-area: 1 / 1; transition: opacity 0.2s, visibility 0.2s; }
.ew-list-empty { align-self: center; justify-self: center; display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; }
.ew-wait { flex: none; width: 24px; height: 36px; animation: ew-wait 1.2s steps(2) infinite; }
@keyframes ew-wait { 50% { transform: translateY(-2px); } }
.ew-list-row { display: flex; flex-direction: column; justify-content: center; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel-2); transition: transform 0.1s, border-color 0.1s, opacity 0.2s, visibility 0.2s; }
.ew-list-row b { font-size: 13px; }
.ew-list-row small { color: var(--text-3); font-size: 12px; }
.ew-list-row.is-pressed { transform: scale(0.98); border-color: var(--accent); }
.ew-list > .is-off { opacity: 0; visibility: hidden; }

/* Launcher panel */

.ew-panel { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.ew-panel-title { margin: 0; font-size: 14px; font-weight: 800; }
.ew-states { flex: 1; display: grid; }
.ew-state { grid-area: 1 / 1; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-width: 0; opacity: 0; visibility: hidden; transition: opacity 0.25s, visibility 0.25s; }
.ew-state.is-on { opacity: 1; visibility: visible; }
.ew-state strong { font-size: 14px; }
.ew-hint, .ew-label, .ew-fact { margin: 0; color: var(--text-3); font-size: 13px; line-height: 1.4; }
.ew-fact { color: var(--text-2); font-weight: 700; }

.ew-status { align-self: stretch; margin: 0; padding: 8px 10px; border: 1px dashed var(--line-2); border-radius: 6px; color: var(--text-2); font-size: 13px; line-height: 1.4; }
.ew-status.is-yes { border: 1px solid #2b5236; background: #16291c; color: #b4e6bd; font-weight: 700; }

.ew-code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ew-code { display: inline-flex; gap: 4px; padding: 5px 8px; border-radius: 6px; background: var(--bg-deep); font: 700 16px ui-monospace, Consolas, monospace; }
.ew-code span { width: 1.05em; border-bottom: 2px solid var(--line-2); text-align: center; line-height: 1.35; }
.ew-code span.is-empty { color: transparent; }
.ew-field { border: 1px solid var(--field-line, var(--line-2)); }

.ew-btn { padding: 6px 12px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel-2); font-size: 13px; font-weight: 700; white-space: nowrap; transition: transform 0.1s, background-color 0.15s, color 0.15s; }
.ew-btn-main { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.ew-btn.is-pressed { transform: translateY(1px) scale(0.97); border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.ew-btn.is-done { border-color: #2b5236; background: #16291c; color: #b4e6bd; }

.demo-token {
  position: absolute; top: 0; left: 0; z-index: 3; visibility: hidden; padding: 6px 10px; border-radius: 6px; background: var(--accent); color: var(--accent-text);
  font: 700 15px ui-monospace, Consolas, monospace; letter-spacing: 0.08em; box-shadow: 0 0 22px rgba(255, 122, 47, 0.75); pointer-events: none;
}
.demo-token.is-on { visibility: visible; }

/* Steps. Without scripts this is a plain numbered list. */

.demo-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 20px; padding: 0; list-style: none; }
.demo-steps li { display: flex; min-width: 0; }
.demo-step {
  position: relative; flex: 1; display: flex; flex-direction: column; justify-content: flex-start; min-width: 0; padding: 0 14px 14px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: inherit; font: inherit; text-align: left; overflow: hidden;
  transition: background-color 0.2s, border-color 0.2s;
}
.demo.is-live .demo-step { cursor: pointer; }
.demo.is-live .demo-step:hover { border-color: var(--line-2); }
.demo-step:focus-visible, .demo-toggle:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
.demo-step.is-current { border-color: var(--line-2); background: var(--panel); }
.demo-step-bar { display: block; height: 3px; margin: 0 -14px 12px; background: var(--line); }
.demo-step-bar i { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; }
.demo-step-title { display: block; margin-bottom: 4px; font-size: 15px; font-weight: 800; line-height: 1.3; }
.demo-step-text { display: block; color: var(--text-3); font-size: 13.5px; line-height: 1.45; }
.demo-step.is-current .demo-step-text { color: var(--text-2); }

.demo-foot { display: flex; align-items: center; gap: 16px; }
.demo-toggle {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: 8px; background: transparent; color: var(--text);
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.demo-toggle[hidden] { display: none; }
.demo-toggle:hover { background: var(--panel-2); }
.demo-toggle svg { width: 12px; height: 12px; fill: currentColor; }
.demo-toggle .demo-icon-pause { display: none; }
.demo-toggle.is-playing .demo-icon-pause { display: inline; }
.demo-toggle.is-playing .demo-icon-play { display: none; }
.demo-note { margin: 0; color: var(--text-3); font-size: 14px; line-height: 1.5; }

/* Column on narrow screens: host, server, friend, with the flow running down. */

@media (max-width: 919px) {
  /* One window at a time, with the step above it, so the action and its explanation fit one screen. */
  .demo-stage { grid-template-columns: minmax(0, 1fr); margin-bottom: 12px; }
  .demo-flow { display: none; }
  .demo-now {
    display: block; grid-row: 1; position: sticky; top: calc(var(--header) + 8px); z-index: 4; min-height: 112px; margin-bottom: 10px; padding: 12px 14px;
    border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel);
  }
  .demo-now-count { margin: 0 0 2px; color: var(--count); font-size: 13px; font-weight: 700; }
  .demo-now-title { margin: 0 0 2px; font-size: 16px; font-weight: 800; line-height: 1.3; }
  .demo-now-text { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.4; }
  .demo-hub { grid-row: 2; flex-direction: row; flex-wrap: wrap; gap: 4px 10px; padding: 0 0 10px; text-align: left; }
  .demo-hub-node { width: 40px; height: 40px; margin: 0; }
  .demo-hub-node .ew-flame { width: 24px; height: 24px; }
  .demo-hub-name, .demo-hub-note { padding: 0; }
  /* Opacity alone: the windows keep their size and place, so the code's flight can be measured. */
  .ew-host, .ew-guest { grid-column: 1; grid-row: 3; transition: opacity 0.25s; }
  .demo-stage .ew-guest { opacity: 0; }
  .demo-stage.show-friend .ew-guest { opacity: 1; }
  .demo-stage.show-friend .ew-host { opacity: 0; }

  /* The step above says it all while the demonstration runs, so the list becomes four numbers. Screen readers still get the text. */
  .demo-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .demo.is-live .demo-steps { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; counter-reset: demo-step; }
  .demo.is-live .demo-steps li { counter-increment: demo-step; }
  .demo.is-live .demo-step { min-height: 44px; padding: 0 0 8px; text-align: center; font-weight: 800; }
  .demo.is-live .demo-step::after { content: counter(demo-step); }
  .demo.is-live .demo-step-bar { margin: 0 0 8px; }
  .demo.is-live .demo-step-title, .demo.is-live .demo-step-text { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@media (max-width: 559px) {
  .demo-steps { grid-template-columns: minmax(0, 1fr); }
  .demo-foot { flex-direction: column; align-items: flex-start; }
  .ew-gbtn { min-width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .ew, .ew-menu, .ew-state, .ew-list > *, .ew-btn, .ew-gbtn-main, .demo-hub-node, .demo-step { transition: none; }
  .ew-wait { animation: none; }
}
