/* =========================
   Base
   ========================= */

body {
  margin: 0;
  padding: 40px;

  font-family: "Courier New", Courier, monospace;
  color: #252525;
  background-color: #f4f0e6;

  /* subtle paper texture */
  background-image:
    radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px);
  background-size: 6px 6px;

  line-height: 1.6;
}


/* =========================
   Main Content
   ========================= */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 30px;

  background: #faf8f0;

  border: 2px solid #252525;
  box-shadow: 6px 6px 0 #252525;
}


/* =========================
   Headings
   ========================= */

h1,
h2,
h3 {
  font-family: "Courier New", Courier, monospace;
  line-height: 1.1;
}

h1 {
  font-size: 2.5rem;
  margin-top: 0;

  /* slightly hand-drawn feeling */
  transform-origin: center;
  transform: rotate(-1deg);
}

h2 {
  margin-top: 2rem;
  border-bottom: 2px solid #252525;
  display: inline-block;
}


/* =========================
   Links
   ========================= */

a {
  color: #252525;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:hover {
  background-color: #252525;
  color: #faf8f0;
}


/* =========================
   Images
   ========================= */

img {
  max-width: 100%;
  height: auto;

  border: 2px solid #252525;
  box-shadow: 4px 4px 0 #252525;
}


/* =========================
   Music carousel (about)
   ========================= */

.music-carousel {
  max-width: 380px;
  margin: 0.5rem 0 1.5rem;
}

.music-carousel-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;

  background: #252525;
  border: 2px solid #252525;
  box-shadow: 4px 4px 0 #252525;
}

.music-carousel-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;

  opacity: 0;
  pointer-events: none;
}

.music-carousel-frame iframe.is-active {
  opacity: 1;
  pointer-events: auto;
}

.music-carousel-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.music-carousel-controls button {
  background: #faf8f0;
  color: #252525;

  border: 2px solid #252525;
  padding: 4px 12px;

  font-family: "Courier New", Courier, monospace;
  font-size: 14px;
  cursor: pointer;

  box-shadow: 3px 3px 0 #252525;
}

.music-carousel-controls button:hover {
  background: #252525;
  color: #faf8f0;
}

.music-carousel-controls button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #252525;
}


/* =========================
   Entry pages (weeks)
   ========================= */

main.entry {
  padding: 36px 48px 32px;
}

main.entry h1 {
  font-size: 2.1rem;
  margin: 0.75rem 0 1.75rem;
}

main.entry h3 {
  font-size: 1.1rem;
  margin: 1.75rem 0 0.5rem;
}

main.entry p {
  margin: 0 0 1rem;
}

/* Every picture: centred, capped to a comfortable size, aspect ratio preserved */
main.entry img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 640px);
  max-height: 480px;
  margin: 1.5rem auto;
}

/* Side-by-side pairs */
.img-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  margin: 1.5rem 0;
}

main.entry .img-row img {
  margin: 0;
  max-width: calc(50% - 14px);
  max-height: 420px;
}

/* three in a row split into thirds */
main.entry .img-row img:first-child:nth-last-child(3),
main.entry .img-row img:first-child:nth-last-child(3) ~ img {
  max-width: calc(33.333% - 18px);
}

/* four in a row split into quarters */
main.entry .img-row img:first-child:nth-last-child(4),
main.entry .img-row img:first-child:nth-last-child(4) ~ img {
  max-width: calc(25% - 20px);
}

/* Videos, embeds and 3D viewers share the picture treatment */
main.entry video,
main.entry iframe,
main.entry model-viewer {
  display: block;
  margin: 1.5rem auto;

  border: 2px solid #252525;
  box-shadow: 4px 4px 0 #252525;
  background: #252525;
}

main.entry video {
  width: auto;
  height: auto;
  max-width: min(100%, 640px);
  max-height: 480px;
}

main.entry iframe {
  width: 100%;
  max-width: 640px;
  height: auto;
  aspect-ratio: 4 / 3;
}

main.entry iframe[height="315"] {
  aspect-ratio: 16 / 9;
}

main.entry model-viewer {
  width: min(100%, 480px);
  height: 360px;
  background: #faf8f0;
}

