/*
 * The plan as a pyramid being built (`src/planner/board.ts`), from the foundation up, linked on the
 * planner page after `planner.css`. The cover is its plinth, dark stone with the game's name cut in
 * it. The sections and the build stages are its blocks, laid in courses from the bottom up
 * (`src/planner/pyramid.ts` places each one, as fractions of the rise), and the concept art is its
 * capstone under a gold rim. A loose block is a blueprint's outline; forming, smoked glass; setting,
 * glass lit as it is laid; set, ivory stone; stale, stone lifted out and edged in amber. The rise is
 * as tall as its base is wide times `--steep`, steeper on a narrow board, and every block shows as
 * much of its words as it has room for.
 */

.pl-board {
  --stone: #f4eee2;
  --stone-2: #e2d6bf;
  --stone-top: #fffbf3;
  --stone-ink: #211c15;
  --stone-dim: #6d604b;
  --bronze: #9b7a3f;
  --gold: #d4af62;
  --gold-2: #f6e3a8;
  --amber: #e2a63a;
  --blueprint: rgb(0 250 105 / 28%);
  --serif: ui-serif, 'New York', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  container: board / inline-size;
  display: grid;
  gap: 28px;
  padding: 18px 0 8px;
  overflow-x: clip;
}

.pl-pyramid {
  /* How far the plinth reaches past the pyramid's base, each side. */
  --m: max(12px, 4.5cqi);
  /* The rise's height over its base's width: Giza's, about. */
  --steep: 0.64;
  /* A block's top, seen from a little above. */
  --ledge: 6px;
  --joint: 1.5px;
  position: relative;
  isolation: isolate;
}

@container board (max-width: 560px) {
  .pl-pyramid {
    --steep: 1.02;
    --ledge: 4px;
  }
}

/* The light it stands in: cool while it is built, warm once it stands whole. */
.pl-pyramid::before,
.pl-pyramid::after {
  content: '';
  position: absolute;
  inset: -8% -4% 16%;
  z-index: -1;
  pointer-events: none;
  transition: opacity 1.6s ease;
}

.pl-pyramid::before {
  background: radial-gradient(46% 44% at 50% 44%, rgb(0 250 105 / 9%), transparent 74%);
}

.pl-pyramid::after {
  opacity: 0;
  background:
    radial-gradient(14% 12% at 50% 6%, rgb(246 227 168 / 30%), transparent 80%),
    radial-gradient(50% 46% at 50% 42%, rgb(212 175 98 / 12%), transparent 74%);
}

.pl-board.is-built .pl-pyramid::before {
  opacity: 0;
}

.pl-board.is-built .pl-pyramid::after {
  opacity: 1;
}

/* The blueprint under it all: the pyramid's outline and its axis. */
.pl-pyramid__lines {
  position: absolute;
  top: 0;
  left: var(--m);
  width: calc(100% - 2 * var(--m));
  height: calc((100cqi - 2 * var(--m)) * var(--steep));
  overflow: visible;
  pointer-events: none;
}

.pl-pyramid__lines path {
  fill: none;
  stroke: rgb(0 250 105 / 24%);
  stroke-dasharray: 1 5;
  stroke-linecap: round;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  transition: stroke 1.6s ease;
}

.pl-board.is-built .pl-pyramid__lines path {
  stroke: rgb(212 175 98 / 28%);
}

.pl-pyramid__courses {
  position: relative;
  display: grid;
  grid-template-rows: calc((100cqi - 2 * var(--m)) * var(--steep)) auto;
  grid-template-columns: minmax(0, 1fr);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Every piece: the blocks and the capstone laid in the rise, the plinth under it. */
.pc {
  position: relative;
  min-width: 0;
  color: rgb(143 195 166 / 80%);
}

/* Its grid area with both end lines: an auto end runs the box to the list's own edge. */
.pc:not(.pc--cover) {
  position: absolute;
  grid-area: 1 / 1 / 2 / 2;
  z-index: calc(var(--c) + 1);
  top: calc(100% * var(--t));
  left: calc(var(--m) + (100% - 2 * var(--m)) * var(--l) + var(--joint));
  width: calc((100% - 2 * var(--m)) * var(--w) - 2 * var(--joint));
  height: calc(100% * var(--h));
}

.pc--block {
  container: block / size;
}

/* A block's top, then its face. */
.pc--block::before,
.pc--cover::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: var(--ledge);
  background: rgb(0 250 105 / 6%);
  clip-path: polygon(
    calc(var(--ledge) * var(--tl, 1)) 0,
    calc(100% - var(--ledge) * var(--tr, 1)) 0,
    100% 100%,
    0 100%
  );
  transition: background 0.5s ease;
}

