/* ParaPrep, CPG Algorithm Builder (Brief 18) page styles.
   Reuses the design tokens + base components from styles.css; adds the flow
   diagram, the draggable label bank and gating. Shared chrome (footer-rich,
   demo-bar, gate) is duplicated per page by project convention (see
   dose-trainer.css). Responsive 360 to 1280px. */

/* ---- Shared chrome (matches dose-trainer.css / tracks.css) ---- */
.footer-rich {
  max-width: 1000px; margin: 0 auto; padding: 1.5rem; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between;
  color: var(--muted); font-size: .8rem;
}
.footer-rich a { color: var(--muted); }
.footer-rich a:hover { color: var(--teal-dark); }
.footer-rich .legal-links { display: flex; gap: 1rem; flex-wrap: wrap; }

#builder { max-width: 1000px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

.demo-bar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  background: #eef5f4; border: 1px dashed var(--teal); color: var(--teal-dark);
  border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1.5rem; font-size: .82rem;
}
.demo-bar strong { font-weight: 700; }
.demo-bar .spacer { margin-left: auto; }
.btn.tiny { padding: .35rem .7rem; font-size: .8rem; }

/* ---- Upgrade prompt (paid gate) ---- */
.gate {
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  color: #fff; border-radius: var(--radius); padding: 2.2rem; box-shadow: var(--shadow);
}
.gate .lock { font-size: 2rem; }
.gate h2 { margin: .4rem 0 .5rem; font-size: 1.6rem; }
.gate p { margin: 0 0 1.2rem; opacity: .95; max-width: 60ch; }
.gate .gate-actions { display: flex; gap: .7rem; flex-wrap: wrap; }
.btn.on-teal { background: #fff; color: var(--teal-dark); }
.btn.on-teal:hover { background: #eef3ff; }
.gate .btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); }
.gate ul.preview { margin: 1.3rem 0 0; padding: 0 0 0 1.1rem; opacity: .95; font-size: .92rem; }
.gate ul.preview li { margin: .25rem 0; }

.view-title { margin: 0 0 .2rem; }
.view-sub { color: var(--muted); font-size: .92rem; margin: .2rem 0 1.4rem; }

/* ---- Draft badge (Brief 17/18, unverified content) ---- */
.draft-badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em;
  color: var(--amber); background: var(--amber-bg); border: 1px solid #f0e3c4;
  border-radius: 999px; padding: .18rem .55rem; white-space: nowrap;
}
.draft-note {
  background: var(--amber-bg); border: 1px solid #f0e3c4; border-left: 4px solid var(--amber);
  color: #6b5418; border-radius: 10px; padding: .7rem .9rem; font-size: .82rem; margin: 0 0 1.2rem;
}

