<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>The Rack by Kevin Church and Benjamin Birdie</title>
  <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&display=swap" rel="stylesheet">
  <style>
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background-color: #226dc0;
  font-family: 'Space Grotesk', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
  overflow-y: scroll;
}
    /* ── Header ── */
    #site-header {
      width: 100%;
      max-width: 760px;
      margin-bottom: 20px;
    }
    #site-header img {
      width: 100%;
      display: block;
    }

    /* ── Viewer ── */
    #viewer {
      width: 100%;
      max-width: 760px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0;
    }

    /* ── Comic image ── */
    #comic-wrap {
      position: relative;
      width: 100%;
      background: #fff;
      line-height: 0;
    }
    #comic-img {
      width: 100%;
      display: block;
    }

    /* Large click-through prev/next overlays on image */
    .img-nav {
      position: absolute;
      top: 0;
      width: 20%;
      height: 100%;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.15s;
    }
    .img-nav:hover { opacity: 1; }
    #img-prev { left: 0; background: linear-gradient(to right, rgba(0,0,0,0.35), transparent); }
    #img-next { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.35), transparent); }
    .img-nav svg { fill: #fff; width: 32px; height: 32px; filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5)); }

    /* ── Toolbar below image ── */
    #toolbar {
      width: 100%;
      background: rgba(0, 0, 0, 0.25);
      padding: 12px 16px;
      display: flex;
      align-items: center;
      gap: 10px;
      flex-wrap: wrap;
    }

    /* Prev / Next buttons */
    .nav-btn {
      background: rgba(255,255,255,0.15);
      border: 1px solid rgba(255,255,255,0.3);
      color: #fff;
      font-family: 'Space Grotesk', sans-serif;
      font-weight: 600;
      font-size: 14px;
      padding: 6px 14px;
      cursor: pointer;
      border-radius: 4px;
      transition: background 0.15s;
      white-space: nowrap;
      line-height: 1;
    }
    .nav-btn:hover:not(:disabled) { background: rgba(255,255,255,0.28); }
    .nav-btn:disabled { opacity: 0.3; cursor: default; }

    /* Date / counter info (center, grows to fill) */
    #info {
      flex: 1;
      text-align: center;
      color: #fff;
      min-width: 0;
    }
#comic-date {
  font-size: 15px;
  font-weight: 600;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 20px;
}
    #comic-counter {
      font-size: 11px;
      opacity: 0.7;
      margin-top: 2px;
      display: block;
    }

    /* Jump to # input */
    #jump-wrap {
      display: flex;
      align-items: center;
      gap: 5px;
      color: #fff;
      font-size: 13px;
      white-space: nowrap;
    }
    #jump-input {
      width: 52px;
      padding: 5px 6px;
      font-family: 'Space Grotesk', sans-serif;
      font-size: 13px;
      border: 1px solid rgba(255,255,255,0.4);
      border-radius: 4px;
      background: rgba(255,255,255,0.12);
      color: #fff;
      text-align: center;
      outline: none;
    }
    #jump-input::placeholder { color: rgba(255,255,255,0.45); }
    #jump-input:focus { border-color: rgba(255,255,255,0.7); background: rgba(255,255,255,0.2); }

    /* First / Last links */
    .edge-link {
      color: rgba(255,255,255,0.65);
      font-size: 12px;
      cursor: pointer;
      text-decoration: underline;
      white-space: nowrap;
      background: none;
      border: none;
      font-family: 'Space Grotesk', sans-serif;
      padding: 0;
    }
    .edge-link:hover { color: #fff; }

    /* keyboard hint */
    #kb-hint {
      width: 100%;
      text-align: center;
      color: rgba(255,255,255,0.45);
      font-size: 11px;
      margin-top: 10px;
    }

#comic-note {
  font-size: 12px;
  font-style: italic;
  opacity: 0.8;
  margin-top: -16px;
  margin-bottom: 20px;
  display: block;
  min-height: 0;
}

    #comic-note:empty { display: none; }

    #comic-img.loading { opacity: 0.5; }

    @media (max-width: 520px) {
      #jump-wrap, .edge-link { display: none; }
    }
  </style>
</head>
<body>

<header id="site-header">
  <img src="https://agreeablecomics.com/therack/comics/rack-header.jpg" alt="The Rack">
</header>

<div id="viewer">
  <div id="comic-wrap">
    <img id="comic-img" alt="Comic strip">
    <div class="img-nav" id="img-prev" title="Previous (←)">
      <svg viewBox="0 0 24 24"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></svg>
    </div>
    <div class="img-nav" id="img-next" title="Next (→)">
      <svg viewBox="0 0 24 24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>
    </div>
  </div>

  <div id="toolbar">
    <button class="edge-link" id="btn-first">First</button>
    <button class="nav-btn" id="btn-prev">← Prev</button>
    <div id="info">
      <span id="comic-date"></span>
      <span id="comic-note"></span>
      <span id="comic-counter"></span>
    </div>
    <button class="nav-btn" id="btn-next">Next →</button>
    <button class="edge-link" id="btn-last">Last</button>
    <div id="jump-wrap">
      <label for="jump-input">#</label>
      <input type="number" id="jump-input" min="1" placeholder="…" title="Jump to comic number">
    </div>
  </div>

  <p id="kb-hint">← → arrow keys to navigate</p>