.pc__face {
  position: absolute;
  inset: var(--ledge) 0 0;
  overflow: hidden;
  border: 1px dashed var(--blueprint);
  border-radius: 1.5px;
  background: linear-gradient(180deg, #071a10, #04100a);
  transition:
    background 0.5s ease,
    border-color 0.5s ease,
    box-shadow 0.5s ease;
}

/* The light that crosses a block as it is laid. */
.pc__face::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background: linear-gradient(105deg, transparent 38%, rgb(255 255 255 / 62%) 50%, transparent 62%)
    160% 0 / 260% 100% no-repeat;
  pointer-events: none;
}

.pc--block.is-forming,
.pc--block.is-setting {
  color: var(--ink);
}

.pc--block.is-forming::before {
  background: #2c5f43;
}

.pc--block.is-forming .pc__face {
  border: 1px solid rgb(84 178 126 / 50%);
  background: linear-gradient(180deg, #163a28, #0b2117 80%);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 8%),
    0 8px 16px -6px rgb(0 0 0 / 60%);
}

.pc--block.is-setting::before {
  background: #47a072;
}

.pc--block.is-setting .pc__face {
  border: 1px solid var(--accent);
  background: linear-gradient(180deg, #1d4d34, #0f2d1f 80%);
  animation: pc-glow 1.4s ease-in-out infinite;
}

.pc--block.is-setting .pc__face::after {
  opacity: 1;
  background-image: linear-gradient(
    105deg,
    transparent 38%,
    rgb(0 250 105 / 24%) 50%,
    transparent 62%
  );
  animation: pc-sweep 1.6s linear infinite;
}

.pc--block.is-set,
.pc--block.is-stale {
  color: var(--stone-ink);
}

.pc--block.is-set::before {
  background: var(--stone-top);
}

.pc--block.is-set .pc__face {
  border: 0;
  border-radius: 1px;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 42%), transparent 34%),
    linear-gradient(180deg, var(--stone), var(--stone-2));
  box-shadow:
    inset 0 -1px 0 rgb(110 86 46 / 24%),
    0 2px 3px rgb(0 0 0 / 50%);
}

.pc.is-stale {
  z-index: 40;
  transform: translateY(-8px);
}

.pc--block.is-stale::before {
  background: #fff4dc;
}

