/* Tutorial guide card, in the site's own look: a white card with the sand
 * hairline, ROOT blue for the guide's marks, the app's own buttons. */
body.with-tutorial { --tut-w: 340px; }
@media (min-width: 981px) {
  body.with-tutorial .workspace { width: min(var(--page), calc(100% - var(--tut-w) - 56px)); margin-right: calc(var(--tut-w) + 16px); }
}
/* Keep the starting-curve preview in view while the parameter boxes below it are edited. */
body.with-tutorial .visual-match-layout .visual-preview-plot { position: sticky; top: 72px; align-self: start; z-index: 2; background: #fff; }
@media (max-width: 980px) { body.with-tutorial .visual-match-layout .visual-preview-plot { top: 0; } }

#tut-layer {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: transparent; overflow: visible; pointer-events: none; z-index: 2147483000;
  color: var(--ink, #343434); font-family: var(--font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif); font-size: 14px; line-height: 1.5;
  --tut-blue: var(--blue, #346295); --tut-line: var(--line, #dfe5ec); --tut-sand: var(--sand, #e9dcbe); --tut-soft: var(--blue-soft, #eaf0f7);
  --tut-muted: var(--muted, #7c8792); --tut-ink2: var(--ink-soft, #5d6873); --tut-ok: #2e8540; --tut-bad: #c9433d;
}
#tut-layer::backdrop { display: none; }
#tut-layer [hidden] { display: none !important; }
#tut-layer p { margin: 0; }

/* ring around the control, and the leader from the card */
#tut-layer .tut-ring { position: fixed; border: 2px solid var(--tut-blue); border-radius: 5px; box-shadow: 0 0 0 3px rgba(52, 98, 149, .18), 0 0 0 9999px rgba(30, 45, 62, .12); transition: left .25s, top .25s, width .25s, height .25s; }
#tut-layer .tut-leader { position: fixed; inset: 0; width: 100%; height: 100%; overflow: visible; }
#tut-layer .tut-leader line { stroke: var(--tut-blue); stroke-width: 1.5; stroke-dasharray: 5 4; }
#tut-layer .tut-leader circle { fill: var(--tut-blue); stroke: #fff; stroke-width: 1.5; }

/* Show me */
#tut-layer .tut-pointer { position: fixed; width: 26px; height: 26px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .3)); }
#tut-layer .tut-pointer::after { content: ""; position: absolute; left: -10px; top: -10px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--tut-blue); opacity: 0; }
#tut-layer .tut-pointer.is-click::after { animation: tut-click .7s ease-out 2; }
@keyframes tut-click { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
#tut-layer .tut-bubble { position: fixed; max-width: 240px; background: #fff; color: var(--ink, #343434); border: 1px solid var(--tut-blue); border-radius: 4px; padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 14px rgba(30, 45, 62, .18); }
#tut-layer kbd { font-family: var(--mono, Menlo, monospace); font-size: 12px; background: #f4f6f9; border: 1px solid var(--tut-line); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; }

/* the card */
#tut-layer .tut-card {
  pointer-events: auto; position: fixed; right: 8px; top: 68px; width: var(--tut-w, 340px); max-height: calc(100vh - 76px);
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--tut-sand); border-top: 3px solid var(--tut-blue);
  border-radius: 4px; box-shadow: 0 6px 24px rgba(30, 45, 62, .14); overflow: hidden;
}
#tut-layer .tut-top { display: flex; align-items: baseline; gap: 8px; padding: 12px 16px 0; }
#tut-layer .tut-lesson { font-size: 15px; font-weight: 600; color: var(--ink, #343434); }
#tut-layer .tut-exit { margin-left: auto; background: none; border: 0; box-shadow: none; padding: 0; min-height: 0; color: var(--tut-blue); font-size: 13px; text-decoration: underline; cursor: pointer; }
#tut-layer .tut-phases { display: flex; gap: 4px; list-style: none; margin: 10px 16px 0; padding: 0; }
#tut-layer .tut-phases li { flex: 1; height: 4px; border-radius: 2px; background: var(--tut-line); }
#tut-layer .tut-phases li.is-done { background: #a9bdd3; }
#tut-layer .tut-phases li.is-current { background: var(--tut-blue); }
#tut-layer .tut-meta { display: flex; justify-content: space-between; padding: 6px 16px 0; font-size: 12.5px; color: var(--tut-muted); }
#tut-layer .tut-count b { color: var(--ink, #343434); font-weight: 600; }
#tut-layer .tut-main { padding: 10px 16px 4px; display: grid; gap: 10px; min-height: 0; overflow: hidden; }
#tut-layer .tut-say { font-size: 16px; line-height: 1.45; font-weight: 500; color: var(--ink, #343434); }
#tut-layer .tut-say strong { font-weight: 700; }
#tut-layer .tut-say code, #tut-layer .tut-note code, #tut-layer .tut-check code { font-family: var(--mono, Menlo, monospace); background: #f4f6f9; border: 1px solid var(--tut-line); border-radius: 3px; padding: 0 4px; font-size: .88em; }
#tut-layer .tut-note { color: var(--tut-ink2); font-size: 13.5px; }
#tut-layer .tut-warn { padding: 8px 11px; border-left: 3px solid var(--tut-bad); background: #fdf0ef; color: #7d2622; font-size: 13.5px; }

/* right / wrong panels, stacked: right on top */
#tut-layer .tut-panels { display: grid; gap: 8px; }
#tut-layer .tut-fig { position: relative; margin: 0; background: #fff; border: 1px solid var(--tut-line); border-radius: 4px; padding: 6px 8px 7px; }
#tut-layer .tut-fig.right { border-color: #b7dcc0; background: #f5fbf6; }
#tut-layer .tut-fig.wrong { border-color: #f0c4c1; background: #fdf6f5; }
#tut-layer .tut-fig.inset { background: #f7f9fb; }
#tut-layer .tut-mark { position: absolute; right: 7px; top: 6px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff; z-index: 1; }
#tut-layer .tut-mark.ok { background: var(--tut-ok); }
#tut-layer .tut-mark.bad { background: var(--tut-bad); }
#tut-layer .tut-pic { background: #fff; border: 1px solid var(--tut-line); border-radius: 3px; overflow: hidden; line-height: 1.2; }
#tut-layer .tut-pic svg { display: block; width: 100%; height: auto; }
#tut-layer .tut-fig figcaption { margin-top: 5px; font-size: 12.5px; color: var(--tut-ink2); line-height: 1.4; }
#tut-layer .tut-fig.right figcaption b { color: var(--tut-ok); }
#tut-layer .tut-fig.wrong figcaption b { color: var(--tut-bad); }

/* Confirm-only checks */
#tut-layer .tut-check { border: 1px solid #c4d4e6; background: var(--tut-soft); border-radius: 4px; padding: 9px 11px 10px; display: grid; gap: 7px; }
#tut-layer .tut-check.is-done { border-color: #b7dcc0; background: #f5fbf6; }
#tut-layer .tut-check-n { font-size: 12px; font-weight: 600; color: var(--tut-blue); }
#tut-layer .tut-check.is-done .tut-check-n { color: var(--tut-ok); }

/* buttons: the app's own */
#tut-layer button.tut-btn, #tut-layer .tut-nav button, #tut-layer .tut-confirm {
  font: inherit; font-size: 14px; min-height: 38px; padding: 0 14px; border-radius: 4px; cursor: pointer; line-height: 1.2;
  background: #fff; color: var(--ink, #343434); border: 1px solid #c7d2de; box-shadow: none; text-transform: none; letter-spacing: normal; height: auto;
}
#tut-layer .tut-nav button:hover:not(:disabled) { background: #f4f6f9; }
#tut-layer .tut-nav button:disabled { color: #a9b3bd; background: #fff; border-color: var(--tut-line); cursor: default; }
#tut-layer .tut-confirm, #tut-layer .tut-next.is-ready { background: var(--tut-blue); border-color: var(--tut-blue); color: #fff; font-weight: 600; }
#tut-layer .tut-confirm:hover, #tut-layer .tut-next.is-ready:hover:not(:disabled) { background: var(--blue-dark, #27496f); border-color: var(--blue-dark, #27496f); }
#tut-layer .tut-confirm { justify-self: start; min-height: 34px; padding: 0 18px; }
#tut-layer .tut-show { color: var(--tut-blue); }

#tut-layer .tut-choices { display: grid; gap: 8px; }
#tut-layer .tut-choice { display: block; width: 100%; text-align: left; min-height: 0; padding: 9px 12px; border-radius: 4px; border: 1px solid #c7d2de; background: #fff; color: var(--ink, #343434); box-shadow: none; cursor: pointer; font: inherit; }
#tut-layer .tut-choice:hover { border-color: var(--tut-blue); background: var(--tut-soft); }
#tut-layer .tut-choice strong { display: block; color: var(--tut-blue); font-size: 14.5px; }
#tut-layer .tut-choice span { font-size: 13px; color: var(--tut-ink2); }

#tut-layer .tut-extra { font-size: 13.5px; color: var(--tut-ink2); }
#tut-layer .tut-extra p { margin: 0 0 6px; }
#tut-layer .tut-extra a:not(.tut-next-lesson):not(.tut-download), #tut-layer .tut-note a, #tut-layer .tut-link, #tut-layer .tut-doit {
  color: var(--tut-blue); background: none; border: 0; box-shadow: none; padding: 0; min-height: 0; font: inherit; text-decoration: underline; cursor: pointer;
}
#tut-layer .tut-downloads { display: flex; gap: 8px; flex-wrap: wrap; }
#tut-layer .tut-downloads a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 4px; border: 1px solid var(--tut-blue); color: var(--tut-blue); background: #fff; text-decoration: none; font-weight: 600; }
#tut-layer .tut-downloads a:hover { background: var(--tut-soft); }
#tut-layer .tut-next-lesson { display: inline-flex; align-items: center; min-height: 40px; padding: 0 18px; border-radius: 4px; background: var(--tut-blue); color: #fff; font-weight: 600; text-decoration: none; }
#tut-layer .tut-next-lesson:hover { background: var(--blue-dark, #27496f); }

