/* ── tour ──
 * The welcome tour (src/tour.js): a centred card, a bottom sheet on phones, with five
 * small animated illustrations drawn in the theme's own colours.
 * Linked from index.html in cascade order — the order is load-bearing.
 *
 * Everything is scoped under #tour: the illustrations reuse short names (.m, .pal,
 * .code, .board) that must never reach the real app's elements. */

#tour {
  position: fixed; inset: 0; z-index: 150;          /* over the palette (100), under the tooltip (200) */
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg-page) 55%, transparent);
  backdrop-filter: blur(3px);
}
#tour.hidden { display: none; }

#tour .tour-card {
  width: min(600px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  animation: tour-in .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes tour-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }

#tour .tour-top { display: flex; align-items: center; gap: 8px; padding: 12px 14px 0; font-size: 11px; color: var(--fg-faint); }
#tour .tour-top .brand { color: var(--fg-dim); }
#tour .tour-top .brand b { color: var(--fg); }
#tour .tour-top .count { margin-left: auto; }
#tour .tour-x { font: inherit; background: none; border: 0; color: var(--fg-faint); cursor: pointer; font-size: 14px; padding: 2px 4px; }
#tour .tour-x:hover { color: var(--fg); }

#tour #tour-stage {
  position: relative; margin: 10px 14px 0; aspect-ratio: 16 / 9; border-radius: 9px; overflow: hidden;
  background: var(--bg-page); border: 1px solid var(--border-soft); font-size: 11px;
}
#tour .tour-copy { padding: 14px 18px 4px; }
#tour .tour-copy h2 { margin: 0 0 6px; font-size: 16px; font-weight: 700; letter-spacing: -.01em; color: var(--fg); }
#tour .tour-copy p { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--fg-dim); min-height: 3.2em; }
#tour .tour-copy kbd { font: inherit; font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg-code); color: var(--fg); }
#tour .tour-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px 16px; }
#tour .tour-dots { display: flex; gap: 6px; }
#tour .tour-dots button { width: 7px; height: 7px; padding: 0; border-radius: 4px; border: 0; background: var(--border); cursor: pointer; transition: width .2s, background .2s; }
#tour .tour-dots button.on { width: 20px; background: var(--accent); }
#tour .tour-check { margin-left: 6px; font-size: 11px; color: var(--fg-faint); display: flex; align-items: center; gap: 6px; cursor: pointer; }
#tour .tour-check input { accent-color: var(--accent); }
#tour .tour-btns { margin-left: auto; display: flex; gap: 8px; }
#tour .tour-btn { white-space: nowrap; font: inherit; font-size: 12px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--fg-dim); cursor: pointer; }
#tour .tour-btn:hover { color: var(--fg); border-color: var(--fg-faint); }
#tour .tour-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg-page); font-weight: 600; }
#tour .tour-btn:focus-visible, #tour .tour-x:focus-visible, #tour .tour-dots button:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* Phones: a bottom sheet, a squarer stage, and the checkbox without its words. */
@media (max-width: 700px) {
  #tour { place-items: end center; }
  #tour .tour-card { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  #tour #tour-stage { aspect-ratio: 4 / 3; font-size: 9.5px; }
  #tour .tour-check span { display: none; }
}

/* ── The mini app the illustrations are drawn in ── */
#tour-stage .m { position: absolute; inset: 0; display: grid; grid-template-columns: 26% 1fr; grid-template-rows: 22px 1fr 18px; color: var(--fg); }
#tour-stage .m.noside { grid-template-columns: 1fr; }
#tour-stage .m-side { grid-row: 1 / 3; background: var(--bg-raised); border-right: 1px solid var(--border-soft); padding: 8px; }
#tour-stage .m-side .h { color: var(--accent); margin-bottom: 6px; }
#tour-stage .m-row { display: flex; gap: 5px; align-items: center; padding: 2px 4px; border-radius: 3px; color: var(--fg-dim); white-space: nowrap; overflow: hidden; transition: background .2s; }
#tour-stage .m-row .b { color: #89b4fa; font-size: .85em; }
#tour-stage .m-row .b.pdf { color: #e06c75; }
#tour-stage .m-row .b.dir { color: var(--accent); }
#tour-stage .m-row.on { background: var(--accent-soft); color: var(--fg); }
#tour-stage .m-tabs { display: flex; gap: 1px; border-bottom: 1px solid var(--border-soft); overflow: hidden; }
#tour-stage .m-tab { padding: 4px 9px; color: var(--fg-dim); white-space: nowrap; }
#tour-stage .m-tab.on { background: var(--accent); color: var(--bg-page); font-weight: 600; }
#tour-stage .m-doc { padding: 12px 16px; overflow: hidden; position: relative; }
#tour-stage .m-status { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; padding: 0 8px; border-top: 1px solid var(--border-soft); color: var(--fg-faint); font-size: .9em; }
#tour-stage .m-status .mode { color: var(--accent); }
#tour-stage .m-status .toast { margin-left: auto; color: var(--accent); opacity: 0; transition: opacity .25s; }
#tour-stage .m-status .toast.show { opacity: 1; }
#tour-stage .ln { display: flex; gap: 10px; line-height: 1.75; }
#tour-stage .ln .n { color: var(--fg-faint); width: 10px; text-align: right; flex: none; }
#tour-stage .ln .t { white-space: pre; }
#tour-stage .ln.h1 .t { font-weight: 700; font-size: 1.25em; }
#tour-stage .caret { display: inline-block; width: 1.5px; height: 1.1em; background: var(--accent); vertical-align: -.2em; animation: tour-blink 1s steps(1) infinite; }
@keyframes tour-blink { 50% { opacity: 0; } }
#tour-stage .md { color: var(--fg-faint); }
#tour-stage .flash { animation: tour-flash 1.4s ease-out; border-radius: 3px; }
@keyframes tour-flash { 0%, 30% { background: color-mix(in srgb, var(--accent) 22%, transparent); } }
#tour-stage mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--fg); border-radius: 2px; }

