:root {
  /* Emil easing curves */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --bg: #fafafa;
  --surface: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #18181b;
  --text-muted: #71717a;
  --text-faint: #a1a1aa;
  --accent: #18181b;
  --hover: #f4f4f5;

  /* contribution scale */
  --c0: #ebedf0;
  --c1: #9be9a8;
  --c2: #40c463;
  --c3: #30a14e;
  --c4: #216e39;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background-color: var(--bg);
  /* whisper-faint dot grid for texture, not noise */
  background-image: radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── layout ────────────────────────────────────────────────────────────── */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 56px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

/* page entrance: each block fades up, gently staggered */
.profile,
.section {
  opacity: 0;
  transform: translateY(10px);
  animation: blockIn 520ms var(--ease-out) forwards;
}
.profile  { animation-delay: 40ms; }
.section:nth-of-type(1) { animation-delay: 110ms; }
.section:nth-of-type(2) { animation-delay: 170ms; }
.section:nth-of-type(3) { animation-delay: 230ms; }
.section:nth-of-type(4) { animation-delay: 290ms; }

@keyframes blockIn {
  to { opacity: 1; transform: translateY(0); }
}

/* ── profile header ────────────────────────────────────────────────────── */
.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

#avatar {
  display: block;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: var(--hover);
  object-fit: cover;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.10);
  transition: transform 240ms var(--ease-out), box-shadow 240ms var(--ease-out);
  cursor: pointer;
}

/* fun: click the avatar for a quick flip */
#avatar.spin { animation: flip 720ms var(--ease-in-out); }

@keyframes flip {
  to { transform: rotateY(360deg); }
}

@media (hover: hover) and (pointer: fine) {
  #avatar:hover {
    transform: scale(1.04);
    box-shadow:
      0 2px 4px rgba(0, 0, 0, 0.08),
      0 14px 34px rgba(0, 0, 0, 0.14);
  }
}

.profile-name {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
  cursor: default;
}

/* fun: hover the name and a colour shimmer sweeps across it */
@media (hover: hover) and (pointer: fine) {
  .profile-name:hover {
    background: linear-gradient(110deg, var(--text) 30%, #6366f1 50%, var(--text) 70%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 900ms var(--ease-in-out);
  }
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to   { background-position: -120% 0; }
}

.profile-sub {
  font-size: 14px;
  color: var(--text-muted);
}

.profile-sub a {
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
  transition: border-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.profile-sub a:hover { border-color: var(--text); }

.profile-stats {
  font-size: 12.5px;
  color: var(--text-faint);
  letter-spacing: 0.01em;
}

/* ── sections ──────────────────────────────────────────────────────────── */
.section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.section-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -4px;
}

/* ── contributions ─────────────────────────────────────────────────────── */
#contrib-graph {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-columns: 1fr;
  gap: 3px;
  width: 100%;
  aspect-ratio: 53 / 7;
}

#contrib-graph .cell {
  border-radius: 2px;
  background: var(--c0);
  /* one-time reveal: a soft wave from left to right (delay set per-column in JS).
     `backwards` shows the start state during the delay, then releases the
     transform so hover interactions can take over afterwards. */
  animation: cellIn 380ms var(--ease-out) backwards;
  animation-delay: var(--cell-delay, 0ms);
}

@keyframes cellIn {
  from { opacity: 0; transform: scale(0.6); }
  to   { opacity: 1; transform: scale(1); }
}

/* qualify with the id so these beat the base `#contrib-graph .cell` rule */
#contrib-graph .cell.level-1 { background: var(--c1); }
#contrib-graph .cell.level-2 { background: var(--c2); }
#contrib-graph .cell.level-3 { background: var(--c3); }
#contrib-graph .cell.level-4 { background: var(--c4); }

/* playful: sweep the mouse across the graph and the days pop up */
@media (hover: hover) and (pointer: fine) {
  #contrib-graph .cell {
    transition: transform 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
  }
  #contrib-graph .cell:hover {
    transform: scale(1.55);
    border-radius: 3px;
    z-index: 2;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
  }
}

/* ── repositories ──────────────────────────────────────────────────────── */
#repo-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.repo-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 15px 17px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transform-origin: center;
  transition:
    transform 130ms var(--ease-out),
    box-shadow 180ms var(--ease-out),
    border-color 180ms var(--ease-out);
  /* staggered entrance once the list is filled (`backwards` releases the
     transform afterwards so the play-tilt can take over) */
  animation: cardIn 420ms var(--ease-out) backwards;
}
.repo-card:nth-child(1) { animation-delay: 30ms; }
.repo-card:nth-child(2) { animation-delay: 65ms; }
.repo-card:nth-child(3) { animation-delay: 100ms; }
.repo-card:nth-child(4) { animation-delay: 135ms; }
.repo-card:nth-child(5) { animation-delay: 170ms; }
.repo-card:nth-child(6) { animation-delay: 205ms; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* shadow + border lift on hover; the 3D tilt itself is driven in JS */
@media (hover: hover) and (pointer: fine) {
  .repo-card:hover {
    border-color: var(--border-strong);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.10);
  }
}