.pc--block.is-stale .pc__face {
  border: 1px dashed var(--amber);
  background: linear-gradient(180deg, #f7eedb, #eadcbd);
  box-shadow: 0 14px 20px -6px rgb(0 0 0 / 65%);
}

/* The words on a block. */

.pc__body {
  position: absolute;
  inset: var(--ledge) 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  padding: 10px 11px 8px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 11.5px;
  line-height: 1.32;
  text-align: left;
}

button.pc__body {
  cursor: pointer;
}

/* A written block opens its part of the plan, and rises a little under the pointer to say so. */
.pc:not(.pc--cover):has(> button.pc__body) {
  transition: transform 0.25s ease;
}

.pc:not(.pc--cover):has(> button.pc__body:hover, > button.pc__body:focus-visible) {
  transform: translateY(-3px);
}

.pc.is-stale:has(> button.pc__body:hover, > button.pc__body:focus-visible) {
  transform: translateY(-11px);
}

button.pc__body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The block the waiting question feeds: the part the planner is talking about now. */
.pc.is-asking .pc__face {
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 26px color-mix(in srgb, var(--accent) 45%, transparent);
}

.pc__head {
  display: grid;
  grid-template-areas:
    'num mark'
    'name name';
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin: 0;
  font-size: 12.5px;
  line-height: 1.2;
}

.pc__head strong {
  display: -webkit-box;
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  font-weight: 650;
  hyphens: auto;
  overflow-wrap: break-word;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.pc__num {
  grid-area: num;
  margin-bottom: 3px;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 11px;
  font-variant-numeric: lining-nums tabular-nums;
  font-weight: 600;
  letter-spacing: 0.12em;
  opacity: 0.7;
}

.pc.is-forming .pc__num,
.pc.is-setting .pc__num {
  opacity: 1;
}

.pc.is-set .pc__num,
.pc.is-stale .pc__num {
  color: var(--bronze);
  opacity: 1;
}

.pc__mark {
  grid-area: mark;
  font-weight: 800;
}

.pc.is-stale .pc__mark::after {
  content: 'Changed';
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--amber);
  color: #2a1a00;
  font-size: 0.78em;
  letter-spacing: 0.02em;
}

.pc.is-setting .pc__mark::after {
  content: '';
  display: block;
  width: 0.8em;
  height: 0.8em;
  border: 1.5px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: pc-spin 0.8s linear infinite;
}

.pc__line {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.pc.is-loose .pc__line {
  font-style: italic;
}

.pc--block.is-set .pc__line,
.pc--block.is-stale .pc__line {
  color: var(--stone-dim);
}

.pc__line.is-fresh {
  border-radius: 3px;
  animation: pc-fresh 1.8s ease-out;
}

.pc__more {
  margin: 0;
  font-size: 0.92em;
  opacity: 0.7;
}

.pc__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  font-size: 10.5px;
}

.pc__chips li {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgb(255 255 255 / 7%);
  white-space: nowrap;
}

.pc--block.is-set .pc__chips li {
  background: rgb(110 86 46 / 11%);
}

.pc__chips--path {
  counter-reset: stage;
}

.pc__chips--path li {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
}

.pc__chips--path li::before {
  content: counter(stage) ' ';
  counter-increment: stage;
  font-weight: 800;
}

/* A tall block says more of its summary, a short one keeps its name, a narrow one its number. */
@container block (min-height: 128px) {
  .pc--section.is-set .pc__line {
    -webkit-line-clamp: 3;
    line-clamp: 3;
  }
}

@container block (max-height: 94px) {
  .pc__line ~ .pc__line,
  .pc__chips,
  .pc__more {
    display: none;
  }

  .pc__line {
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }
}

@container block (max-height: 78px) or (max-width: 116px) {
  .pc__line,
  .pc__chips,
  .pc__more {
    display: none;
  }
}

@container block (max-width: 84px) or (max-height: 46px) {
  .pc__body {
    align-items: center;
    justify-content: center;
    padding: 2px;
  }

  .pc__head strong {
    display: none;
  }

  /* The stages have no number, so they keep their name on one line. */
  .pc--stages .pc__head strong {
    display: -webkit-box;
    font-size: 11px;
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }
}

/* The foundation: the cover, a plinth of dark stone with the game's name cut in it. */

.pc--cover {
  --ledge: 12px;
  grid-area: 2 / 1;
  z-index: 0;
  color: #efe6d2;
}

.pc--cover::before {
  background: linear-gradient(180deg, #26372d, #172219);
  clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 100%, 0 100%);
}

.pc--cover::after {
  content: '';
  position: absolute;
  inset: auto 5% -20px;
  z-index: -1;
  height: 26px;
  background: radial-gradient(closest-side, rgb(0 0 0 / 75%), transparent);
}

.pc--cover .pc__face {
  border: 1px solid #1f3027;
  border-top-color: rgb(212 175 98 / 60%);
  border-radius: 0 0 3px 3px;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 4%), transparent 40%),
    linear-gradient(180deg, #111c16, #060b08);
  box-shadow: inset 0 1px 0 rgb(246 227 168 / 12%);
}

