/* Patterns page — drill decks. Leans on style.css for tokens and base. */

:root,
[data-theme="dark"] {
  --code-bg: rgba(124, 155, 255, 0.07);
  --code-str: #9db4e8;
  --code-num: #7c9bff;
  --panel: rgba(124, 155, 255, 0.04);
}

[data-theme="light"] {
  --code-bg: rgba(34, 71, 232, 0.05);
  --code-str: #44599c;
  --code-num: #2247e8;
  --panel: rgba(34, 71, 232, 0.03);
}

body.patterns-page {
  background-image: var(--grid-tex);
}

.patterns {
  display: flex;
  width: min(100%, 960px);
  min-height: 100svh;
  padding: clamp(1.5rem, 4vh, 3rem) var(--page-pad) 1.75rem;
  margin-inline: auto;
  flex-direction: column;
}

.patterns-top {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}

.patterns-home {
  color: var(--text-soft);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: color 180ms ease;
}

.patterns-home:hover {
  color: var(--accent);
}

.patterns h1 {
  margin-top: clamp(2.5rem, 7vh, 4.5rem);
  font-size: clamp(2.4rem, 5.5vw, 4.2rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.95;
  text-wrap: balance;
}

.patterns-intro {
  max-width: 640px;
  margin-top: clamp(1.25rem, 3vh, 2rem);
  color: var(--text-soft);
  font-size: clamp(1.02rem, 1.4vw, 1.2rem);
  letter-spacing: -0.015em;
  line-height: 1.5;
}

.patterns-app {
  margin-top: clamp(2rem, 5vh, 3.5rem);
}

/* ------------------------------------------------------------- deck list */

.deck-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.deck-card {
  display: flex;
  padding: clamp(1.25rem, 2.5vw, 1.75rem);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-bg);
  box-shadow: var(--glass-rim), var(--glass-drop);
  flex-direction: column;
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  transition: border-color 200ms ease;
}

.deck-card:hover {
  border-color: var(--accent);
}

.deck-meta {
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.deck-card h2 {
  margin: 0.85rem 0 0;
  font-size: clamp(1.35rem, 2.2vw, 1.7rem);
  font-weight: 500;
  letter-spacing: -0.03em;
}

.deck-blurb {
  margin-top: 0.6rem;
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.5;
}

.deck-progress {
  display: flex;
  margin-top: 1.4rem;
  gap: 0.75rem;
  align-items: center;
}

.deck-bar {
  display: block;
  overflow: hidden;
  height: 2px;
  flex: 1;
  border-radius: 999px;
  background: var(--line);
}

.deck-bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 400ms ease;
}