.repo-card:active { transform: scale(0.98); }

.repo-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.repo-name {
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.repo-desc {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-muted);
}

.repo-lang {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  padding-top: 2px;
}

.repo-lang::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c3);
  flex-shrink: 0;
}

/* the featured live demo gets a gently pulsing dot */
.repo-lang.live::before {
  background: var(--c2);
  animation: livePulse 2.2s var(--ease-in-out) infinite;
}
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(64, 196, 99, 0.45); }
  70%  { box-shadow: 0 0 0 6px rgba(64, 196, 99, 0); }
  100% { box-shadow: 0 0 0 0 rgba(64, 196, 99, 0); }
}

/* ── diversion: reflex game ────────────────────────────────────────────── */
.game {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.game-score {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
/* a small pop each time the score ticks up (class re-triggered in JS) */
.game-score.bump { animation: scoreBump 240ms var(--ease-out); }
@keyframes scoreBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.game-best {
  font-size: 12.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* slim countdown bar; the fill drains left over the round (driven in JS) */
.game-track {
  height: 4px;
  border-radius: 999px;
  background: var(--c0);
  overflow: hidden;
}
.game-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: var(--c3);
  transform-origin: left center;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  aspect-ratio: 1;
}

.game-cell {
  border-radius: 8px;
  background: var(--c0);
  /* only transform/opacity/shadow animate — cheap, GPU-friendly */
  transition:
    transform 150ms var(--ease-out),
    box-shadow 200ms var(--ease-out),
    background-color 220ms var(--ease-out);
}

.game-cell.lit {
  background: var(--c2);
  box-shadow: 0 4px 14px rgba(48, 161, 78, 0.35);
}

/* press feedback — the whole grid is the playfield */
@media (hover: hover) and (pointer: fine) {
  .game-cell.lit:hover { transform: scale(1.04); }
}
.game.playing .game-cell { cursor: pointer; }
.game.playing .game-cell:active { transform: scale(0.94); }

/* a quick ring-out pop when a lit cell is caught */
.game-cell.hit { animation: cellHit 320ms var(--ease-out); }
@keyframes cellHit {
  0%   { transform: scale(1); box-shadow: 0 0 0 0 rgba(48, 161, 78, 0.5); }
  40%  { transform: scale(1.1); }
  100% { transform: scale(1); box-shadow: 0 0 0 12px rgba(48, 161, 78, 0); }
}

/* a gentle nudge on a wrong tap — feedback without punishment */
.game-cell.miss { animation: cellMiss 260ms var(--ease-in-out); }
@keyframes cellMiss {
  0%, 100% { transform: translateX(0); }
  30%      { transform: translateX(-3px); }
  70%      { transform: translateX(3px); }
}

/* overlay holds the start / replay button; fades + blurs out during play */
.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(2px);
  transition: opacity 220ms var(--ease-out);
}
.game.playing .game-overlay {
  opacity: 0;
  pointer-events: none;
}

.game-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--surface);
  background: var(--accent);
  border: none;
  border-radius: 11px;
  padding: 11px 22px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
  transition: transform 140ms var(--ease-out), box-shadow 180ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .game-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.20);
  }
}
.game-btn:active { transform: scale(0.96); }

/* ── konami easter egg: the playfield overloads ────────────────────────── */
body.freakout .game-grid { animation: rainbow 900ms linear 3; }
body.freakout #contrib-graph { animation: rainbow 900ms linear 3; }

@keyframes rainbow {
  to { filter: hue-rotate(360deg); }
}

body.freakout .profile-name {
  animation: shake 480ms var(--ease-in-out) 3;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-5px) rotate(-2deg); }
  75%      { transform: translateX(5px) rotate(2deg); }
}

/* ── footer ────────────────────────────────────────────────────────────── */
.footer {
  padding: 44px 0 52px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}

.footer a {
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
  transition: border-color 160ms var(--ease-out), color 160ms var(--ease-out);
}
.footer a:hover { color: var(--text); border-color: var(--text); }

/* ── larger screens ────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .container { padding-top: 88px; gap: 64px; }
  #avatar { width: 120px; height: 120px; }
  .profile-name { font-size: 38px; }
}

/* ── reduced motion: keep fades, drop movement ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .profile, .section, .repo-card, #contrib-graph .cell {
    animation: none;
    opacity: 1;
    transform: none;
  }
  #avatar.spin,
  body.freakout .game-grid, body.freakout #contrib-graph,
  body.freakout .profile-name,
  .repo-lang.live::before { animation: none; }
  #avatar:hover { transform: none; }
  .repo-card:hover { transform: none; }
  #contrib-graph .cell:hover { transform: scale(1.3); }
  /* keep the game playable: colour cues stay, movement drops */
  .game-cell, .game-cell.hit, .game-cell.miss,
  .game-score { animation: none; transition: background-color 180ms var(--ease-out); }
  .game-cell.lit:hover, .game.playing .game-cell:active,
  .game-score.bump { transform: none; }
}