</div>

<script>
const BASE = 'https://agreeablecomics.com/therack/comics/';

const COMICS = ['2000-01-01-intro.jpg',
  '2007-02-02.jpg','2007-02-05.jpg','2007-02-09.jpg','2007-02-12.jpg',
  '2007-02-14.jpg','2007-02-16.jpg','2007-02-19.jpg','2007-02-21.jpg',
  '2007-02-23.jpg','2007-02-26.jpg','2007-02-28.jpg','2007-03-02.jpg',
  '2007-03-05.jpg','2007-03-07.jpg','2007-03-09.jpg','2007-03-12.jpg',
  '2007-03-14.jpg','2007-03-16.jpg','2007-03-19.jpg','2007-03-21.jpg',
  '2007-03-23.jpg','2007-03-26.jpg','2007-03-28.jpg','2007-03-30.jpg',
  '2007-04-02.jpg','2007-04-04.jpg','2007-04-06.jpg','2007-04-09.jpg',
  '2007-04-11.jpg','2007-04-13.jpg','2007-04-16.jpg','2007-04-18.jpg',
  '2007-04-20.jpg','2007-04-23.jpg','2007-04-25.jpg','2007-04-27.jpg',
  '2007-04-30.jpg','2007-05-02.jpg','2007-05-04.jpg','2007-05-07.jpg',
  '2007-05-09.jpg','2007-05-11.jpg','2007-05-14.jpg','2007-05-16.jpg',
  '2007-05-18.jpg','2007-05-21.jpg','2007-05-23.jpg','2007-05-25.jpg',
  '2007-05-28.jpg','2007-05-30.jpg','2007-05-31.jpg','2007-06-01.jpg',
  '2007-06-04.jpg','2007-06-06.jpg','2007-06-07.jpg','2007-06-08.jpg',
  '2007-06-11.jpg','2007-06-13.jpg','2007-06-14.jpg','2007-06-15.jpg',
  '2007-06-18.jpg','2007-06-20.jpg','2007-06-21.jpg','2007-06-22.jpg',
  '2007-06-25.jpg','2007-06-27.jpg','2007-06-28.jpg','2007-06-29.jpg',
  '2007-07-02.jpg','2007-07-04.jpg','2007-07-05.jpg','2007-07-06.jpg',
  '2007-07-09.jpg','2007-07-11.jpg','2007-07-12.jpg','2007-07-13.jpg',
  '2007-07-18.jpg','2007-07-19.jpg','2007-07-20.jpg','2007-07-21.jpg',
  '2007-07-22.jpg','2007-07-23.jpg','2007-07-24.jpg','2007-07-25.jpg',
  '2007-07-26.jpg','2007-07-27.jpg','2007-08-01.jpg','2007-08-02.jpg',
  '2007-08-03.jpg','2007-08-06.jpg','2007-08-08.jpg','2007-08-09.jpg',
  '2007-08-10.jpg','2007-08-13.jpg','2007-08-15.jpg','2007-08-17.jpg',
  '2007-08-20.jpg','2007-08-22.jpg','2007-08-23.jpg','2007-08-24.jpg',
  '2007-08-27.jpg','2007-08-29.jpg','2007-08-30.jpg','2007-09-05.jpg',
  '2007-09-06.jpg','2007-09-07.jpg','2007-09-10.jpg','2007-09-12.jpg',
  '2007-09-13.jpg','2007-09-14.jpg','2007-09-17.jpg','2007-09-18.jpg',
  '2007-09-19.jpg','2007-09-21.jpg','2007-09-24.jpg','2007-09-25.jpg',
  '2007-09-26.jpg','2007-09-28.jpg','2007-10-01.jpg','2007-10-02.jpg',
  '2007-10-03.jpg','2007-10-05.jpg','2007-10-08.jpg','2007-10-09.jpg',
  '2007-10-10.jpg','2007-10-13.jpg','2007-10-15.jpg','2007-10-16.jpg',
  '2007-10-17.jpg','2007-10-19.jpg','2007-10-22.jpg','2007-10-23.jpg',
  '2007-10-24.jpg','2007-10-26.jpg','2007-10-29.jpg','2007-10-30.jpg',
  '2007-10-31.jpg','2007-11-01.jpg','2007-11-02.jpg','2007-11-05.jpg',
  '2007-11-06.jpg','2007-11-07.jpg','2007-11-09.jpg','2007-11-12.jpg',
  '2007-11-13.jpg','2007-11-14.jpg','2007-11-17.jpg','2007-11-19.jpg',
  '2007-11-20.jpg','2007-11-21.jpg','2007-11-26.jpg','2007-11-27.jpg',
  '2007-11-29.jpg','2007-11-30.jpg','2007-12-03.jpg','2007-12-04.jpg',
  '2007-12-05.jpg','2007-12-07.jpg','2007-12-10.jpg','2007-12-11.jpg',
  '2007-12-12.jpg','2007-12-14.jpg','2007-12-18.jpg','2007-12-19.jpg',
  '2007-12-21.jpg','2007-12-25.jpg','2007-12-26.jpg','2007-12-28.jpg',
  '2007-12-31.jpg','2007-22-06.jpg',
  '2008-01-02.jpg','2008-01-03.jpg','2008-01-04.jpg','2008-01-07.jpg',
  '2008-01-08.jpg','2008-01-09.jpg','2008-01-11.jpg','2008-01-14.jpg',
  '2008-01-15.jpg','2008-01-16.jpg','2008-01-19.jpg','2008-01-21.jpg',
  '2008-01-22.jpg','2008-01-23.jpg','2008-01-25.jpg','2008-01-28.jpg',
  '2008-01-29.jpg','2008-01-30.jpg','2008-02-02.jpg','2008-02-04.jpg',
  '2008-02-05.jpg','2008-02-06.jpg','2008-02-08.jpg','2008-02-11.jpg',
  '2008-02-13.jpg','2008-02-18.jpg','2008-02-19.jpg','2008-02-21.jpg',
  '2008-02-24.jpg','2008-02-26.jpg','2008-02-29.jpg','2008-03-03.jpg',
  '2008-03-05.jpg','2008-03-07.jpg','2008-03-11.jpg','2008-03-12.jpg',
  '2008-03-14.jpg','2008-03-18.jpg','2008-03-19.jpg','2008-03-21.jpg',
  '2008-03-24.jpg','2008-03-26.jpg','2008-03-28.jpg','2008-03-31.jpg',
  '2008-04-02.jpg','2008-04-04.jpg','2008-04-07.jpg','2008-04-08.jpg',
  '2008-04-09.jpg','2008-04-11.jpg','2008-04-14.jpg','2008-04-15.jpg',
  '2008-04-17.jpg','2008-04-18.jpg','2008-04-21.jpg','2008-04-22.jpg',
  '2008-04-23.jpg','2008-04-25.jpg','2008-04-28.jpg','2008-04-29.jpg',
  '2008-04-30.jpg','2008-05-03.jpg','2008-05-05.jpg','2008-05-06.jpg',
  '2008-05-07.jpg','2008-05-09.jpg','2008-05-13.jpg','2008-05-14.jpg',
  '2008-05-19.jpg','2008-05-20.jpg','2008-05-21.jpg','2008-05-23.jpg',
  '2008-05-26.jpg','2008-05-27.jpg','2008-05-29.jpg','2008-05-30.jpg',
  '2008-06-02.jpg','2008-06-03.jpg','2008-06-04.jpg','2008-06-06.jpg',
  '2008-06-09.jpg','2008-06-10.jpg','2008-06-11.jpg','2008-06-13.jpg',
  '2008-06-16.jpg','2008-06-17.jpg','2008-06-18.jpg','2008-06-20.jpg',
  '2008-06-24.jpg','2008-06-25.jpg','2008-06-26.jpg','2008-06-27.jpg',
  '2008-06-30.jpg','2008-07-01.jpg','2008-07-02.jpg','2008-07-04.jpg',
  '2008-07-08.jpg','2008-07-09.jpg','2008-07-10.jpg','2008-07-11.jpg',
  '2008-07-15.jpg','2008-07-16.jpg','2008-07-17.jpg','2008-07-18.jpg',
  '2008-07-21.jpg','2008-07-22.jpg','2008-07-23.jpg','2008-07-25.jpg',
  '2008-07-28.jpg','2008-07-29.jpg','2008-07-30.jpg','2008-08-04.jpg',
  '2008-08-05.jpg','2008-08-06.jpg','2008-08-08.jpg','2008-08-11.jpg',
  '2008-08-12.jpg','2008-08-13.jpg','2008-08-15.jpg','2008-08-18.jpg',
  '2008-08-19.jpg','2008-08-20.jpg','2008-08-25.jpg','2008-08-26.jpg',
  '2008-08-27.jpg','2008-08-29.jpg','2008-09-01.jpg','2008-09-03.jpg',
  '2008-09-04.jpg','2008-09-05.jpg','2008-09-08.jpg','2008-09-09.jpg',
  '2008-09-10.jpg','2008-09-11.jpg','2008-09-12.jpg','2008-09-15.jpg',
  '2008-09-16.jpg','2008-09-17.jpg','2008-09-19.jpg','2008-09-22.jpg',
  '2008-09-23.jpg','2008-09-24.jpg','2008-09-26.jpg','2008-09-29.jpg',
  '2008-09-30.jpg','2008-10-02.jpg','2008-10-03.jpg','2008-10-06.jpg',
  '2008-10-07.jpg','2008-10-08.jpg','2008-10-10.jpg','2008-10-13.jpg',
  '2008-10-14.jpg','2008-10-16.jpg','2008-10-20.jpg','2008-10-21.jpg',
  '2008-10-22.jpg','2008-10-24.jpg','2008-10-27.jpg','2008-10-28.jpg',
  '2008-10-29.jpg','2008-10-30.jpg','2008-10-31.jpg','2008-11-03.jpg',
  '2008-11-04.jpg','2008-11-05.jpg','2008-11-07.jpg','2008-11-10.jpg',
  '2008-11-11.jpg','2008-11-12.jpg','2008-11-14.jpg','2008-11-18.jpg',
  '2008-11-19.jpg','2008-11-20.jpg','2008-11-21.jpg','2008-11-25.jpg',
  '2008-11-26.jpg','2008-11-27.jpg','2008-12-01.jpg','2008-12-02.jpg',
  '2008-12-03.jpg','2008-12-06.jpg','2008-12-08.jpg','2008-12-09.jpg',
  '2008-12-10.jpg','2008-12-12.jpg','2008-12-15.jpg','2008-12-16.jpg',
  '2008-12-17.jpg','2008-12-18.jpg','2008-12-22.jpg','2008-12-23.jpg',
  '2008-12-24.jpg','2008-12-26.jpg','2008-12-29.jpg','2008-12-30.jpg',
  '2008-12-31.jpg',
  '2009-01-02.jpg','2009-01-06.jpg','2009-01-07.jpg','2009-01-08.jpg',
  '2009-01-09.jpg','2009-01-12.jpg','2009-01-13.jpg','2009-01-14.jpg',
  '2009-01-15.jpg','2009-01-16.jpg','2009-01-19.jpg','2009-01-20.jpg',
  '2009-01-21.jpg','2009-01-23.jpg','2009-01-25.png','2009-01-27.jpg',
  '2009-01-28.jpg','2009-01-30.jpg','2009-02-02.jpg','2009-02-03.jpg',
  '2009-02-04.jpg','2009-02-06.jpg','2009-02-09.jpg','2009-02-11.jpg',
  '2009-02-13.jpg','2009-02-17.jpg','2009-02-18.jpg','2009-02-19.jpg',
  '2009-02-20.jpg','2009-02-23.jpg','2009-02-24.jpg','2009-02-25.jpg',
  '2009-02-27.jpg','2009-03-02.jpg','2009-03-03.jpg','2009-03-04.jpg',
  '2009-03-06.jpg','2009-03-09.jpg','2009-03-10.jpg','2009-03-11.jpg',
  '2009-03-13.jpg','2009-03-16.jpg','2009-03-17.jpg','2009-03-18.jpg',
  '2009-03-20.jpg','2009-03-23.jpg','2009-03-24.jpg','2009-03-25.jpg',
  '2009-03-27.jpg','2009-03-30.jpg','2009-03-31.jpg','2009-04-01.jpg',
  '2009-04-03.jpg','2009-04-06.jpg','2009-04-07.jpg','2009-04-08.jpg',
  '2009-04-10.jpg','2009-04-13.jpg','2009-04-14.jpg','2009-04-15.jpg',
  '2009-04-17.jpg','2009-04-20.jpg','2009-04-21.jpg','2009-04-22.jpg',
  '2009-04-24.jpg','2009-04-27.jpg','2009-04-28.jpg','2009-04-29.jpg',
  '2009-04-30.jpg','2009-05-01.jpg','2009-05-05.jpg','2009-05-06.jpg',
  '2009-05-07.jpg','2009-05-08.jpg','2009-05-11.jpg','2009-05-12.jpg',
  '2009-05-13.jpg','2009-05-14.jpg','2009-05-18.jpg','2009-05-19.jpg',
  '2009-05-20.jpg','2009-05-21.jpg','2009-05-22.jpg','2009-05-26.jpg',
  '2009-05-27.jpg','2009-05-28.png','2009-05-29.png','2009-06-01.png',
  '2009-06-02.jpg','2009-06-03.png','2009-06-05.png','2009-06-10.png',
  '2009-06-11.png','2009-06-12.png','2009-06-15.jpg','2009-06-16.jpg',
  '2009-06-17.png','2009-06-21.png','2009-06-22.jpg','2009-06-23.png',
  '2009-06-24.png','2009-06-26.png','2009-06-29.png','2009-06-30.jpg',
  '2009-07-01.png','2009-07-02.jpg','2009-07-03.png','2009-07-06.png',
  '2009-07-07.jpg','2009-07-08.png','2009-07-10.png','2009-07-13.png',
  '2009-07-14.jpg','2009-07-15.png','2009-07-16.jpg','2009-07-17.png',
  '2009-07-20.jpg','2009-07-21.png','2009-07-23.png','2009-07-24.png',
  '2009-07-27.png','2009-07-28.jpg','2009-07-29.png','2009-07-31.png',
  '2009-08-03.png','2009-08-04.jpg','2009-08-05.png',
  '2009-08-07.png','2009-08-10.png','2009-08-11.jpg','2009-08-12.png',
  '2009-08-14.png','2009-08-17.png','2009-08-18.jpg','2009-08-20.png',
  '2009-08-21.png','2009-08-24.png','2009-08-25.jpg','2009-08-26.png',
  '2009-08-31.png','2009-09-01.png','2009-09-02.jpg','2009-09-03.png',
  '2009-09-04.png','2009-09-08.png','2009-09-09.jpg','2009-09-10.png',
  '2009-09-11.png','2009-09-14.png','2009-09-15.jpg','2009-09-16.png',
  '2009-09-18.jpg','2009-09-21.png','2009-09-22.png','2009-09-23.png',
  '2009-09-25.png','2009-09-28.png','2009-09-29.jpg','2009-10-01.png',
  '2009-10-02.png','2009-10-05.png','2009-10-06.jpg','2009-10-07.jpg',
  '2009-10-09.png','2009-10-12.png','2009-10-13.jpg','2009-10-14.png',
  '2009-10-16.png','2009-10-19.png','2009-10-20.jpg','2009-10-21.png',
  '2009-10-23.jpg','2009-10-26.png','2009-10-27.jpg','2009-10-28.png',
  '2009-11-02.png','2009-11-03.jpg','2009-11-04.png',
  '2009-11-06.png','2009-11-09.png','2009-11-10.jpg','2009-11-11.png',
  '2009-11-13.png','2009-11-16-rack-tomorrow.png','2009-11-17.png',
  '2009-11-18.jpg','2009-11-19.png','2009-11-20.png','2009-11-23.png',
  '2009-11-24.jpg','2009-11-30.png','2009-12-01.jpg',
  '2009-12-02.png','2009-12-04.png','2009-12-07.png','2009-12-08.jpg',
  '2009-12-09.png','2009-12-11.png','2009-12-14.png','2009-12-15.jpg',
  '2009-12-16.png','2009-12-18.png','2009-12-21.jpg','2009-12-22.png',
  '2009-12-23.jpg','2009-12-24.png','2009-12-28.png','2009-12-30.png',
  '2010-01-04.png','2010-01-05.jpg','2010-01-06.png','2010-01-09.png',
  '2010-01-11.png','2010-01-12.jpg','2010-01-13.png','2010-01-15.png',
  '2010-01-19.png','2010-01-20.jpg','2010-01-21.png','2010-01-22.png',
  '2010-01-25.png','2010-01-26.jpg','2010-01-27.jpg','2010-01-29.png',
  '2010-02-02.png','2010-02-03.jpg','2010-02-04.jpg','2010-02-05.png',
  '2010-02-09.jpg','2010-02-10-20010-02-10.jpg','2010-02-11.jpg',
  '2010-02-16.png','2010-02-17.jpg','2010-02-18.jpg','2010-02-19.jpg',
  '2010-02-23.jpg','2010-02-24-022310-wednesday.png',
  '2010-02-25-the-rack-02-25-2010.png','2010-02-26-022510-friday.gif',
  '2010-03-02-rack-ming-pinup.png','2010-03-03-reg-weapon-pinup.png',
  '2010-03-04-Rack_TJ big.jpg','2010-03-04-rs-newrackswing.jpg',
  '2010-03-08-mauk.jpg',
  '2010-03-09.jpg','2010-03-10.jpg','2010-03-11.jpg','2010-03-12.jpg',
  '2010-03-16.jpg','2010-03-17.jpg','2010-03-18.jpg','2010-03-19.jpg',
  '2010-03-22.jpg','2010-03-23.jpg','2010-03-24.jpg','2010-03-25.gif',
  '2010-03-26.jpg','2010-03-30.jpg','2010-03-31.jpg','2010-04-01.jpg',
  '2010-04-02.jpg','2010-04-06.jpg','2010-04-07.jpg','2010-04-08.jpg',
  '2010-04-09.png','2010-04-13.jpg','2010-04-14.jpg','2010-04-15.png',
  '2010-04-16.jpg','2010-04-20.jpg','2010-04-21-04-21-2010.jpg',
  '2010-04-22.jpg','2010-04-23.jpg','2010-04-27.jpg','2010-04-28.jpg',
  '2010-04-29.jpg','2010-04-30.jpg','2010-05-04.jpg','2010-05-05.jpg',
  '2010-05-06.jpg','2010-05-10.jpg','2010-05-12.jpg','2010-05-13.jpg',
  '2010-05-14.jpg','2010-05-18.jpg','2010-05-19.jpg','2010-05-20.jpg',
  '2010-05-21.png','2010-05-25.png','2010-06-01.jpg','2010-06-02.jpg',
  '2010-06-03.jpg','2010-06-04.jpg','2010-06-08.jpg','2010-06-09.jpg',
  '2010-06-10.jpg','2010-06-11.jpg','2010-06-15.jpg','2010-06-16.jpg',
  '2010-06-17.jpg','2010-06-18.jpg','2010-06-22.jpg','2010-06-23.jpg',
  '2010-06-24.jpg','2010-06-25.jpg','2010-06-29.jpg','2010-06-30.jpg',
  '2010-07-01-ask-yavin-iv-01.jpg','2010-07-02.jpg','2010-07-06.png',
  '2010-07-07-2010-007-07.jpg','2010-07-08-ask-yavin-iv-02.jpg',
  '2010-07-09.jpg','2010-07-13.jpg','2010-07-14.jpg',
  '2010-07-15-ask-yavin-iv-03.jpg','2010-07-16.png','2010-07-20.jpg',
  '2010-07-27.jpg','2010-07-28.jpg','2010-07-29-ask-yavin-iv-04.jpg',
  '2010-07-30.jpg','2010-08-03.png','2010-08-04.jpg',
  '2010-08-05-ask-yavin-iv-05.jpg','2010-08-06.png','2010-08-10.jpg',
  '2010-08-11-ask-yavin-iv-06.jpg','2010-08-13.jpg','2010-08-17.jpg',
  '2010-08-18-ask-yavin-iv-07.jpg','2010-08-20.jpg','2010-08-24.jpg',
  '2010-08-25-ask-yavin-iv-08.jpg','2010-08-27.jpg','2010-08-31.jpg',
  '2010-09-01-ask-yavin-iv-09.jpg','2010-09-03.jpg','2010-09-07.jpg',
  '2010-09-09-ask-yavin-iv-10.jpg','2010-09-10.jpg','2010-09-14.jpg',
  '2010-09-15-ask-yavin-iv-11.jpg','2010-09-17.jpg','2010-09-21.jpg',
  '2010-09-22-ask-yavin-iv-12.jpg','2010-09-24.jpg','2010-09-28.jpg',
  '2010-09-29-ask-yavin-iv-13.jpg','2010-10-01.jpg','2010-10-06.jpg',
  '2010-10-08.jpg','2010-10-12.jpg','2010-10-13.jpg','2010-10-15.jpg',
  '2010-10-19.png','2010-10-20.jpg','2010-10-21.jpg',
  '2010-10-22-Rack01.png','2010-10-22.png',
  '2010-10-25-rack-halloweek-01.gif','2010-10-26-Rack02.gif',
  '2010-10-27-rack-halloweek-03.gif','2010-10-28-rack-halloweek-04.gif',
  '2010-10-29-rack-halloweek-05.gif','2010-11-02.png',
  '2010-11-03-ask-yavin-iv-16.jpg','2010-11-05.png','2010-11-09.png',
  '2010-11-10-ask-yavin-iv-17.jpg','2010-11-12.png','2010-11-16.png',
  '2010-11-17-ask-yavin-iv-18.jpg','2010-11-19.jpg','2010-11-23.png',
  '2010-11-26.jpg','2010-11-30.jpg','2010-12-02.jpg','2010-12-03.png',
  '2010-12-07.jpg','2010-12-08.jpg','2010-12-10.jpg','2010-12-14.jpg',
  '2010-12-15-ask-yavin-iv-20.jpg','2010-12-17.png','2010-12-21.png',
  '2010-12-22-ask-yavin-iv-21.jpg','2010-12-24.png',
  '2011-01-04.png','2011-01-05-ask-yavin-iv-22.jpg','2011-01-07.png',
  '2011-01-11.png','2011-01-12-ask-yavin-iv-23.jpg','2011-01-14.png',
  '2011-01-18.png','2011-01-19-ask-yavin-iv-24.jpg','2011-01-21.png',
  '2011-01-25.png','2011-01-26-ask-yavin-iv-25.png','2011-01-28.png',
  '2011-02-01.png','2011-02-28-rack-cast-page.jpg',
  '2011-03-01.png','2011-03-04.png','2011-03-08.png','2011-03-11.png',
  '2011-03-15.png','2011-03-18.png','2011-03-22.png',
  '2011-03-23-panels-music-01-liner-notes.png',
  '2011-03-25.png','2011-03-29.png','2011-04-06.png','2011-04-08.png',
  '2011-04-12.png','2011-04-15.png','2011-04-19.png',
  '2011-04-22-04-22-2011.png','2011-04-26.png','2011-04-29.png',
  '2011-05-03.png','2011-05-06.jpg','2011-05-10.jpg','2011-05-13.png',
  '2011-05-17.png','2011-05-20.png','2011-05-24.png','2011-05-25.png',
  '2011-05-27-the-rack-2011-05-27-letters.png','2011-06-01.png',
  '2011-06-02-the-rack-2011-06-02.png',
  '2011-06-03-sandra-guest-strip-june-3.png',
  '2011-06-08-HeroesConRack.jpg','2011-06-10-the-rack-456.png',
  '2011-06-15-the-rack-457.png','2011-06-17-the-rack458-letters-2.png',
  '2011-06-22-the-rack-459.jpg','2011-06-24-the-rack-460.png',
  '2011-06-29-the-rack-461.png','2011-07-01-the-rack-462.png',
  '2011-07-06-the-rack-463.png','2011-07-08-the-rack-464.png',
  '2011-07-13-the-rack-465.png','2011-07-15-the-rack-466.png',
  '2011-07-20-the-rack-477.png','2011-07-22-the-rack-468.png',
  '2011-07-29-the-rack-469.png','2011-08-03-the-rack-470.png',
  '2011-08-05-the-rack-471.png',
  '2011-08-12-the-rack-friday-august-12.png',
  '2011-08-17-the-rack-473.png','2011-08-19-the-rack-474.png',
  '2011-08-24-the-rack-475-final.png','2011-08-26-the-rack-476.png',
  '2011-08-31-the-rack-477.png','2011-09-02-the-rack-458.png',
  '2011-09-06-canete-bellaire-church-ultra-humanite.jpg',
  '2011-09-07-the-rack-479.png','2011-09-09-the-rack-480.png',
  '2011-09-14-the-rack-481.png',
  '2011-09-15-sloane-church-jubes-site.png',
  '2011-09-16-the-rack-482-erb.png','2011-09-21-the-rack-483.png',
  '2011-09-26-the-rack-484.png',
  '2011-09-30-the-rack-friday-september-30.png',
  '2011-10-07-the-rack-486.png',
  '2011-10-11-the-rack-church-shavley-punisher-web.jpg',
  '2011-10-14.png','2011-10-21-the-rack-487.png',
  '2011-10-31-the-rack-488.jpg',
  '2011-11-04-the-rack-friday-november-4.jpg',
  '2011-11-11-the-rack-friday-november-11.png',
  '2011-11-18-the-rack-492.png',
  '2011-11-25-the-rack-492-5-huffman.png',
  '2011-12-02-the-rack-494.png',
  '2011-12-06-three-days-promo-site.jpg',
  '2011-12-12-the-rack-495.png','2011-12-16-the-rack-496.jpg',
  '2012-01-06-the-rack-497.jpg','2012-01-12-the-rack-498-web.jpg',
  '2012-01-20-the-rack-499-web.jpg','2012-01-26-the-rack-500-web.jpg',
  '2012-02-02-rack-joe-hunter-pinup.jpg',
  '2012-02-12-the-rack-501-web.jpg','2012-02-16-the-rack-502-web.jpg',
  '2012-02-24-the-rack-503-web.jpg','2012-03-01-the-rack-504-web.jpg',
  '2012-03-08-the-rack-505.jpg','2012-03-15-the-rack-506-web.jpg',
  '2012-03-23-the-rack-507.jpg','2012-04-05-rack-lydia-message.jpg',
  '2012-04-12-the-rack-508.jpg','2012-04-19-the-rack-509-web.jpg',
  '2012-04-26-the-rack-510.jpg','2012-05-10-the-rack-511.jpg',
  '2012-05-17-the-rack-512.jpg','2012-05-24-the-rack-513.jpg',
  '2012-06-10-the-rack-514.jpg','2012-06-14-the-rack-515.jpg',
  '2012-07-05-the-rack-516.jpg','2012-07-13-the-rack-517.jpg',
  '2012-07-19-the-rack-518.jpg','2012-07-27-the-rack-519.jpg',
  '2012-08-02-the-rack-520.jpg','2012-08-09-the-rack-521.jpg',
  '2012-08-17-the-rack-522.jpg','2012-08-23-the-rack-523.jpg',
  '2012-08-30-the-rack-524.jpg','2012-09-07-the-rack-525.jpg',
  '2012-09-13-the-rack-526.jpg','2012-09-21-the-rack-527.jpg',
  '2012-09-28-the-rack-528.jpg','2012-10-04-the-rack-529.jpg',
  '2012-10-25-the-rack-530.jpg','2012-11-01-the-rack-531.jpg',
  '2012-11-09-the-rack-532.jpg','2012-11-15-the-rack-533.jpg',
  '2012-11-29-the-rack-534.jpg','2012-12-06-the-rack-535.jpg',
  '2012-12-13-the-rack-536.jpg','2012-12-20-the-rack-537.jpg',
  '2013-01-03-the-rack-538.jpg','2013-01-10-the-rack-539.jpg',
  '2013-01-17-the-rack-540.jpg','2013-01-24-the-rack-541.jpg',
  '2013-01-31-the-rack-542.jpg','2013-02-07-the-rack-543.jpg',
  '2013-02-14-the-rack-544.jpg','2013-02-21-superman-rack-special.jpg',
  '2013-03-07-the-rack-545-web.jpg','2013-03-14-the-rack-546.jpg',
  '2013-03-29-the-rack-547.jpg','2013-04-05-the-rack-548.jpg',
  '2013-04-11-the-rack-549.jpg','2013-04-18-the-rack-550.jpg',
  '2013-04-25-the-rack-551.jpg','2013-05-03-the-rack-552.jpg',
  '2013-05-10-the-rack-553.jpg'
];

