/* ========== TOKENS ========== */
:root {
  --bg: #faf8f1;
  --bg-deep: #f3f0e6;
  --ink: #121212;
  --ink-soft: #4a4a45;
  --ink-faint: #8a8880;
  --tile-bg: #efefe6;
  --tile-bg-hover: #e6e5d9;
  --tile-selected: #5a594e;
  --tile-selected-text: #ffffff;
  --rule: #1c1c1c;

  --yellow: #f9df6d;
  --green:  #a0c35a;
  --blue:   #b0c4ef;
  --purple: #ba81c5;
  --pink:   #ffb3d1;

  --serif: "Fraunces", "Times New Roman", Georgia, serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  --radius: 10px;
  --max:   720px;
  --max-w: 880px;

  --shadow-soft: 0 1px 0 rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.04);
}

/* ========== RESET ========== */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; cursor: pointer; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; }

/* ========== LAYOUT ========== */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 56px 24px 80px;
}

/* ========== TYPING EFFECT ========== */
[data-type] { opacity: 0; }
[data-type].typing,
[data-type].typed { opacity: 1; }
[data-type].typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 4px;
  font-weight: 400;
  color: var(--ink-faint);
  animation: caret 0.7s step-end infinite;
}
@keyframes caret {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ========== HERO ========== */
.hero { text-align: center; padding: 32px 0 28px; }
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 18px;
}
.hero h1 {
  font-size: clamp(40px, 10vw, 96px);
  margin: 0;
  letter-spacing: -0.035em;
}
.hero h1 .italic {
  font-style: italic;
  font-weight: 600;
  display: inline-block;
  background: linear-gradient(180deg, transparent 60%, var(--pink) 60%);
  padding: 0 6px;
}
.tagline {
  font-family: var(--serif);
  font-size: clamp(17px, 2.2vw, 22px);
  color: var(--ink-soft);
  margin: 14px auto 0;
  max-width: 540px;
}
.dim { color: var(--ink-faint); }

/* Hand-drawn pencil circle */
.circled {
  position: relative;
  display: inline-block;
  white-space: nowrap;
  padding: 2px 4px;
}
.circle-doodle {
  position: absolute;
  left: -10px;
  right: -10px;
  bottom: -14px;
  width: calc(100% + 20px);
  height: 18px;
  transform: rotate(-0.5deg);
  pointer-events: none;
  overflow: visible;
}
.circle-doodle path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 240;
  stroke-dashoffset: 240;
  animation: drawCircle 1.1s cubic-bezier(0.4, 0, 0.2, 1) 1.6s forwards;
}
@keyframes drawCircle {
  to { stroke-dashoffset: 0; }
}

/* ========== GAME ========== */
.game {
  margin: 36px auto 64px;
  max-width: var(--max);
}
.solved { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.solved-row {
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
  color: #1a1a1a;
  font-weight: 600;
  letter-spacing: 0.02em;
  animation: revealRow 0.5s ease;
}
.solved-row .row-label {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 800;
  font-size: 18px;
  display: block;
  margin-bottom: 2px;
}
.solved-row .row-items {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}
.solved-row.yellow { background: var(--yellow); }
.solved-row.green  { background: var(--green); }
.solved-row.blue   { background: var(--blue); }
.solved-row.purple { background: var(--purple); }

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.tile {
  appearance: none;
  border: none;
  background: var(--tile-bg);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 6px 8px;
  aspect-ratio: 1.55 / 1;
  font-family: var(--sans);
  font-weight: 700;
  font-size: clamp(10px, 1.8vw, 14px);
  letter-spacing: 0.02em;
  line-height: 1.15;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow-wrap: break-word;
  hyphens: manual;
  cursor: pointer;
  user-select: none;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease;
  animation: tilePop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}
.tile:hover:not(.selected):not(.locked) { background: var(--tile-bg-hover); transform: translateY(-1px); }
.tile.selected {
  background: var(--tile-selected);
  color: var(--tile-selected-text);
  transform: translateY(-2px);
}
.tile.shake { animation: shake 0.45s ease; }
.tile.pop   { animation: pop   0.35s ease; }
.tile.locked { pointer-events: none; opacity: 0; transform: scale(0.9); transition: opacity 0.4s ease, transform 0.4s ease; }
.tile.fade-out { opacity: 0; transform: scale(0.92); transition: opacity 0.35s ease, transform 0.35s ease; }

.meta {
  display: flex; justify-content: center; align-items: center;
  margin: 22px 0 6px;
  font-size: 14px;
  color: var(--ink-soft);
}
.mistakes { display: flex; align-items: center; gap: 10px; }
.dots { display: flex; gap: 7px; }
.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--ink);
  transition: background 200ms ease, transform 200ms ease;
}
.dot.spent { background: transparent; border: 1.5px solid var(--ink-faint); transform: scale(0.85); }

