/* ============================================================
   THE POST ROOM
   A team inbox dressed as a mail sorting desk.
   Design notes:
   - Theme lock: one dark "postal felt" desk theme, light paper on top.
   - Color lock: airmail red is the single brand accent. Status inks
     (amber, blue, red, green) are semantic, not decoration.
   - Shape lock: sharp corners everywhere (2px max). The only circles
     are postmarks and the stamp, because real postmarks are round.
   - Z-index scale: grain 40, sticky controls 50, dialog = top layer.
   ============================================================ */

@font-face {
  font-family: "DM Serif Display";
  src: url("assets/dm-serif.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  --desk: #173128;
  --desk-deep: #10241c;
  --desk-line: rgba(242, 234, 214, 0.14);
  --sage: #c7d6c1;

  --paper: #f2ead6;
  --paper-2: #e8dec4;
  --ink: #262013;
  --ink-soft: #635a44;
  --rule: rgba(38, 32, 19, 0.24);

  --accent: #b93a2b;      /* airmail red, the one brand accent */
  --airmail-blue: #2f4f8f;

  /* semantic status inks */
  --todo: #9a6a17;
  --prog: #2f4f8f;
  --blocked: #b93a2b;
  --done: #2e7a45;

  --stripe: repeating-linear-gradient(
    45deg,
    var(--accent) 0 12px,
    var(--paper) 12px 18px,
    var(--airmail-blue) 18px 30px,
    var(--paper) 30px 36px
  );

  --shadow-lift: 0 14px 30px rgba(8, 22, 16, 0.5), 0 3px 8px rgba(8, 22, 16, 0.35);
  --shadow-rest: 0 8px 20px rgba(8, 22, 16, 0.42), 0 2px 5px rgba(8, 22, 16, 0.3);
}

* { box-sizing: border-box; }

html { scrollbar-gutter: stable; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 520px at 18% -8%, #20402f, var(--desk) 55%, var(--desk-deep));
  color: var(--paper);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  line-height: 1.5;
}

/* Paper grain over the whole desk. Fixed, never scroll-painting. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0.07;
  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='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.wrap {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 28px;
}

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

.skip {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 100;
  background: var(--paper);
  color: var(--ink);
  padding: 10px 16px;
  font-size: 12px;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip:focus-visible { top: 12px; }

:focus-visible {
  outline: 2px dashed #ead9b8;
  outline-offset: 2px;
}
.letter-card :focus-visible,
.letter-dialog :focus-visible,
.controls :focus-visible {
  outline-color: var(--accent);
}
.btn:focus-visible { outline-color: var(--paper); }

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

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding: 28px 0 20px;
}

.brand { display: flex; gap: 16px; align-items: flex-start; }

.brand-mark {
  width: 44px; height: 30px;
  color: var(--paper);
  flex: none;
  margin-top: 4px;
}

.wordmark {
  margin: 0;
  font-family: "DM Serif Display", serif;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--sage);
  letter-spacing: 0.02em;
}

.tally {
  list-style: none;
  display: flex;
  margin: 0;
  padding: 0;
  align-items: stretch;
}
.tally li {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 0 20px;
  border-left: 1px solid var(--desk-line);
}
.tally li:first-child { border-left: 0; padding-left: 0; }
.t-count {
  font-family: "DM Serif Display", serif;
  font-size: 24px;
  line-height: 1;
}
.t-label {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--sage);
}
.t-label[data-ink="todo"]    { color: #d9a94e; }
.t-label[data-ink="in-progress"] { color: #93a9dd; }
.t-label[data-ink="blocked"] { color: #e0857a; }
.t-label[data-ink="done"]    { color: #7cba92; }

/* ----------------------------------------------------------
   Controls (sticky, so the sort is always at hand)
   ---------------------------------------------------------- */

.controls {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 22px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 16px 0 18px;
  background: var(--desk);
  border-bottom: 1px solid var(--desk-line);
  box-shadow: 0 14px 22px -16px rgba(8, 22, 16, 0.9);
}

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

.field label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--sage);
}

