/* ========================================================== COURSE PATH ==
   An opening course as a road of tiles (js/path.js groups the lines, the
   course player draws it). Units are white cards on the grey canvas; under
   each, its tiles step down in a zig-zag of isometric blocks: done work in
   mint, the tile to play next in ink, everything ahead in paper grey.
   ========================================================================= */

:root {
  --tile-done-top: #2cc56f;
  --tile-done-left: #22a95c;
  --tile-done-right: #1a8f4c;
  --tile-done-icon: #ffffff;

  --tile-now-top: #1d1d1f;
  --tile-now-left: #3a3a3e;
  --tile-now-right: #29292c;
  --tile-now-icon: #ffffff;

  --tile-open-top: #ffffff;
  --tile-open-left: #dcdce2;
  --tile-open-right: #cdcdd4;
  --tile-open-icon: #1d1d1f;

  --tile-shut-top: #e6e6eb;
  --tile-shut-left: #d6d6dc;
  --tile-shut-right: #c9c9d0;
  --tile-shut-icon: #a1a1a8;
}
[data-theme="dark"] {
  --tile-done-top: #2fbf6c;
  --tile-done-left: #239655;
  --tile-done-right: #1a7642;
  --tile-done-icon: #04140b;

  --tile-now-top: #f5f5f7;
  --tile-now-left: #b9b9be;
  --tile-now-right: #9a9aa0;
  --tile-now-icon: #000000;

  --tile-open-top: #3a3a3f;
  --tile-open-left: #26262a;
  --tile-open-right: #1d1d20;
  --tile-open-icon: #f5f5f7;

  --tile-shut-top: #232326;
  --tile-shut-left: #19191b;
  --tile-shut-right: #141416;
  --tile-shut-icon: #5c5c62;
}

/* ------------------------------------------------------------- the view -- */

.cr-path {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.course.is-path .course-body { display: none; }
.course:not(.is-path) .cr-path { display: none; }

.crp-wrap {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 580px);
  justify-content: center;
  align-items: start;
  gap: clamp(1.5rem, 4vw, 4rem);
  padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 3vw, 2rem) 6rem;
  max-width: 1200px;
  margin-inline: auto;
}

/* --------------------------------------------------------- side column -- */