/* Toast popup — for game progress messages */
#toast-host {
  position: fixed;
  top: 24px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 200;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 999px;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18), 0 2px 0 rgba(0,0,0,0.04);
  opacity: 0;
  transform: translateY(-16px) scale(0.96);
  transition: opacity 220ms ease, transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.controls {
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
  margin: 6px 0 18px;
}
.btn {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  padding: 11px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  transition: background 150ms ease, color 150ms ease, transform 100ms ease;
}
.btn:hover { background: var(--ink); color: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: transparent; color: var(--ink); }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: #000; }
.btn-primary:disabled { background: var(--ink); color: var(--bg); }

.skip-link {
  display: block;
  margin: 4px auto 0;
  background: none; border: none;
  color: var(--ink-faint);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.skip-link:hover { color: var(--ink); }

/* ========== SECTION CHROME ========== */
section.about, section.timeline, section.contact {
  border-top: 1px solid var(--rule);
  padding: 56px 0 24px;
  margin-top: 24px;
}
.section-eyebrow {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 14px;
}
section h2 {
  font-size: clamp(34px, 6vw, 56px);
  margin: 0 0 24px;
}
section h2 .italic {
  font-style: italic;
  font-weight: 600;
  background: linear-gradient(180deg, transparent 60%, var(--pink) 60%);
  padding: 0 6px;
}
.about p { font-size: 18px; max-width: 640px; line-height: 1.65; color: var(--ink-soft); }
.about p strong { color: var(--ink); }
.about a { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* ========== TIMELINE ========== */
.track {
  list-style: none;
  margin: 0;
  padding: 0 0 0 28px;
  position: relative;
  border-left: 1.5px dashed #1c1c1c33;
}
.entry {
  position: relative;
  padding: 0 0 44px;
  display: block;
}
.entry:has(.thumb), .entry:has(.thumb-stack) {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 28px;
  align-items: start;
}
.entry:has(.thumb-stack) { display: block; }
.entry-body { min-width: 0; }
.entry::before {
  content: "";
  position: absolute;
  left: -35px;
  top: 6px;
  width: 14px; height: 14px;
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.entry.now::before { background: var(--pink); border-color: var(--ink); }

/* Entry pair: two timeline nodes sharing one image */
.entry-pair {
  position: relative;
  padding: 0 0 44px;
  display: grid;
  grid-template-columns: 1fr 180px;
  grid-template-areas:
    "first  image"
    "second image";
  column-gap: 28px;
  row-gap: 24px;
  align-items: start;
}
.entry-pair > .entry-body { position: relative; min-width: 0; }
.entry-pair > .entry-body:nth-of-type(1) { grid-area: first; }
.entry-pair > .entry-body:nth-of-type(2) { grid-area: second; }
.entry-pair > figure { grid-area: image; align-self: center; }
.entry-pair > .entry-body::before {
  content: "";
  position: absolute;
  left: -35px;
  top: 6px;
  width: 14px; height: 14px;
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 50%;
}

/* Thumbnails (polaroid-style) */
.thumb {
  margin: 0;
  background: #fff;
  padding: 8px 8px 22px;
  border-radius: 3px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.10), 0 1px 0 rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  position: relative;
  transform: rotate(-2deg);
  transition: transform 250ms ease, box-shadow 250ms ease;
}
.thumb {
  perspective: 800px;
}
.thumb img {
  display: block;
  width: 100%;
  height: auto;
  background: #f3f0e6;
  transition: transform 120ms ease-out;
  transform-style: preserve-3d;
  will-change: transform;
}
.thumb figcaption {
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--ink);
  margin-top: 10px;
}
.thumb:hover {
  transform: rotate(0deg) translateY(-3px);
  box-shadow: 0 14px 28px rgba(0,0,0,0.14), 0 2px 0 rgba(0,0,0,0.04);
}

/* Bare thumbnail — for transparent images (logos, illustrations) */
.thumb.thumb-bare {
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
  cursor: pointer;
  transition: transform 280ms ease, filter 280ms ease;
}
.thumb.thumb-bare img {
  background: transparent;
  transition: filter 280ms ease;
}
.thumb.thumb-bare:hover {
  transform: scale(1.04) rotate(-1deg);
  box-shadow: none;
}
.thumb.thumb-bare:hover img {
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.18));
}