.field input,
.field select {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  padding: 10px 12px;
  min-width: 0;
}

.field-search { position: relative; }
.field-search input { width: min(340px, 62vw); padding-left: 34px; }
.search-icon {
  position: absolute;
  left: 11px; bottom: 11px;
  width: 13px; height: 13px;
  color: var(--ink-soft);
  pointer-events: none;
}
.field-search input::-webkit-search-cancel-button { cursor: pointer; }

.field select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23262013' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px 7px;
  cursor: pointer;
}

/* ----------------------------------------------------------
   Results line + pile
   ---------------------------------------------------------- */

.results {
  margin: 18px 0 16px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--sage);
  text-transform: uppercase;
}

.pile {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding-bottom: 20px;
}

.letter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px;
  box-shadow: var(--shadow-rest);
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}
.letter-card:hover {
  transform: rotate(0deg) translateY(-4px);
  box-shadow: var(--shadow-lift);
}
.pile > .letter-card:nth-of-type(4n+1) { --tilt: -1.1deg; }
.pile > .letter-card:nth-of-type(4n+2) { --tilt: 0.8deg; }
.pile > .letter-card:nth-of-type(4n+3) { --tilt: -0.6deg; }
.pile > .letter-card:nth-of-type(4n+4) { --tilt: 1.2deg; }

.airmail {
  height: 6px;
  border-radius: 2px 2px 0 0;
  background: var(--stripe);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px 0;
}

.card-meta { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }

.route {
  margin: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
}

.class {
  margin: 0;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  align-self: flex-start;
  padding: 2px 7px;
  border: 1px solid currentColor;
  border-radius: 2px;
}
.class.high   { color: var(--accent); }
.class.medium { color: var(--airmail-blue); }
.class.low    { color: var(--ink-soft); }

.postmark {
  flex: none;
  width: 56px; height: 56px;
  border: 1.5px solid rgba(38, 32, 19, 0.75);
  border-radius: 50%;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.15;
  transform: rotate(-9deg);
  color: rgba(38, 32, 19, 0.75);
}
.postmark::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px dashed rgba(38, 32, 19, 0.55);
  border-radius: 50%;
}
.pm-day { font-size: 11px; letter-spacing: 0.03em; }
.pm-year { font-size: 8.5px; letter-spacing: 0.22em; margin-top: 1px; }

.pm-delivered {
  position: absolute;
  top: 12px; right: 8px;
  width: 58px; height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 8.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--done);
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: rotate(-14deg);
  opacity: 0.85;
  mix-blend-mode: multiply;
  background: rgba(46, 122, 69, 0.05);
}

