:root {
  --beige: #e7e3d4;
  --beige-dark: #d6d1bf;
  --beige-light: #f2efe6;
  --ink: #1b1b1b;
  --shadow: #8b8778;
  --focus: #007aff;
  --header-h: 80px;
  --vent-w: 120px;
  --font: Chicago, Geneva, "Courier New", monospace;
}

* { box-sizing: border-box; }

html {
  scroll-padding-top: calc(var(--header-h) + 1rem);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.4;
  background: radial-gradient(circle at top, var(--beige-light), var(--beige));
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
  cursor: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpolygon points='0,0 0,16 6,12 10,16 10,10 16,10' fill='black'/%3E%3C/svg%3E") 0 0, auto;
}

a, button, .gallery-item.openable { cursor: pointer; }

/* Visible keyboard focus everywhere */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 0.5rem;
  z-index: 400;
  padding: 0.5rem 0.75rem;
  background: var(--beige-light);
  border: 2px solid var(--ink);
  color: var(--ink);
}
.skip-link:focus { top: 0.5rem; }

main { display: block; outline: none; }

/* ---------- Header ---------- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  padding: 0 1.5rem;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--beige);
  border-bottom: 2px solid var(--ink);
  z-index: 120;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--ink);
  text-decoration: none;
}
.logo {
  width: 56px;
  height: 56px;
  flex: none;
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--shadow);
  background: var(--beige-dark) url('logo.png') center/contain no-repeat;
}

nav { display: flex; gap: 0.75rem; }
nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.25rem 0.8rem;
  font-family: var(--font);
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--ink);
  background: var(--beige-dark);
  box-shadow: 2px 2px 0 var(--shadow);
}
nav a:hover { background: var(--beige-light); }
nav a:active { box-shadow: none; transform: translate(2px, 2px); }
nav a[aria-current="page"] {
  background: var(--ink);
  color: var(--beige-light);
  box-shadow: none;
}

/* ---------- Sections ---------- */
section { display: none; }
section.active { display: block; }

/* ---------- Hero ---------- */
.hero {
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  height: calc(100svh - var(--header-h));
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  background: linear-gradient(to bottom, var(--beige-light), var(--beige));
  overflow: hidden;
  padding: 0 calc(var(--vent-w) + 1rem);
}
.hero::before,
.hero::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--vent-w);
  background: repeating-linear-gradient(to bottom, var(--beige-dark), var(--beige-dark) 10px, var(--beige) 10px, var(--beige) 20px);
}
.hero::before { left: 0; border-right: 2px solid var(--ink); }
.hero::after { right: 0; border-left: 2px solid var(--ink); }

.hero-text { position: relative; z-index: 1; will-change: transform, opacity; }
.hero h1 { font-size: clamp(3rem, 12vw, 5rem); line-height: 1; margin: 0; }
.hero h2 { margin: 0.5rem 0; font-size: clamp(1.5rem, 5vw, 2rem); }
.hero p { font-size: clamp(1rem, 3.4vw, 1.2rem); margin: 0; }

.scroll-hint {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  font-family: var(--font);
  font-size: 0.9rem;
  text-align: center;
  color: var(--ink);
}
.scroll-hint span {
  display: block;
  font-size: 1.4rem;
  animation: bounce 1s infinite alternate;
}
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-6px); } }

/* ---------- Gallery ---------- */
.gallery-wrap {
  margin: 0;
  padding: 2rem 1.5rem 4rem;
  border-left: 0;
  border-right: 0;
  box-shadow: none;
}
/* Column count adapts to screen width: roughly one column per 300px, so wide
   monitors fill edge to edge. Change --gallery-col to make photos bigger/smaller. */
.gallery {
  --gallery-col: 300px;
  column-width: var(--gallery-col);
  column-gap: 1rem;
}

.gallery-item {
  position: relative;
  display: block;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
  background: var(--beige-dark);
  break-inside: avoid;
  font: inherit;
  color: inherit;
  aspect-ratio: 4 / 3;       /* placeholder until the image loads; removed in JS */
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.gallery-item.loaded { aspect-ratio: auto; }

.gallery-item img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.4s linear, transform 0.4s linear;
}
.gallery-item img.visible { opacity: 1; transform: translateY(0); }

/* "Click to enlarge" tag only on devices that can hover */
@media (hover: hover) {
  .gallery-item.openable::after {
    content: "Click to enlarge";
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font);
    font-size: 0.8rem;
    white-space: nowrap;
    color: var(--ink);
    background: rgba(231, 227, 212, 0.9);
    padding: 0 6px;
    border: 1px solid var(--ink);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
  }
  .gallery-item.openable.loaded:hover::after,
  .gallery-item.openable.loaded:focus-visible::after { opacity: 1; }
}

.gallery-empty { text-align: center; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, var(--beige-light), var(--beige));
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: pan-y;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  display: block;
  max-width: 92vw;
  max-height: calc(100vh - 12rem);
  max-height: calc(100dvh - 12rem);   /* leaves room for the caption and hint */
  border: 3px solid var(--ink);
  box-shadow: 6px 6px 0 var(--shadow);
  background: var(--beige-dark);
  opacity: 0;
  transition: opacity 0.2s linear;
}
.lightbox img.ready { opacity: 1; }
.lb-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  max-width: 100%;
}
.lb-caption {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-width: min(60ch, calc(100vw - 8rem));
  padding: 0.5rem 0.9rem;
  text-align: center;
  background: var(--beige-light);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
}
.lb-caption[hidden], .lb-caption [hidden] { display: none; }
.lb-caption-text { font-weight: 700; overflow-wrap: anywhere; }
.lb-caption-meta { font-size: 0.85rem; }
.lb-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font);
  font-size: 1.2rem;
}
.lb-status[hidden] { display: none; }
.lb-hint {
  position: absolute;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-family: var(--font);
  font-size: 0.9rem;
}
.lb-btn {
  position: absolute;
  z-index: 2;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 2rem/1 var(--font);
  color: var(--ink);
  background: var(--beige-dark);
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--shadow);
  padding: 0 0 4px;
}
.lb-btn:active { box-shadow: none; transform: translate(2px, 2px); }
.lb-close { top: calc(0.75rem + env(safe-area-inset-top)); right: calc(0.75rem + env(safe-area-inset-right)); }
.lb-prev { left: calc(0.75rem + env(safe-area-inset-left)); top: 50%; margin-top: -24px; }
.lb-next { right: calc(0.75rem + env(safe-area-inset-right)); top: 50%; margin-top: -24px; }

