/*
 * tutorial.css: styles for the CART tutorial.
 * Uses the same design tokens, font, and left rail as CART itself (css/app.css
 * in the app), so the tutorial looks like part of the tool. The layout follows
 * an R Markdown tutorial: a title block, a floating table of contents, numbered
 * sections, figure captions, code chunks, callouts, and tabsets.
 * The font comes from this folder (vendor/ibm-plex-sans/); nothing is downloaded.
 */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("../vendor/ibm-plex-sans/IBMPlexSans-VariableFont_wdth,wght.ttf") format("truetype");
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("../vendor/ibm-plex-sans/IBMPlexSans-Italic-VariableFont_wdth,wght.ttf") format("truetype");
  font-weight: 100 700;
  font-style: italic;
  font-display: swap;
}

:root {
  /* Same tokens as CART */
  --bg: #f8f9f7;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d6d9dd;
  --line-strong: #8b939c;
  --subtle: #f1f3f2;
  --accent: #0f5c5e;
  --accent-hover: #0b4749;
  --accent-soft: #e6f0f0;
  --amber: #d97706;
  --amber-ink: #8a4b06;
  --warn-bg: #fdf6ea;
  --warn-line: #e3b36a;
  --ok: #3f7d5a;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(31, 41, 55, 0.06);
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, "SF Mono", monospace;
  --rail-w: 17rem;
  --rail-bg: #1d2a2c;
  --rail-ink: #e6eded;
  --rail-muted: #a3b2b3;
  --rail-line: #3a4c4e;
  --rail-accent: #7cc4c2;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; scroll-padding-top: 1rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, kbd { font-family: var(--mono); font-size: 0.88em; }
p code, li code, td code, figcaption code {
  background: var(--subtle); border: 1px solid #e3e6e8; border-radius: 3px; padding: 0.05em 0.3em;
}
kbd {
  background: #fff; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 3px; padding: 0.02em 0.35em; font-size: 0.82em;
}
/* A CART button name, written the way it looks in the app */
.ui {
  display: inline-block; font-weight: 600; font-size: 0.92em; line-height: 1.35;
  border: 1px solid var(--line-strong); border-radius: 3px; padding: 0 0.4em; background: #fff;
  white-space: nowrap;
}
.ui.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ui.option { border-radius: 999px; font-weight: 500; padding: 0 0.6em; }

/* ---------- Left rail: floating table of contents ---------- */

.rail {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--rail-w);
  background: var(--rail-bg); color: var(--rail-ink);
  border-right: 1px solid #111b1c;
  display: flex; flex-direction: column;
  overflow-y: auto; z-index: 20;
}
.rail-head { padding: 1.2rem 1.1rem 0.9rem; border-bottom: 1px solid var(--rail-line); }
.rail-head .kicker { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--rail-accent); font-weight: 600; }
.rail-head .name { font-size: 1.15rem; font-weight: 600; margin-top: 0.15rem; }
.rail-head .sub { font-size: 0.8rem; color: var(--rail-muted); line-height: 1.4; margin-top: 0.15rem; }
.progress { height: 3px; background: var(--rail-line); margin-top: 0.8rem; border-radius: 2px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--rail-accent); transition: width 0.15s; }

.toc { padding: 0.6rem 0.6rem 1.4rem; font-size: 0.86rem; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc .toc-part {
  margin: 0.9rem 0 0.25rem; padding: 0 0.5rem;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--rail-muted);
}
.toc .toc-part:first-child { margin-top: 0.2rem; }
.toc a {
  display: flex; gap: 0.55rem; align-items: baseline;
  color: var(--rail-ink); text-decoration: none;
  padding: 0.26rem 0.5rem; border-radius: var(--radius-sm); line-height: 1.35;
  border-left: 2px solid transparent;
}
.toc a:hover { background: rgba(255, 255, 255, 0.07); }
.toc a .num { color: var(--rail-muted); font-variant-numeric: tabular-nums; min-width: 1.4rem; font-size: 0.8rem; }
.toc a.active { background: rgba(124, 196, 194, 0.13); border-left-color: var(--rail-accent); }
.toc a.active .num { color: var(--rail-accent); }
.toc ol ol { display: none; margin: 0.05rem 0 0.3rem 1.95rem; }
.toc li.open > ol { display: block; }
.toc ol ol a { font-size: 0.8rem; color: var(--rail-muted); padding: 0.16rem 0.5rem; }
.toc ol ol a.active { color: var(--rail-ink); }