.card-title { margin: 10px 16px 0; }
.card-title button {
  font-family: "DM Serif Display", serif;
  font-size: 20px;
  line-height: 1.18;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-weight: 400;
}
.card-title button:hover {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.card-summary {
  margin: 8px 16px 14px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
}

.status-chip {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  padding: 3px 8px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  white-space: nowrap;
}
.status-chip[data-status="todo"]        { color: var(--todo); }
.status-chip[data-status="in-progress"] { color: var(--prog); }
.status-chip[data-status="blocked"]     { color: var(--blocked); }
.status-chip[data-status="done"]        { color: var(--done); }

.addressee { font-size: 11px; color: var(--ink-soft); }
.notes { font-size: 10.5px; color: var(--ink-soft); margin-left: auto; white-space: nowrap; }

.letter-card.is-done .card-summary { opacity: 0.75; }

/* First load: the mail is dealt onto the desk */
@media (prefers-reduced-motion: no-preference) {
  .letter-card.deal { animation: deal 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; animation-delay: calc(var(--i, 0) * 45ms); }
  @keyframes deal {
    from { opacity: 0; transform: translateY(16px) rotate(var(--tilt, 0deg)); }
    to   { opacity: 1; transform: translateY(0) rotate(var(--tilt, 0deg)); }
  }
}

/* Skeleton mail */
.letter-card.skeleton { pointer-events: none; cursor: default; }
.skeleton .airmail { opacity: 0.25; }
.sk { background: var(--paper-2); margin: 14px 16px 0; height: 12px; border-radius: 2px; }
.skeleton .sk-a { width: 45%; margin-top: 20px; }
.skeleton .sk-b { width: 80%; height: 26px; margin-top: 12px; }
.skeleton .sk-c { width: 65%; margin-top: 10px; margin-bottom: 26px; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton .sk, .skeleton .airmail { animation: shimmer 1.2s ease-in-out infinite alternate; }
  .skeleton .sk-b { animation-delay: 0.15s; }
  .skeleton .sk-c { animation-delay: 0.3s; }
  @keyframes shimmer { from { opacity: 0.45; } to { opacity: 0.9; } }
}

/* ----------------------------------------------------------
   Empty state: a cancellation mark
   ---------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 64px 20px 80px;
}
.empty[hidden] { display: none; }

.empty-mark {
  width: 170px; height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.3em;
  line-height: 2;
  text-transform: uppercase;
  color: rgba(242, 234, 214, 0.55);
  border: 3px dashed rgba(242, 234, 214, 0.45);
  border-radius: 50%;
  transform: rotate(-8deg);
  margin-bottom: 14px;
}
.empty h2 {
  margin: 0;
  font-family: "DM Serif Display", serif;
  font-weight: 400;
  font-size: 28px;
}
.empty p { margin: 0; font-size: 13px; color: var(--sage); max-width: 44ch; }

.btn {
  font: inherit;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--paper);
  background: var(--accent);
  border: 0;
  border-radius: 2px;
  padding: 12px 20px;
  cursor: pointer;
  margin-top: 14px;
  transition: transform 0.1s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: #a53325; }
.btn:active { transform: translateY(1px); }

/* ----------------------------------------------------------
   The letter detail: a par avion frame around one opened letter
   ---------------------------------------------------------- */

dialog.letter-dialog {
  border: 0;
  padding: 10px;
  background: var(--stripe);
  border-radius: 3px;
  width: min(880px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  color: var(--ink);
}
dialog.letter-dialog::backdrop {
  background: rgba(6, 18, 13, 0.62);
  backdrop-filter: blur(2px);
}

.letter-paper {
  background: var(--paper);
  border-radius: 2px;
  padding: 30px 40px 28px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}

.letter-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.letter-brand {
  margin: 0;
  font-family: "DM Serif Display", serif;
  font-size: 19px;
}
.letter-kind {
  margin: 2px 0 0;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
}

.close-x {
  flex: none;
  width: 34px; height: 34px;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  color: var(--ink);
  background: none;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.close-x:hover { background: var(--ink); color: var(--paper); }

.letter-mark {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 20px 0 2px;
  color: rgba(38, 32, 19, 0.72);
  transform: rotate(-7deg);
}
.postmark.big { width: 84px; height: 84px; }
.postmark.big .pm-day { font-size: 15px; }
.postmark.big .pm-year { font-size: 10px; }
.waves { width: 64px; height: 44px; flex: none; }
.waves path { stroke: rgba(38, 32, 19, 0.62); stroke-width: 2; fill: none; }

.letter-title {
  margin: 6px 0 0;
  font-family: "DM Serif Display", serif;
  font-weight: 400;
  font-size: clamp(26px, 4.4vw, 36px);
  line-height: 1.12;
  max-width: 24ch;
}

.letter-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px 28px;
  margin: 22px 0 0;
  padding: 16px 0;
  border-top: 3px double var(--rule);
  border-bottom: 1px solid var(--rule);
}
.letter-meta div { display: flex; gap: 10px; align-items: baseline; }
.letter-meta dt {
  margin: 0;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  flex: none;
  width: 108px;
}
.letter-meta dd { margin: 0; font-size: 13px; }

.letter-body { margin-top: 20px; max-width: 68ch; }
.letter-body p { margin: 0 0 14px; font-size: 13.5px; line-height: 1.7; }

.stamping {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 28px;
  flex-wrap: wrap;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
}

.stamping-form { display: flex; flex-direction: column; gap: 7px; }
.stamping-form label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
}
.stamping-form select {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  padding: 10px 14px;
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23262013' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px 7px;
  cursor: pointer;
}

.stamp-zone {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.stamp {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 18px;
  border: 4px double currentColor;
  border-radius: 3px;
  transform: rotate(-7deg);
  text-align: center;
  line-height: 1.1;
}
.stamp .stamp-word {
  font-size: 21px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.stamp small {
  font-size: 8.5px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  opacity: 0.75;
}
.stamp[data-status="todo"]        { color: var(--todo); }
.stamp[data-status="in-progress"] { color: var(--prog); }
.stamp[data-status="blocked"]     { color: var(--blocked); }
.stamp[data-status="done"]        { color: var(--done); }

@media (prefers-reduced-motion: no-preference) {
  .stamp.slam { animation: slam 0.34s cubic-bezier(0.2, 0.7, 0.3, 1.25) both; }
  @keyframes slam {
    0%   { transform: rotate(-7deg) scale(2.2); opacity: 0; }
    60%  { transform: rotate(-7deg) scale(0.95); opacity: 1; }
    80%  { transform: rotate(-7deg) scale(1.05); }
    100% { transform: rotate(-7deg) scale(1); opacity: 1; }
  }
}

.stamp-log {
  margin: 0;
  font-size: 11px;
  color: var(--ink-soft);
  min-height: 1.2em;
  text-align: right;
}

.letter-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

/* Load error */
.load-error {
  grid-column: 1 / -1;
  padding: 48px 20px;
  text-align: center;
  color: var(--sage);
  font-size: 13px;
}
.load-error .btn { display: block; margin: 16px auto 0; }

/* ----------------------------------------------------------
   Desk footer
   ---------------------------------------------------------- */

.deskfoot {
  margin-top: 44px;
  padding: 26px 0 30px;
  border-top: 1px solid var(--desk-line);
}
.deskfoot p { margin: 0; font-size: 10.5px; color: var(--sage); letter-spacing: 0.04em; }

/* ----------------------------------------------------------
   Mobile: straighten the pile, full-bleed letters
   ---------------------------------------------------------- */

@media (max-width: 760px) {
  .wrap { padding: 0 18px; }

  .masthead { flex-direction: column; align-items: flex-start; gap: 18px; padding-top: 22px; }
  .wordmark { font-size: 25px; }
  .brand-mark { width: 36px; height: 25px; }
  .tagline { max-width: 34ch; }

  .tally { flex-wrap: wrap; gap: 10px 0; }
  .tally li { padding: 0 14px; }
  .t-count { font-size: 20px; }

  .controls { gap: 14px; position: static; }
  .field-search input, .field input { width: 100%; }
  .field-search { width: 100%; }

  .pile { grid-template-columns: 1fr; gap: 16px; }
  .pile > .letter-card { --tilt: 0deg; transform: none; }
  .letter-card:hover { transform: translateY(-2px); }

  .card-title button { font-size: 19px; }

  dialog.letter-dialog {
    width: 100vw;
    max-height: 100dvh;
    border-radius: 0;
    padding: 8px;
    margin: 0;
  }
  .letter-paper { padding: 20px 18px 22px; max-height: calc(100dvh - 16px); }
  .letter-title { max-width: none; }
  .stamping { align-items: stretch; }
  .stamping-form select { width: 100%; }
  .stamp-zone { align-items: flex-start; }
  .stamp-log { text-align: left; }
  .letter-foot { justify-content: stretch; }
  .letter-foot .btn { width: 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