#tut-layer .tut-status { margin: 0 16px; color: var(--tut-ok); font-weight: 600; font-size: 13.5px; }
#tut-layer .tut-nav { display: flex; gap: 8px; padding: 12px 16px 14px; margin-top: auto; border-top: 1px solid var(--tut-line); }
#tut-layer .tut-nav .n { display: none; }
#tut-layer .tut-next { margin-left: auto; min-width: 84px; }
#tut-layer .tut-help, #tut-layer .tut-keys { margin: -6px 16px 12px; font-size: 12.5px; color: var(--tut-muted); }
#tut-layer .tut-card.is-final .tut-say { font-size: 18px; }
#tut-layer .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* small pictures of the app's own controls, for the right/wrong panels */
#tut-layer .tut-mini { width: 100%; border-collapse: collapse; font-size: 11.5px; }
#tut-layer .tut-mini th, #tut-layer .tut-mini td { border: 1px solid #dfe5ec; padding: 3px 5px; text-align: left; white-space: nowrap; }
#tut-layer .tut-mini th { background: #f1f4f8; font-weight: 600; color: #3a4553; }
#tut-layer .tut-mini td { font-family: var(--mono, Menlo, monospace); }
#tut-layer .tut-mini .sel { background: #cfe0f5; }
#tut-layer .tut-mini .bad { background: #fde3e2; }
#tut-layer .tut-mini .dim { color: #9aa4b1; }
#tut-layer .tut-mini .colhead { background: #e9edf2; color: #6b7785; text-align: center; font-weight: 500; }
#tut-layer .tut-ctl { padding: 7px 8px; display: flex; align-items: center; gap: 6px; font-size: 12px; flex-wrap: wrap; }
#tut-layer .tut-ctl .lbl { font-weight: 600; color: #3a4553; }
#tut-layer .tut-ctl .sel-box { border: 1px solid #b9c6d4; border-radius: 3px; padding: 2px 18px 2px 6px; background: #fff linear-gradient(135deg, transparent 50%, #657487 50%) no-repeat right 7px center / 5px 5px; }
#tut-layer .tut-ctl .num-box { border: 1px solid #b9c6d4; border-radius: 3px; padding: 2px 6px; font-family: var(--mono, Menlo, monospace); min-width: 38px; }
#tut-layer .tut-ctl .use { margin-left: auto; margin-right: 22px; border: 1px solid #b9c6d4; border-radius: 3px; padding: 2px 8px; }
#tut-layer .tut-ctl.hi { background: var(--tut-soft); }

@media (max-width: 980px) {
  #tut-layer .tut-card { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 52vh; border-radius: 6px 6px 0 0; border-width: 3px 0 0; box-shadow: 0 -6px 20px rgba(30, 45, 62, .14); }
  body.with-tutorial { padding-bottom: 52vh; }
  #tut-layer .tut-say { font-size: 15px; }
  #tut-layer .tut-panels { grid-template-columns: 1fr 1fr; }
  #tut-layer .tut-panels:has(.inset) { grid-template-columns: 1fr; }
  #tut-layer .tut-panels:has(.inset) .tut-fig:not(.inset) { display: none; }
  #tut-layer .tut-fig figcaption { font-size: 11.5px; }
  #tut-layer .tut-nav { padding: 10px 16px 12px; }
  #tut-layer .tut-nav .w { display: none; }
  #tut-layer .tut-nav .n { display: inline; font-size: 20px; line-height: 1; }
  #tut-layer .tut-nav .tut-back, #tut-layer .tut-nav .tut-next { min-width: 48px; }
}
/* On a phone the card is a bottom sheet: lift the app's sticky Fit bar above it. */
@media (max-width: 980px) { body.with-tutorial .fit-bar { bottom: var(--tut-sheet, 0px); } }