/* Stacked polaroids — side-by-side pair, sit BELOW the entry text */
.thumb-stack {
  display: flex;
  flex-direction: row;
  gap: 28px;
  margin: 28px 0 0;
  max-width: 620px;
  align-items: flex-start;
}
.thumb-stack .thumb {
  flex: 1 1 0;
  max-width: 280px;
  margin: 0;
  transition: transform 280ms ease, box-shadow 280ms ease;
}
.thumb-stack .thumb img {
  aspect-ratio: 4 / 5;
  object-fit: contain;
}
.thumb-stack .back  { transform: rotate(-3deg); z-index: 1; }
.thumb-stack .front { transform: rotate(3deg);  z-index: 2; }
.thumb-stack:hover .back  { transform: rotate(-5deg) translateY(-4px); }
.thumb-stack:hover .front { transform: rotate(5deg)  translateY(-4px); box-shadow: 0 14px 28px rgba(0,0,0,0.16); }
.entry-date {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
  font-weight: 600;
}
.entry h3 {
  font-family: var(--serif);
  font-size: clamp(20px, 3vw, 26px);
  margin: 4px 0 8px;
  font-weight: 800;
  letter-spacing: -0.015em;
}
.entry p { margin: 0 0 12px; color: var(--ink-soft); max-width: 600px; }
.entry strong { color: var(--ink); }
.tags {
  list-style: none; padding: 0; margin: 6px 0 0;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.tags li {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border: 1px solid #1c1c1c33;
  border-radius: 999px;
  color: var(--ink-soft);
}
.badge-row {
  margin-bottom: 14px;
}
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink); color: var(--bg);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
}
.badge .pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--pink);
  animation: pulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(255,179,209,0.7);
}

/* ========== CONTACT ========== */
.results-card {
  background: var(--bg-deep);
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  padding: 36px 32px;
  max-width: 520px;
  text-align: center;
  box-shadow: 8px 8px 0 var(--ink);
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.results-card:hover { transform: translate(-2px, -2px); box-shadow: 12px 12px 0 var(--ink); }
.results-title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 800;
  font-size: 22px;
  margin: 0 0 14px;
}
.results-grid {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px;
  line-height: 1.25;
  margin: 0 auto 24px;
  text-align: center;
}
.links { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.link-pill {
  display: flex; justify-content: space-between; align-items: center;
  text-decoration: none;
  background: var(--bg);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 600;
  font-size: 15px;
  transition: transform 120ms ease, background 120ms ease;
}
.link-pill span {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}
.link-pill:hover { background: var(--ink); color: var(--bg); transform: translateY(-1px); }
.link-pill:hover span { color: rgba(255,255,255,0.6); }

/* ========== FOOTER ========== */
footer {
  text-align: center;
  padding: 64px 0 0;
  color: var(--ink-faint);
  font-size: 14px;
}
footer em { font-family: var(--serif); font-style: italic; color: var(--ink-soft); }
.tiny { font-size: 12px; margin-top: 8px; }

/* ========== CONFETTI ========== */
#confetti {
  position: fixed; inset: 0; pointer-events: none; z-index: 100;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 10px; height: 14px;
  border-radius: 2px;
  animation: fall 2.4s linear forwards;
}

