:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e2dfd8;
  --line-strong: #cbc7bd;
  --ink: #23211d;
  --ink-dim: #6b675e;
  --accent: #2f4858;
  --accent-soft: #eef1f3;
  --good: #2e7d4f;
  --good-soft: #e8f3ec;
  --bad: #b23b3b;
  --bad-soft: #f6e9e9;

  --ci: #1f7a8c;
  --ci-soft: #e6f1f4;
  --cd: #a2582b;
  --cd-soft: #f6eee7;

  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ---------- header ---------- */
.site-header {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 20px 8px;
}
.site-header h1 {
  font-size: 1.7rem;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
}

.scorebar {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  width: fit-content;
  background: var(--surface);
}
.score-pill {
  padding: 8px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 72px;
  border-right: 1px solid var(--line);
}
.score-pill:last-child { border-right: none; }
.score-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
}
.score-value { font-size: 1.15rem; font-weight: 650; }
.score-value.bump { animation: bump 0.3s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); color: var(--good); }
  100% { transform: scale(1); }
}

main { max-width: 880px; margin: 0 auto; padding: 24px 20px 8px; }

/* ---------- step hint ---------- */
.step-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-dim);
  font-size: 0.96rem;
  margin: 0 0 18px;
}
.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}
.stage-inline {
  font-weight: 700;
  font-family: "SFMono-Regular", "Consolas", "Menlo", monospace;
}
.stage-inline.ci { color: var(--ci); }
.stage-inline.cd { color: var(--cd); }

/* ---------- deck + card ---------- */
.deck-row {
  display: flex;
  align-items: stretch;
  gap: 30px;
  margin-bottom: 30px;
}

.deck {
  position: relative;
  width: 122px;
  height: 190px;
  flex-shrink: 0;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  /* A hatched back, so the deck reads as face-down cards. */
  background:
    repeating-linear-gradient(
      45deg,
      var(--accent-soft) 0 6px,
      var(--surface-2) 6px 12px
    );
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  /* Two offset copies behind it read as the rest of the stack. */
  box-shadow:
    4px 4px 0 0 var(--surface), 4px 4px 0 1px var(--line-strong),
    8px 8px 0 0 var(--surface), 8px 8px 0 1px var(--line);
}

/* Inset frame, matching the face-up card. */
.deck::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
}

/* The count sits on a solid plate so it stays readable over the hatching. */
.deck-count,
.deck-label {
  position: relative;
  z-index: 1;
  background: var(--surface);
  padding: 0 8px;
}
.deck-count { display: inline-block; font-size: 1.3rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.deck-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; }
.deck.empty { opacity: 0.35; box-shadow: none; }

/* The deck shakes when a missed card is slotted back into it. */
.deck.wiggle {
  animation: deck-wiggle 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
.deck.wiggle .deck-count {
  animation: deck-count-pop 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes deck-wiggle {
  0%   { transform: translateX(0) rotate(0deg); }
  15%  { transform: translateX(-5px) rotate(-3.5deg); }
  32%  { transform: translateX(4px) rotate(3deg); }
  50%  { transform: translateX(-3px) rotate(-2deg); }
  68%  { transform: translateX(2px) rotate(1.5deg); }
  85%  { transform: translateX(-1px) rotate(-0.5deg); }
  100% { transform: translateX(0) rotate(0deg); }
}
@keyframes deck-count-pop {
  0%   { transform: scale(1); color: var(--ink); }
  25%  { transform: scale(1.4); color: var(--good); }
  60%  { transform: scale(1.15); color: var(--good); }
  100% { transform: scale(1); color: var(--ink); }
}
@media (prefers-reduced-motion: reduce) {
  .deck.wiggle,
  .deck.wiggle .deck-count { animation: none; }
}

.card {
  position: relative;
  flex: 1;
  max-width: 400px;
  min-height: 190px;
  background: linear-gradient(145deg, #ffffff 0%, var(--surface-2) 100%);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 20px 22px 22px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.18s ease, transform 0.18s ease, opacity 0.15s;
  /* A thin inner highlight plus a soft drop shadow gives the impression of a
     physical card resting slightly above the page. */
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.9),
    0 1px 1px rgba(0, 0, 0, 0.04),
    0 6px 16px rgba(0, 0, 0, 0.08);
}

/* Faint diagonal stripes across the top of the card, echoing the deck's
   hatching. They sit inside the printed frame and fade out downwards, so the
   card text below stays on a clean background. */
.card-stripes {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  height: 78px;
  border-radius: 8px 8px 0 0;
  background: repeating-linear-gradient(
    45deg,
    var(--accent-soft) 0 3px,
    transparent 3px 9px
  );
  -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 0%, transparent 100%);
  pointer-events: none;
}

/* An inset hairline border, like the printed frame on a playing card. */
.card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  pointer-events: none;
}