main.entry math[display="block"] {
  margin: 1.25rem 0;
  font-size: 1.15rem;
}

/* Tables */
main.entry table {
  width: 100%;
  margin: 1.25rem 0 1.75rem;

  border-collapse: collapse;
  border: 2px solid #252525;
  box-shadow: 4px 4px 0 #252525;
  background: #faf8f0;
  font-size: 0.95rem;
}

main.entry th,
main.entry td {
  padding: 8px 12px;
  border: 1px solid #252525;
  text-align: left;
  vertical-align: top;
}

main.entry th {
  background: #252525;
  color: #faf8f0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Parts lists: toggle highlighter for in-stock vs to-buy rows */
.parts {
  --have: #cdebb7;
  --buy: #ffe88a;
  margin: 1.25rem 0 1.75rem;
}

.parts table {
  margin: 10px 0 0;
}

.parts-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
}

.parts-filter > span {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.parts-filter label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;

  background: #faf8f0;
  border: 2px solid #252525;
  box-shadow: 3px 3px 0 #252525;
  cursor: pointer;
  user-select: none;
}

.parts-filter input {
  appearance: none;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 2px solid #252525;
  background: #faf8f0;
  cursor: pointer;
}

.parts-filter label[data-stock="have"] input:checked { background: var(--have); }
.parts-filter label[data-stock="buy"] input:checked { background: var(--buy); }

.parts:has(.filter-have:checked) tr[data-stock="have"] td { background: var(--have); }
.parts:has(.filter-buy:checked) tr[data-stock="buy"] td { background: var(--buy); }

/* Top link back to the notebook */
.entry-top {
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* Previous / next week */
.entry-nav {
  display: flex;
  justify-content: space-between;
  gap: 20px;

  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px dashed #252525;
}

.entry-nav a,
.entry-nav-empty {
  flex: 1 1 0;
  min-width: 0;
}

.entry-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;

  padding: 12px 16px;

  text-decoration: none;
  background: #faf8f0;
  border: 2px solid #252525;
  box-shadow: 4px 4px 0 #252525;

  transition: transform 0.1s, box-shadow 0.1s;
}

.entry-nav a:hover {
  background: #252525;
  color: #faf8f0;
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #252525;
}

.entry-nav-next {
  text-align: right;
  align-items: flex-end;
}

.entry-nav-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.entry-nav-title {
  font-weight: bold;
}

@media (max-width: 600px) {
  body {
    padding: 16px;
  }

  main.entry {
    padding: 24px 20px;
  }

  main.entry h1 {
    font-size: 1.6rem;
  }

  main.entry .img-row img,
  main.entry .img-row img:first-child:nth-last-child(3),
  main.entry .img-row img:first-child:nth-last-child(3) ~ img,
  main.entry .img-row img:first-child:nth-last-child(4),
  main.entry .img-row img:first-child:nth-last-child(4) ~ img {
    max-width: 100%;
  }

  .entry-nav {
    flex-direction: column;
  }

  .entry-nav-empty {
    display: none;
  }
}


/* =========================
   Little "sketchbook" details
   ========================= */

hr {
  border: none;
  border-top: 2px dashed #252525;
  margin: 2rem 0;
}

blockquote {
  margin: 2rem 0;
  padding-left: 20px;

  border-left: 4px solid #252525;

  font-style: italic;
}

pre {
  line-height: 1.2; 
  margin: 1rem 0;
  max-width: 100%;
  overflow-x: auto;
}

pre.ascii-art {
  overflow: hidden;
}

/* =========================
   Mute Toggle
   ========================= */

.mute-toggle {
  position: fixed;
  z-index: 20;
  top: 16px;
  right: 16px;

  background: #faf8f0;
  color: #252525;

  border: 2px solid #252525;
  padding: 5px 10px;

  font-family: "Courier New", Courier, monospace;
  font-size: 12px;

  cursor: pointer;

  box-shadow: 3px 3px 0 #252525;
}

.mute-toggle:hover,
.mute-toggle[aria-pressed="true"] {
  background: #252525;
  color: #faf8f0;
}

.mute-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #252525;
}

/* =========================
   Mallet Cursor
   ========================= */

html.mallet-ready a[href],
html.mallet-ready a[href] * {
  cursor: none;
}