.rail-foot { margin-top: auto; padding: 0.8rem 1.1rem 1rem; border-top: 1px solid var(--rail-line); font-size: 0.78rem; color: var(--rail-muted); }
.rail-foot a { color: var(--rail-accent); }

/* Narrow screens: the rail becomes a top bar with a menu button */
.menu-btn { display: none; }

/* ---------- Page ---------- */

.page { margin-left: var(--rail-w); }
.content { max-width: 52rem; margin: 0 auto; padding: 2.2rem 2rem 5rem; }

/* Title block, like an R Markdown header */
.title-block { border-bottom: 1px solid var(--line); padding-bottom: 1.4rem; margin-bottom: 1.6rem; }
.title-block .kicker { font-size: 0.75rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.title-block h1 { font-size: 2.1rem; line-height: 1.15; font-weight: 600; margin: 0.3rem 0 0.4rem; letter-spacing: -0.01em; }
.title-block .subtitle { font-size: 1.15rem; color: var(--muted); margin: 0 0 0.9rem; }
.meta { display: flex; flex-wrap: wrap; gap: 0.3rem 1.4rem; font-size: 0.88rem; color: var(--muted); }
.meta b { color: var(--ink); font-weight: 600; }

.abstract {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.2rem; margin: 1.2rem 0; box-shadow: var(--shadow);
}
.abstract h2 { margin: 0 0 0.4rem; font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); border: none; padding: 0; }
.abstract p { margin: 0.35rem 0; }

/* Part banners: a sheet header strip, like CART's "1 · CAPE-Vr form" */
.part {
  margin: 3.4rem 0 1.4rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: 2px;
  box-shadow: var(--shadow); overflow: hidden;
}
.part .tag {
  background: var(--subtle); border-bottom: 1px solid var(--line);
  padding: 0.45rem 1.2rem; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}
.part .tag .optional-tag { font-style: italic; font-weight: 400; letter-spacing: 0; text-transform: none; margin-left: 0.4rem; }
.part .body { padding: 1rem 1.2rem 1.1rem; }
.part h1 { margin: 0 0 0.3rem; font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.part p { margin: 0.3rem 0; color: #374151; }
.part ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }

/* Numbered section headings */
h2.sec { font-size: 1.4rem; font-weight: 600; line-height: 1.25; margin: 2.6rem 0 0.7rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--line); }
h3.sub { font-size: 1.1rem; font-weight: 600; margin: 1.8rem 0 0.4rem; }
.secnum { color: var(--accent); font-variant-numeric: tabular-nums; margin-right: 0.5rem; }
h2.sec .badge, h3.sub .badge {
  font-size: 0.72rem; font-weight: 500; font-style: italic; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.05rem 0.55rem; margin-left: 0.5rem; vertical-align: 0.2em;
}
.content p { margin: 0.55rem 0; }
.content ul, .content ol { padding-left: 1.4rem; }
.content li { margin: 0.25rem 0; }

/* Numbered steps: circles like CART's progress bar */
ol.steps { list-style: none; padding: 0; counter-reset: step; margin: 0.8rem 0; }
ol.steps > li { counter-increment: step; position: relative; padding-left: 2.6rem; margin: 0.7rem 0; }
ol.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0.05rem;
  width: 1.7rem; height: 1.7rem; border-radius: 50%;
  border: 1.5px solid var(--accent); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 600; background: #fff;
}

