/* =========================================================
   Look: Ink palette, Fraunces + Inter, fine colour grain
   ========================================================= */
:root {
  --bg: #0b0b0e;
  --text: #ececf1;
  --muted: #8c8c99;
  --line: #24242c;
  --surface: rgba(255, 255, 255, .05);
  --accent: #ffffff;
  --glow-1: rgba(110, 130, 180, .22);
  --glow-2: rgba(160, 160, 190, .14);
  --glow-3: rgba(90, 110, 150, .14);

  --font-head: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;

  --radius: 12px;
  color-scheme: dark;
}

/* ---------- Glow + grain layers ---------- */
html { background: var(--bg); }
body::before {
  content: ""; position: fixed; inset: -25%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(38% 42% at 18% 22%, var(--glow-1), transparent 70%),
    radial-gradient(34% 40% at 82% 30%, var(--glow-2), transparent 70%),
    radial-gradient(40% 36% at 55% 85%, var(--glow-3), transparent 70%);
  filter: blur(40px);
  animation: drift 38s ease-in-out infinite alternate;
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: 100; pointer-events: none;
  opacity: .1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 100px 100px;
}
@keyframes drift {
  0%   { transform: translate(0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate(4%, 3%) rotate(8deg) scale(1.08); }
  100% { transform: translate(-3%, 5%) rotate(-6deg) scale(1.02); }
}

/* =========================================================
   Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
}
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration-color: var(--muted); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 0;
}

.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 600px) { .wrap { padding: 0 16px; } body { font-size: 16px; } }

.muted { color: var(--muted); }

/* ---------- Header / footer ---------- */
.site-header .wrap { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding-top: 28px; padding-bottom: 28px; flex-wrap: wrap; }
.brand { font-family: var(--font-head); font-weight: 600; text-decoration: none; font-size: 1.05rem; }
.nav { display: flex; gap: 22px; }
.nav a { text-decoration: none; color: var(--muted); }
.nav a:hover, .nav a[aria-current="page"] { color: var(--text); }
.site-footer { margin-top: 112px; border-top: 1px solid var(--line); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 24px; padding-bottom: 40px; font-size: .85rem; color: var(--muted); }
.site-footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { color: var(--text); }

/* ---------- Intro ---------- */
.intro { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 48px; align-items: start; padding: 48px 0 16px; }
.portrait {
  width: 200px; aspect-ratio: 4 / 5; border-radius: 16px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  transform: rotate(-3deg); transition: transform .4s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .8);
}
.portrait:hover { transform: rotate(2deg) scale(1.03); }
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.portrait .initials {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-family: var(--font-head); font-size: 4rem; color: var(--muted);
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, .08), transparent 60%);
}
.hello { font-family: var(--font-head); font-style: italic; font-weight: 400; color: var(--muted); font-size: 1.15rem; margin: 0 0 6px; }
.intro h1 { font-size: clamp(2.4rem, 6vw, 3.6rem); }
.intro p { font-size: 1.12rem; margin: 18px 0 0; max-width: 60ch; }
.intro p a { text-decoration-color: var(--muted); text-underline-offset: 4px; transition: text-decoration-color .2s; }
.intro p a:hover { text-decoration-color: var(--text); }
.links { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 24px; }
.links a { font-weight: 600; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 5px; }
.links a:hover { text-decoration-color: var(--text); }
@media (max-width: 720px) {
  .intro { grid-template-columns: minmax(0, 1fr); gap: 28px; padding-top: 24px; }
  .portrait { width: 140px; }
}