.mallet {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;

  width: 37px;
  height: 37px;

  pointer-events: none;
  transform-origin: 33px 33px;
  rotate: 20deg;

  display: none;
}

.mallet.visible {
  display: block;
}

.mallet.striking {
  animation: mallet-strike 0.22s ease-out;
}

@keyframes mallet-strike {
  0%   { rotate: 20deg; }
  35%  { rotate: -4deg; }
  55%  { rotate: 2deg; }
  100% { rotate: 20deg; }
}

@media (prefers-reduced-motion: reduce) {
  .mallet.striking {
    animation: none;
  }
}

/* =========================
   Desk (home page)
   ========================= */

.desk-page {
  padding: 24px 32px 40px;
}

.desk-page pre.ascii-art {
  margin: 0 0 20px;
}

.desk {
  position: relative;
  max-width: 1500px;
  margin: 0 auto;
  padding: 64px 48px;
  box-sizing: border-box;

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 56px;

  background-color: #d8c39c;
  background-image:
    repeating-linear-gradient(178deg, rgba(37, 37, 37, 0.06) 0 1px, transparent 1px 11px),
    repeating-linear-gradient(181deg, rgba(37, 37, 37, 0.04) 0 2px, transparent 2px 37px);

  border: 2px solid #252525;
  box-shadow: 6px 6px 0 #252525;
}

