:root {
  --paper: #f5f0e4;
  --surface: #fcfaf3;
  --ink: #1b1a2b;
  --muted: #55526b;
  --rule: #1b1a2b;
  --blue: #2b44ff;
  --blue-deep: #1d2fd1;
  --pink: #c10f7c;
  --pink-fill: #ff48b0;
  --pink-wash: #fde3f1;
  --blue-wash: #e4e7ff;

  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Courier New", monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --gutter: clamp(20px, 4vw, 56px);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .1 0 0 0 0 .1 0 0 0 0 .2 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.6;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- Masthead ---------- */

#app { overflow-x: clip; }

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 480px);
  align-items: stretch;
  border-bottom: 3px solid var(--ink);
}

.mast-left {
  padding: clamp(28px, 4vw, 56px) var(--gutter) clamp(28px, 3vw, 44px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  min-width: 0;
}

.kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3.2rem, 12.4vw, 9.75rem);
  line-height: 0.95;
  letter-spacing: -0.035em;
  color: var(--blue);
  text-shadow: 0.035em 0.03em 0 var(--pink-fill);
  animation: settle 900ms var(--ease) backwards;
}

@keyframes settle {
  from { text-shadow: 0.13em 0.08em 0 var(--pink-fill); opacity: 0.2; }
  to { text-shadow: 0.035em 0.03em 0 var(--pink-fill); opacity: 1; }
}

.lede {
  margin: 0;
  max-width: 52ch;
  font-size: 1.1rem;
  line-height: 1.55;
}

/* Rack: the inverted blue block that bleeds off the right edge */