#tour-stage .url { position: absolute; left: 0; right: 0; top: 0; height: 22px; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: var(--bg-code); border-bottom: 1px solid var(--border-soft); color: var(--fg-faint); z-index: 2; }
#tour-stage .url .dots i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--border); margin-right: 3px; }
#tour-stage .url .addr { flex: 1; padding: 2px 8px; border-radius: 4px; background: var(--bg-page); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#tour-stage .url .hash { color: var(--accent); }
#tour-stage .chip { position: absolute; z-index: 5; padding: 4px 9px; border-radius: 6px; background: var(--bg-raised); border: 1px solid var(--accent-line); color: var(--fg); font-size: 1.05em; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); opacity: 0; transform: translateY(6px) scale(.96); transition: opacity .2s, transform .2s; }
#tour-stage .chip.show { opacity: 1; transform: none; }
#tour-stage .chip.press { transform: scale(.92); }

#tour-stage .pal { position: absolute; z-index: 4; width: 52%; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 7px; box-shadow: 0 14px 40px rgba(0, 0, 0, .5); padding: 4px; opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
#tour-stage .pal.show { opacity: 1; transform: none; }
#tour-stage .pal .q { padding: 3px 6px 5px; border-bottom: 1px solid var(--border-soft); margin-bottom: 3px; color: var(--fg); }
#tour-stage .pal .q .s { color: var(--accent); }
#tour-stage .pal .r { display: flex; gap: 7px; padding: 3px 6px; border-radius: 4px; color: var(--fg); }
#tour-stage .pal .r .i { width: 13px; text-align: center; color: var(--fg-dim); }
#tour-stage .pal .r .d { color: var(--fg-faint); }
#tour-stage .pal .r.on { background: var(--accent-soft); }
#tour-stage .pal .r .sn { display: block; color: var(--fg-faint); font-size: .9em; margin-top: 1px; }

#tour-stage .code { margin: 4px 0 0 20px; border: 1px solid var(--border-soft); border-left: 2px solid var(--accent); border-radius: 5px; background: var(--bg-code); padding: 6px 8px; opacity: 0; transition: opacity .3s; }
#tour-stage .code.show { opacity: 1; }
#tour-stage .code .lang { color: var(--accent); font-size: .85em; margin-bottom: 3px; }
#tour-stage .k { color: #c678dd; }
#tour-stage .fn { color: #61afef; }
#tour-stage .str { color: #98c379; }

