/* /problemset dashboard strip and pattern roadmap.
   Markup: _includes/problemset-dash.html, _includes/problemset-roadmap.html.
   Script: assets/js/problemset.js.

   Everything is scoped under #ps-top. The page sits on layout: default, where
   assets/css/content.css styles prose by element under .content (ul, li, a, p,
   details, summary at 0,1,1 to 0,2,2); the id lifts each rule here above them,
   the same move content/problemset.md's #catalog-section block makes.

   Height budget: the strip and the closed roadmap row add ~200px above the
   list at desktop widths, which still leaves a dozen problems inside the
   first 1000px (Requirement 2 AC 10). Below 640px the three cards become a
   swipe row one card tall instead of a stack three cards tall. */

#ps-top { max-width: var(--measure); margin: 0 auto var(--sp-4); display: grid; gap: var(--sp-3); }
#ps-top a { color: inherit; text-decoration: none; }
#ps-top ul, #ps-top ol { margin: 0; padding: 0; list-style: none; max-width: none; color: inherit; }
#ps-top li { margin: 0; line-height: inherit; }
#ps-top li::marker { content: none; }

/* ---- the three cards ---------------------------------------------------- */
.ps-dash { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-3); }
.ps-card {
  position: relative; display: flex; flex-direction: column; gap: var(--sp-1h); min-width: 0; min-height: 148px;
  padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg, 14px);
}
a.ps-card { transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
a.ps-card:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }
a.ps-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ps-kicker { display: flex; align-items: center; gap: var(--sp-1h); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.ps-when { margin-left: auto; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ps-flame { font-size: 0.95rem; letter-spacing: 0; }
.ps-title { font-size: var(--fs-md); font-weight: 700; line-height: 1.3; color: var(--text); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; text-wrap: balance; }
.ps-meta { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); }
.ps-meta .badge { flex-shrink: 0; }
.ps-meta-t { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ps-go { margin-top: auto; font-size: var(--fs-sm); font-weight: 650; color: var(--accent); }
.ps-daily.is-done .ps-go { color: var(--text-muted); }
.ps-daily.is-done::after {
  content: '\2713'; position: absolute; top: var(--sp-4); right: var(--sp-4); width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; color: var(--bg); background: var(--easy);
}
.ps-daily.is-done .ps-when { margin-right: 28px; }

/* Progress: a ring split by difficulty, then a bar per difficulty. */
.ps-prog { flex-direction: row; align-items: center; gap: var(--sp-4); }
/* The mask cuts the hole and would cut the label too, so the label is a
   sibling layer on the wrapper rather than a child of the ring. */
.ps-ringwrap { position: relative; flex: 0 0 auto; width: 112px; height: 112px; }
.ps-ring {
  --a: 0%; --b: 0%; --c: 0%;
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--easy) 0 var(--a), var(--medium) var(--a) var(--b), var(--hard) var(--b) var(--c), var(--surface-2, var(--border)) var(--c) 100%);
  -webkit-mask: radial-gradient(circle, transparent 0 43px, #000 44px); mask: radial-gradient(circle, transparent 0 43px, #000 44px);
}
.ps-ringwrap .ps-ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ps-ring-label strong { font-size: 1.6rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ps-ring-label span { font-size: var(--fs-xs); color: var(--text-dim); }
.ps-prog-body { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; flex: 1; }
.ps-diffs { display: grid; gap: var(--sp-1h); }
.ps-diff { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); }
.ps-diff-l { font-weight: 600; }
.ps-d-easy .ps-diff-l { color: var(--easy); }
.ps-d-medium .ps-diff-l { color: var(--medium); }
.ps-d-hard .ps-diff-l { color: var(--hard); }
.ps-diff-bar { height: 6px; border-radius: var(--r-full); background: var(--surface-2, var(--border)); overflow: hidden; }
.ps-diff-bar i { display: block; height: 100%; width: 0; border-radius: inherit; transition: width 0.5s var(--ease); }
.ps-d-easy .ps-diff-bar i { background: var(--easy); }
.ps-d-medium .ps-diff-bar i { background: var(--medium); }
.ps-d-hard .ps-diff-bar i { background: var(--hard); }
.ps-diff-n { color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 4.5ch; text-align: right; }
.ps-diff-n b { color: var(--text); font-weight: 700; }
.ps-sync { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.5; }
#ps-top .ps-sync a { color: var(--accent); font-weight: 600; }
.ps-signin { font: inherit; font-weight: 650; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.ps-signin:hover, #ps-top .ps-sync a:hover { text-decoration: underline; }
.ps-sync-in { display: none; }
html[data-auth="in"] .ps-sync-in { display: inline; }
html[data-auth="in"] .ps-sync-out { display: none; }

/* ---- roadmap row and grid ------------------------------------------------ */
#ps-top details.ps-rm { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg, 14px); overflow: visible; }
#ps-top .ps-rm-sum {
  display: flex; align-items: center; gap: var(--sp-3); min-height: 48px; padding: var(--sp-1h) var(--sp-4); margin: 0;
  list-style: none; cursor: pointer; font-size: var(--fs-sm); font-weight: 400; color: var(--text-muted); border: 0; border-radius: inherit;
}
#ps-top .ps-rm-sum::-webkit-details-marker { display: none; }
#ps-top .ps-rm-sum::before { content: none; }
#ps-top .ps-rm-sum:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); color: var(--text-muted); }
#ps-top .ps-rm-sum:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#ps-top details[open] > .ps-rm-sum { border-bottom: 1px solid var(--border); border-radius: var(--r-lg, 14px) var(--r-lg, 14px) 0 0; margin: 0; }
.ps-rm-h { font-weight: 700; color: var(--text); white-space: nowrap; }
.ps-rm-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-rm-n { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.ps-rm-n b { color: var(--text); }
.ps-rm-cta { flex-shrink: 0; padding: var(--sp-1) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-full); font-weight: 650; color: var(--text); }
.ps-rm-cta::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: var(--sp-2); border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform var(--dur-fast) var(--ease); }
details[open] .ps-rm-cta::after { transform: translateY(1px) rotate(-135deg); }
.ps-rm-close, details[open] .ps-rm-open { display: none; }
details[open] .ps-rm-close { display: inline; }