.crp-side {
  position: sticky;
  top: clamp(1.25rem, 3vw, 2.5rem);
  display: grid;
  gap: 1rem;
}
.crp-card {
  display: grid;
  gap: 0.9rem;
  padding: 1.4rem 1.4rem 1.3rem;
  border-radius: var(--radius-lg);
  background: var(--paper-raised);
  box-shadow: var(--lift);
}
.crp-eyebrow {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-faint);
}
.crp-count {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  margin: -0.35rem 0 0;
  font-variant-numeric: tabular-nums;
}
.crp-count b {
  font-size: 2.6rem;
  font-weight: 600;
  letter-spacing: -0.05em;
  line-height: 1;
}
.crp-count span { font-size: 0.95rem; font-weight: 600; color: var(--ink-faint); }
.crp-bar {
  height: 6px;
  border-radius: 6px;
  background: var(--paper-sunk);
  overflow: hidden;
}
.crp-bar i {
  display: block;
  height: 100%;
  width: calc(var(--p, 0) * 100%);
  border-radius: inherit;
  background: var(--mint-dot);
  transition: width 0.9s var(--ease);
}
.crp-meta { margin: -0.3rem 0 0; font-size: 0.86rem; color: var(--ink-soft); }
.crp-continue {
  display: grid;
  gap: 0.1rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.25s var(--ease), opacity 0.2s;
}
.crp-continue:hover { transform: translateY(-1px); }
.crp-continue:active { transform: translateY(1px); }
.crp-continue b { font-size: 0.98rem; font-weight: 600; letter-spacing: -0.01em; }
.crp-continue small {
  font-size: 0.8rem;
  opacity: 0.68;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crp-level { display: grid; gap: 0.4rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
.crp-level-head { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.84rem; font-weight: 600; }
.crp-level-head span { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.crp-level .crp-bar i { background: var(--ink); }

.crp-units {
  display: grid;
  gap: 2px;
  padding: 0.5rem;
  border-radius: var(--radius-lg);
  background: var(--paper-raised);
  box-shadow: var(--lift);
}
.crp-unit-link {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.7rem;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s var(--ease-soft);
}
.crp-unit-link:hover { background: var(--paper); }
.crp-unit-link.is-here { background: var(--paper); }
.crp-unit-link span:nth-child(2) {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crp-unit-link small { font-size: 0.76rem; font-weight: 600; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.crp-unit-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.4px solid color-mix(in srgb, var(--ink) 11%, transparent);
  display: grid;
  place-items: center;
  color: #fff;
}
.crp-unit-dot svg { width: 12px; height: 12px; }
.crp-unit-dot.is-done { border: 0; background: var(--mint-dot); }
/* In progress: a thin activity ring, mint arc on a soft track, so it reads
   as the same family as the mint "graduated" tick. */
.crp-unit-dot.is-going { border: 0; }
.crp-unit-dot.is-going svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.crp-unit-dot .d-track { fill: none; stroke: color-mix(in srgb, var(--ink) 11%, transparent); stroke-width: 2.4; }
.crp-unit-dot .d-arc { fill: none; stroke: var(--mint-dot); stroke-width: 2.4; stroke-linecap: round; }

.crp-more { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.crp-link {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s var(--ease-soft);
}
.crp-link:hover { border-color: var(--ink); }

.crp-preview { margin: 0; font-size: 0.88rem; line-height: 1.5; color: var(--ink-soft); }

/* ---------------------------------------------------------------- road -- */

.crp-road { display: grid; gap: 1.5rem; }

.crp-unit { display: grid; gap: 1.1rem; scroll-margin-top: 1.5rem; }
.crp-unit-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.25rem 1rem;
  padding: 1.2rem 1.35rem 1.15rem;
  border-radius: var(--radius-lg);
  background: var(--paper-raised);
  box-shadow: var(--lift);
}
.crp-unit-eyebrow {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-faint);
}
.crp-unit-title {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.2;
}
.crp-unit-state {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding-top: 0.2rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.crp-unit.is-graduated .crp-unit-state { color: var(--mint-ink); }
.crp-unit-state .crp-unit-dot { width: 18px; height: 18px; }
.crp-unit-moves {
  grid-column: 1 / -1;
  margin: 0.15rem 0 0;
  font-size: 0.84rem;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crp-unit-meter {
  grid-column: 1 / -1;
  margin-top: 0.7rem;
  height: 4px;
  border-radius: 4px;
  background: var(--paper-sunk);
  overflow: hidden;
}
.crp-unit-meter i {
  display: block;
  height: 100%;
  width: calc(var(--p, 0) * 100%);
  background: var(--mint-dot);
  border-radius: inherit;
  transition: width 0.9s var(--ease);
}
.crp-unit.is-shut .crp-unit-title { color: var(--ink-soft); }

/* The tiles of one unit: a column the tiles are placed in by JS (--x, --y in
   steps), so the zig-zag is the same at every width. */
.crp-tiles {
  --tw: 96px;                      /* tile width */
  --dx: calc(var(--tw) * 0.58);    /* one step sideways */
  --dy: calc(var(--tw) * 0.36);    /* one step down */
  position: relative;
  height: calc(var(--rows) * var(--dy) + var(--tw) * 0.8);
  /* Room over the first tile for its "Start" label. */
  margin: 2.4rem 0 0.6rem;
}

.crp-tile {
  position: absolute;
  left: calc(50% + var(--x) * var(--dx) - var(--tw) / 2);
  top: calc(var(--y) * var(--dy));
  width: var(--tw);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  z-index: calc(10 + var(--i));
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.25s var(--ease);
}
.crp-tile svg { display: block; width: 100%; height: auto; overflow: visible; }
.crp-tile .t-top { fill: var(--top); transition: fill 0.5s var(--ease-soft); }
.crp-tile .t-left { fill: var(--left); transition: fill 0.5s var(--ease-soft); }
.crp-tile .t-right { fill: var(--right); transition: fill 0.5s var(--ease-soft); }
.crp-tile .t-icon { color: var(--icon); transition: color 0.5s var(--ease-soft); }
.crp-tile .t-shadow { fill: color-mix(in srgb, var(--ink) 9%, transparent); }

.crp-tile { --top: var(--tile-shut-top); --left: var(--tile-shut-left); --right: var(--tile-shut-right); --icon: var(--tile-shut-icon); }
.crp-tile.is-open { --top: var(--tile-open-top); --left: var(--tile-open-left); --right: var(--tile-open-right); --icon: var(--tile-open-icon); }
.crp-tile.is-done { --top: var(--tile-done-top); --left: var(--tile-done-left); --right: var(--tile-done-right); --icon: var(--tile-done-icon); }
.crp-tile.is-current { --top: var(--tile-now-top); --left: var(--tile-now-left); --right: var(--tile-now-right); --icon: var(--tile-now-icon); }

.crp-tile:not(.is-shut):hover { transform: translateY(-3px); }
.crp-tile:not(.is-shut):active { transform: translateY(2px); transition-duration: 0.08s; }
.crp-tile.is-shut { cursor: default; }
.crp-tile.is-store { cursor: pointer; }
.crp-tile:focus-visible { outline: none; }
.crp-tile:focus-visible .t-top { stroke: var(--accent); stroke-width: 3px; }

/* The unit test sits a size up. --dx/--dy were fixed on the column, so only
   this tile's own width and centring change. */
.crp-tile--graduate { --tw: 112px; }
/* A game is optional: a size down, so the road reads past it. */
.crp-tile--game { --tw: 80px; }

/* The tile to play next: a slow breathing ring on the floor around it. */
.crp-tile .t-ring { fill: none; stroke: var(--ink); stroke-width: 2; opacity: 0; }
.crp-tile.is-current .t-ring { animation: tileRing 2.4s var(--ease-soft) infinite; }
@keyframes tileRing {
  0% { opacity: 0.45; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.32); }
}
.crp-tile .t-ring { transform-box: fill-box; transform-origin: center; }

/* "Start" over the tile to play next. */
.crp-start {
  position: absolute;
  left: calc(50% + var(--x) * var(--dx));
  top: calc(var(--y) * var(--dy) - 40px);
  z-index: 60;
  transform: translateX(-50%);
  padding: 0.38rem 0.75rem;
  border-radius: 9px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  animation: startBob 1.8s var(--ease-soft) infinite;
}
.crp-start::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: inherit;
  border-radius: 2px;
  transform: translateX(-50%) rotate(45deg);
  z-index: -1;
}
@keyframes startBob {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -5px); }
}

/* ---------------------------------------------------------- the bubble -- */

.crp-pop {
  position: absolute;
  z-index: 80;
  left: clamp(0px, calc(50% + var(--x) * var(--dx) - 150px), calc(100% - 300px));
  top: calc(var(--y) * var(--dy) + var(--tw) * 0.84);
  width: 300px;
  max-width: 100%;
  display: grid;
  gap: 0.55rem;
  padding: 1.05rem 1.1rem 1.1rem;
  border-radius: 18px;
  background: var(--paper-raised);
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px -24px rgba(0, 0, 0, 0.35);
  transform-origin: 50% 0;
  animation: popIn 0.32s var(--ease) both;
}
.crp-pop.is-done-tile { box-shadow: 0 0 0 1px color-mix(in srgb, var(--mint-dot) 45%, var(--line)), 0 24px 60px -24px rgba(0, 0, 0, 0.35); }
@keyframes popIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
}
.crp-pop-kind { margin: 0; font-size: 0.78rem; font-weight: 600; color: var(--ink-faint); }
.crp-pop.is-done-tile .crp-pop-kind { color: var(--mint-ink); }
.crp-pop strong { font-size: 1.02rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.3; }
.crp-pop p:not(.crp-pop-kind) { margin: 0; font-size: 0.86rem; line-height: 1.45; color: var(--ink-soft); }
.crp-pop-go {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding: 0.72rem 0.95rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.crp-pop-go small { font-size: 0.78rem; opacity: 0.7; font-variant-numeric: tabular-nums; }
.crp-pop-go.is-quiet { background: var(--paper-sunk); color: var(--ink); }
.crp-pop-lines { display: grid; gap: 0.2rem; margin: 0; padding: 0; list-style: none; }
.crp-pop-lines li {
  position: relative;
  padding-left: 0.95rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crp-pop-lines li::before {
  content: "";
  position: absolute;
  left: 0.15rem;
  top: 0.5em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
}

/* ------------------------------------------------------ arrivals (JS) -- */

/* A tile finished in the run just played sets down in mint, and the next one
   lifts its padlock and rises into place. */
.crp-tile.is-just-done svg { animation: tileSet 0.7s var(--ease) both; }
@keyframes tileSet {
  0% { transform: translateY(0); }
  35% { transform: translateY(-10px) scale(1.06); }
  100% { transform: none; }
}
.crp-tile.is-just-open svg { animation: tileRise 0.8s var(--ease) 0.45s both; }
@keyframes tileRise {
  0% { transform: translateY(8px); filter: saturate(0.2); }
  60% { transform: translateY(-8px); }
  100% { transform: none; }
}
.crp-tile .t-unlock {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  color: var(--ink-faint);
  pointer-events: none;
  animation: lockOff 0.9s var(--ease) 0.2s both;
}
@keyframes lockOff {
  0% { opacity: 1; transform: none; }
  40% { opacity: 1; transform: translateY(-6px) rotate(-8deg); }
  100% { opacity: 0; transform: translateY(-34px) rotate(-18deg); }
}
.crp-unit.is-just-graduated .crp-unit-head { animation: unitDone 1.1s var(--ease) both; }
@keyframes unitDone {
  0% { box-shadow: var(--lift), 0 0 0 0 color-mix(in srgb, var(--mint-dot) 60%, transparent); }
  100% { box-shadow: var(--lift), 0 0 0 14px transparent; }
}

/* -------------------------------------------------- the player, in a tile */

.cr-tile-steps {
  display: flex;
  align-items: center;
  gap: 5px;
}
.cr-tile-steps i {
  flex: 1 1 0;
  max-width: 64px;
  height: 6px;
  border-radius: 6px;
  background: var(--paper-sunk);
  transition: background 0.35s var(--ease-soft);
}
.cr-tile-steps i.is-done { background: var(--mint-dot); }
.cr-tile-steps i.is-now { background: var(--ink); }
.cr-tile-steps i.is-again { background: color-mix(in srgb, var(--danger) 55%, var(--paper-sunk)); }

.course[data-run] .cr-mode-switch,
.course[data-run] #crLinesTab { display: none; }
.course[data-run] .cr-done { display: none; }

.crb-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-right: -0.4rem;
  padding: 0.45rem 0.7rem 0.45rem 0.45rem;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.crb-back:hover { background: var(--paper-sunk); }

/* On a desktop the player's bar heads its panel column (style.css); the road
   has no panel, so the bar goes back to a strip across the top. */
@media (min-width: 941px), (orientation: landscape) and (max-height: 620px) {
  .course.is-path {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    padding-inline: 0;
  }
  .course.is-path .course-bar {
    grid-column: 1;
    grid-row: 1;
    flex-wrap: nowrap;
    padding: 0.85rem clamp(1rem, 3vw, 2rem);
    background: var(--paper);
  }
  .course.is-path .cr-path { grid-column: 1; grid-row: 2; }
}

/* ------------------------------------------------------------- narrow -- */

@media (max-width: 1000px) {
  .crp-wrap { grid-template-columns: minmax(0, 580px); gap: 1.25rem; padding-top: 1rem; }
  .crp-side { position: static; }
  .crp-units { display: none; }
}
@media (max-width: 940px) and (orientation: portrait) {
  /* The player's phone grid places the board pieces; the road needs only
     the bar and itself. */
  .course.is-path {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "bar" "path";
  }
  .course.is-path .cr-path { grid-area: path; }
  .course[data-run] .cr-tile-steps { grid-area: mode; margin-left: var(--gut); align-self: center; }
  .crb-back span { display: none; }
  .crb-back { padding: 0.4rem; margin-right: -0.2rem; }
}
@media (max-width: 560px) {
  .crp-wrap { padding: 0.75rem 12px 5rem; }
  .crp-card { padding: 1.15rem 1.1rem 1.1rem; gap: 0.75rem; }
  .crp-count b { font-size: 2.1rem; }
  .crp-unit-head { padding: 1rem 1.05rem; }
  .crp-tiles { --tw: 84px; }
  .crp-tile--graduate { --tw: 98px; }
  .crp-pop { width: min(300px, 100%); left: clamp(0px, calc(50% + var(--x) * var(--dx) - 150px), calc(100% - min(300px, 100%))); }
}

@media (prefers-reduced-motion: reduce) {
  .crp-tile.is-current .t-ring,
  .crp-start,
  .crp-tile.is-just-done svg,
  .crp-tile.is-just-open svg,
  .crp-unit.is-just-graduated .crp-unit-head { animation: none; }
  .crp-tile .t-unlock { display: none; }
}