.deck-count {
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

.link-reset,
.link-back {
  padding: 0;
  border: none;
  background: none;
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 180ms ease;
}

.link-reset:hover,
.link-back:hover {
  color: var(--accent);
}

/* --------------------------------------------------------------- buttons */

.btn {
  padding: 0.8rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  /* --tx/--ty: magnetic lean toward the pointer, set from main.js */
  transform: translate(var(--tx, 0px), var(--ty, 0px));
  transition:
    border-color 200ms ease,
    background 200ms ease,
    color 200ms ease,
    transform 90ms ease;
}

.btn:active {
  transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(0.96);
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.btn-primary:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.deck-card .btn {
  margin-top: 1.25rem;
  align-self: flex-start;
}

/* --------------------------------------------------------------- session */

.session-top {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
}

.session-count {
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Acknowledges a registered grade as the counter advances */
.session-count.is-ticked {
  animation: count-tick 450ms ease;
}

@keyframes count-tick {
  30% {
    color: var(--accent);
  }
}

.drill {
  padding: clamp(1.25rem, 3vw, 2rem);
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-bg);
  box-shadow: var(--glass-rim), var(--glass-drop);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}

/* Animate the card's contents, never .drill itself: animating opacity or
   transform on the glass element blanks its backdrop-filter until done */
.drill > .drill-kicker,
.drill > .drill-prompt,
.drill > .drill-actions,
.drill > .drill-keys {
  animation: drill-in 200ms ease both;
}

@keyframes drill-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
}

.drill-kicker {
  display: flex;
  gap: 0.85rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.drill-type {
  padding: 0.25rem 0.55rem;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 999px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.drill-title {
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.drill-prompt,
.drill-answer {
  margin-top: 1.25rem;
}

/* Plays when [hidden] is removed on reveal, not on initial render */
.drill-answer {
  animation: reveal-in 240ms ease both;
}

@keyframes reveal-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.drill-prompt p,
.drill-answer p,
.end-missed li {
  max-width: 640px;
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.6;
}

.drill-prompt p + p,
.drill-answer p + p {
  margin-top: 0.75rem;
}

.drill-answer {
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.drill-list {
  max-width: 640px;
  padding: 0;
  margin: 0.75rem 0 0;
  counter-reset: drill;
  list-style: none;
}

.drill-list li {
  display: flex;
  padding-block: 0.3rem;
  gap: 0.75rem;
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.6;
}

.drill-list li::before {
  flex: none;
  color: var(--accent);
  font-family: var(--mono);
}

ol.drill-list li::before {
  counter-increment: drill;
  content: counter(drill);
}

ul.drill-list li::before {
  content: "→";
}

.drill-list + p {
  margin-top: 0.75rem;
}

.drill-prompt code,
.drill-answer code,
.end-missed code {
  padding: 0.1em 0.35em;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.85em;
}

code.nb {
  white-space: nowrap;
}

pre.code {
  overflow-x: auto;
  max-width: 100%;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 1rem 0 0;
  background: var(--code-bg);
  font-size: 0.84rem;
  line-height: 1.6;
  tab-size: 2;
}

pre.code code {
  padding: 0;
  background: none;
  font-family: var(--mono);
  font-size: 1em;
}

/* Prism tokens mapped onto the site palette (both themes via vars) */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: var(--text-mute); font-style: italic; }

.token.keyword { color: var(--accent); font-weight: 600; }

.token.string,
.token.template-string,
.token.attr-value,
.token.regex { color: var(--code-str); }

.token.number,
.token.boolean,
.token.constant { color: var(--code-num); }

.token.function { font-weight: 600; }

.token.class-name,
.token.tag { color: var(--accent); }

.token.tag .token.punctuation { color: var(--accent); }

.token.attr-name { color: var(--code-num); }

.token.punctuation,
.token.operator { color: var(--text-soft); }

.token.interpolation-punctuation { color: var(--accent); }

.drill-actions {
  display: flex;
  margin-top: 1.5rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.drill-keys {
  margin-top: 1.25rem;
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.05em;
}

/* ------------------------------------------------------------- end screen */

.session-end {
  padding-top: clamp(1.5rem, 5vh, 3rem);
}

.end-title {
  margin: 0.85rem 0 0;
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.95;
}

.end-score {
  margin-top: 1rem;
  color: var(--text-soft);
  font-size: 1.05rem;
}

.end-dots {
  display: flex;
  margin-top: 1.4rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.end-dot {
  width: 11px;
  height: 11px;
  border: 1px solid var(--line);
  border-radius: 50%;
  animation: dot-pop 400ms cubic-bezier(0.2, 0.9, 0.3, 1.4) backwards;
}

.end-dot.is-got {
  border-color: var(--accent);
  background: var(--accent);
}

@keyframes dot-pop {
  from {
    opacity: 0;
    transform: scale(0.2);
  }
}

.confetti {
  position: fixed;
  z-index: 150;
  inset: 0;
  pointer-events: none;
}

.end-missed {
  margin-top: 1.5rem;
}

.end-missed ul {
  padding: 0;
  margin-top: 0.75rem;
  list-style: none;
}

.end-missed li {
  display: flex;
  padding-block: 0.3rem;
  gap: 0.75rem;
}

.end-missed li::before {
  color: var(--accent);
  content: "→";
  font-family: var(--mono);
}

/* ------------------------------------------------------------------- 404 */

.not-found-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
}

.not-found-body h1 {
  margin-top: 0.85rem;
}

.not-found-body .drill-actions {
  margin-top: 2.25rem;
}

.not-found-body .btn {
  text-align: center;
}

/* ---------------------------------------------------------------- footer */

.patterns-foot {
  display: flex;
  margin-top: auto;
  padding-top: 1.1rem;
  gap: 1rem;
  justify-content: space-between;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.patterns-app {
  padding-bottom: clamp(2rem, 5vh, 3.5rem);
}

/* ----------------------------------------------------------- responsive */

@media (max-width: 620px) {
  .deck-grid {
    grid-template-columns: 1fr;
  }

  .drill-actions .btn {
    flex: 1;
    text-align: center;
  }

  .patterns-foot {
    flex-direction: column;
    gap: 0.4rem;
  }
}

/* Screen-level view transitions (home ⇄ session ⇄ end), via swapView() */
::view-transition-old(root) {
  animation: vt-out 140ms ease both;
}

::view-transition-new(root) {
  animation: vt-in 220ms ease both;
}

@keyframes vt-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .end-dot,
  .drill > .drill-kicker,
  .drill > .drill-prompt,
  .drill > .drill-actions,
  .drill > .drill-keys,
  .drill-answer,
  .session-count.is-ticked {
    animation: none;
  }

  .btn:active {
    transform: none;
  }
}

/* Solid fallbacks where backdrop-filter isn't supported */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .deck-card,
  .drill {
    background: var(--panel);
    box-shadow: none;
  }
}