.pc--cover.is-forming .pc__face {
  border-style: dashed;
  border-color: rgb(212 175 98 / 24%);
  background: linear-gradient(180deg, #0d1712, #060b08);
}

.pc--cover .pc__body {
  position: relative;
  inset: auto;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: calc(var(--ledge) + 18px) clamp(16px, 6cqi, 40px) 20px;
  font-size: 12.5px;
  text-align: center;
}

.pc__kicker {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.pc__title {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: #fbf5e6;
  font-family: var(--serif);
  font-size: clamp(24px, 6.2cqi, 40px);
  font-weight: 500;
  letter-spacing: 0.015em;
  line-height: 1.08;
  text-overflow: ellipsis;
  text-shadow:
    0 1px 0 rgb(0 0 0 / 70%),
    0 0 26px rgb(212 175 98 / 20%);
  white-space: nowrap;
}

.pc--cover.is-forming .pc__title {
  color: rgb(251 245 230 / 80%);
}

.pc--cover .pc__line {
  max-width: 60ch;
  color: rgb(239 230 210 / 66%);
}

.pc--cover .pc__chips {
  justify-content: center;
  margin: 4px 0 0;
  font-size: 11px;
}

.pc--cover .pc__chips li {
  padding: 2px 10px;
  border: 1px solid rgb(212 175 98 / 24%);
  background: rgb(212 175 98 / 5%);
  color: rgb(239 230 210 / 82%);
}

/* The capstone: the concept art cut to the tip, its two faces lit and shaded, under a gold rim. */

.pc--art {
  container: cap / size;
}

.pc__stone {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: rgb(0 250 105 / 3%);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  transition: background 0.6s ease;
}

.pc__art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s ease;
}

.pc__art[src] {
  opacity: 1;
}

/* Before the sheet is drawn, the look picked from the gallery shows faint in the capstone. */
.pc--art.is-forming .pc__art[src] {
  opacity: 0.34;
  filter: saturate(0.75);
}

.pc--art.is-stale .pc__art {
  opacity: 0.55;
}

.pc--art.is-forming .pc__stone {
  background: linear-gradient(180deg, #163a28, #0b2117);
}

.pc--art.is-setting .pc__stone {
  background: linear-gradient(180deg, #1d4d34, #0f2d1f);
}

.pc--art.is-set .pc__stone,
.pc--art.is-stale .pc__stone {
  background: linear-gradient(160deg, var(--gold-2), var(--gold) 55%, #9c7a37);
}

.pc__stone::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background:
    linear-gradient(180deg, rgb(255 240 200 / 26%), transparent 42%),
    linear-gradient(90deg, rgb(255 244 214 / 10%) 50%, rgb(8 5 0 / 30%) 50%);
  transition: opacity 0.6s ease;
}

.pc--art.is-set .pc__stone::after,
.pc--art.is-stale .pc__stone::after {
  opacity: 1;
}

.pc__rim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.pc__rim path {
  fill: none;
  stroke: var(--blueprint);
  stroke-dasharray: 4 4;
  stroke-linejoin: round;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  transition: stroke 0.5s ease;
}

.pc--art.is-forming .pc__rim path {
  stroke: rgb(84 178 126 / 60%);
  stroke-dasharray: none;
}

.pc--art.is-setting .pc__rim path {
  stroke: var(--accent);
  stroke-dasharray: none;
}

.pc--art.is-setting .pc__rim {
  animation: pc-rim 1.4s ease-in-out infinite;
}

.pc--art.is-set .pc__rim path {
  stroke: var(--gold-2);
  stroke-dasharray: none;
  stroke-width: 1.5;
}

.pc--art.is-stale .pc__rim path {
  stroke: var(--amber);
  stroke-dasharray: 5 3;
  stroke-width: 1.5;
}

/* The tip catches the light once the pyramid stands whole. */
.pc--art::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 34px;
  height: 34px;
  opacity: 0;
  background: radial-gradient(
    circle,
    rgb(255 251 235 / 95%),
    rgb(255 230 160 / 35%) 28%,
    transparent 66%
  );
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.pl-board.is-built .pc--art {
  filter: drop-shadow(0 0 18px rgb(246 227 168 / 32%));
}

.pl-board.is-built .pc--art::before {
  opacity: 0.85;
  animation: pc-glint 2.4s ease-in-out 0.6s both;
}

.pc--art .pc__body {
  inset: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  padding: 0 10% 7%;
  text-align: center;
  text-shadow: 0 1px 3px rgb(0 0 0 / 85%);
}

.pc--art .pc__head {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 11.5px;
  white-space: nowrap;
}

.pc--art .pc__mark {
  margin-left: 0;
}

.pc--art.is-forming,
.pc--art.is-setting {
  color: var(--ink);
}

.pc--art.is-set .pc__head,
.pc--art.is-stale .pc__head {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgb(18 13 4 / 74%);
  color: var(--gold-2);
  backdrop-filter: blur(6px);
}

.pc--art .pc__line {
  font-size: 10.5px;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

@container cap (max-height: 130px) {
  .pc--art .pc__line {
    display: none;
  }
}

@container cap (max-width: 110px) {
  .pc--art .pc__head {
    display: none;
  }
}

/* A piece whose state moved since the plan last showed is laid again, in turn, from the bottom. */

.pc.is-moved {
  animation: 0.8s cubic-bezier(0.22, 0.9, 0.3, 1.04) both;
  animation-delay: calc(var(--at) * 80ms);
}

.pc.is-moved.is-set,
.pc.is-moved.is-setting {
  animation-name: pc-lay;
}

.pc--cover.is-moved.is-set {
  animation-name: pc-found;
}

.pc.is-moved.is-forming {
  animation-name: pc-form;
}

.pc.is-moved.is-stale {
  animation-name: pc-lift;
}

.pc.is-moved.is-set .pc__face::after {
  animation: pc-shine 1.2s ease-out both;
  animation-delay: calc(var(--at) * 80ms + 0.5s);
}

@keyframes pc-lay {
  from {
    opacity: 0.2;
    transform: translateY(-28px);
  }

  62% {
    opacity: 1;
    transform: translateY(1.5px);
  }

  to {
    transform: none;
  }
}

@keyframes pc-found {
  from {
    opacity: 0.5;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pc-form {
  from {
    opacity: 0.3;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pc-lift {
  from {
    transform: none;
  }

  to {
    transform: translateY(-8px);
  }
}

@keyframes pc-shine {
  from {
    opacity: 1;
    background-position: 160% 0;
  }

  to {
    opacity: 1;
    background-position: -60% 0;
  }
}

@keyframes pc-sweep {
  from {
    background-position: 160% 0;
  }

  to {
    background-position: -60% 0;
  }
}

@keyframes pc-glow {
  0%,
  100% {
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 12%),
      0 0 10px rgb(0 250 105 / 16%);
  }

  50% {
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 12%),
      0 0 26px rgb(0 250 105 / 40%);
  }
}

@keyframes pc-rim {
  0%,
  100% {
    filter: drop-shadow(0 0 2px rgb(0 250 105 / 30%));
  }

  50% {
    filter: drop-shadow(0 0 9px rgb(0 250 105 / 70%));
  }
}

@keyframes pc-glint {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
  }

  40% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.3);
  }

  100% {
    opacity: 0.85;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes pc-spin {
  to {
    transform: rotate(1turn);
  }
}

@keyframes pc-fresh {
  0% {
    background: rgb(0 250 105 / 35%);
    box-shadow: 0 0 0 4px rgb(0 250 105 / 25%);
  }

  100% {
    background: transparent;
    box-shadow: 0 0 0 0 transparent;
  }
}

/* Under the pyramid: how many blocks are laid, and the way into the written plan. */

.pl-board__foot {
  display: grid;
  gap: 10px;
  justify-items: center;
  color: var(--ink-dim);
  font-size: 0.88rem;
  text-align: center;
}

.pl-board__foot p {
  max-width: 52ch;
  margin: 0;
}

.pl-board__foot strong {
  color: var(--ink);
}

.pl-board__progress {
  width: min(320px, 100%);
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(255 255 255 / 8%);
}

.pl-board__progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #9dfcc6);
  box-shadow: 0 0 10px rgb(0 250 105 / 55%);
  transition: width 0.6s ease;
}

.pl-board.is-built .pl-board__progress span {
  background: linear-gradient(90deg, var(--gold), var(--gold-2));
  box-shadow: 0 0 10px rgb(246 227 168 / 45%);
}

.planner .pl-board__read {
  margin: 2px 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .pc,
  .pc.is-moved,
  .pc__face,
  .pc__face::after,
  .pc__rim,
  .pc__line.is-fresh,
  .pc.is-setting .pc__mark::after,
  .pc--art::before {
    animation: none !important;
  }
}
