:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  font-synthesis: none;
  --header-height: 58px;
  --gap: 4px;
}

* { box-sizing: border-box; }

html { background: #fff; scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: #050505;
  background: #fff;
  overflow-x: hidden;
}

button, a { font: inherit; }
button { color: inherit; }

.intro {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: #fff;
  transition: opacity 140ms steps(2, end);
}

.intro-copy { text-align: center; transform: translateY(-1vh); }
.intro-copy p {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0.015em;
  text-transform: lowercase;
}

.enter-button {
  margin-top: 22px;
  padding: 5px 9px;
  border: 0;
  color: #000;
  background: transparent;
  font-family: "Courier New", monospace;
  font-size: 0.72rem;
  text-decoration: underline;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
}

.intro--ready .intro-copy p { animation: intro-flicker 310ms steps(2, end) 1; }
.intro--ready .enter-button { opacity: 1; pointer-events: auto; }
.enter-button:focus-visible { outline: 1px dotted #000; outline-offset: 3px; }

.boot-noise {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}
.boot-noise span { position: absolute; font: 11px "Times New Roman", serif; }
.boot-noise span:nth-child(1) { top: 12%; left: 8%; }
.boot-noise span:nth-child(2) { right: 13%; bottom: 19%; }
.boot-noise span:nth-child(3) { top: 47%; right: 5%; }

.intro--leaving { animation: white-corrupt 720ms steps(2, end) both; }
.intro--leaving .boot-noise { animation: artifact-flash 720ms steps(1, end) both; }
.intro--leaving .intro-copy { animation: text-corrupt 190ms steps(2, end) infinite; }

.archive-shell { opacity: 0; transition: opacity 100ms linear; }
.archive-shell--visible { opacity: 1; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #000;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 2px solid #000;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.08em;
}
.brand-name { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 5px; }

.old-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 1px solid #000;
  border-radius: 0;
  background: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
}
.old-button--primary { color: #fff; background: #000; }
.old-button:hover, .old-button:focus-visible { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #000; }

.mosaic {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-auto-flow: dense;
  grid-auto-rows: 18px;
  gap: var(--gap);
  padding: var(--gap);
  background: #fff;
}

.meme-tile {
  position: relative;
  grid-column: span 1;
  grid-row: span 8;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #e9e9e9;
  cursor: zoom-in;
  animation: tile-drift 8s ease-in-out var(--delay) infinite alternate;
  content-visibility: auto;
  contain-intrinsic-size: 180px 165px;
}
.meme-tile--wide { grid-column: span 2; grid-row: span 9; }
.meme-tile--tall { grid-row: span 13; }
.meme-tile--hero { grid-column: span 2; grid-row: span 15; }
.meme-tile img { width: 100%; height: 100%; display: block; object-fit: cover; filter: saturate(0.96) contrast(1.03); }
.meme-tile:hover { z-index: 2; outline: 2px solid #000; outline-offset: -2px; }
.meme-tile:hover img { transform: scale(1.025); }
.meme-tile:focus-visible { z-index: 3; outline: 3px dashed #0057ff; outline-offset: -3px; }

.artifact {
  z-index: 1;
  grid-column: span 1;
  grid-row: span 3;
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 6px;
  overflow: hidden;
  border: 1px dotted #000;
  background: #fff;
  font: 0.68rem "Courier New", monospace;
  text-align: center;
}
.artifact--1 { color: #00f; font-family: "Times New Roman", serif; text-decoration: underline; }
.artifact--2 { color: #f00; font-weight: 700; animation: blink 1s steps(1, end) infinite; }

.meme-modal {
  width: min(900px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 3px;
  border: 2px solid #111;
  border-radius: 0;
  background: #c0c0c0;
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.4);
}
.meme-modal::backdrop { background: rgba(255, 255, 255, 0.78); backdrop-filter: blur(4px); }
.viewer-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 3px 4px 3px 8px;
  color: #fff;
  background: #000080;
  font: 700 0.72rem Tahoma, Arial, sans-serif;
}
.viewer-close { width: 27px; height: 23px; padding: 0; border: 2px outset #eee; background: #c0c0c0; font: 700 0.72rem Arial; cursor: pointer; }
.viewer-body { padding: 18px; background: #fff; }
.viewer-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.viewer-heading h2 { margin: 0; font-size: 1rem; line-height: 1.2; }
.viewer-heading time { font: 0.85rem "Courier New", monospace; }
.viewer-image-wrap { display: grid; place-items: center; min-height: 180px; max-height: calc(100dvh - 180px); overflow: auto; background: #ececec; }
.viewer-image-wrap img { display: block; max-width: 100%; max-height: calc(100dvh - 210px); object-fit: contain; }
.viewer-memory { margin: 14px 0 0; font: 0.72rem "Courier New", monospace; text-align: center; }
.modal-open { overflow: hidden; }

.status-toast {
  position: fixed;
  z-index: 1200;
  left: 50%;
  bottom: 22px;
  translate: -50% 10px;
  padding: 7px 10px;
  border: 1px solid #000;
  color: #000;
  background: #fffb00;
  font: 0.72rem "Courier New", monospace;
  opacity: 0;
  pointer-events: none;
  transition: opacity 100ms linear, translate 100ms linear;
}
.status-toast--visible { opacity: 1; translate: -50% 0; }

.screen-shake { animation: shake 80ms steps(2, end) 4; }
.myspace-mode { background: #120032 url("memes/thumbs/031_trollface.jpg") 0 0 / 140px auto fixed; }
.myspace-mode .mosaic { background: transparent; }
.myspace-mode .site-header { color: #0ff; background: linear-gradient(90deg, #f0f, #00f, #0ff); }
.myspace-mode .meme-tile:nth-child(5n) { outline: 4px ridge #ff0; }

@keyframes intro-flicker { 0%, 35%, 67%, 100% { opacity: 1; } 20%, 52%, 78% { opacity: 0.05; } }
@keyframes white-corrupt { 0% { filter: none; } 15% { transform: skewX(-1deg); filter: contrast(4); } 31% { transform: translateX(7px); background: #000; } 34% { background: #fff; } 50% { clip-path: inset(18% 0 41% 0); } 68% { clip-path: none; filter: invert(1); } 83% { filter: none; opacity: 1; } 100% { opacity: 0; } }
@keyframes artifact-flash { 0%, 12%, 29%, 53%, 100% { opacity: 0; } 13%, 16%, 30%, 35%, 54%, 58% { opacity: 1; } }
@keyframes text-corrupt { 0% { transform: translate(0); } 50% { transform: translate(-5px, 2px); } }
@keyframes tile-drift { from { transform: translateY(0); } to { transform: translateY(2px); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake { 0% { translate: 0 0; } 50% { translate: 5px -2px; } 100% { translate: -4px 2px; } }

@media (max-width: 980px) {
  .mosaic { grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-rows: 19px; }
}

@media (max-width: 620px) {
  :root { --header-height: 54px; --gap: 3px; }
  .site-header { gap: 7px; padding: 7px; }
  .brand { gap: 6px; }
  .brand-mark { width: 32px; height: 32px; font-size: 0.9rem; }
  .brand-name { display: none; }
  .header-actions { margin-left: auto; }
  .old-button { min-height: 34px; padding: 0 8px; font-size: 0.64rem; box-shadow: 1px 1px 0 #000; }
  .mosaic { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 17px; }
  .meme-tile { grid-row: span 7; }
  .meme-tile--wide { grid-row: span 8; }
  .meme-tile--tall { grid-row: span 11; }
  .meme-tile--hero { grid-row: span 13; }
  .viewer-body { padding: 12px; }
  .viewer-heading { align-items: flex-start; }
  .viewer-heading h2 { font-size: 0.9rem; }
}

@media (max-width: 370px) {
  .mosaic { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .old-button { padding-inline: 6px; font-size: 0.58rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .meme-tile, .artifact--2, .intro--ready .intro-copy p { animation: none; }
  .archive-shell { transition: none; }
}