/* Figures */
figure { margin: 1.1rem 0 1.5rem; }
figure .shot {
  display: block; width: 100%; height: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(31, 41, 55, 0.08);
  background: #fff; cursor: zoom-in;
}
figure.narrow .shot { max-width: 26rem; }
figure.mid .shot { max-width: 38rem; }
figure.praat .shot { background: #e9ebec; }
figcaption { font-size: 0.86rem; color: var(--muted); margin-top: 0.5rem; line-height: 1.45; }
figcaption .fignum { font-weight: 600; color: var(--ink); margin-right: 0.3rem; }
.fig-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.fig-pair figure { margin: 0; }

/* Code chunks, R Markdown style: a grey block with a small label */
.chunk { position: relative; margin: 0.9rem 0 1.2rem; }
.chunk pre {
  margin: 0; overflow-x: auto;
  background: #f4f5f4; border: 1px solid #e1e4e6; border-radius: var(--radius-sm);
  padding: 0.85rem 1rem; font-family: var(--mono); font-size: 0.82rem; line-height: 1.55; color: #24313a;
}
.chunk .label {
  position: absolute; top: 0; right: 0;
  font-family: var(--mono); font-size: 0.7rem; color: var(--muted);
  background: #e9ecea; border-left: 1px solid #e1e4e6; border-bottom: 1px solid #e1e4e6;
  border-radius: 0 var(--radius-sm) 0 var(--radius-sm); padding: 0.1rem 0.5rem;
}
.chunk .c { color: #7a8691; }      /* comment */
.chunk .k { color: var(--accent); font-weight: 600; }  /* key / folder */
.chunk .s { color: #8a4b06; }      /* string / value */

/* "Show / hide" folds (like code_folding in R Markdown) */
details.fold { margin: 0.8rem 0 1.2rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); }
details.fold > summary { cursor: pointer; padding: 0.5rem 0.9rem; font-weight: 600; font-size: 0.92rem; color: var(--accent); }
details.fold > summary:hover { background: var(--accent-soft); }
details.fold[open] > summary { border-bottom: 1px solid var(--line); }
details.fold > .fold-body { padding: 0.3rem 0.9rem 0.6rem; }
details.fold .chunk { margin: 0.6rem 0; }

/* Callouts: the same note style as CART's messages */
.callout {
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  background: var(--panel); border-radius: var(--radius-sm);
  padding: 0.65rem 1rem; margin: 1rem 0;
}
.callout > .ct { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.15rem; }
.callout p { margin: 0.25rem 0; font-size: 0.95rem; }
.callout ul { margin: 0.25rem 0; font-size: 0.95rem; }
.callout.tip { border-left-color: var(--ok); }
.callout.tip > .ct { color: var(--ok); }
.callout.caution { border-color: var(--warn-line); border-left-color: var(--amber); background: var(--warn-bg); }
.callout.caution > .ct { color: var(--amber-ink); }
.callout.optional { background: var(--accent-soft); border-color: #c9dcdc; border-left-color: var(--accent); }
.callout.done { border-left-color: var(--ok); background: #f1f7f3; border-color: #cfe2d6; }
.callout.done > .ct { color: var(--ok); }

/* The path diagram: CART's four steps, with the optional ones dashed */
.path { display: flex; align-items: stretch; gap: 0; margin: 1.2rem 0 0.6rem; flex-wrap: wrap; }
.path .node {
  flex: 1 1 0; min-width: 9rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 0.8rem; position: relative; box-shadow: var(--shadow);
}
.path .node.opt { border-style: dashed; border-color: var(--line-strong); background: #fbfcfb; box-shadow: none; }
.path .node .mark {
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 600; background: var(--accent); color: #fff; margin-right: 0.4rem;
}
.path .node.opt .mark { background: #fff; color: var(--accent); border: 1.5px solid var(--accent); }
.path .node b { font-size: 0.95rem; }
.path .node .req { display: block; font-size: 0.76rem; color: var(--muted); margin-top: 0.3rem; }
.path .node.opt .req { font-style: italic; }
.path .arrow { display: flex; align-items: center; padding: 0 0.3rem; color: var(--line-strong); font-size: 1.1rem; }

/* Tabsets, like {.tabset} in R Markdown */
.tabset { margin: 1rem 0 1.4rem; }
.tabset [role="tablist"] { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--line); }
.tabset [role="tab"] {
  font: inherit; font-size: 0.92rem; font-weight: 600; color: var(--muted);
  background: none; border: 1px solid transparent; border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0; padding: 0.4rem 0.95rem; margin-bottom: -1px; cursor: pointer;
}
.tabset [role="tab"]:hover { color: var(--ink); background: var(--subtle); }
.tabset [role="tab"][aria-selected="true"] { color: var(--accent); background: var(--panel); border-color: var(--line); }
.tabset [role="tabpanel"] {
  background: var(--panel); border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm); padding: 0.5rem 1.1rem 0.8rem;
}

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 0.8rem 0 1.2rem; background: var(--panel); }
table.tbl th, table.tbl td { border: 1px solid var(--line); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
table.tbl th { background: var(--subtle); font-weight: 600; }

/* Recap checklists */
ul.check { list-style: none; padding: 0; }
ul.check li { position: relative; padding-left: 1.8rem; }
ul.check li::before {
  content: "✓"; position: absolute; left: 0; top: 0.12rem;
  width: 1.2rem; height: 1.2rem; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 0.72rem; display: flex; align-items: center; justify-content: center; font-weight: 700;
}

/* "Session info" block at the end */
.info-grid { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1.2rem; font-size: 0.9rem; }
.info-grid dt { color: var(--muted); }
.info-grid dd { margin: 0; }

.foot { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: 0.82rem; color: var(--muted); }

.back-top {
  position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 15;
  font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--accent);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 3px; padding: 0.35rem 0.75rem;
  box-shadow: var(--shadow); cursor: pointer; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.back-top.show { opacity: 1; pointer-events: auto; }
.back-top:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Click a screenshot to see it full size */
.lightbox {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(17, 27, 28, 0.86); padding: 2rem; cursor: zoom-out;
  align-items: center; justify-content: center; flex-direction: column; gap: 0.7rem;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: calc(100% - 3rem); border-radius: var(--radius); background: #fff; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.lightbox .lb-cap { color: #dfe9e9; font-size: 0.9rem; max-width: 60rem; text-align: center; }

/* ---------- Narrow screens ---------- */

@media (max-width: 999px) {
  .rail { position: fixed; top: 0; left: 0; right: 0; bottom: auto; width: auto; max-height: 100vh; }
  .rail-head { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 1rem; }
  .rail-head .sub, .rail-head .progress { display: none; }
  .rail-head .name { font-size: 1rem; margin: 0; }
  .menu-btn {
    display: inline-block; margin-left: auto;
    font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--rail-ink);
    background: none; border: 1px solid var(--rail-line); border-radius: 3px; padding: 0.25rem 0.7rem; cursor: pointer;
  }
  .toc, .rail-foot { display: none; }
  .rail.open .toc, .rail.open .rail-foot { display: block; }
  .rail.open { bottom: 0; }
  .page { margin-left: 0; padding-top: 3.2rem; }
  html { scroll-padding-top: 4rem; }
}
@media (max-width: 640px) {
  .content { padding: 1.4rem 1rem 4rem; }
  .title-block h1 { font-size: 1.6rem; }
  .fig-pair { grid-template-columns: 1fr; }
  .path { flex-direction: column; }
  .path .arrow { justify-content: center; transform: rotate(90deg); padding: 0.1rem; }
}

/* ---------- Print: just the content ---------- */
@media print {
  .rail, .back-top, .lightbox { display: none !important; }
  .page { margin: 0; padding: 0; }
  .content { max-width: none; padding: 0; }
  details.fold { break-inside: avoid; }
  figure { break-inside: avoid; }
  .tabset [role="tabpanel"][hidden] { display: block !important; }
  .tabset [role="tablist"] { display: none; }
}
