:root {
  --bg: #0d1117;
  --card: #161b22;
  --line: #30363d;
  --ink: #e6edf3;
  --mute: #8b949e;
  --snippet: #4caf50;
  --site: #2196f3;
  --insight: #ff9800;
  --shop: #e91e63;
  --W: min(340px, calc(100vw - 80px));
  --H: min(440px, 70vh);
  --sans: "Arimo", Arial, "Helvetica Neue", Helvetica, sans-serif;
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  overscroll-behavior-x: none; /* a sideways trackpad swipe shouldn't trigger browser back */
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

body {
  font: 700 16px/1.4 var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

[data-type="snippet"] { --a: var(--snippet); }
[data-type="site"] { --a: var(--site); }
[data-type="insight"] { --a: var(--insight); }
[data-type="shop"] { --a: var(--shop); }

/* ---------- header ---------- */

.top {
  padding: 18px 16px 0;
}

.home {
  color: var(--mute);
  text-decoration: none;
  font-size: 0.85rem;
}

.home span { display: inline-block; transition: transform 0.2s; }
.home:hover { color: var(--ink); }
.home:hover span { transform: translateX(-4px); }

/* ---------- stage + cards ---------- */

.stage {
  position: relative;
  flex: 1 0 auto;
  min-height: calc(var(--H) + 120px);
  overflow: hidden;
  isolation: isolate; /* keep the cards' z-index stacking inside the stage */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}

body.dragging, body.dragging * { cursor: grabbing !important; }
.card:not(.is-front) .tilt { cursor: pointer; }

/* "3 / 20", sitting just above the front card */
.counter {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - var(--H) / 2 - 40px);
  z-index: 20000;
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: var(--mute);
  pointer-events: none;
}

.deck {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* only the card faces take clicks: a card's own (invisible) box would otherwise sit in front of
   whichever part of the tilted face leans back, and swallow clicks there */
.deck > .card { pointer-events: none; }
.deck > .card > .tilt, .empty { pointer-events: auto; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--mute);
}

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--W);
  height: var(--H);
  margin: calc(var(--H) / -2) 0 0 calc(var(--W) / -2);
  transform-style: preserve-3d;
  will-change: transform;
}

.tilt {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--card);
  border: 2px solid var(--a);
  border-radius: var(--radius);
}

/* fades cards that are further back (everything on them, buttons included) */
.tilt::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: var(--radius);
  z-index: 3;
  background: var(--bg);
  opacity: var(--dim, 0);
  pointer-events: none;
}

.card:not(.is-front) .face { pointer-events: none; }

.face {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius) - 2px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mute);
}

.kind { color: var(--a); }

.face h2 {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.face p, .steps {
  margin: 0;
  font-weight: 400;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--mute);
}

.face .blurb { font-size: 1rem; color: var(--ink); }

.steps { padding-left: 1.4em; }
.steps li { margin: 0.25em 0; }
.steps li::marker { color: var(--a); font-weight: 700; }

.face p code, .steps code {
  font-family: var(--mono);
  font-size: 0.92em;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0 0.3em;
}

.code {
  margin: 0;
  flex: none;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  font: 400 0.8rem/1.55 var(--mono);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
  position: relative;
  cursor: copy;
  transition: border-color 0.4s;
}

.is-front .code:hover, .code.copied { border-color: var(--a); }

/* shop cards: a list of linked items */
.items {
  list-style: none;
  margin: 0;
  padding: 0;
}

.items li { border-bottom: 1px solid var(--line); }
.items li:last-child { border-bottom: 0; }

.items .row {
  display: block;
  padding: 4px 0;
  color: var(--ink);
  text-decoration: none;
  line-height: 1.3;
}

.items .name { font-size: 0.9rem; }
.items a .name::after { content: " \2197"; color: var(--a); }
.items a:hover .name { color: var(--a); }

.items .detail {
  display: block;
  font-weight: 400;
  font-size: 0.76rem;
  color: var(--mute);
}

/* small "copied" note that fades in on the code block */
.code::after {
  content: "copied";
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 0 6px;
  background: var(--bg);
  color: var(--a);
  font: 700 0.7rem/1.6 var(--sans);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.code.copied::after { opacity: 1; }

.actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 4px;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  color: var(--a);
  background: var(--card);
  border: 2px solid var(--a);
  padding: 6px 14px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.btn:hover { background: color-mix(in srgb, var(--a) 14%, var(--card)); }
.btn:active { background: var(--a); color: var(--bg); }