#ps-top .ps-rm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(264px, 1fr)); gap: var(--sp-3); padding: var(--sp-4); }
.ps-grp { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-subtle, transparent); min-width: 0; }
.ps-grp.is-next { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent); }
.ps-grp-h { display: flex; align-items: center; gap: var(--sp-2); }
.ps-grp-i { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: var(--text-muted); background: var(--surface-2, var(--border)); font-variant-numeric: tabular-nums; }
.ps-grp.is-next .ps-grp-i { color: var(--accent-contrast); background: var(--accent); }
.ps-grp.is-done .ps-grp-i { color: var(--bg); background: var(--easy); }
.ps-grp-name { font-weight: 700; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-grp-n { margin-left: auto; font-size: var(--fs-xs); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ps-grp-n b { color: var(--text); }
.ps-grp-bar { height: 4px; border-radius: var(--r-full); background: var(--surface-2, var(--border)); overflow: hidden; }
.ps-grp-bar i { display: block; height: 100%; width: 0; background: var(--easy); border-radius: inherit; transition: width 0.5s var(--ease); }
/* minmax(0, 1fr), not the implicit auto track: a grid item's min-width is its
   content, so "Longest Substring Without Repeating Characters" would widen
   the card past its column instead of ellipsing. */
#ps-top .ps-grp-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; }
#ps-top .ps-grp-list > li { min-width: 0; }
#ps-top .ps-grp-list a { display: flex; align-items: center; gap: var(--sp-2); min-height: 32px; padding: var(--sp-0) var(--sp-1h); margin: 0 -6px; border-radius: var(--r-sm); font-size: var(--fs-sm); color: var(--text-muted); }
#ps-top .ps-grp-list a:hover { background: var(--surface-2, var(--border)); color: var(--text); }
#ps-top .ps-grp-list a:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.ps-grp-list .prog-dot { width: 14px; height: 14px; }
.ps-grp-t { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ps-dd { flex-shrink: 0; font-size: 11px; font-weight: 650; }
.ps-dd-easy { color: var(--easy); }
.ps-dd-medium { color: var(--medium); }
.ps-dd-hard { color: var(--hard); }

/* ---- narrower ---------------------------------------------------------- */
@media (max-width: 1100px) {
  .ps-dash { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ps-prog { grid-column: 1 / -1; min-height: 0; }
  .ps-prog-body { max-width: 560px; }
}
@media (max-width: 760px) {
  .ps-rm-sub { display: none; }
}
@media (max-width: 640px) {
  /* One card tall: the cards scroll sideways, and the next one peeks in.
     The scroller runs edge to edge, so it cancels the page gutter and then
     restores it as its own inline padding -- that way card one still lines up
     with the heading above it while the row can scroll past both edges.
     Both halves read --page-pad (content.css, on .page-layout) rather than
     naming a step of the spacing scale. They said --sp-4, which is the gutter
     at 640px but not below 400px, where the page drops to --sp-3: on a 390px
     iPhone the row hung 4px past each edge and card one sat 4px left of the
     heading. */
  .ps-dash { display: flex; gap: var(--sp-2); overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin-inline: calc(var(--page-pad, 1rem) * -1); padding-inline: var(--page-pad, 1rem); scroll-padding-inline: var(--page-pad, 1rem); }
  .ps-dash::-webkit-scrollbar { display: none; }
  .ps-card { flex: 0 0 84%; scroll-snap-align: start; min-height: 136px; padding: var(--sp-3); }
  .ps-prog { gap: var(--sp-3); }
  .ps-ringwrap { width: 84px; height: 84px; }
  .ps-ring { -webkit-mask: radial-gradient(circle, transparent 0 31px, #000 32px); mask: radial-gradient(circle, transparent 0 31px, #000 32px); }
  .ps-ring-label strong { font-size: 1.25rem; }
  .ps-diff { grid-template-columns: 56px minmax(0, 1fr) auto; }
  #ps-top .ps-rm-grid { padding: var(--sp-3); }
  .ps-rm-cta { padding: var(--sp-1) var(--sp-2h); }
}
@media (prefers-reduced-motion: reduce) {
  .ps-diff-bar i, .ps-grp-bar i, a.ps-card { transition: none; }
}
