:root {
  --paper: #ece1c8;
  --paper-dark: #ddccA4;
  --kraft: #c9a86a;
  --kraft-dark: #a9824c;
  --wood: #6b4a30;
  --wood-dark: #4a3220;
  --ink: #2c2418;
  --ink-soft: #574a34;
  --red-wax: #a5372a;
  --amber: #b8823a;
  --green-post: #386b4c;
  --blue-transit: #2f5a73;
  --focus-ring: #1c5fae;
  --card-shadow: 0 3px 0 rgba(0, 0, 0, 0.08), 0 8px 16px rgba(43, 30, 12, 0.18);
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

@media (prefers-reduced-motion: no-preference) {
  :root {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    repeating-linear-gradient(
      45deg,
      rgba(0, 0, 0, 0.015) 0px,
      rgba(0, 0, 0, 0.015) 2px,
      transparent 2px,
      transparent 8px
    ),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-dark) 100%);
  color: var(--ink);
  font-family: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  line-height: 1.5;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1rem;
  z-index: 100;
  border-radius: 0 0 6px 0;
}

.skip-link:focus {
  left: 0;
}

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

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

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

.masthead {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 1rem;
  border-bottom: 4px double var(--wood);
}

.postmark {
  flex-shrink: 0;
  color: var(--ink-soft);
}

.masthead-text .eyebrow {
  margin: 0;
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--ink-soft);
}

.masthead-text h1 {
  margin: 0.1rem 0 0.15rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.masthead-text .tagline {
  margin: 0;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- Control desk ---------- */

.control-desk {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 1.25rem;
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
  background: var(--kraft);
  border-bottom: 4px solid var(--wood);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field label {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wood-dark);
  font-weight: 700;
}

.search-field {
  flex: 1 1 260px;
}

#search-input,
#filter-select {
  border: 2px solid var(--wood);
  background: var(--paper);
  padding: 0.55rem 0.7rem;
  border-radius: 3px;
  font-size: 1rem;
}

.filter-field {
  flex: 0 0 auto;
  min-width: 220px;
}

.result-count {
  margin: 0 0 0.4rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.8rem;
  color: var(--wood-dark);
}

/* ---------- Wall of pigeonholes ---------- */

main {
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 3rem;
}

.wall {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .wall {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .wall {
    grid-template-columns: 1fr;
  }
}

.slot {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.04)), var(--kraft);
  border: 3px solid var(--wood);
  border-radius: 6px;
  padding: 0.75rem;
  min-height: 140px;
}

.slot[hidden] {
  display: none;
}

.slot-heading {
  margin: 0 0 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px dashed var(--wood-dark);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.4rem;
}

.slot-heading .slot-sub {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 400;
}

.slot-count {
  font-weight: 700;
  color: var(--wood-dark);
}

.slot-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---------- Envelope cards ---------- */

.envelope {
  margin: 0;
}

.envelope-open {
  width: 100%;
  text-align: left;
  background: var(--paper);
  border: 2px solid var(--ink-soft);
  border-radius: 4px;
  padding: 0.65rem 0.7rem 0.6rem;
  cursor: pointer;
  position: relative;
  display: block;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .envelope-open {
    transition: none;
  }
}

.envelope-open:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.08), 0 12px 20px rgba(43, 30, 12, 0.22);
}

.envelope-open::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 34px;
  background: linear-gradient(
      to bottom right,
      transparent calc(50% - 1px),
      var(--wood) calc(50%),
      transparent calc(50% + 1px)
    ),
    linear-gradient(
      to bottom left,
      transparent calc(50% - 1px),
      var(--wood) calc(50%),
      transparent calc(50% + 1px)
    );
  opacity: 0.35;
  pointer-events: none;
  border-radius: 4px 4px 0 0;
}

.wax-seal {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--red-wax);
  color: #f6e7c9;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15), 0 2px 3px rgba(0, 0, 0, 0.3);
}

.envelope-title {
  display: block;
  font-weight: 700;
  font-size: 1.02rem;
  margin: 0.9rem 2rem 0.35rem 0;
  color: var(--ink);
}

.envelope-meta {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.envelope-meta span {
  display: block;
}

.envelope-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px dashed var(--ink-soft);
  padding-top: 0.4rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
}

.postage-stamp {
  border: 2px solid var(--ink-soft);
  padding: 0.1rem 0.4rem;
  letter-spacing: 0.06em;
  border-radius: 2px;
}

.postage-stamp[data-priority='high'] {
  color: var(--red-wax);
  border-color: var(--red-wax);
}

.postage-stamp[data-priority='medium'] {
  color: var(--amber);
  border-color: var(--amber);
}

.postage-stamp[data-priority='low'] {
  color: var(--green-post);
  border-color: var(--green-post);
}

.due-date {
  color: var(--ink-soft);
}

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--ink-soft);
}

.empty-stamp {
  font-size: 2.4rem;
  margin: 0 0 0.5rem;
}

.empty-state button {
  margin-top: 0.75rem;
  border: 2px solid var(--wood);
  background: var(--kraft);
  padding: 0.55rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
}

.empty-state button:hover {
  background: var(--kraft-dark);
}

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

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}

.detail-overlay[hidden] {
  display: none;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 6, 0.55);
}

.detail {
  position: relative;
  width: min(560px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--paper);
  border-left: 6px solid var(--wood);
  padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 3rem;
  box-shadow: -12px 0 30px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: no-preference) {
  .detail {
    animation: slide-in 0.25s ease-out;
  }
  @keyframes slide-in {
    from {
      transform: translateX(24px);
      opacity: 0;
    }
    to {
      transform: translateX(0);
      opacity: 1;
    }
  }
}

@media (max-width: 620px) {
  .detail {
    width: 100%;
    border-left: none;
    border-top: 6px solid var(--wood);
  }
}

.close-detail {
  border: 2px solid var(--wood);
  background: var(--kraft);
  padding: 0.5rem 0.9rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  margin-bottom: 1.25rem;
}

.close-detail:hover {
  background: var(--kraft-dark);
}

.tracking-number {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  margin: 0 0 0.2rem;
  text-transform: uppercase;
}

.detail h2 {
  margin: 0 0 1rem;
  font-family: Georgia, serif;
  font-size: 1.6rem;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem 1.2rem;
  margin: 0 0 1.25rem;
  padding: 0.9rem;
  background: var(--paper-dark);
  border: 1px dashed var(--ink-soft);
  border-radius: 4px;
}

.detail-meta div {
  min-width: 0;
}

.detail-meta dt {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.detail-meta dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.detail-body {
  white-space: pre-line;
  margin: 0 0 1.5rem;
  font-size: 1.02rem;
  line-height: 1.7;
}

.stamp-desk {
  border-top: 3px double var(--wood);
  padding-top: 1.25rem;
}

.stamp-desk-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.stamp-desk-row label {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--wood-dark);
}

#status-control {
  border: 2px solid var(--wood);
  background: var(--paper);
  padding: 0.6rem 0.7rem;
  border-radius: 3px;
  font-size: 1rem;
  max-width: 320px;
}

.ink-stamp {
  display: inline-block;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.4rem 0.8rem;
  border: 3px solid currentColor;
  border-radius: 4px;
  transform: rotate(-4deg);
  margin-bottom: 0.6rem;
}

.ink-stamp[data-status='todo'] {
  color: var(--blue-transit);
}
.ink-stamp[data-status='in-progress'] {
  color: var(--amber);
}
.ink-stamp[data-status='blocked'] {
  color: var(--red-wax);
}
.ink-stamp[data-status='done'] {
  color: var(--green-post);
}

.status-feedback {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 1.3em;
}