/* ---------- Pages & windows ---------- */
.window {
  border: 2px solid var(--ink);
  background: var(--beige);
  box-shadow: 4px 4px 0 var(--shadow);
}
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 0 1rem;
  margin-top: calc(var(--header-h) + 1.5rem);
  margin-bottom: 2rem;
}
.titlebar {
  margin: 0;
  padding: 0.5rem 0.8rem;
  border-bottom: 2px solid var(--ink);
  background: linear-gradient(to right, #ff3b30, #ffcc00, #34c759, #007aff);
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--ink);
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.7);
}

.card {
  margin: 1.5rem;
  padding: 0;
  background: var(--beige-dark);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
  display: flex;
  flex-direction: column;
}
.card[hidden] { display: none; }

.project-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 2px solid var(--ink);
  background: linear-gradient(to bottom, #1f3fa6, #162f7a);
  color: #fff;
}
.project-titlebar h2 {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: anywhere;
}

.window-controls { display: flex; gap: 0.35rem; flex: none; }
.window-controls button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--ink);
  background: var(--beige-light);
  color: var(--ink);
  font: 700 1.2rem/1 var(--font);
}
.window-controls button:active { transform: translate(1px, 1px); }

.project-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.project-content p { margin: 0 0 1rem; }
.project-content img,
.thumb-placeholder {
  width: 100%;
  margin-bottom: 1rem;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
  background: var(--beige-light);
}
.project-content img { height: auto; }
.thumb-placeholder {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 3rem;
  color: var(--shadow);
  background: repeating-linear-gradient(45deg, var(--beige-light), var(--beige-light) 8px, var(--beige) 8px, var(--beige) 16px);
}

/* Window states */
.card.collapsed .project-content { display: none; }
.card.maximized {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 110;
  margin: 0;
  overflow: auto;
  background: var(--beige-dark);
  box-shadow: none;
}
.card.maximized .project-content { max-width: 800px; margin: 0 auto; width: 100%; }

.restore-bar { margin: 1.5rem; text-align: center; }
.restore-bar[hidden] { display: none; }

/* Buttons / links */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.25rem 1rem;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--ink);
  text-decoration: none;
  border: 2px solid var(--ink);
  background: var(--beige-light);
  box-shadow: 2px 2px 0 var(--shadow);
}
.btn:hover { background: #fff; }
.btn:active { box-shadow: none; transform: translate(2px, 2px); }

/* About */
.about-card { align-items: stretch; padding-bottom: 1rem; }
.about-img {
  display: block;
  width: calc(100% - 2rem);
  max-width: 100%;
  height: auto;
  margin: 1rem;
  padding: 0.5rem;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--shadow);
  background: var(--beige-light);
}
.about-lead {
  margin: 0 1rem;
  font-family: var(--font);
  font-size: 1.2rem;
  line-height: 1.4;
  text-align: center;
}

footer {
  text-align: center;
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 2rem 1rem calc(2rem + env(safe-area-inset-bottom));
  border-top: 2px solid var(--ink);
}

/* ---------- Tablet / mobile ---------- */
@media (max-width: 700px) {
  :root { --header-h: 104px; --vent-w: 28px; }
  body { font-size: 1rem; }

  /* two-row header: brand on top, nav as equal-width tabs below */
  .site-header {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }
  .brand { font-size: 1.2rem; gap: 0.5rem; }
  .logo { width: 32px; height: 32px; }
  nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
  nav a { padding: 0.15rem 0.2rem; font-size: 0.95rem; }

  .hero { padding: 0 calc(var(--vent-w) + 0.75rem); }
  .hero::before, .hero::after { background-size: auto; }

  .gallery-wrap { padding: 1rem 0.75rem 3rem; }
  .gallery { column-gap: 0.75rem; column-width: 240px; }
  .gallery-item { margin-bottom: 0.75rem; }

  .page { margin-top: calc(var(--header-h) + 0.75rem); margin-left: 0.5rem; margin-right: 0.5rem; }
  .card { margin: 0.75rem; }
  .project-content { padding: 0.75rem; }
  .window-controls button { width: 36px; height: 36px; }  /* bigger tap targets */

  .about-lead { font-size: 1.1rem; }

  .lb-prev, .lb-next { top: auto; bottom: calc(2.75rem + env(safe-area-inset-bottom)); margin-top: 0; }
  .lightbox img { max-height: calc(100dvh - 15rem); }
}

/* Short landscape phones: don't let the header eat the screen */
@media (max-height: 480px) and (orientation: landscape) {
  :root { --header-h: 64px; }
  .site-header { flex-direction: row; align-items: center; padding: 0 1rem; }
  nav { display: flex; }
  .hero { min-height: 300px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .gallery-item img { transform: none; }
  .hero-text { transform: none !important; }
}