/* ---- Algorithm picker grid ---- */
.algo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.algo-card {
  display: flex; flex-direction: column; gap: .5rem; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); cursor: pointer; width: 100%;
  font: inherit; color: inherit; transition: transform .12s ease, box-shadow .12s ease;
}
.algo-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(20,50,55,.12); }
.algo-card .algo-title { font-size: 1.05rem; font-weight: 700; margin: 0; }
.algo-card .algo-summary { color: var(--muted); font-size: .85rem; margin: 0; }
.algo-chips { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.algo-chips .chip {
  font-size: .7rem; font-weight: 700; padding: .18rem .55rem; border-radius: 999px;
  background: var(--teal-soft); color: var(--teal-dark);
}
.algo-chips .chip.topic { background: #eef2f4; color: var(--muted); }
.algo-card .algo-foot { display: flex; align-items: center; gap: .5rem; margin-top: auto; padding-top: .3rem; }
.best-pill {
  font-size: .72rem; font-weight: 800; color: var(--green); background: #e6f5ec;
  border: 1px solid #bfe6cf; border-radius: 999px; padding: .15rem .5rem;
}
.best-pill.done::after { content: " ✓"; }
.algo-card .go { margin-left: auto; color: var(--teal); font-weight: 800; font-size: .85rem; }

/* Locked (non-taster for free users) */
.algo-card.locked { border-style: dashed; background: #fbfcfc; cursor: default; }
.algo-card.locked:hover { transform: none; box-shadow: var(--shadow); }
.algo-card.locked .algo-title { color: var(--muted); }
.algo-card .lock-tag {
  font-size: .72rem; font-weight: 800; color: var(--amber); background: var(--amber-bg);
  border: 1px solid #f0e3c4; border-radius: 999px; padding: .15rem .55rem; margin-left: auto;
}

/* Free-user upgrade banner above the grid */
.upgrade-strip {
  display: flex; align-items: center; gap: 1rem; justify-content: space-between; flex-wrap: wrap;
  background: var(--amber-bg); border: 1px solid #f0e3c4; border-left: 4px solid var(--amber);
  border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.4rem;
}
.upgrade-strip strong { color: var(--amber); }
.upgrade-strip p { margin: .15rem 0 0; color: #6b5418; font-size: .88rem; }
.btn.amber { background: var(--amber); color: #fff; white-space: nowrap; }
.btn.amber:hover { filter: brightness(.95); }

/* ---- Exercise header ---- */
.exercise-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .4rem; }
.exercise-head .titles { flex: 1 1 280px; }
.exercise-head h2 { margin: 0; font-size: 1.4rem; }
.exercise-head .meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .35rem; }
.exercise-head .meta .chip {
  font-size: .7rem; font-weight: 700; padding: .18rem .55rem; border-radius: 999px;
  background: var(--teal-soft); color: var(--teal-dark);
}
.exercise-head .meta .chip.topic { background: #eef2f4; color: var(--muted); }
.source-line { color: var(--muted); font-size: .78rem; margin: .5rem 0 0; }

/* ---- Score + toolbar ---- */
.exercise-toolbar {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem 1rem; box-shadow: var(--shadow); margin: 1rem 0 1.3rem;
  position: sticky; top: 4.2rem; z-index: 5;
}
.score-readout { font-weight: 700; font-size: .95rem; }
.score-readout .pct { font-size: 1.3rem; font-weight: 800; color: var(--teal-dark); }
.score-readout.good .pct { color: var(--green); }
.score-readout.bad .pct { color: var(--red); }
.exercise-toolbar .spacer { margin-left: auto; }
.exercise-toolbar .btn.tiny { font-size: .85rem; }

/* ---- The flow diagram ---- */
.flow-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.6rem 1rem 1.8rem; box-shadow: var(--shadow); overflow-x: auto;
}
.flow-stack { display: flex; flex-direction: column; align-items: center; }
.flow-item { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; }
/* Vertical connector between stacked items */
.flow-stack > .flow-item + .flow-item { margin-top: 26px; }
.flow-stack > .flow-item + .flow-item::before {
  content: ""; position: absolute; top: -26px; left: 50%; width: 2px; height: 26px;
  background: var(--line); transform: translateX(-1px);
}

/* Node boxes */
.node {
  position: relative; width: 100%; max-width: 460px; box-sizing: border-box;
  border-radius: 12px; padding: .85rem 1rem; font-size: .92rem; line-height: 1.4;
  border: 1px solid var(--line); background: var(--surface); text-align: center;
}
.node .node-kind {
  display: block; font-size: .62rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: .25rem;
}
/* Given anchors (pre-filled) */
.node.node-given { background: var(--teal-soft); border-color: #bcdedb; color: var(--teal-dark); font-weight: 600; }
.node.node-start { border-radius: 999px; }
.node.node-end { border-radius: 999px; background: #eef2f4; }

/* Decision node, a distinct box (diamond hinted via the angled accent) */
.node.node-decision {
  background: #fff7e9; border-color: #ecd9ac; color: #6b5418; font-weight: 700; max-width: 420px;
}
.node.node-decision .node-kind { color: var(--amber); }

/* Slot (empty drop zone), dashed + greyed */
.node.slot {
  border-style: dashed; border-color: #c4d0d4; background: #fbfdfd; color: var(--muted);
  min-height: 3.2rem; display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
}
.node.slot.empty .slot-placeholder { font-style: italic; font-size: .85rem; }
.node.slot.filled { border-style: solid; background: var(--surface); color: var(--ink); font-weight: 600; }
.node.slot:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.node.slot.over { border-color: var(--teal); background: var(--teal-soft); box-shadow: 0 0 0 3px rgba(15,125,119,.15); }
.node.slot.target { border-color: var(--teal); border-style: dashed; }
.node.slot.correct { border-color: var(--green); background: #e6f5ec; color: #1f5b3c; border-style: solid; }
.node.slot.incorrect { border-color: var(--red); background: #fbe9e7; color: #8a2a1e; border-style: solid; }
.node.slot .mark { position: absolute; top: .4rem; right: .55rem; font-weight: 900; }
.node.slot.correct .mark::before { content: "✓"; color: var(--green); }
.node.slot.incorrect .mark::before { content: "✗"; color: var(--red); }
.node.slot .pickup-hint { font-size: .66rem; color: var(--muted); margin-top: .2rem; }

/* Branch split */
.flow-branches {
  position: relative; display: flex; gap: 1.1rem; justify-content: center; align-items: flex-start;
  padding-top: 26px; width: 100%; flex-wrap: wrap;
}
/* horizontal "bus" the branches hang from */
.flow-branches::before {
  content: ""; position: absolute; top: 13px; left: 12%; right: 12%; height: 2px; background: var(--line);
}
/* stub from incoming connector down to the bus */
.flow-branches::after {
  content: ""; position: absolute; top: 0; left: 50%; width: 2px; height: 13px;
  background: var(--line); transform: translateX(-1px);
}
.branch-col { position: relative; flex: 1 1 220px; min-width: 200px; display: flex; flex-direction: column; align-items: center; padding-top: 13px; }
/* tick from the bus down into each column */
.branch-col::before {
  content: ""; position: absolute; top: 0; left: 50%; width: 2px; height: 13px;
  background: var(--line); transform: translateX(-1px);
}
.branch-label {
  font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em;
  color: var(--teal-dark); background: var(--teal-soft); border: 1px solid #bcdedb;
  border-radius: 999px; padding: .2rem .7rem; margin-bottom: 16px; position: relative;
}
/* connector from the branch label down to the first node in the column */
.branch-label::after {
  content: ""; position: absolute; bottom: -16px; left: 50%; width: 2px; height: 16px;
  background: var(--line); transform: translateX(-1px);
}
.branch-col > .flow-stack { width: 100%; }

/* ---- The label bank (sits below the diagram; the parts tray) ---- */
.bank {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.3rem; box-shadow: var(--shadow); margin-top: 1.4rem;
}
.bank h3 { margin: 0 0 .2rem; font-size: 1rem; }
.bank .bank-hint { color: var(--muted); font-size: .8rem; margin: 0 0 .8rem; }
.bank-tokens { display: flex; flex-wrap: wrap; gap: .55rem; min-height: 2.6rem; }
.token {
  font: inherit; text-align: left; cursor: grab; max-width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .8rem; font-size: .88rem; box-shadow: var(--shadow);
}
.token:hover { border-color: var(--teal); }
.token:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.token.selected { border-color: var(--teal); background: var(--teal-soft); box-shadow: 0 0 0 3px rgba(15,125,119,.18); }
.token:active { cursor: grabbing; }
.bank-empty { color: var(--muted); font-size: .85rem; font-style: italic; }

.selected-note { font-size: .82rem; color: var(--teal-dark); font-weight: 700; margin: .6rem 0 0; min-height: 1rem; }

/* ---- Completion banner ---- */
.complete-banner {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  background: #e6f5ec; border: 1px solid var(--green); color: #1f5b3c;
  border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1.3rem 0;
}
.complete-banner strong { font-size: 1.05rem; }

@media (max-width: 620px) {
  .exercise-toolbar { position: static; }
  .node { max-width: 100%; }
  .flow-branches { gap: .6rem; }
  .branch-col { flex-basis: 100%; min-width: 0; }
  /* On a single-column stack the bus/ticks look odd, hide them, keep the labels */
  .flow-branches::before, .flow-branches::after, .branch-col::before { display: none; }
  .branch-col { padding-top: 0; }
}