#tour-stage .board { position: absolute; left: 4%; top: 12%; width: 50%; height: 76%; border: 1px dashed var(--fg-faint); border-radius: 6px; }
#tour-stage .board svg { width: 100%; height: 100%; }
#tour-stage .board path, #tour-stage .board rect, #tour-stage .board ellipse { fill: none; stroke: var(--fg); stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 400; stroke-dashoffset: 400; }
#tour-stage .board .drawn { transition: stroke-dashoffset 1s ease-in-out; stroke-dashoffset: 0; }
#tour-stage .board .tag { position: absolute; left: 8px; top: -8px; background: var(--bg-page); padding: 0 5px; color: var(--fg-faint); font-size: .85em; }
#tour-stage .pdfpage { position: absolute; right: 5%; top: 9%; width: 34%; height: 82%; background: #f4f1ea; border-radius: 3px; padding: 9px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }
#tour-stage .pdfpage .pl { height: 4px; background: #c9c3b6; border-radius: 2px; margin: 0 0 6px; position: relative; overflow: hidden; }
#tour-stage .pdfpage .pl.t { height: 7px; width: 60%; background: #6b665c; margin-bottom: 10px; }
#tour-stage .pdfpage .hl { position: absolute; inset: 0; width: 0; background: #ffd54a; mix-blend-mode: multiply; transition: width 1.1s ease-out; }
#tour-stage .pdfpage .pin { position: absolute; right: 8px; top: 46%; background: #ff8fb3; color: #111; font-size: .8em; font-weight: 700; padding: 2px 5px 3px; border-radius: 5px 5px 5px 0; opacity: 0; transform: translateY(-12px); transition: opacity .25s, transform .35s cubic-bezier(.3, 1.6, .6, 1); }
#tour-stage .pdfpage .pin.show { opacity: 1; transform: none; }
#tour-stage .droppdf { position: absolute; left: 40%; top: 40%; padding: 5px 8px; border-radius: 5px; background: var(--bg-raised); border: 1px solid var(--border); color: #e06c75; font-weight: 700; opacity: 0; transition: transform 1s cubic-bezier(.5, 0, .3, 1), opacity .3s; }

#tour-stage .laptop { position: absolute; left: 6%; top: 18%; width: 52%; color: var(--fg); }
#tour-stage .laptop .scr { border: 2px solid var(--border); border-radius: 6px 6px 0 0; height: 110px; padding: 8px; background: var(--bg-code); position: relative; }
#tour-stage .laptop .base { height: 6px; background: var(--border); border-radius: 0 0 8px 8px; margin: 0 -8%; }
#tour-stage .laptop .dim { color: var(--fg-dim); }
#tour-stage .laptop .pp { margin-top: 6px; }
#tour-stage .laptop .pp span { color: var(--accent); }
#tour-stage .laptop .ok { margin-top: 8px; color: var(--accent); opacity: 0; transition: opacity .3s; }
#tour-stage .laptop .ok.show { opacity: 1; }
#tour-stage .syncline { position: absolute; left: 58%; top: 46%; width: 9%; height: 2px; background: repeating-linear-gradient(90deg, var(--accent) 0 5px, transparent 5px 9px); background-size: 18px 2px; animation: tour-dash .6s linear infinite; opacity: 0; transition: opacity .3s; }
#tour-stage .syncline.show { opacity: 1; }
@keyframes tour-dash { to { background-position: 18px 0; } }

#tour-stage .phonef { position: absolute; right: 7%; top: 6%; width: 26%; height: 88%; border-radius: 16px; border: 2px solid var(--border); background: var(--bg-page); overflow: hidden; }
#tour-stage .phonef .scr { position: absolute; inset: 0; padding: 14px 8px; }
#tour-stage .phonef .faint { color: var(--fg-faint); }
#tour-stage .phonef .pnote { margin-top: 8px; opacity: 0; transition: opacity .3s; color: var(--fg-dim); }
#tour-stage .phonef .pnote b { display: block; color: var(--fg); margin-bottom: 4px; }
#tour-stage .phonef .pnote.show { opacity: 1; }
#tour-stage .phonef .fabs { position: absolute; right: 7px; bottom: 7px; display: flex; gap: 5px; }
#tour-stage .phonef .fab { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; background: var(--accent); color: var(--bg-page); font-weight: 700; }
#tour-stage .phonef .fab.mic { background: var(--bg-raised); color: var(--accent); border: 1px solid var(--accent-line); }
#tour-stage .phonef .fab.mic svg { width: 12px; height: 12px; }
#tour-stage .phonef .fab.mic.pulse { animation: tour-micpulse 1s ease-in-out infinite; }
@keyframes tour-micpulse { 50% { box-shadow: 0 0 0 5px var(--accent-soft); } }
#tour-stage .phonef .sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg-raised); border-top: 1px solid var(--border); border-radius: 10px 10px 0 0; padding: 7px; transform: translateY(105%); transition: transform .3s; }
#tour-stage .phonef .sheet.show { transform: none; }
#tour-stage .phonef .sh { color: var(--fg); }
#tour-stage .phonef .sh span { float: right; color: var(--fg-dim); }
#tour-stage .wave { display: flex; gap: 2px; align-items: center; height: 16px; margin: 4px 0; }
#tour-stage .wave i { width: 3px; border-radius: 2px; background: var(--accent); height: 20%; animation: tour-wave .8s ease-in-out infinite; }
@keyframes tour-wave { 50% { height: 100%; } }

@media (prefers-reduced-motion: reduce) {
  #tour *, #tour { animation: none !important; transition: none !important; }
}