.card:hover {
  transform: translateY(-3px) rotate(-0.4deg);
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.9),
    0 2px 3px rgba(0, 0, 0, 0.05),
    0 14px 30px rgba(0, 0, 0, 0.13);
}
.card:active {
  cursor: grabbing;
  transform: translateY(-1px) rotate(0deg) scale(0.99);
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.card.dragging { opacity: 0.35; }
.card.dealing { animation: deal 0.4s cubic-bezier(0.2, 0.85, 0.3, 1); }
@keyframes deal {
  0% {
    transform: translateX(-150px) translateY(6px) rotate(-9deg) scale(0.94);
    opacity: 0;
  }
  60% { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .card.dealing { animation: none; }
}
.card-kicker {
  position: relative;
  align-self: flex-start;
  padding-right: 30px;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-weight: 700;
  color: var(--ink-dim);
}

/* The card's face: the step itself, centred in the remaining space. */
.card-text {
  position: relative;
  margin: 0;
  flex: 1;
  display: flex;
  align-items: center;
  font-size: 1.12rem;
  font-weight: 550;
  line-height: 1.45;
  text-wrap: balance;
}

/* A small mark in the bottom corner, mirroring the kicker, the way a playing
   card repeats its rank at the opposite end. */
.card::after {
  content: "CI / CD";
  position: absolute;
  bottom: 18px;
  right: 22px;
  font-size: 0.6rem;
  letter-spacing: 0.13em;
  font-weight: 700;
  color: var(--line-strong);
  pointer-events: none;
}

/* ---------- the "?" marker and its tooltip ---------- */
.card-help {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.card-help:hover,
.card-help:focus-visible {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  outline: none;
}

.card-hint {
  position: absolute;
  top: 40px;
  right: 12px;
  z-index: 20;
  width: min(330px, calc(100% - 24px));
  background: var(--ink);
  color: #f4f3ef;
  border-radius: 6px;
  padding: 11px 14px;
  font-size: 0.87rem;
  font-weight: 400;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  pointer-events: none;
}
.card-hint::before {
  content: "";
  position: absolute;
  top: -5px;
  right: 8px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--ink);
}
.card-help:hover + .card-hint,
.card-help:focus-visible + .card-hint,
.card-hint.pinned {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: linear-gradient(145deg, #ffffff 0%, var(--surface-2) 100%);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 20px 22px;
  width: 280px;
  min-height: 150px;
  display: flex;
  align-items: center;
  font-weight: 550;
  line-height: 1.45;
  box-shadow:
    inset 0 1px 0 0 rgba(255, 255, 255, 0.9),
    0 18px 36px rgba(0, 0, 0, 0.22);
  transform: rotate(-3deg);
}

/* ---------- piles ---------- */
.piles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.pile {
  position: relative;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px 20px 20px;
  min-height: 132px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.pile-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.pile-abbr {
  font-family: "SFMono-Regular", "Consolas", "Menlo", monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.pile-name { font-size: 0.88rem; color: var(--ink-dim); }
.pile-blurb { margin: 8px 0 0; font-size: 0.92rem; color: var(--ink-dim); }
.pile-blurb strong { color: var(--ink); font-weight: 600; }

.pile[data-stage="ci"] .pile-abbr { color: var(--ci); }
.pile[data-stage="cd"] .pile-abbr { color: var(--cd); }

.pile[data-stage="ci"].drag-over {
  border-color: var(--ci);
  border-style: solid;
  background: var(--ci-soft);
  transform: translateY(-2px);
}
.pile[data-stage="cd"].drag-over {
  border-color: var(--cd);
  border-style: solid;
  background: var(--cd-soft);
  transform: translateY(-2px);
}

.pile-tally {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--ink-dim);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1px 10px;
}

/* After a drop, the correct pile is green and a wrongly chosen pile is red.
   These stay on screen while the player reads the feedback. */
.pile.flash-good {
  border-color: var(--good);
  border-style: solid;
  background: var(--good-soft);
}
.pile.flash-bad {
  border-color: var(--bad);
  border-style: solid;
  background: var(--bad-soft);
}
.pile.flash-good .pile-abbr { color: var(--good); }
.pile.flash-bad .pile-abbr { color: var(--bad); }
.pile.flash-good .pile-tally { border-color: var(--good); color: var(--good); }
.pile.flash-bad .pile-tally { border-color: var(--bad); color: var(--bad); }

/* A tick or cross in the corner, so the verdict does not rely on colour alone. */
.pile.flash-good::after,
.pile.flash-bad::after {
  position: absolute;
  bottom: 14px;
  right: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  animation: verdict-in 0.25s ease;
}
.pile.flash-good::after { content: "✓"; color: var(--good); }
.pile.flash-bad::after { content: "✕"; color: var(--bad); }
@keyframes verdict-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

/* The tally shakes and swells when a card lands on that pile. */
.pile-tally.wiggle {
  animation: tally-wiggle 0.55s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes tally-wiggle {
  0%   { transform: scale(1) rotate(0deg); }
  15%  { transform: scale(1.35) rotate(-9deg); background: var(--accent-soft); border-color: var(--accent); }
  35%  { transform: scale(1.3) rotate(8deg); }
  55%  { transform: scale(1.25) rotate(-6deg); }
  75%  { transform: scale(1.15) rotate(4deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
  .pile-tally.wiggle { animation: none; }
}

/* ---------- category choices ---------- */
.category-area .step-hint { margin-bottom: 10px; }
.echoed-card {
  margin: 0 0 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 550;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}
.choice {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 14px 16px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 0.98rem;
  transition: border-color 0.12s, background 0.12s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-2); }
.choice:disabled { cursor: default; }
.choice-name { display: block; font-weight: 600; }
.choice-description { display: block; font-size: 0.86rem; color: var(--ink-dim); margin-top: 3px; }
.choice.correct { background: var(--good-soft); border-color: var(--good); }
.choice.correct .choice-name { color: var(--good); }
.choice.wrong { background: var(--bad-soft); border-color: var(--bad); }
.choice.wrong .choice-name { color: var(--bad); }

/* ---------- result ---------- */
.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 16px;
}
.result-card.good { border-left-color: var(--good); }
.result-card.partial { border-left-color: #c97d1a; }
.result-card.bad { border-left-color: var(--bad); }

.result-verdict { margin: 0 0 10px; font-size: 1.08rem; font-weight: 650; }
.result-card.good .result-verdict { color: var(--good); }
.result-card.partial .result-verdict { color: #a8690f; }
.result-card.bad .result-verdict { color: var(--bad); }

.result-lines { margin: 0; padding: 0; list-style: none; }
.result-lines li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 7px;
  color: var(--ink-dim);
  font-size: 0.95rem;
}
.result-lines li:last-child { margin-bottom: 0; }
.result-lines li::before {
  position: absolute;
  left: 0;
  font-weight: 700;
}
.result-lines li.correct::before { content: "✓"; color: var(--good); }
.result-lines li.incorrect::before { content: "✕"; color: var(--bad); }
.result-lines li.info::before { content: "→"; color: var(--accent); }
.result-lines li.repeat::before { content: "↻"; color: var(--ink-dim); }
.result-lines strong { color: var(--ink); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 10px 22px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.9; }

/* ---------- summary ---------- */
.summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
}
.summary h2 { margin: 0 0 8px; font-size: 1.6rem; }
.summary-line { color: var(--ink-dim); margin: 0 0 22px; }

.summary-rules {
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 22px;
}
.summary-rules p { margin: 0 0 8px; font-size: 0.94rem; color: var(--ink-dim); }
.summary-rules p:last-child { margin-bottom: 0; }

.summary-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  text-align: left;
  margin-bottom: 24px;
}
.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 13px;
  font-size: 0.9rem;
  background: var(--surface-2);
}
.breakdown-label { color: var(--ink-dim); }
.breakdown-value { font-weight: 650; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 550;
  font-size: 0.9rem;
  z-index: 50;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---------- footer ---------- */
.site-footer {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.82rem;
  padding: 32px 20px;
  border-top: 1px solid var(--line);
  max-width: 880px;
  margin: 24px auto 0;
}

@media (max-width: 620px) {
  .piles { grid-template-columns: 1fr; }
  .deck-row { gap: 16px; }
  .deck { width: 82px; height: 168px; }
  .deck-count { font-size: 1.1rem; }
  .deck-label { font-size: 0.6rem; }
  .card { min-height: 168px; padding: 16px 18px 18px; }
  .card-text { font-size: 1rem; }
  .card::after { bottom: 14px; right: 18px; }
  .scorebar { width: 100%; }
  .score-pill { flex: 1; padding: 8px 12px; min-width: 0; }
}