const MONTHS = [
  'January','February','March','April','May','June',
  'July','August','September','October','November','December'
];

function parseDate(filename) {
  // Extract first YYYY-MM-DD from filename
  const m = filename.match(/^(\d{4})-(\d{2})-(\d{2})/);
  if (!m) return filename.replace(/\.[^.]+$/, '');
  const y = parseInt(m[1], 10);
  let mo = parseInt(m[2], 10);
  let d = parseInt(m[3], 10);
  // Handle anomalous YYYY-DD-MM (e.g. 2007-22-06)
  if (mo > 12 && d <= 12) { const tmp = mo; mo = d; d = tmp; }
  if (mo < 1 || mo > 12) return filename.replace(/\.[^.]+$/, '');
  return `${MONTHS[mo - 1]} ${d}, ${y}`;
}

let current = 0;
let notesMap = new Map(); // filename → note string

function loadNotes() {
  fetch('notes.csv')
    .then(r => r.ok ? r.text() : '')
    .then(text => {
      text.split('\n').forEach(line => {
        line = line.trim();
        if (!line || line.startsWith('#')) return;
        const comma = line.indexOf(',');
        if (comma === -1) return;
        const filename = line.slice(0, comma).trim();
        const note = line.slice(comma + 1).trim().replace(/^"|"$/g, '');
        if (filename && note) notesMap.set(filename, note);
      });
    })
    .catch(() => {}); // notes file is optional — fail silently
}

