/* En Garde Gazette — Elite Fencers Club, Chatham NJ */
:root {
  --ink: #1d1a16;
  --paper: #f1e9d6;
  --paper-dk: #d9cdb0;
  --brass: #c8a45a;
  --brass-dk: #8a6d2f;
  --oxblood: #7a1f1f;
  --room: #16201b;
  --head-h: 72px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --display: "Didot", "Bodoni 72", "Bodoni MT", "Playfair Display", Georgia, serif;
}
* { box-sizing: border-box; }
html { margin: 0; min-height: 100%; background: #0e1511; } /* solid fallback covers overscroll / full scroll height */
body { margin: 0; }
body::after { /* viewport-fixed room gradient (background-attachment:fixed is unreliable on mobile) */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 35%, #34463b 0%, #1f2d25 55%, #0e1511 100%);
}
body {
  font-family: var(--serif);
  color: var(--paper);
  background: transparent;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
body::before { /* linoleum grain */
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .22; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .5  0 0 0 0 .5  0 0 0 0 .5  0 0 0 .9 0'/></filter><rect width='240' height='240' filter='url(%23n)'/></svg>");
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- masthead bar ---------- */
.bar {
  position: relative; z-index: 2;
  height: var(--head-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 clamp(12px, 2vw, 28px);
}
.brand { text-decoration: none; display: block; line-height: 1.05; }
.brand b {
  display: block; font-family: var(--display); font-weight: 800; font-style: italic;
  font-size: clamp(22px, 3vw, 34px); letter-spacing: .01em; color: #f6eed9;
  text-shadow: 0 2px 0 rgba(0,0,0,.5);
}
.brand small {
  font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--brass);
}
.hint { margin: 0; font-style: italic; font-size: 14px; color: #b9bfa9; text-align: center; flex: 1; }
.nav { display: flex; gap: 10px; align-items: center; }
.btn {
  font: inherit; font-size: 14px; letter-spacing: .08em; text-transform: uppercase;
  color: #2a2012; text-decoration: none; cursor: pointer;
  background: linear-gradient(#e2c27d, #b8913f);
  border: 1px solid #6f5420; border-radius: 3px; padding: 8px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 2px 4px rgba(0,0,0,.5);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: linear-gradient(#ecd08f, #c29c48); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.ghost { color: var(--paper); background: rgba(255,255,255,.06); border-color: rgba(200,164,90,.5); box-shadow: none; }
.btn.ghost:hover { background: rgba(255,255,255,.14); }

/* ---------- desk ---------- */
.desk-view { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding: 0 12px 12px; position: relative; z-index: 1; }
.stage {
  position: relative;
  aspect-ratio: 1520 / 1012;
  width: min(100vw - 24px, (100vh - var(--head-h) - 12px) * 1.502);
  width: min(100vw - 24px, (100dvh - var(--head-h) - 12px) * 1.502);
  overflow: visible;
}
.desk-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; filter: drop-shadow(0 18px 28px rgba(0,0,0,.65)); user-select: none; -webkit-user-drag: none; pointer-events: none; }
.stage-fx { position: absolute; inset: 0; z-index: 2147483000; pointer-events: none; border-radius: 2%;
  background:
    radial-gradient(ellipse at 22% 6%, rgba(255,236,190,.16), transparent 55%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(10,6,0,.38) 100%);
  mix-blend-mode: multiply; }
.stains { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.coffee {
  position: absolute; border-radius: 50%; aspect-ratio: 1; mix-blend-mode: multiply; opacity: .55;
  background: radial-gradient(circle, rgba(70,35,10,.08) 55%, rgba(70,35,10,.5) 62%, rgba(70,35,10,.18) 68%, transparent 72%);
  filter: blur(.4px);
}
.inkblot { position: absolute; width: 1.4%; aspect-ratio: 1; border-radius: 48% 52% 45% 55%; background: #0c0a14; opacity: .55; mix-blend-mode: multiply; filter: blur(.6px); }

.item {
  position: absolute; transform: translate(-50%, -50%);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,.35)) drop-shadow(7px 11px 12px rgba(0,0,0,.32));
  transition: filter .15s;
}
.item.dragging { cursor: grabbing; filter: drop-shadow(4px 6px 4px rgba(0,0,0,.3)) drop-shadow(16px 26px 22px rgba(0,0,0,.38)); }
.sheet { position: relative; width: 100%; height: 100%; transform: rotate(var(--r, 0deg)); transition: transform .15s;
  animation: settle .55s cubic-bezier(.2,.7,.3,1) backwards; animation-delay: var(--d, 0s); }
.item.dragging .sheet { transform: rotate(var(--r, 0deg)) scale(1.025); }
@keyframes settle {
  from { transform: rotate(calc(var(--r) + 10deg)) scale(1.12); opacity: 0; }
  to { transform: rotate(var(--r)) scale(1); opacity: 1; }
}
.sheet img { width: 100%; height: 100%; display: block; -webkit-user-drag: none; pointer-events: none; }
.paper { width: 24%; aspect-ratio: 8.5 / 11; }
.paper .sheet { background: var(--paper); border-radius: 1px; }
.paper img { object-fit: cover; filter: sepia(.14) saturate(.9) brightness(.975) contrast(.98); }
.paper .sheet::after { /* aging, fold, edge wear */
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background:
    linear-gradient(105deg, rgba(255,250,230,.0) 40%, rgba(120,90,30,.07) 100%),
    radial-gradient(ellipse at 50% 50%, transparent 62%, rgba(110,80,25,.16) 100%);
  box-shadow: inset 0 0 0 1px rgba(90,70,30,.18);
}
.paper.fold-h .sheet::before, .paper.fold-v .sheet::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.paper.fold-h .sheet::before { background: linear-gradient(to bottom, transparent 49%, rgba(0,0,0,.13) 49.7%, rgba(255,255,255,.28) 50.5%, transparent 52%); }
.paper.fold-v .sheet::before { background: linear-gradient(to right, transparent 49%, rgba(0,0,0,.12) 49.7%, rgba(255,255,255,.26) 50.5%, transparent 52%); }
.paper:focus-visible { outline: none; }
.paper:focus-visible .sheet { outline: 3px solid var(--brass); outline-offset: 4px; }
.tin .sheet img { display: block; width: 100%; height: 100%; }
/* 3D pencils: one fixed, click-through WebGL canvas whose camera maps the desk plane 1:1 to CSS px */
.pencil-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 3; pointer-events: none; }
.stage { touch-action: none; }
body.pencil-hover, body.pencil-hover .item { cursor: grab; }
body.pencil-drag, body.pencil-drag .item { cursor: grabbing; }

/* ---------- mobile / small-screen fallback ---------- */
.mobile-view { display: none; padding: 4px 16px 36px; max-width: 560px; margin: 0 auto; width: 100%; position: relative; z-index: 1; }
.mobile-view h2 { font-family: var(--display); font-style: italic; font-weight: 700; color: #f6eed9; margin: 22px 0 10px; font-size: 22px; }
.cover { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; text-align: left; color: inherit; }
.cover img { width: 100%; height: auto; display: block; background: var(--paper); box-shadow: 0 10px 24px rgba(0,0,0,.6); transform: rotate(-1deg); filter: sepia(.12); }
.cover-cap { margin: 14px 0 0; font-size: 17px; line-height: 1.3; }
.cover-cap small { display: block; color: var(--brass); letter-spacing: .12em; text-transform: uppercase; font-size: 12px; margin-bottom: 4px; }
.m-list { list-style: none; margin: 0; padding: 0; }
.m-list li { border-top: 1px solid rgba(200,164,90,.3); padding: 12px 0; }
.m-list .meta { color: var(--brass); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.m-list .row { display: flex; gap: 8px; margin-top: 8px; }
@media (max-width: 720px), (max-height: 460px) {
  .desk-view, .hint, #shuffle, .pencil-canvas { display: none; }
  .mobile-view { display: block; }
  :root { --head-h: 60px; }
}

/* ---------- archive ---------- */
.archive { position: relative; z-index: 1; width: min(860px, 100% - 24px); margin: 8px auto 48px; }
.sheet-card {
  background: var(--paper); color: var(--ink); padding: clamp(18px, 4vw, 44px);
  box-shadow: 0 14px 34px rgba(0,0,0,.6), inset 0 0 60px rgba(120,90,30,.18);
  background-image: radial-gradient(ellipse at 50% 0, rgba(255,255,255,.4), transparent 60%);
}
.sheet-card h1 { font-family: var(--display); font-style: italic; font-size: clamp(30px, 5vw, 46px); margin: 0; text-align: center; letter-spacing: .01em; }
.sheet-card .rule { border: 0; border-top: 3px double var(--ink); margin: 12px 0 6px; }
.sheet-card .sub { text-align: center; margin: 0 0 22px; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: #5a4a2a; }
.issues { list-style: none; margin: 0; padding: 0; }
.issue { display: grid; grid-template-columns: 4.5rem 1fr auto; gap: 6px 18px; align-items: center; padding: 16px 0; border-top: 1px solid rgba(29,26,22,.35); }
.issue .no { font-family: var(--display); font-size: 1.9rem; font-weight: 800; color: var(--oxblood); line-height: 1; }
.issue .no small { display: block; font: 600 .65rem var(--serif); letter-spacing: .15em; text-transform: uppercase; color: #5a4a2a; margin-bottom: 4px; }
.issue time { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: #5a4a2a; }
.issue h2 { margin: 2px 0 0; font-size: 1.2rem; line-height: 1.25; font-weight: 700; }
.issue .links { display: flex; gap: 8px; }
.issue .links a { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; text-decoration: none; padding: 7px 12px; border: 1.5px solid var(--ink); color: var(--ink); background: transparent; }
.issue .links a:first-child { background: var(--ink); color: var(--paper); }
.issue .links a:hover { background: var(--oxblood); border-color: var(--oxblood); color: #fff; }
.issue .links a:focus-visible { outline-color: var(--oxblood); }
@media (max-width: 560px) {
  .issue { grid-template-columns: 3.4rem 1fr; }
  .issue .links { grid-column: 1 / -1; }
}

/* ---------- reader overlay ---------- */
body.reading { overflow: hidden; }
.reader { position: fixed; inset: 0; z-index: 2147483600; display: flex; flex-direction: column; background: rgba(8,10,8,.93); color: var(--paper); }
.reader[hidden] { display: none; }
.reader-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px clamp(10px, 2vw, 24px); background: #11160f; border-bottom: 1px solid rgba(200,164,90,.35); }
.reader-heading { min-width: 0; }
.reader-heading strong { display: block; font-family: var(--display); font-style: italic; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-heading span { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--brass); }
.reader-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.reader-controls .btn { padding: 7px 11px; }
.reader-controls .readout { min-width: 5.2em; text-align: center; font-size: 13px; color: #cfd3c0; }
.reader-controls .sep { width: 1px; height: 24px; background: rgba(200,164,90,.35); margin: 0 4px; }
.reader-view { flex: 1; overflow: auto; display: flex; padding: 16px; outline: none; overscroll-behavior: contain; touch-action: none; }
.reader-view.pan { cursor: grab; } .reader-view.panning { cursor: grabbing; user-select: none; }
.reader-page { margin: auto; flex: none; position: relative; }
.reader-curl { display: none; position: absolute; pointer-events: none; z-index: 2; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.reader-page img { display: block; background: var(--paper); box-shadow: 0 12px 40px rgba(0,0,0,.7); max-width: none; user-select: none; -webkit-user-drag: none; }
@media (max-width: 560px) { .reader-controls .label { display: none; } .reader-view { padding: 8px; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none !important; } .item, .sheet { transition: none; } }