.rack {
  background: var(--blue);
  color: #fff;
  padding: clamp(24px, 3vw, 40px) var(--gutter) clamp(24px, 3vw, 36px) clamp(24px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-left: 3px solid var(--ink);
}

.rack-head { display: flex; align-items: center; gap: 20px; }
.rack-count { margin: 0; }

.numeral {
  display: block;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(4.5rem, 8vw, 7.5rem);
  line-height: 0.85;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.rack-title { margin: 0; font-size: 1.25rem; line-height: 1.2; font-family: var(--display); }
.rack-sub { margin: 4px 0 0; font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.06em; }

.rack-list { list-style: none; margin: 0; padding: 0; border-top: 2px solid #fff; }
.rack-list li { border-bottom: 1px solid rgba(255, 255, 255, 0.55); }

.hole {
  width: 100%;
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 6px 12px;
  background: transparent;
  border: 0;
  color: #fff;
  text-align: left;
  transition: background-color 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease);
}

.hole-label { font-weight: 600; }
.hole-dots { display: flex; flex-wrap: wrap; gap: 3px; max-width: 120px; justify-content: flex-end; }
.hole-dots i { width: 8px; height: 8px; background: currentColor; display: block; }
.hole-dots i.hollow { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.hole-n { font-family: var(--mono); font-weight: 700; min-width: 2ch; text-align: right; font-variant-numeric: tabular-nums; }

.hole[aria-pressed="true"] { background: var(--paper); color: var(--blue-deep); }
.hole:active { transform: scale(0.97); }
.rack .hole:focus-visible { outline: 3px solid #fff; outline-offset: -3px; }
.rack .hole[aria-pressed="true"]:focus-visible { outline-color: var(--ink); }

/* ---------- Toolbar ---------- */

main { padding: 0 var(--gutter) 64px; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px auto;
  align-items: end;
  gap: 20px;
  padding: 28px 0 20px;
  background: var(--paper);
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.field input, .field select {
  min-height: 48px;
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 0;
  transition: box-shadow 160ms var(--ease), background-color 160ms var(--ease);
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 44px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.field input::placeholder { color: #6d6a80; }

.field input:focus-visible, .field select:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  box-shadow: 4px 4px 0 var(--pink-fill);
}

.result-count {
  margin: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Slips ---------- */

.slips { list-style: none; margin: 0; padding: 0; border-top: 3px solid var(--ink); }

.slip {
  position: relative;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 210px 150px;
  grid-template-areas: "stub main meta chip";
  column-gap: 24px;
  align-items: start;
  padding: 22px 8px 22px 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  transition: background-color 180ms var(--ease);
}

.slip.stamped { animation: flash 1400ms var(--ease); }

@keyframes flash {
  0%, 30% { background-color: var(--pink-wash); }
  100% { background-color: transparent; }
}

.stub {
  grid-area: stub;
  align-self: stretch;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2px;
  border-right: 2px dashed var(--ink);
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.slip-main { grid-area: main; min-width: 0; }
.slip-meta { grid-area: meta; }
.chip-cell { grid-area: chip; justify-self: start; }

.slip-title {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.25rem, 1.6vw, 1.6rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-weight: 700;
}

.open-item {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
  transition: text-decoration-color 160ms var(--ease), color 160ms var(--ease);
}

/* The whole slip is the hit area */
.open-item::after { content: ""; position: absolute; inset: 0; }
.open-item:focus-visible { outline: none; }
.open-item:focus-visible::after { outline: 3px solid var(--blue); outline-offset: -3px; }

.summary {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 62ch;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tags { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li {
  padding: 1px 8px;
  border: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.slip-meta { margin: 0; display: grid; gap: 4px; font-size: 0.92rem; }
.slip-meta div { display: flex; gap: 8px; align-items: baseline; }
.slip-meta dt {
  width: 3.6em;
  flex: none;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.slip-meta dd { margin: 0; min-width: 0; }

.prio { display: inline-flex; align-items: center; gap: 8px; }
.prio-bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.prio-bars i { width: 4px; background: var(--ink); opacity: 0.18; display: block; }
.prio-bars i:nth-child(1) { height: 5px; }
.prio-bars i:nth-child(2) { height: 8px; }
.prio-bars i:nth-child(3) { height: 12px; }
.prio-bars i.on { opacity: 1; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 2px 12px;
  border: 2px solid var(--ink);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--surface);
}
.chip[data-status="in-progress"] { color: var(--blue-deep); border-color: var(--blue); background: var(--blue-wash); }
.chip[data-status="blocked"] { color: var(--pink); border-color: var(--pink); background: var(--pink-wash); }
.chip[data-status="done"] { color: var(--paper); background: var(--ink); }

/* ---------- Empty / loading ---------- */

.loading { font-family: var(--mono); padding: 32px 0; }

.empty {
  border-top: 3px solid var(--ink);
  padding: 56px 0 24px;
  max-width: 560px;
}
.empty h3 { margin: 0 0 8px; font-family: var(--display); font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.1; letter-spacing: -0.02em; }
.empty p { margin: 0 0 24px; color: var(--muted); }
.empty .term { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }

.btn {
  min-height: 48px;
  padding: 12px 20px;
  border: 2px solid var(--ink);
  background: var(--surface);
  font-weight: 700;
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease), background-color 160ms var(--ease);
}
.btn-primary { background: var(--blue); border-color: var(--blue-deep); color: #fff; box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: scale(0.97); }

/* ---------- Detail ---------- */

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(27, 26, 43, 0.5);
  animation: fade 200ms var(--ease) both;
}

.detail {
  position: fixed; z-index: 50;
  top: 0; right: 0; bottom: 0;
  width: min(620px, 100%);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border-left: 3px solid var(--ink);
  padding: 0 clamp(20px, 3vw, 40px) 48px;
  animation: slide 260ms var(--ease) both;
}

@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.detail-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 0 calc(-1 * clamp(20px, 3vw, 40px));
  padding: 12px clamp(20px, 3vw, 40px);
  background: var(--paper);
  border-bottom: 2px solid var(--ink);
}
.detail-slip { margin: 0; font-family: var(--mono); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }

.close-btn {
  min-height: 44px;
  padding: 8px 16px;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  font-weight: 700;
  transition: transform 160ms var(--ease), background-color 160ms var(--ease);
}
.close-btn:active { transform: scale(0.97); }

.detail-title {
  margin: 28px 0 20px;
  font-family: var(--display);
  font-size: clamp(1.9rem, 4.6vw, 2.8rem);
  line-height: 1.08;
  letter-spacing: -0.025em;
  font-weight: 800;
  overflow-wrap: break-word;
}

.stamp-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }

.status-form { flex: 1 1 220px; max-width: 280px; }
.status-form select { border-color: var(--blue-deep); border-width: 3px; }
.status-note { margin: 8px 0 0; font-size: 0.85rem; color: var(--muted); min-height: 1.4em; }

.stamp {
  flex: none;
  display: inline-block;
  padding: 8px 18px 6px;
  border: 4px double currentColor;
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transform: rotate(-5deg);
  color: var(--ink);
  background: var(--surface);
}
.stamp[data-status="in-progress"] { color: var(--blue-deep); }
.stamp[data-status="blocked"] { color: var(--pink); }
.stamp[data-status="done"] { color: var(--paper); background: var(--ink); border-color: var(--paper); outline: 2px solid var(--ink); }
.stamp.slam { animation: slam 420ms var(--ease) both; }

@keyframes slam {
  0% { transform: rotate(-18deg) scale(2.4); opacity: 0; }
  55% { transform: rotate(-4deg) scale(0.94); opacity: 1; }
  100% { transform: rotate(-5deg) scale(1); opacity: 1; }
}

.facts {
  margin: 0 0 28px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 2px solid var(--ink);
}
.facts div { padding: 12px 12px 12px 0; border-bottom: 1px solid var(--ink); }
.facts dt { font-family: var(--mono); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }

.detail-body {
  white-space: pre-line;
  font-size: 1.06rem;
  line-height: 1.7;
  max-width: 62ch;
  padding-left: 16px;
  border-left: 4px solid var(--pink-fill);
}

.detail .tags { margin-top: 24px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; z-index: 60;
  left: 50%; bottom: 20px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  pointer-events: none;
}
.toast-card {
  pointer-events: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 10px 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--paper);
  box-shadow: 5px 5px 0 var(--pink-fill);
  animation: toast-in 240ms var(--ease) both;
}
.toast-card p { margin: 0; font-size: 0.95rem; line-height: 1.4; }
.toast-card strong { color: #fff; }
.toast-undo {
  flex: none; min-height: 44px; padding: 8px 16px;
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--paper); font-weight: 700;
  transition: transform 160ms var(--ease), background-color 160ms var(--ease);
}
.toast-undo:active { transform: scale(0.97); }
.toast-undo:focus-visible { outline: 3px solid var(--pink-fill); outline-offset: 2px; }

@keyframes toast-in { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Footer ---------- */

.footer { border-top: 3px solid var(--ink); padding: 24px var(--gutter) 32px; font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.footer p { margin: 0; }

/* ---------- Hover (pointer devices only) ---------- */

@media (hover: hover) and (pointer: fine) {
  .hole:hover { background: rgba(255, 255, 255, 0.18); }
  .hole[aria-pressed="true"]:hover { background: #fff; }
  .slip:hover { background-color: var(--surface); }
  .slip:hover .open-item { text-decoration-color: var(--pink-fill); color: var(--blue-deep); }
  .field input:hover, .field select:hover { box-shadow: 4px 4px 0 var(--ink); }
  .btn:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
  .btn-primary:hover { background: var(--blue-deep); }
  .close-btn:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
  .toast-undo:hover { background: var(--pink-fill); border-color: var(--pink-fill); }
  .tags li:hover { background: var(--ink); color: var(--paper); }
  .wordmark:hover { text-shadow: 0.06em 0.045em 0 var(--pink-fill); }
}

.wordmark { transition: text-shadow 240ms var(--ease); }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .slip {
    grid-template-columns: 64px minmax(0, 1fr) 180px;
    grid-template-areas: "stub main chip" "stub main meta";
    row-gap: 12px;
  }
  .chip-cell { justify-self: end; }
}

@media (max-width: 900px) {
  .masthead { grid-template-columns: minmax(0, 1fr); }
  .rack { border-left: 0; border-top: 3px solid var(--ink); padding: 24px var(--gutter); }
  .mast-left { gap: 16px; padding-block: 24px 28px; }
  .lede { font-size: 1rem; }
  .toolbar { grid-template-columns: minmax(0, 1fr) 220px; }
  .result-count { grid-column: 1 / -1; min-height: 0; }
}

@media (min-width: 901px) {
  .toolbar { position: sticky; top: 0; z-index: 5; }
}

@media (max-width: 720px) {
  .toolbar { grid-template-columns: minmax(0, 1fr); gap: 14px; padding-top: 24px; }
  .slip {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "stub . chip" "main main main" "meta meta meta";
    row-gap: 12px;
    padding: 18px 0;
  }
  .stub { align-self: center; border-right: 0; padding: 0 12px 0 0; border-bottom: 0; font-size: 1.1rem; }
  .chip-cell { justify-self: end; }
  .slip-meta { grid-template-columns: 1fr 1fr; gap: 6px 16px; }
  .slip-meta dt { width: auto; }
  .slip-meta div { flex-direction: column; gap: 0; }
  .detail { width: 100%; border-left: 0; }
  .facts { grid-template-columns: 1fr 1fr; }
  .stamp-row { flex-direction: column-reverse; align-items: flex-start; }
  .status-form { max-width: none; width: 100%; }
  .rack-head { gap: 16px; }
  .hole { grid-template-columns: minmax(0, 1fr) auto; }
  .hole-dots { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .wordmark { animation: none; }
}