const img       = document.getElementById('comic-img');
const dateEl    = document.getElementById('comic-date');
const counterEl = document.getElementById('comic-counter');
const btnPrev   = document.getElementById('btn-prev');
const btnNext   = document.getElementById('btn-next');
const btnFirst  = document.getElementById('btn-first');
const btnLast   = document.getElementById('btn-last');
const imgPrev   = document.getElementById('img-prev');
const imgNext   = document.getElementById('img-next');
const noteEl    = document.getElementById('comic-note');
const jumpInput = document.getElementById('jump-input');

jumpInput.max = COMICS.length;

function goTo(n, pushHash) {
  n = Math.max(0, Math.min(COMICS.length - 1, n));
  current = n;
  window.scrollTo(0, 0);
  const filename = COMICS[current];
  img.classList.add('loading');
  img.onload = () => img.classList.remove('loading');
  img.onerror = () => img.classList.remove('loading');
  img.src = BASE + encodeURIComponent(filename);
  img.alt = `The Rack — ${parseDate(filename)}`;
  dateEl.textContent = parseDate(filename);
  noteEl.innerHTML = notesMap.get(filename) || '';
   counterEl.textContent = `#${current + 1} of ${COMICS.length}`;
  btnPrev.disabled = current === 0;
  imgPrev.style.display = current === 0 ? 'none' : '';
  btnNext.disabled = current === COMICS.length - 1;
  imgNext.style.display = current === COMICS.length - 1 ? 'none' : '';
  btnFirst.disabled = current === 0;
  btnLast.disabled = current === COMICS.length - 1;
  if (pushHash !== false) {
    history.replaceState(null, '', '#' + (current + 1));
  }
  jumpInput.value = '';
}