.pencil {
  position: absolute;
  top: 28px;
  right: 72px;

  width: 200px;
  height: 14px;

  background: linear-gradient(90deg,
    #8a8478 0 14px, #252525 14px 16px,
    #c9c3b6 16px 30px, #252525 30px 32px,
    #faf8f0 32px);
  border: 2px solid #252525;
  border-radius: 3px 0 0 3px;
  box-shadow: 3px 3px 0 #252525;

  transform: rotate(-8deg);
}

.pencil::after {
  content: "";
  position: absolute;
  top: -2px;
  right: -26px;

  width: 26px;
  height: 18px;

  background: linear-gradient(90deg, #e9dcc0 0 68%, #252525 68%);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}


/* =========================
   Book
   ========================= */

.book-area {
  /* half the desk's inner width: body padding (64) + desk padding (96) + margin */
  --page-w: min(380px, calc((100vw - 220px) / 2));
  --page-h: calc(var(--page-w) * 1.32);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;

  font-size: calc(var(--page-w) / 27);
}

.book-viewport {
  width: calc(var(--page-w) * 2);
  height: var(--page-h);
}

.book {
  position: relative;
  width: 100%;
  height: 100%;

  perspective: 2400px;
  user-select: none;

  /* same timing as .leaf so the re-centring slide tracks the turning page */
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.book.closed-front {
  transform: translateX(calc(var(--page-w) * -0.5));
}

.book.closed-back {
  transform: translateX(calc(var(--page-w) * 0.5));
}

/* page stacks under the open pages */
.book::before,
.book::after {
  content: "";
  position: absolute;
  top: 0;
  z-index: 0;

  width: 50%;
  height: 100%;
  box-sizing: border-box;

  background: #faf8f0;
  border: 2px solid #252525;

  opacity: 0;
  /* hide once the departing page has lifted past edge-on */
  transition: opacity 0.15s 0.35s;
}

.book::before {
  left: 0;
  box-shadow: -2px 2px 0 #faf8f0, -3px 3px 0 #252525, -5px 5px 0 #faf8f0, -6px 6px 0 #252525;
}

.book::after {
  left: 50%;
  box-shadow: 2px 2px 0 #faf8f0, 3px 3px 0 #252525, 5px 5px 0 #faf8f0, 6px 6px 0 #252525;
}

.book.has-left::before,
.book.has-right::after {
  opacity: 1;
  /* show as the arriving page lands */
  transition-delay: 0.5s;
}

.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 1;

  width: 50%;
  height: 100%;

  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
  pointer-events: none;
}

.face {
  pointer-events: auto;
}

.leaf.flipped {
  transform: rotateY(-180deg);
}

.book.no-anim,
.book.no-anim::before,
.book.no-anim::after,
.book.no-anim .leaf {
  transition: none !important;
}

.face {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  padding: 2em 1.9em 2.6em;

  display: flex;
  flex-direction: column;
  overflow: hidden;

  background-color: #faf8f0;
  background-image:
    linear-gradient(90deg, rgba(37, 37, 37, 0.12), transparent 12%),
    radial-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: auto, 10px 10px;
  border: 2px solid #252525;

  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  cursor: pointer;
}

.face.front {
  border-radius: 0 6px 6px 0;
}

.face.back {
  transform: rotateY(180deg);
  border-radius: 6px 0 0 6px;
  background-image:
    linear-gradient(270deg, rgba(37, 37, 37, 0.12), transparent 12%),
    radial-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
}

/* folded corner hint */
.face:not(.cover)::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 22px;
  height: 22px;
  transition: width 0.15s, height 0.15s;
}

.face.front:not(.cover)::after {
  right: 0;
  background: linear-gradient(-45deg, #d8c39c 0 50%, #252525 50% 54%, #e9e3d4 54%);
}

.face.back:not(.cover)::after {
  left: 0;
  background: linear-gradient(45deg, #d8c39c 0 50%, #252525 50% 54%, #e9e3d4 54%);
}

.face:not(.cover):hover::after {
  width: 30px;
  height: 30px;
}

.face h2 {
  display: block;
  margin: 0 0 0.7em;
  border-bottom: none;
  font-size: 1.55em;
  line-height: 1.15;
}

.face p {
  margin: 0 0 1em;
  line-height: 1.55;
}

.page-kicker {
  font-size: 0.8em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-open {
  align-self: flex-start;
  margin-top: auto;
  padding: 0.3em 0.6em;

  background: #faf8f0;
  border: 2px solid #252525;
  box-shadow: 3px 3px 0 #252525;

  font-weight: bold;
  text-decoration: none;
}

.page-num {
  position: absolute;
  bottom: 0.9em;
  font-size: 0.75em;
}

.front .page-num {
  right: 2.6em;
}

.back .page-num {
  left: 2.6em;
}

.page-figure {
  position: relative;
  margin: 0.4em 0 1.2em;
}

.page-figure img {
  display: block;
  width: 100%;
  height: calc(var(--page-h) * 0.42);
  object-fit: cover;
  transform: rotate(-1.5deg);
}

.page-figure::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  z-index: 1;

  width: 64px;
  height: 18px;

  background: rgba(250, 248, 240, 0.8);
  border: 1px solid rgba(37, 37, 37, 0.35);
  transform: translateX(-50%) rotate(3deg);
}

.page-caption {
  font-style: italic;
  font-size: 0.9em;
}

.page-sections-title {
  margin-bottom: 0.4em !important;
  font-size: 0.8em;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.page-sections {
  margin: 0;
  padding-left: 1.2em;
  font-size: 0.92em;
  line-height: 1.5;
}

.toc {
  display: flex;
  flex-direction: column;
  gap: 0.55em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc a {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  padding: 0.1em 0.2em;
  text-decoration: none;
}

.toc a span:first-child {
  order: 1;
}

.toc a::after {
  content: "";
  order: 2;
  flex: 1;
  border-bottom: 2px dotted rgba(37, 37, 37, 0.45);
}

.toc a span:last-child {
  order: 3;
}

/* covers */

.face.cover {
  align-items: center;
  justify-content: space-between;
  padding-top: 3.5em;

  background: #252525;
  color: #faf8f0;
  text-align: center;
}

.face.front.cover {
  box-shadow: inset 10px 0 0 rgba(250, 248, 240, 0.08);
}

.back-cover {
  justify-content: flex-end !important;
}

.cover-label {
  padding: 1.2em 1.4em;
  background: #faf8f0;
  color: #252525;
  transform: rotate(-1.5deg);
}

.face .cover-kicker {
  margin: 0 0 0.6em;
  font-size: 0.8em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.face .cover-title {
  margin: 0;
  font-size: 2.2em;
  font-weight: bold;
  line-height: 1.1;
}

.face .cover-name {
  margin: 0.6em 0 0;
  font-size: 0.9em;
}

.face .cover-hint {
  margin: 0;
  font-size: 0.8em;
  opacity: 0.7;
}

.inside-cover {
  align-items: center;
  justify-content: center;
  background-color: #efe9da !important;
  text-align: center;
}

.face .belongs {
  margin: 0;
  font-size: 0.85em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.face .signature {
  margin: 0.3em 0 0.8em;
  padding: 0 0.4em;
  border-bottom: 2px solid #252525;
  font-family: "Brush Script MT", "Segoe Script", cursive;
  font-size: 2.4em;
  transform: rotate(-3deg);
}

.face .belongs-note {
  margin: 0.2em 0;
  font-size: 0.8em;
}

/* controls */

.book-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

#pageSelect {
  -webkit-appearance: none;
  appearance: none;

  min-width: 11em;
  padding: 6px 30px 6px 12px;

  background-color: #faf8f0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23252525' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 2px solid #252525;
  border-radius: 0;
  box-shadow: 3px 3px 0 #252525;
  color: #252525;

  font-family: "Courier New", Courier, monospace;
  font-size: 14px;
  text-align: center;
  text-align-last: center;

  cursor: pointer;
}

#pageSelect:hover {
  background-color: #efe9da;
}

#pageSelect:focus-visible {
  outline: 2px solid #252525;
  outline-offset: 2px;
}


/* =========================
   Buttons (play + page turn)
   ========================= */

#playBtn,
.book-controls button {
  flex-shrink: 0;

  background: #faf8f0;
  color: #252525;

  border: 2px solid #252525;
  padding: 7px 13px;

  font-family: "Courier New", Courier, monospace;
  font-size: 14px;

  cursor: pointer;

  box-shadow: 3px 3px 0 #252525;
}

#playBtn:hover,
.book-controls button:hover:enabled {
  background: #252525;
  color: #faf8f0;
}

#playBtn:active,
.book-controls button:active:enabled {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #252525;
}

.book-controls button:disabled {
  opacity: 0.4;
  cursor: default;
}


/* =========================
   Tape Recorder
   ========================= */

.recorder {
  width: min(560px, 100%);
  flex-shrink: 0;
  box-sizing: border-box;
  padding: 16px 18px 18px;

  display: flex;
  flex-direction: column;
  gap: 12px;

  background: #faf8f0;
  border: 2px solid #252525;
  border-radius: 10px;
  box-shadow: 6px 6px 0 #252525;

  transform: rotate(-2deg);
}

.recorder-top {
  display: flex;
  align-items: center;
  justify-content: space-between;

  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.recorder-led {
  width: 10px;
  height: 10px;

  background: #faf8f0;
  border: 2px solid #252525;
  border-radius: 50%;
}

.recorder.playing .recorder-led {
  background: #d23c2a;
  box-shadow: 0 0 6px #d23c2a;
}

.recorder-window {
  padding: 10px 12px;

  background: #efe9da;
  border: 2px solid #252525;
  border-radius: 6px;
  box-shadow: inset 3px 3px 0 rgba(37, 37, 37, 0.15);
}

#tapeDeck {
  display: block;
  width: 100%;
  height: 88px;
}

.recorder-bottom {
  display: flex;
  align-items: center;
  gap: 16px;
}

.recorder-grille {
  flex: 1;
  height: 34px;

  background-image: radial-gradient(#252525 1.6px, transparent 1.8px);
  background-size: 8px 8px;
  opacity: 0.8;
}


/* =========================
   Reduced motion
   ========================= */

@media (prefers-reduced-motion: reduce) {
  .book,
  .leaf {
    transition-duration: 0.01s !important;
  }
}


/* =========================
   Mobile
   ========================= */

@media (max-width: 760px) {
  .desk-page {
    padding: 16px 12px 30px;
  }

  .desk {
    padding: 40px 14px;
    gap: 36px;
  }

  .pencil {
    display: none;
  }

  .book-area {
    --page-w: min(380px, calc(100vw - 70px));
  }

  .book-viewport {
    width: var(--page-w);
    overflow: hidden;
  }

  .book.closed-front,
  .book.closed-back {
    transform: none;
  }

  .leaf,
  .book::after {
    left: 0;
    width: 100%;
  }

  .recorder {
    transform: none;
  }

  #tapeDeck {
    height: 64px;
  }
}
