:root {
  --ink: #1b2646;
  --paper: #f4e9cf;
  --paper2: #e6d6b0;
  --kraft: #d9bb8a;
  --felt: #24503f;
  --felt2: #1c4033;
  --wood: #3a2515;
  --wood2: #2a1a0d;
  --brass: #d8b45a;
  --gold: #ffd45c;
  --cream: #fbf3de;

  --c-todo: #234a9e;
  --c-in-progress: #a8520a;
  --c-blocked: #9d1f63;
  --c-done: #1f6e3d;

  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --type: "American Typewriter", "Courier New", Courier, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--type);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--felt2);
}
body.lock { overflow: hidden; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--gold);
}

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

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 350px minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  padding: 22px 22px 18px;
  color: var(--cream);
  background:
    repeating-linear-gradient(92deg, rgba(0,0,0,.0) 0 7px, rgba(0,0,0,.16) 7px 8px, rgba(255,255,255,.03) 8px 15px),
    linear-gradient(var(--wood), var(--wood2));
  border-right: 6px solid #170d05;
  display: flex; flex-direction: column; gap: 18px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.mark { width: 76px; height: 76px; flex: none; color: var(--gold); transform: rotate(-9deg); transition: transform .8s cubic-bezier(.3,1.5,.5,1); }
.brand:hover .mark { transform: rotate(351deg); }
.brand h1 {
  margin: 0; font-family: var(--serif); font-size: 38px; line-height: 1; letter-spacing: .02em;
  font-style: italic; font-weight: 700; color: var(--cream);
}
.tag { margin: 4px 0 0; font-size: 12.5px; color: #e9d9b4; line-height: 1.3; }

.controls { display: grid; gap: 12px; padding: 14px; background: var(--paper); color: var(--ink); border-radius: 3px; box-shadow: 0 6px 0 #0006; transform: rotate(-.6deg); }
.field { display: grid; gap: 4px; }
.field label { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
input[type=search], select {
  width: 100%; min-height: 44px; padding: 8px 10px;
  background: #fffaf0; border: 2px solid var(--ink); border-radius: 2px; font-size: 16px;
}
select { appearance: auto; }

.rackwrap h2 { margin: 0 0 8px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: #e9d9b4; }
.rack { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cubby {
  position: relative; overflow: hidden; height: 98px; padding: 7px 8px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 4px;
  text-align: left; cursor: pointer; color: var(--cream);
  background: linear-gradient(#120a04, #2d1c0e);
  border: 3px solid #6d4628; border-radius: 2px;
  box-shadow: inset 0 10px 16px #000b;
}
.cubby[data-v="all"] { grid-column: 1 / -1; height: 76px; }
.cubby:hover { border-color: #9a6a3c; }
.cubby[aria-pressed="true"] { border-color: var(--gold); }
.cubby .plate {
  position: relative; z-index: 2; padding: 2px 7px; border-radius: 2px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  background: linear-gradient(var(--brass), #b08d3a); color: #2a1a0d;
}
.cubby .num { position: relative; z-index: 2; font-family: var(--serif); font-size: 26px; font-weight: 700; line-height: 1; text-shadow: 0 2px 0 #000a; }
.slivers { position: absolute; left: 8px; right: 8px; bottom: 0; height: 46px; display: flex; align-items: flex-end; gap: 3px; pointer-events: none; }
.sliver {
  flex: none; width: 13px; height: calc(30px + var(--h) * 5px);
  background: linear-gradient(90deg, var(--c) 70%, rgba(0,0,0,.35));
  border-radius: 2px 2px 0 0; transform: rotate(var(--r)); transform-origin: bottom;
  border-top: 3px solid rgba(255,255,255,.35);
}
.cubby[data-v="all"] .sliver { width: 11px; height: calc(24px + var(--h) * 3px); }
.cubby.catch { animation: catch .6s cubic-bezier(.3,1.8,.5,1); }
@keyframes catch { 0% { transform: translateY(0); } 30% { transform: translateY(5px) scale(.97); } 100% { transform: none; } }

.deskbtns { display: flex; gap: 10px; }
.btn {
  min-height: 44px; padding: 8px 14px; cursor: pointer; font-weight: 700; letter-spacing: .04em;
  background: var(--paper); color: var(--ink); border: 2px solid var(--ink); border-radius: 2px;
  box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn[aria-pressed="true"] { background: var(--gold); }
.deskbtns .btn { flex: 1; }
.btn.big { margin-top: 6px; }
.hint { margin: 0; font-size: 12.5px; color: #e9d9b4; }
kbd { padding: 0 6px; border: 1px solid #e9d9b4; border-radius: 3px; font-family: inherit; }

/* ---------- desk ---------- */
.desk {
  padding: 28px 34px 60px;
  color: var(--cream);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.07), transparent 40%),
    radial-gradient(rgba(255,255,255,.05) 1px, transparent 1.5px) 0 0 / 7px 7px,
    var(--felt);
  min-width: 0;
}
.deskhead { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.deskhead h2 { margin: 0; font-family: var(--serif); font-style: italic; font-size: 34px; }
.deskhead h2:focus { outline: none; }
#tally { margin: 0; font-size: 14px; color: #d8e8dc; }
.deskmsg { padding: 14px; background: var(--paper); color: var(--ink); border-radius: 3px; }

.pile {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 34px 28px;
}

/* ---------- envelope ---------- */
.env {
  --k: 1;
  position: relative; list-style: none;
  transform: translate(calc(var(--dx) * var(--k) * 1px), calc(var(--dy) * var(--k) * 1px)) rotate(calc(var(--r) * var(--k) * 1deg));
  transition: transform .35s cubic-bezier(.3,1.6,.5,1);
}
.desk.intro .env {
  animation: land .5s both cubic-bezier(.3,1.4,.5,1);
  animation-delay: calc(var(--n) * 25ms);
}
@keyframes land { from { opacity: 0; transform: translateY(-30px) rotate(8deg); } }
.desk.tidy .env { --k: 0; }
.env:hover, .env:focus-within { transform: translateY(-6px) scale(1.025) rotate(0deg); z-index: 3; }
.env.shaking { animation: shake .55s; }
@keyframes shake { 20% { transform: rotate(-7deg) translateY(-8px); } 50% { transform: rotate(6deg); } 80% { transform: rotate(-3deg); } }

.env-body {
  --sheet: var(--paper);
  position: relative; display: flex; flex-direction: column; height: 100%; min-height: 200px;
  padding: 58px 12px 12px; overflow: hidden;
  background: var(--sheet); border: 7px solid var(--sheet); border-radius: 3px;
  box-shadow: 0 10px 16px -8px #000c, 0 2px 3px #0007;
  --st: var(--c-todo);
}
.env[data-status="todo"] .env-body { --st: var(--c-todo); }
.env[data-status="in-progress"] .env-body { --st: var(--c-in-progress); }
.env[data-status="blocked"] .env-body { --st: var(--c-blocked); }
.env[data-status="done"] .env-body { --st: var(--c-done); }

.env[data-priority="high"] .env-body {
  border-image: repeating-linear-gradient(135deg, #c8372d 0 12px, var(--paper) 12px 20px, #27499b 20px 32px, var(--paper) 32px 40px) 7;
}
.env[data-priority="low"] .env-body { --sheet: var(--kraft); }

.flap {
  position: absolute; left: 0; right: 0; top: 0; height: 50px;
  background: linear-gradient(rgba(0,0,0,.13), rgba(0,0,0,.03)), var(--sheet);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.flap::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.08); clip-path: polygon(0 0, 50% 100%, 0 100%, 0 40%); }

.top { display: flex; justify-content: space-between; gap: 10px; flex: 1; }
.top .l { min-width: 0; flex: 1; }
.to { margin: 0 0 4px; font-size: 12px; letter-spacing: .06em; }
.to b { font-weight: 700; }
.subject { margin: 0; font-family: var(--serif); font-size: 19px; line-height: 1.2; font-weight: 700; overflow-wrap: anywhere; }
.open {
  all: unset; cursor: pointer; display: inline;
}
.open::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.open:focus-visible { outline: none; box-shadow: none; }
.open:focus-visible::after { outline: 4px solid var(--ink); outline-offset: -4px; box-shadow: inset 0 0 0 8px var(--gold); }
.env:hover .open { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

.stamps { position: relative; display: flex; flex-direction: column; align-items: flex-end; width: 66px; flex: none; }
.postage {
  --pc: #b3261e;
  width: 58px; padding: 5px 3px 6px; text-align: center; color: #fff;
  background: var(--pc); border: 4px dotted var(--pc); background-clip: padding-box;
  outline: 1px solid rgba(0,0,0,.15); outline-offset: -4px;
  box-shadow: 1px 2px 0 rgba(0,0,0,.25);
  transform: rotate(3deg);
}
.postage[data-p="medium"] { --pc: #2b4a9a; }
.postage[data-p="low"] { --pc: #52632f; }
.postage small { display: block; font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; opacity: .9; }
.postage strong { display: block; font-family: var(--serif); font-size: 14px; line-height: 1.15; margin-top: 4px; border-top: 1px solid rgba(255,255,255,.6); padding-top: 4px; text-transform: uppercase; }
.postmark {
  position: relative; margin: -16px 12px 0 0; width: 54px; height: 54px; border-radius: 50%;
  border: 2px solid rgba(27,38,70,.75); color: rgba(27,38,70,.85);
  display: grid; place-content: center; text-align: center; font-size: 9.5px; font-weight: 700; line-height: 1.15; letter-spacing: .05em;
  transform: rotate(-14deg); mix-blend-mode: multiply; pointer-events: none;
}
.postmark b { font-size: 15px; display: block; }
.postmark::before {
  content: ""; position: absolute; right: 100%; top: 14px; width: 40px; height: 22px;
  background: repeating-linear-gradient(0deg, rgba(27,38,70,.7) 0 2px, transparent 2px 7px);
}

.foot { margin-top: 12px; display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.route { margin: 0; font-size: 12px; line-height: 1.35; min-width: 0; }
.route b { display: block; text-transform: uppercase; letter-spacing: .08em; }
.ink {
  flex: none; padding: 5px 8px 4px; border: 3px double var(--st); border-radius: 4px; color: var(--st);
  font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap;
  transform: rotate(-7deg); mix-blend-mode: multiply;
}
.ink.slam { animation: slam .5s cubic-bezier(.2,1.4,.4,1); }
@keyframes slam { 0% { transform: scale(2.6) rotate(-25deg); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1) rotate(-7deg); } }

/* ---------- empty ---------- */
.empty {
  max-width: 520px; margin: 30px auto; padding: 26px; text-align: center;
  background: var(--paper); color: var(--ink); border-radius: 3px; border: 3px dashed var(--ink);
  transform: rotate(-1deg);
}
.empty h3 { margin: 10px 0 6px; font-family: var(--serif); font-size: 26px; }
.empty p { margin: 0 0 8px; }
.empty-art { display: flex; justify-content: center; gap: 6px; height: 40px; align-items: flex-end; }
.empty-art span { width: 14px; border: 2px dashed var(--ink); border-bottom: 0; }
.empty-art span:nth-child(1) { height: 22px; } .empty-art span:nth-child(2) { height: 36px; } .empty-art span:nth-child(3) { height: 28px; }

/* ---------- letter (detail) ---------- */
dialog.letter {
  position: fixed; inset: 0; margin: auto; padding: 0; border: 0;
  width: min(700px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  overflow: auto; overscroll-behavior: contain;
  background: var(--paper); color: var(--ink); border-radius: 3px;
  box-shadow: 0 30px 60px #000a;
}
dialog.letter::backdrop { background: rgba(10, 24, 18, .78); backdrop-filter: blur(2px); }
dialog.letter[open] { animation: rise .4s cubic-bezier(.3,1.3,.5,1); }
@keyframes rise { from { opacity: 0; transform: translateY(60px) rotate(-2deg); } }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 10px 8px 18px; background: var(--ink); color: var(--cream);
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
}
.closebtn {
  min-height: 44px; padding: 6px 14px; cursor: pointer; font-weight: 700; letter-spacing: .06em;
  background: var(--gold); color: var(--ink); border: 2px solid var(--cream); border-radius: 2px;
}
.closebtn:focus-visible { outline-color: var(--cream); box-shadow: 0 0 0 6px var(--c-blocked); }

.flapwrap { height: 46px; background: var(--kraft); overflow: hidden; position: relative; }
.flapopen {
  position: absolute; inset: 0; background: var(--paper2);
  clip-path: polygon(0 100%, 100% 100%, 50% 0);
  transform-origin: bottom; box-shadow: inset 0 -4px 8px #0002;
}
dialog.letter[open] .flapopen { animation: flap .6s .15s both cubic-bezier(.3,1.3,.5,1); }
@keyframes flap { from { transform: scaleY(-1); } }

.sheet { padding: 22px 30px 30px; background: repeating-linear-gradient(transparent 0 31px, rgba(27,38,70,.06) 31px 32px); }
.sheet .to { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; margin: 0 0 6px; }
.sheet h2 { margin: 0 0 18px; font-family: var(--serif); font-size: 32px; line-height: 1.12; overflow-wrap: anywhere; }

.facts { display: grid; grid-template-columns: repeat(4, auto); gap: 12px 22px; margin: 0 0 22px; padding: 12px 0; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); justify-content: start; }
.facts div { min-width: 0; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }
.facts dd { margin: 2px 0 0; font-weight: 700; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { padding: 1px 9px; border: 2px solid var(--ink); border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--paper); }

.body { white-space: pre-line; font-size: 16.5px; line-height: 32px; margin: 0 0 26px; max-width: 60ch; }
.body strong { background: linear-gradient(transparent 55%, rgba(255,212,92,.8) 55%); }

.padbox { padding: 14px 16px 12px; background: #17213f; color: var(--cream); border-radius: 4px; box-shadow: inset 0 4px 12px #000a; }
.padbox h3, .trail h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
.padbox h3 { color: var(--gold); }
.padrow { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.padrow .field { flex: 1 1 220px; max-width: 320px; }
.padbox select { color: var(--ink); }
.padbox select:focus-visible { outline-color: var(--cream); box-shadow: 0 0 0 6px var(--gold); }
.bigstamp-slot { min-width: 150px; min-height: 64px; display: grid; place-items: center; }
.bigstamp {
  --st: var(--c-todo);
  display: inline-block; padding: 8px 14px 6px; background: var(--paper); color: var(--st);
  border: 4px double var(--st); border-radius: 5px; transform: rotate(-8deg);
  font-family: var(--serif); font-size: 22px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap;
}
.bigstamp.slam { animation: slam .55s cubic-bezier(.2,1.4,.4,1); }
.feedback { margin-top: 10px; min-height: 24px; font-size: 14px; }
.feedback.flash { animation: flash 1.2s; }
@keyframes flash { 0% { background: rgba(255,212,92,.45); } 100% { background: transparent; } }
.feedback .btn { min-height: 38px; margin: 6px 0 0; padding: 4px 10px; font-size: 13px; box-shadow: 0 3px 0 var(--cream); border-color: var(--cream); }
.thump { animation: thump .3s; }
@keyframes thump { 40% { transform: translateY(4px); } }

.trail { margin-top: 22px; }
.trail ol { margin: 0; padding: 0; list-style: none; font-size: 13.5px; }
.trail li { padding: 5px 0; border-bottom: 1px dashed rgba(27,38,70,.4); }
.trail li.none { opacity: .7; border: 0; }

/* ---------- narrow ---------- */
@media (max-width: 899px) {
  .app { display: block; }
  .rail { position: static; height: auto; overflow: visible; padding: 16px 14px 18px; gap: 14px; border-right: 0; border-bottom: 6px solid #170d05; }
  .mark { width: 56px; height: 56px; }
  .brand h1 { font-size: 32px; }
  .controls { grid-template-columns: 1.4fr 1fr; gap: 10px; padding: 10px; }
  .rack { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .cubby, .cubby[data-v="all"] { grid-column: auto; height: 96px; padding: 5px 4px; flex-direction: column; align-items: stretch; }
  .cubby .plate { font-size: 9.5px; padding: 1px 3px; letter-spacing: .02em; align-self: flex-start; line-height: 1.25; }
  .cubby .num { font-size: 22px; align-self: flex-end; }
  .slivers { left: 4px; right: 4px; height: 38px; gap: 2px; }
  .sliver, .cubby[data-v="all"] .sliver { width: 8px; height: calc(22px + var(--h) * 3px); }
  .rackwrap h2 { margin-bottom: 6px; }
  .hint { display: none; }
  .desk { padding: 20px 16px 48px; }
  .deskhead h2 { font-size: 28px; }
  .pile { grid-template-columns: 1fr; gap: 26px; }
  .env { --k: .6; }
  .desk.tidy .env { --k: 0; }
  dialog.letter { width: 100vw; max-width: none; height: 100dvh; max-height: none; border-radius: 0; }
  .sheet { padding: 18px 18px 30px; }
  .sheet h2 { font-size: 26px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .body { font-size: 16px; }
  .bigstamp-slot { min-width: 0; margin-left: auto; }
}

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