btnPrev.addEventListener('click', () => goTo(current - 1));
btnNext.addEventListener('click', () => goTo(current + 1));
btnFirst.addEventListener('click', () => goTo(0));
btnLast.addEventListener('click', () => goTo(COMICS.length - 1));
imgPrev.addEventListener('click', () => goTo(current - 1));
imgNext.addEventListener('click', () => goTo(current + 1));

jumpInput.addEventListener('keydown', (e) => {
  if (e.key === 'Enter') {
    const n = parseInt(jumpInput.value, 10);
    if (!isNaN(n)) goTo(n - 1);
  }
});

document.addEventListener('keydown', (e) => {
  if (e.target === jumpInput) return;
  if (e.key === 'ArrowLeft')  goTo(current - 1);
  if (e.key === 'ArrowRight') goTo(current + 1);
  if (e.key === 'Home') goTo(0);
  if (e.key === 'End')  goTo(COMICS.length - 1);
});

// Handle hash on load
function loadFromHash() {
  const hash = window.location.hash;
  if (hash && hash.length > 1) {
    const n = parseInt(hash.slice(1), 10);
    if (!isNaN(n) && n >= 1 && n <= COMICS.length) {
      goTo(n - 1, false);
      return;
    }
  }
  goTo(0, false);
}

window.addEventListener('hashchange', () => {
  const n = parseInt(window.location.hash.slice(1), 10);
  if (!isNaN(n)) goTo(n - 1, false);
});

loadNotes();
loadFromHash();
</script>
</body>
</html>