/* ---------- Sections ---------- */
.section { margin-top: 88px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding-bottom: 12px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.section-head h2 { font-size: 1.5rem; }
.section-head a { color: var(--muted); text-decoration: none; font-size: .95rem; }
.section-head a:hover { color: var(--text); }

/* ---------- Project tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 20px; }
.tile {
  --rx: 0deg; --ry: 0deg; --mx: 50%; --my: 50%;
  position: relative; aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden;
  background: #16161b; border: 1px solid var(--line);
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), box-shadow .35s ease, border-color .35s ease;
  outline: none;
}
.tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .6s cubic-bezier(.2, .8, .2, 1), filter .4s ease; }
.tile img.contain { object-fit: contain; padding: 18px; }
.tile::after { /* glare that follows the cursor */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s ease;
  background: radial-gradient(circle at var(--mx) var(--my), rgba(255, 255, 255, .16), transparent 45%);
}
.tile-badge {
  position: absolute; top: 12px; left: 12px; z-index: 2;
  font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  padding: 4px 9px; border-radius: 999px; background: rgba(11, 11, 14, .75); color: var(--text);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tile-base {
  position: absolute; inset: auto 0 0 0; padding: 40px 16px 14px;
  background: linear-gradient(to top, rgba(11, 11, 14, .92), transparent);
  transition: opacity .3s ease, transform .3s ease;
}
.tile-base h3, .tile-info h3 { font-size: 1.2rem; }
.tile-base span { font-size: .8rem; color: #b6b6c2; }
.tile-info {
  position: absolute; inset: 0; z-index: 1; padding: 18px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px;
  background: linear-gradient(to top, rgba(11, 11, 14, .95) 35%, rgba(11, 11, 14, .5));
  opacity: 0; transform: translateY(14px);
  transition: opacity .3s ease, transform .35s cubic-bezier(.2, .8, .2, 1);
}
.tile-info .meta { font-size: .78rem; color: #b6b6c2; }
.tile-info p { margin: 0; font-size: .92rem; line-height: 1.5; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; flex-shrink: 0; }
.tile-info .roles { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.tile-info .roles span { font-size: .72rem; padding: 2px 8px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .18); color: #d4d4dc; }
.tile-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tile-links a {
  font-size: .85rem; font-weight: 600; text-decoration: none;
  padding: 6px 12px; border-radius: 999px; background: var(--text); color: var(--bg); border: 1px solid var(--text);
  transition: transform .2s ease;
}
.tile-links a + a { background: transparent; color: var(--text); border-color: rgba(255, 255, 255, .35); }
.tile-links a:hover { transform: translateX(3px); }

.tile:hover, .tile:focus-within, .tile.open {
  border-color: rgba(255, 255, 255, .22);
  box-shadow: 0 24px 50px -24px rgba(0, 0, 0, .9), 0 0 0 1px rgba(255, 255, 255, .04);
}
.tile:hover img, .tile:focus-within img, .tile.open img { transform: scale(1.08); filter: blur(1px) brightness(.7); }
.tile:hover::after { opacity: 1; }
.tile:hover .tile-info, .tile:focus-within .tile-info, .tile.open .tile-info { opacity: 1; transform: none; }
.tile:hover .tile-base, .tile:focus-within .tile-base, .tile.open .tile-base { opacity: 0; transform: translateY(10px); }
.tile:hover .tile-badge, .tile:focus-within .tile-badge, .tile.open .tile-badge { opacity: 0; }

/* ---------- Projects page ---------- */
.page-head { padding: 48px 0 8px; max-width: 640px; }
.page-head h1 { font-size: clamp(2.2rem, 5vw, 3rem); }
.page-head p { margin: 14px 0 0; color: var(--muted); }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 28px 0 28px; }
.tabs button {
  font: inherit; font-size: .9rem; cursor: pointer; color: var(--muted);
  background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.tabs button:hover { color: var(--text); border-color: var(--muted); }
.tabs button[aria-pressed="true"] { color: var(--bg); background: var(--text); border-color: var(--text); }

/* ---------- Post list ---------- */
.posts { list-style: none; margin: 0; padding: 0; }
.posts li { display: grid; grid-template-columns: 130px 1fr; gap: 16px; padding: 14px 0; }
.posts time { color: var(--muted); font-size: .9rem; }
.posts a { text-decoration: none; font-weight: 600; }
.posts a:hover { text-decoration: underline; }
.posts p { margin: 4px 0 0; color: var(--muted); font-size: .95rem; }
@media (max-width: 600px) { .posts li { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- Article ---------- */
.article { max-width: 660px; padding: 40px 0 0; }
.back-link { display: inline-block; margin-bottom: 32px; color: var(--muted); text-decoration: none; font-size: .9rem; }
.back-link:hover { color: var(--text); }
.article-head h1 { font-size: clamp(2rem, 5vw, 2.8rem); }
.article-meta { color: var(--muted); font-size: .9rem; margin-top: 12px; }
.article-body { margin-top: 32px; font-size: 1.08rem; line-height: 1.75; }
.article-body p { margin: 0 0 1.25em; }
.article-body h2 { font-size: 1.45rem; margin: 2em 0 .5em; }
.article-body a { text-decoration: underline; }
.article-body ul { padding-left: 1.2em; margin: 0 0 1.25em; }
mark.todo { background: #ffe066; color: #1a1a1a; padding: 0 4px; border-radius: 3px; }
.article-body blockquote { margin: 1.5em 0; padding-left: 18px; border-left: 2px solid var(--text); font-family: var(--font-head); font-style: italic; font-weight: 400; font-size: 1.2rem; }
.article-foot { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: .95rem; }
.article-foot a { text-decoration: none; color: var(--muted); }
.article-foot a:hover { color: var(--text); }

/* ---------- Buttons (used by the Monty Hall game) ---------- */
.btn {
  font: inherit; font-size: .9rem; cursor: pointer;
  padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--text);
}
.btn:hover { border-color: var(--text); }
.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- Monty Hall game ---------- */
.monty { margin: 2em 0; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: .95rem; line-height: 1.5; }
.monty h3 { font-size: 1.2rem; }
.monty-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 14px 0; }
.monty-controls label { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.monty-controls input[type="range"] { accent-color: var(--text); width: 150px; }
.monty-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.doors { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 5px; margin: 12px 0; }
.doors.few { grid-template-columns: repeat(3, minmax(0, 100px)); gap: 10px; }
.door {
  aspect-ratio: 3 / 4; border: 1px solid var(--muted); border-radius: 3px; background: transparent;
  color: var(--text); cursor: pointer; padding: 0; font: inherit; font-size: .75rem;
  display: grid; place-items: center;
}
.doors.few .door { font-size: 1.8rem; }
.door.picked { background: var(--text); color: var(--bg); border-color: var(--text); }
.door.open { opacity: .35; border-style: dashed; cursor: default; }
.door.car { opacity: 1; border-width: 2px; border-color: var(--text); }
.door:disabled { cursor: default; }
.monty-status { min-height: 1.5em; font-weight: 600; margin: 10px 0; }
.monty-stats { display: grid; gap: 6px; margin-top: 16px; font-size: .85rem; }
.bar-row { display: grid; grid-template-columns: 56px 1fr 110px; gap: 10px; align-items: center; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--text); transition: width .3s ease; }
.bar-row.stay .bar > span { background: var(--muted); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  .tile, .tile img, .tile-info, .tile-base, .portrait { transition: none; }
  .tile { transform: none !important; }
  .tile:hover img, .tile:focus-within img, .tile.open img { transform: none; }
}
