:root {
  --ink: #1c1915;
  --muted: #6f685e;
  --paper: #e8e0d4;
  --card: #fffdf8;
  --manila: #f4e4c0;
  --manila-deep: #e7d3a4;
  --line: rgba(48, 36, 22, 0.12);
  --accent: #8f2d2a;
  --shadow: 0 12px 28px rgba(48, 36, 22, 0.12);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1000px 520px at 8% -10%, rgba(255, 250, 242, 0.9), transparent 60%),
    radial-gradient(800px 480px at 100% 0%, rgba(214, 186, 150, 0.45), transparent 55%),
    var(--paper);
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

header {
  padding: 28px 0 8px;
}

header h1 {
  margin: 0;
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-size: clamp(40px, 6vw, 64px);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

header p {
  margin: 8px 0 0;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.portals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 22px 0 8px;
}

.portal {
  position: relative;
  display: grid;
  grid-template-columns: 148px 1fr;
  min-height: 148px;
  background: var(--card);
  color: inherit;
  text-decoration: none;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.portals.is-swapping .portal { transition: none; }

.portal img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 18%;
  background: #d9d0c3;
}

.portal div { padding: 16px 18px 14px; }

.portal small {
  display: block;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.portal strong {
  display: block;
  margin-top: 6px;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.portal span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.35;
}

.portal em {
  display: inline-block;
  margin-top: 12px;
  font-style: normal;
  font-size: 14px;
}

.portal:hover { transform: translateY(-2px); }
.portal:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--muted);
}

.crumb[hidden] { display: none; }

.crumb button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 68vh;
  overflow: hidden;
}

#stage.still {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 16px;
  padding-bottom: 32px;
}

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: 176px;
  height: 132px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.card.folder { width: 196px; height: 150px; }

#stage.still .card { position: relative; left: auto; top: auto; }

.face {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card:hover .face,
.card:focus-visible .face {
  transform: translateY(-4px) scale(1.04);
  box-shadow: 0 18px 36px rgba(48, 36, 22, 0.18);
}

.card:focus-visible { outline: none; }
.card:focus-visible .face { outline: 2px solid var(--ink); outline-offset: 2px; }

.folder .face {
  background: linear-gradient(180deg, var(--manila), var(--manila-deep));
  padding: 0 14px 12px;
}

.tab {
  width: 74px;
  height: 16px;
  margin-bottom: 10px;
  border-radius: 0 0 8px 8px;
  background: rgba(255, 253, 248, 0.45);
}

.mark {
  width: 28px;
  height: 28px;
  color: #6a4a28;
}

.mark svg { width: 28px; height: 28px; display: block; }

.thumb {
  height: 74px;
  background: #efe7db center/cover no-repeat;
  display: grid;
  place-items: center;
  color: #6a4a28;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; }

.thumb svg { width: 28px; height: 28px; }

.title {
  padding: 8px 10px 0;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 16px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.folder .title { padding: 8px 0 0; font-size: 22px; }

.count {
  margin-top: auto;
  color: #6d5840;
  font-size: 13px;
}

.status {
  position: absolute;
  inset: 24px 0 auto;
  color: var(--muted);
}

#reader {
  position: fixed;
  margin: 0;
  padding: 22px 22px 28px;
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(28, 22, 14, 0.28);
  overflow: auto;
  max-width: none;
  max-height: none;
}

#reader::backdrop { background: rgba(28, 24, 18, 0.48); }

#reader h2 {
  margin: 4px 46px 0 0;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.reader-kicker, .reader-date { margin: 0; color: var(--muted); }

.reader-kicker { color: var(--accent); font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }

.reader-date { margin-top: 8px; }

#reader-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

#reader-body {
  margin-top: 18px;
  font-size: 17px;
  line-height: 1.55;
}

#reader-body p { margin: 0 0 0.9em; }
#reader-body a { color: var(--accent); }
#reader-body img { max-width: 100%; height: auto; border-radius: 8px; }
#reader-body ul, #reader-body ol { padding-left: 1.2em; }
#reader-body figure.video {
  margin: 0 0 1em;
  aspect-ratio: 16 / 9;
}
#reader-body iframe { width: 100%; height: 100%; border: 0; border-radius: 8px; }
#reader-body video { width: 100%; max-height: 70vh; background: #161410; border-radius: 8px; }
#reader-body .gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin: 0 0 1em;
}
#reader-body .gallery a { display: block; }
#reader-body .gallery img { width: 100%; height: 140px; object-fit: cover; }

@media (max-width: 720px) {
  .portals { grid-template-columns: 1fr; }
  .portal { grid-template-columns: 112px 1fr; min-height: 112px; }
  .portal strong { font-size: 24px; }
  #stage { min-height: 78vh; }
}

@media (prefers-reduced-motion: reduce) {
  .portal, .face { transition: none; }
  #reader { transition: none !important; }
}
