:root {
  --night: #131a30;
  --dusk: #24304f;
  --green: #4e8b45;   /* the 1948 cover's green panel */
  --stock: #d5c8b3;   /* the cover's paper, sampled */
  --amber: #f0b23c;   /* dash lamps and headlights */
  --esso: #c8202f;
  --ink: #1d1a16;
  --serif: "Rokkitt", "Rockwell", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--stock); font-family: var(--serif); overflow: hidden; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
canvas#scene.hot { cursor: pointer; }
button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

/* cards: a ticket of Green Book stock on the night */
.card {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
  background: var(--stock); color: var(--ink);
  padding: 30px 32px 28px; border-top: 22px solid var(--green);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}
.card .year { margin: 0 0 4px; font-style: italic; color: var(--green); font-size: 18px; }
.card h1, .card h2 { margin: 0 0 14px; font-weight: 700; line-height: 1.02; }
.card h1 { font-size: clamp(34px, 7vw, 50px); }
.card h2 { font-size: clamp(24px, 5vw, 32px); }
.card p { font-size: 18px; line-height: 1.5; margin: 0 0 14px; }
.card .src { font-size: 14px; font-style: italic; opacity: .78; }
.card button {
  margin-top: 6px; background: var(--green); color: var(--stock); border: 0;
  padding: 12px 22px; font-size: 18px; font-weight: 700;
}
.card button:hover { background: #3f7537; }
.card a.enter[hidden] { display: none; }
.card a.enter { display: inline-block; margin: 6px 10px 0 0; background: var(--esso); color: #fff; padding: 12px 22px; font-size: 18px; font-weight: 700; text-decoration: none; }
.card a.enter + button { background: none; color: var(--ink); border: 1px solid rgba(29,26,22,.4); font-weight: 400; }
.card img.clip { width: 100%; margin: 2px 0 14px; border: 1px solid rgba(29, 26, 22, .2); }
.card[hidden], #book[hidden], #hint[hidden], #note[hidden] { display: none; }

#hint {
  position: fixed; left: 50%; bottom: 64px; transform: translateX(-50%);
  margin: 0; padding: 8px 16px; background: rgba(19, 26, 48, .78);
  font-style: italic; font-size: 16px; text-align: center; max-width: calc(100% - 32px);
}

#radio { position: fixed; left: 16px; top: 16px; margin: 0; max-width: min(420px, calc(100% - 32px)); padding: 10px 14px; background: rgba(19, 26, 48, .86); border-left: 4px solid var(--amber); font-size: 15px; line-height: 1.45; z-index: 2; }
#radio[hidden] { display: none; }
footer {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 16px; align-items: center; justify-content: space-between;
  padding: 10px 16px; font-size: 13px; color: rgba(213, 200, 179, .72);
}
footer a.home { color: var(--stock); flex: none; }
footer button { background: none; border: 1px solid rgba(213, 200, 179, .5); color: var(--stock); padding: 5px 12px; font-size: 13px; flex: none; }

/* the book */
#book {
  position: fixed; inset: 0; z-index: 5; background: rgba(10, 13, 25, .92); overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; padding: 16px 16px 24px;
}
.book-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.spread {
  --pw: min(30vw, calc((100vh - 170px) * .714));
  position: relative; display: flex; perspective: 2200px;
  width: calc(var(--pw) * 2); height: calc(var(--pw) * 1.4);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .6);
}
.page, .face { width: var(--pw); height: 100%; background: var(--stock); position: relative; overflow: hidden; }
.page img, .face img { width: 100%; height: 100%; object-fit: fill; display: block; }
.page.left::after { content: ""; position: absolute; inset: 0 0 0 auto; width: 18%; background: linear-gradient(to left, rgba(0,0,0,.22), transparent); pointer-events: none; }
.page.right::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 14%; background: linear-gradient(to right, rgba(0,0,0,.2), transparent); pointer-events: none; }
.page.blank img { visibility: hidden; }
.leaf {
  position: absolute; top: 0; left: 50%; width: var(--pw); height: 100%;
  transform-origin: left center; transform-style: preserve-3d; display: none;
}
.leaf.on { display: block; }
.face { position: absolute; inset: 0; backface-visibility: hidden; }
.face.back { transform: rotateY(180deg); }

/* pencil marks over the real page */
.marks { position: absolute; inset: 0; pointer-events: none; }
.marks svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.marks path { fill: none; stroke: var(--esso); stroke-width: 2.4; stroke-linecap: round; vector-effect: non-scaling-stroke; opacity: .85; }
.marks path.draw { stroke-dasharray: 600; stroke-dashoffset: 600; animation: pencil 900ms ease-out forwards; }
@keyframes pencil { to { stroke-dashoffset: 0; } }

.ribbons { position: absolute; top: 18px; right: -2px; transform: translateX(100%); display: flex; flex-direction: column; gap: 6px; z-index: 3; }
.ribbons button {
  background: var(--green); color: var(--stock); border: 0; padding: 7px 14px 7px 10px; font-size: 15px; text-align: left;
  clip-path: polygon(0 0, 100% 0, 88% 50%, 100% 100%, 0 100%);
  padding-right: 22px;
}
.ribbons button[aria-current="true"] { background: var(--esso); }

.turns { display: flex; align-items: center; gap: 16px; margin-top: 14px; width: 100%; justify-content: space-between; }
.turns button { background: none; border: 1px solid rgba(213,200,179,.5); color: var(--stock); padding: 7px 14px; font-size: 15px; }
.turns button:disabled { opacity: .3; cursor: default; }
#cap { margin: 0; font-size: 14px; font-style: italic; text-align: center; color: rgba(213,200,179,.85); }

#note {
  position: absolute; left: -2px; top: 18px; transform: translateX(-100%);
  width: 230px; background: var(--stock); color: var(--ink); padding: 14px 16px; font-size: 15px; line-height: 1.45;
  border-left: 6px solid var(--esso); z-index: 3;
}
#note p { margin: 0 0 10px; }
#note q { font-style: italic; }
#note button { background: var(--esso); color: #fff; border: 0; padding: 8px 12px; font-size: 15px; font-weight: 700; }
#close { margin-top: 12px; background: var(--stock); color: var(--ink); border: 0; padding: 9px 18px; font-size: 16px; }

@media (max-width: 1180px) {
  #note { position: static; transform: none; width: 100%; max-width: 560px; margin-top: 12px; border-left-width: 4px; }
  .ribbons { position: static; transform: none; flex-direction: row; flex-wrap: wrap; justify-content: center; margin-bottom: 10px; order: -1; }
  .ribbons button { clip-path: none; padding: 6px 10px; }
}
@media (max-width: 720px) {
  .spread { --pw: min(calc(100vw - 32px), calc((100vh - 300px) * .714)); width: var(--pw); }
  .turns button { padding: 6px 10px; font-size: 14px; }
  .page.left { display: none; }
  .leaf { left: 0; }
  footer span { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .marks path.draw { animation: none; stroke-dashoffset: 0; }
}

#fade { position: fixed; inset: 0; background: #05070d; opacity: 0; pointer-events: none; transition: opacity .6s ease; z-index: 1; }
#fade.on { opacity: 1; }
@media (prefers-reduced-motion: reduce) { #fade { transition: none; } }
.card { z-index: 3; }
