/* The problem section: one window, the inbox and then the plan (index.html, problem.js).
   Everything is scoped under .idemo-p2 and named p2-; colours are site.css tokens, plus the
   app's own card and canvas colours below (src/accent.js) so the plan reads as the app.
   Orange is for the critical path and the one hand-off arrow (both drawn by problem.js). */

/* The app's look for the plan: card fill and line off the critical path (accent.js fill / a500),
   a selected card's wash (selWash), the canvas ground (surfaceAlt) and its grid (washSoft at 20 px, chip at 100 px: canvasSurface.jsx),
   and links off the critical path in the app's edge colour. */
.idemo-p2 { --p2-link: var(--edge); --p2-box-fill: #ecf6fd; --p2-box-line: #5aa9d6; --p2-sel-wash: #bae6fd; --p2-canvas: var(--canvas); --p2-grid-minor: #e3edf5; --p2-grid-major: var(--sky-wash); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .idemo-p2 { --p2-box-fill: #132b40; --p2-box-line: #3b8cc0; --p2-sel-wash: #1d4f73; --p2-canvas: #16293c; --p2-grid-minor: #182a3d; } }
:root[data-theme="dark"] .idemo-p2 { --p2-box-fill: #132b40; --p2-box-line: #3b8cc0; --p2-sel-wash: #1d4f73; --p2-canvas: #16293c; --p2-grid-minor: #182a3d; }

/* Laptops: the story's label, heading and foot on the left, the window on the right. */
.idemo-p2 .p2-one { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); grid-template-rows: auto 1fr; column-gap: 40px; padding: 32px; }
.idemo-p2 .p2-head { grid-column: 1; grid-row: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.idemo-p2 .p2-titles { min-width: 0; }
.idemo-p2 .p2-head .k { display: grid; }
.idemo-p2 .p2-head h3 { margin: 4px 0 0; }
/* The name in the 600 label: 700, the heaviest Outfit the page loads. */
.idemo-p2 .p2-head .pq { font-weight: 700; }
.idemo-p2 .p2-head .good { color: var(--sky-text); }
.idemo-p2 .p2-stage { grid-column: 2; grid-row: 1 / span 2; min-width: 0; }
.idemo-p2 .p2-foot { grid-column: 1; grid-row: 2; align-self: start; margin-top: 28px; display: flex; flex-direction: column; align-items: flex-start; gap: 14px; color: var(--ink-2); font-size: 16px; }
.idemo-p2 .p2-foot > span { text-wrap: pretty; }

/* Two states in one place: problem.js fades "a" (the inbox) out and "b" (prereq) in.
   Without JS only "b" shows. */
.idemo-p2 .p2-swap { display: grid; justify-items: start; }
.idemo-p2 .p2-swap > * { grid-area: 1 / 1; }
.idemo-p2 .p2-swap > .p2-a { opacity: 0; }

/* ── The window ─────────────────────────────────── */
.idemo-p2 .p2-win { position: relative; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 14px; overflow: hidden; transform-origin: 50% 60%; }
.idemo-p2 .p2-bar { position: relative; display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.idemo-p2 .p2-dots { display: flex; gap: 6px; flex: none; }
.idemo-p2 .p2-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.idemo-p2 .p2-ttl { position: relative; flex: 1; min-width: 0; height: 100%; }
.idemo-p2 .p2-ttl > span { position: absolute; left: 0; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.idemo-p2 .p2-url { padding: 3px 10px; border-radius: 7px; background: var(--surface-3); font-weight: 500; color: var(--ink-2); }
.idemo-p2 .p2-badge { min-width: 26px; padding: 1px 8px; border-radius: 999px; background: var(--sky-btn); color: var(--sky-on); font-size: 12.5px; line-height: 19px; text-align: center; }
.idemo-p2 .p2-body { position: relative; height: 300px; }
.idemo-p2 .p2-layer { position: absolute; inset: 0; }
.idemo-p2 .p2-num { font-family: var(--mono); font-weight: 500; letter-spacing: 0; }

/* The message: To, the subject as it gets retyped, the attachment and Send. */
.idemo-p2 .p2-compose { display: flex; flex-direction: column; padding: 4px 20px 18px; }
.idemo-p2 .p2-row { display: flex; align-items: baseline; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 15px; color: var(--ink); }
.idemo-p2 .p2-lbl { flex: none; width: 58px; color: var(--muted); }
.idemo-p2 .p2-row.p2-srow { align-items: flex-start; }
.idemo-p2 .p2-srow .p2-lbl { line-height: 24px; }
.idemo-p2 .p2-row b { font-weight: 600; }
.idemo-p2 .p2-subjs { position: relative; flex: 1; min-width: 0; height: 72px; }
.idemo-p2 .p2-sl { position: absolute; left: 0; max-width: 100%; height: 24px; line-height: 24px; white-space: nowrap; overflow: hidden; text-overflow: clip; font-weight: 600; color: var(--ink); }
/* A subject that went out: muted, and struck through left to right (--k, problem.js). */
.idemo-p2 .p2-sl.p2-gone { font-weight: 500; color: var(--muted); }
.idemo-p2 .p2-sl::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1.5px; background: currentColor; transform: scaleX(var(--k, 0)); transform-origin: 0 50%; }
.idemo-p2 .p2-caret { position: absolute; left: 0; top: 0; width: 1.5px; height: 18px; background: var(--sky); }
.idemo-p2 .p2-skel { display: flex; flex-direction: column; gap: 10px; padding: 16px 0 0; }
.idemo-p2 .p2-skel i { display: block; height: 8px; border-radius: 4px; background: var(--surface-3); }
.idemo-p2 .p2-cbot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.idemo-p2 .p2-attf { min-width: 0; display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; background: var(--surface-3); color: var(--ink-2); font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.idemo-p2 .p2-attf svg { flex: none; width: 10px; height: 12px; display: block; }
.idemo-p2 .p2-attf span { overflow: hidden; text-overflow: ellipsis; }
.idemo-p2 .p2-sendb { flex: none; padding: 8px 18px; border-radius: 9px; background: var(--sky-btn); color: var(--sky-on); font-size: 14px; font-weight: 600; }

/* The inbox: rows placed by problem.js, newest on top. */
.idemo-p2 .p2-inbox { overflow: hidden; }
.idemo-p2 .p2-list { position: absolute; inset: 0; }
.idemo-p2 .p2-r { position: absolute; top: 0; left: 0; right: 0; height: 40px; display: flex; align-items: center; gap: 10px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 14.5px; white-space: nowrap; }
.idemo-p2 .p2-r svg { flex: none; width: 15px; height: 15px; display: block; color: var(--sky); }
.idemo-p2 .p2-r b { flex: none; font-weight: 600; color: var(--ink); }
.idemo-p2 .p2-r .p2-rs { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.idemo-p2 .p2-r .p2-dot-u { flex: none; margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--sky); }

/* The plan: the canvas, then the one sent row. */
.idemo-p2 .p2-plan { padding: 14px 16px 16px; }
.idemo-p2 .p2-canvas { position: relative; }
.idemo-p2 .p2-canvas svg { display: block; width: 100%; height: auto; }
.idemo-p2 .p2-canvas text { font-family: Outfit, system-ui, sans-serif; }
.idemo-p2 .p2-bg { fill: var(--p2-canvas); stroke: var(--line-strong); }
.idemo-p2 .p2-gmin { stroke: var(--p2-grid-minor); }
.idemo-p2 .p2-gmaj { stroke: var(--p2-grid-major); }
.idemo-p2 .p2-t { font-weight: 600; fill: var(--ink); }
.idemo-p2 .p2-canvas .p2-tn { font-family: var(--mono); font-weight: 500; fill: var(--ink-2); }
.idemo-p2 .p2-chip-l { font-weight: 500; fill: var(--muted); }
.idemo-p2 .p2-canvas .p2-chip-v { font-family: var(--mono); font-weight: 500; fill: var(--ink); }
.idemo-p2 .p2-float { font-weight: 500; fill: var(--sky-text); }
.idemo-p2 .p2-canvas .p2-float-n { font-family: var(--mono); }
.idemo-p2 .p2-halo { paint-order: stroke; stroke: var(--p2-canvas); stroke-width: 4px; stroke-linejoin: round; }

.idemo-p2 .p2-card { display: flex; align-items: center; gap: 12px; height: 54px; padding: 0 14px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; color: var(--ink); line-height: 1.3; }
.idemo-p2 .p2-av { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--sky-wash); color: var(--sky-text); }
.idemo-p2 .p2-av svg { width: 18px; height: 18px; display: block; }
.idemo-p2 .p2-send { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.idemo-p2 .p2-arrow { flex: none; width: 56px; height: 30px; overflow: visible; }
.idemo-p2 .p2-sent { flex: 1; min-width: 0; }
.idemo-p2 .p2-sent-line { min-width: 0; font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idemo-p2 .p2-sent-line b { font-weight: 600; }
.idemo-p2 .p2-file { font-weight: 500; }
.idemo-p2 .p2-mute, .idemo-p2 .p2-sep { color: var(--muted); }

/* ── Chips (as the site's loop cards) ───────────── */
.idemo-p2 .p2-chip { flex: none; white-space: nowrap; font-weight: 500; font-size: 15px; padding: 4px 10px; border-radius: 8px; background: var(--surface-3); color: var(--ink-2); }
.idemo-p2 .p2-chip.p2-good { background: var(--sky-wash); color: var(--sky-text); }

/* ── The control: pause while playing, replay when finished ── */
.idemo-p2 .p2-ctl { flex: none; width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); display: grid; place-items: center; cursor: pointer; }
@media (hover: hover) { .idemo-p2 .p2-ctl:hover { border-color: var(--sky); color: var(--sky-text); } } /* a tap leaves no hover behind on phones */
.idemo-p2 .p2-ctl:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; border-radius: 50%; }
.idemo-p2 .p2-ctl svg { width: 14px; height: 14px; display: block; }

/* Tablets and phones: one centred column, head, window, foot. */
@media (max-width: 999px) {
  .idemo-p2 .p2-one { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; padding: 28px; }
  .idemo-p2 .p2-head, .idemo-p2 .p2-stage, .idemo-p2 .p2-foot { grid-column: 1; grid-row: auto; width: 100%; max-width: 640px; margin-inline: auto; }
  .idemo-p2 .p2-stage { margin-top: 22px; }
  .idemo-p2 .p2-foot { flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 12px; margin-top: 0; padding-top: 22px; }
}
/* Phones: the control keeps a 44 px target. */
@media (max-width: 560px) {
  .idemo-p2 .p2-one { padding: 24px 16px 22px; }
  .idemo-p2 .p2-stage { margin-top: 18px; }
  .idemo-p2 .p2-ctl { width: 44px; height: 44px; margin-top: -4px; }
  .idemo-p2 .p2-bar { height: 36px; padding: 0 12px; gap: 10px; }
  .idemo-p2 .p2-dots i { width: 8px; height: 8px; }
  .idemo-p2 .p2-ttl > span { font-size: 13px; }
  .idemo-p2 .p2-compose { padding: 2px 14px 14px; }
  .idemo-p2 .p2-row { font-size: 14px; gap: 10px; }
  .idemo-p2 .p2-lbl { width: 52px; }
  .idemo-p2 .p2-attf { font-size: 12.5px; }
  .idemo-p2 .p2-sendb { padding: 7px 14px; font-size: 13.5px; }
  .idemo-p2 .p2-r { height: 36px; gap: 8px; padding: 0 12px; font-size: 13.5px; }
  .idemo-p2 .p2-r svg { width: 14px; height: 14px; }
  .idemo-p2 .p2-plan { padding: 10px 8px 12px; }
  .idemo-p2 .p2-card { gap: 10px; padding: 0 12px; height: 50px; }
  .idemo-p2 .p2-av { width: 28px; height: 28px; }
  .idemo-p2 .p2-av svg { width: 16px; height: 16px; }
  .idemo-p2 .p2-send { flex-direction: column; gap: 4px; margin-top: 8px; }
  .idemo-p2 .p2-arrow { width: 30px; height: 34px; }
  .idemo-p2 .p2-sent { flex: none; width: 100%; }
  .idemo-p2 .p2-sent-line { font-size: 14px; }
  .idemo-p2 .p2-foot { font-size: 15px; padding-top: 18px; }
}
/* Under 400 px the sent row drops its avatar, so the whole line fits, and the inbox rows
   drop their unread dot, so the "final" subjects stay readable. */
@media (max-width: 399px) {
  .idemo-p2 .p2-sent .p2-av, .idemo-p2 .p2-r .p2-dot-u { display: none; }
  .idemo-p2 .p2-r { gap: 6px; padding: 0 10px; font-size: 13px; }
}
@media (max-width: 359px) { .idemo-p2 .p2-sent-line { font-size: 13px; } .idemo-p2 .p2-lbl { width: 46px; } }
@media (max-width: 339px) { .idemo-p2 .p2-attf { font-size: 11.5px; padding: 5px 8px; gap: 5px; } .idemo-p2 .p2-sendb { padding: 7px 10px; } }

/* Without JS: no empty window or dead control; the head and foot show where it ends up. */
html:not(.js) .idemo-p2 :is(.p2-ctl, .p2-stage) { display: none; }

/* The closing line: the promise, said once under the panel. */
.idemo-p2 .p2-close { margin: 44px 0 0; font-size: clamp(24px, 2.6vw, 32px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; color: var(--ink); text-wrap: balance; }
@media (max-width: 760px) { .idemo-p2 .p2-close { margin-top: 32px; } }