/* ========== ANIMATIONS ========== */
@keyframes tilePop {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@keyframes pop {
  0%   { transform: translateY(-2px) scale(1); }
  40%  { transform: translateY(-8px) scale(1.05); }
  100% { transform: translateY(-2px) scale(1); }
}
@keyframes revealRow {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,179,209,0.7); }
  70%  { box-shadow: 0 0 0 10px rgba(255,179,209,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,179,209,0); }
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 600px) {
  .page {
    padding: 32px 16px calc(64px + env(safe-area-inset-bottom));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
  }
  .hero { padding: 8px 0 4px; }
  .tagline { font-size: 16px; padding: 0 4px; }
  .board { gap: 5px; }
  .tile {
    aspect-ratio: 1 / 1;
    padding: 3px;
    font-size: clamp(8.5px, 2.3vw, 11px);
    letter-spacing: 0;
    line-height: 1.08;
    overflow-wrap: anywhere;
    hyphens: manual;
  }
  .controls { gap: 8px; flex-wrap: wrap; }
  .btn { padding: 10px 16px; font-size: 13px; min-height: 40px; }
  .meta { font-size: 13px; }
  .solved-row { padding: 12px 14px; }
  .solved-row .row-label { font-size: 16px; }
  .solved-row .row-items { font-size: 10.5px; letter-spacing: 0.04em; }
  section.about, section.timeline, section.contact { padding-top: 44px; }
  .about p { font-size: 16px; }
  .entry,
  .entry:has(.thumb),
  .entry:has(.thumb-stack),
  .entry-pair {
    display: block;
    padding-bottom: 36px;
  }
  .entry-pair > .entry-body { margin-bottom: 24px; }
  .entry-pair > figure { max-width: 220px; margin-top: 8px; }
  .entry h3 { font-size: 20px; }
  .thumb { max-width: 220px; margin-top: 16px; }
  .thumb-stack { gap: 12px; margin-top: 20px; max-width: 100%; }
  .thumb-stack .thumb { max-width: none; }
  .thumb-stack .back  { transform: rotate(-2deg); }
  .thumb-stack .front { transform: rotate(2deg);  }
  .results-card { padding: 28px 20px; box-shadow: 6px 6px 0 var(--ink); }
  .results-card:hover { box-shadow: 8px 8px 0 var(--ink); }
  .results-grid { font-size: 18px; }
  .link-pill { flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 16px; font-size: 13px; }
  .toast { font-size: 13px; padding: 10px 18px; }
  #toast-host { top: max(16px, env(safe-area-inset-top)); }
  .badge { font-size: 10px; letter-spacing: 0.16em; padding: 5px 10px; }
  .circle-doodle {
    left: -6px;
    right: -6px;
    bottom: -8px;
    width: calc(100% + 12px);
    height: 12px;
  }
  .circle-doodle path { stroke-width: 1.8; }
}

/* Very small screens (older / smaller phones) */
@media (max-width: 380px) {
  .page { padding: 24px 12px calc(48px + env(safe-area-inset-bottom)); }
  .hero h1 { font-size: 36px; }
  .tile { font-size: clamp(8px, 2.2vw, 10px); padding: 2px; }
  .controls .btn { padding: 9px 12px; font-size: 12px; }
  .entry h3 { font-size: 18px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
