/* ============================================================
   PHIAT WORKS — Victorian steampunk factory floor
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IM+Fell+English+SC&family=IM+Fell+English:ital@0;1&family=Special+Elite&family=JetBrains+Mono:wght@400;700&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #15100a;
  --bg-2:      #1f1710;
  --bg-3:      #2a1d12;
  --wood:      #5a3a22;
  --wood-2:    #7a5232;
  --wood-dk:   #3a2515;
  --wood-darkest: #221409;
  --brass:     #c9a36b;
  --brass-lt:  #e7c790;
  --brass-dk:  #8c6d3f;
  --brass-vd:  #5a4525;
  --copper:    #b87333;
  --copper-dk: #7a4a1f;
  --paper:     #ead8a8;
  --paper-2:   #d8c081;
  --paper-dim: #b8a06b;
  --ink:       #1a0f06;
  --ink-2:     #2a1810;
  --red:       #8a2818;
  --red-lt:    #b34225;
  --glow:      #ffc788;
  --moss:      #5e6e3d;
  --shadow-deep: 0 10px 25px rgba(0,0,0,.6);
}

html, body { height: 100%; }
html { overflow-y: scroll; } /* lock scrollbar so filter-change can't reflow the page width */

body {
  font-family: 'IM Fell English', 'Garamond', Georgia, serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(184,115,51,.10), transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(255,199,136,.06), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.012) 0 1px, transparent 1px 4px);
  color: var(--paper);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: .01em;
}

/* faint paper grain */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 12% 30%, rgba(0,0,0,.18), transparent 40%),
    radial-gradient(circle at 88% 70%, rgba(0,0,0,.22), transparent 45%);
  mix-blend-mode: multiply;
}

a { color: var(--brass-lt); text-decoration: none; }
a:hover { color: var(--glow); }

/* ===== layout ============================================== */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100vh;
}

.viewport {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 360px;
  gap: 24px;
  padding: 22px 28px 40px;
  align-items: start;
}

/* Below this width, the inspection rail stacks under the floor instead of
   disappearing, so a crate click is always visible. */
@media (max-width: 1180px) {
  .viewport {
    grid-template-columns: 220px minmax(0, 1fr);
    grid-template-areas:
      "filter floor"
      "inspect inspect";
  }
  .filter-rail     { grid-area: filter; }
  .floor, #floor   { grid-area: floor; }
  .inspection-rail {
    grid-area: inspect;
    position: relative;
    top: 0;
    max-height: none;
  }
}
@media (max-width: 820px) {
  .viewport {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "floor" "filter" "inspect";
    padding: 16px;
  }
}

/* ===== top bar ============================================= */

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 20px 32px 22px;
  background:
    linear-gradient(180deg, var(--bg-3) 0%, var(--bg-2) 100%);
  border-bottom: 2px solid var(--brass-vd);
  position: relative;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}

.topbar::before, .topbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 4px;
}
.topbar::before { top: 0; background: linear-gradient(180deg, var(--brass-dk), transparent); }
.topbar::after  { bottom: -4px; background: linear-gradient(180deg, var(--brass-dk), transparent); }

.rivets {
  position: absolute;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.rivets.top    { top: 6px; left: 14px; right: 14px; }
.rivets.bottom { bottom: 6px; left: 14px; right: 14px; }
.rivet {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--brass-lt) 0%, var(--brass) 45%, var(--brass-dk) 80%, var(--ink) 100%);
  box-shadow: inset 0 -1px 1px rgba(0,0,0,.5), 0 1px 1px rgba(0,0,0,.4);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand .cog {
  width: 56px; height: 56px;
  color: var(--brass);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
  animation: spin-cog 9s linear infinite;
}
.brand .cog.alt { animation-direction: reverse; animation-duration: 12s; width: 36px; height: 36px; margin-left: -22px; opacity: .7; }

@keyframes spin-cog { to { transform: rotate(360deg); } }
@keyframes spin-cog-rev { to { transform: rotate(-360deg); } }

.brand h1 {
  font-family: 'IM Fell English SC', serif;
  font-size: 30px;
  line-height: 1;
  color: var(--paper);
  letter-spacing: .04em;
  text-shadow: 0 1px 0 var(--ink), 0 0 18px rgba(255,199,136,.12);
}
.brand .sub {
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--brass);
  margin-top: 4px;
}

/* gauge cluster */
.gauges {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  padding: 0 12px;
}

.gauge {
  position: relative;
  width: 118px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.gauge svg { display: block; filter: drop-shadow(0 4px 6px rgba(0,0,0,.55)); }

.gauge .label {
  margin-top: 6px;
  font-family: 'IM Fell English SC', serif;
  font-size: 11px;
  letter-spacing: .2em;
  color: var(--brass);
  text-transform: uppercase;
}

/* stat readouts */
.readouts {
  justify-self: end;
  display: flex;
  gap: 14px;
  align-items: center;
}
.readout {
  text-align: center;
  padding: 8px 14px 9px;
  min-width: 90px;
  background:
    linear-gradient(180deg, #1a0e05, #0d0703 70%);
  border: 1px solid var(--brass-vd);
  border-radius: 4px;
  box-shadow: inset 0 0 12px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,199,136,.06);
  position: relative;
}
.readout .num {
  font-family: 'Special Elite', monospace;
  font-size: 22px;
  color: var(--glow);
  text-shadow: 0 0 8px rgba(255,199,136,.55), 0 0 2px rgba(255,199,136,.9);
  letter-spacing: .04em;
}
.readout .cap {
  display: block;
  margin-top: 2px;
  font-family: 'Special Elite', monospace;
  font-size: 9px;
  letter-spacing: .25em;
  color: var(--brass);
  text-transform: uppercase;
}
.readout.warn .num { color: #ffb37a; text-shadow: 0 0 10px rgba(255,140,80,.6); }

/* ===== toolbar ============================================= */

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 28px 14px;
  background:
    linear-gradient(180deg, #1c130a, #14100b);
  border-bottom: 1px solid #0a0703;
  position: relative;
  flex-wrap: wrap;
}
.toolbar::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -3px;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--brass-dk) 0 6px, var(--ink) 6px 12px);
  opacity: .6;
}

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
}
.search input {
  width: 100%;
  font-family: 'Special Elite', monospace;
  font-size: 14px;
  padding: 9px 14px 9px 34px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--brass-vd);
  border-radius: 3px;
  box-shadow: inset 0 1px 4px rgba(0,0,0,.4), 0 1px 0 rgba(255,199,136,.1);
  outline: none;
}
.search input::placeholder { color: rgba(26,15,6,.45); font-style: italic; }
.search .magnify {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--brass-dk);
  pointer-events: none;
  width: 18px; height: 18px;
}

.sort-knob {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  color: var(--brass);
  text-transform: uppercase;
  letter-spacing: .2em;
}
.sort-knob select {
  background: var(--paper);
  border: 1px solid var(--brass-vd);
  color: var(--ink);
  font-family: 'Special Elite', monospace;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.4);
}

.lever-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--paper);
  background: linear-gradient(180deg, var(--copper) 0%, var(--copper-dk) 100%);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.2),
    inset 0 -2px 4px rgba(0,0,0,.4),
    0 2px 0 var(--ink);
  text-decoration: none;
}
.lever-btn:hover {
  color: var(--glow);
  background: linear-gradient(180deg, #cf8a4f, var(--copper-dk));
}

/* htmx loading indicator (toolbar pneumatic spark) — absolutely positioned
   so it can't shove the toolbar's flex layout around when it appears. */
.belt-indicator {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--glow);
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
}
form.toolbar.htmx-request .belt-indicator { opacity: 1; }
.belt-indicator .spark {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--glow);
  box-shadow: 0 0 10px var(--glow), 0 0 2px var(--glow);
  animation: pulse-spark .6s ease-in-out infinite;
}
@keyframes pulse-spark {
  0%, 100% { opacity: .35; transform: scale(.7); }
  50%      { opacity: 1;   transform: scale(1.1); }
}

/* active-filter banner inside #floor */
.active-filter-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background:
    linear-gradient(180deg, #2a1d12, #1a120a);
  border: 1px solid var(--brass-vd);
  border-radius: 4px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  color: var(--paper-dim);
  flex-wrap: wrap;
}
.active-filter-banner .lbl {
  color: var(--brass);
  letter-spacing: .2em;
  text-transform: uppercase;
}
.active-filter-banner .chip {
  padding: 4px 10px;
  background: var(--red);
  color: var(--paper);
  border-radius: 2px;
  border: 1px solid #5a1810;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.active-filter-banner .clear {
  font-family: 'Special Elite', monospace;
  color: var(--brass-lt);
  border-bottom: 1px dotted var(--brass-dk);
  cursor: pointer;
  letter-spacing: .15em;
}
.active-filter-banner .clear:hover { color: var(--glow); }
.active-filter-banner .tally {
  margin-left: auto;
  color: var(--brass);
  letter-spacing: .12em;
}

/* ===== filter rail ========================================= */

.filter-rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background:
    linear-gradient(180deg, #241810 0%, #1a120a 100%);
  border: 1px solid #0d0703;
  border-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255,199,136,.06),
    inset 0 0 0 1px rgba(140,109,63,.18),
    var(--shadow-deep);
  position: relative;
  padding: 16px 16px 18px;
}
.panel::before {
  /* brass plate top */
  content: '';
  position: absolute;
  top: -1px; left: 8px; right: 8px;
  height: 22px;
  background:
    linear-gradient(180deg, var(--brass), var(--brass-dk));
  border-radius: 2px 2px 0 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.panel > .plate-label {
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
  margin: -2px -8px 14px;
  padding: 4px 0 6px;
  font-family: 'IM Fell English SC', serif;
  font-size: 13px;
  letter-spacing: .2em;
  color: var(--ink);
  text-transform: uppercase;
}
.panel > .plate-label::before,
.panel > .plate-label::after {
  content: '◆';
  margin: 0 8px;
  color: var(--ink-2);
  opacity: .6;
  font-size: 9px;
  vertical-align: middle;
}

.filter-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--brass-dk) transparent;
}
.filter-list::-webkit-scrollbar { width: 6px; }
.filter-list::-webkit-scrollbar-thumb { background: var(--brass-dk); border-radius: 3px; }

.filter-list a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-family: 'Special Elite', monospace;
  font-size: 12px;
  color: var(--paper-dim);
  border-radius: 2px;
  border-left: 2px solid transparent;
}
.filter-list a:hover {
  color: var(--paper);
  background: rgba(201,163,107,.08);
  border-left-color: var(--brass-dk);
}
.filter-list a.active {
  color: var(--glow);
  background: rgba(184,115,51,.18);
  border-left-color: var(--copper);
}
.filter-list a .dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.4);
}
.filter-list a .n {
  margin-left: auto;
  font-size: 10px;
  color: var(--brass-dk);
  letter-spacing: 0;
}

/* sync notice */
.sync-card {
  background: linear-gradient(180deg, #1c1208, #120a04);
  border: 1px solid var(--brass-vd);
  border-radius: 4px;
  padding: 12px 14px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  color: var(--brass);
  letter-spacing: .1em;
  text-align: center;
  position: relative;
}
.sync-card .lamp {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--moss);
  box-shadow: 0 0 6px var(--moss), inset 0 0 2px rgba(0,0,0,.4);
  margin-right: 6px;
  vertical-align: middle;
  animation: pulse-lamp 3s ease-in-out infinite;
}
@keyframes pulse-lamp {
  0%, 100% { opacity: .6; }
  50% { opacity: 1; box-shadow: 0 0 10px var(--moss); }
}
.sync-card .ts {
  display: block;
  color: var(--paper-dim);
  margin-top: 4px;
  text-transform: none;
  font-size: 10px;
}

/* ===== floor =============================================== */

.floor {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.section-title {
  font-family: 'IM Fell English SC', serif;
  font-size: 14px;
  letter-spacing: .25em;
  text-transform: uppercase;
  color: var(--brass);
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.section-title::before, .section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass-dk), transparent);
}

/* Featured shelf */
.shelf {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 1380px) { .shelf { grid-template-columns: repeat(2, 1fr); } }

.shelf-crate {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 14px;
  min-height: 130px;
  background:
    linear-gradient(180deg, #6c4427 0%, #4a2d17 60%, #3a2210 100%);
  border: 2px solid var(--wood-darkest);
  border-radius: 5px;
  box-shadow:
    inset 0 1px 0 rgba(255,199,136,.12),
    inset 0 0 0 1px rgba(0,0,0,.4),
    0 8px 14px rgba(0,0,0,.55);
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.shelf-crate::before {
  /* wood plank line */
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(0,0,0,.35);
  box-shadow: 0 -1px 0 rgba(255,199,136,.05);
}
.shelf-crate:hover {
  transform: translateY(-3px);
  box-shadow:
    inset 0 1px 0 rgba(255,199,136,.18),
    0 12px 22px rgba(0,0,0,.65),
    0 0 0 1px var(--brass-dk);
}
.shelf-crate .seal {
  position: absolute;
  top: 10px; right: 10px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--red-lt) 0%, var(--red) 50%, #4a1408 100%);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IM Fell English SC', serif;
  font-size: 11px;
  color: var(--paper);
  letter-spacing: .05em;
  text-shadow: 0 1px 0 rgba(0,0,0,.6);
}
.shelf-crate h3 {
  font-family: 'IM Fell English SC', serif;
  font-size: 18px;
  color: var(--paper);
  letter-spacing: .03em;
  margin-right: 50px;
  line-height: 1.1;
  text-shadow: 0 1px 0 rgba(0,0,0,.5);
}
.shelf-crate .desc {
  font-size: 12px;
  color: rgba(234,216,168,.7);
  font-style: italic;
  margin-top: 6px;
  line-height: 1.3;
  flex: 1;
}
.shelf-crate .meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  color: var(--paper-dim);
  letter-spacing: .08em;
}
.shelf-crate .meta .star { color: var(--glow); }

/* Belt */
.belt {
  position: relative;
  border: 1px solid #0a0603;
  border-radius: 4px;
  background: var(--bg-2);
  box-shadow: var(--shadow-deep);
}
.belt-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px 9px;
  background: linear-gradient(180deg, #241810, #1a120a);
  border-bottom: 1px solid #0a0603;
}
.belt-head .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.5), 0 0 8px currentColor;
}
.belt-head h3 {
  font-family: 'IM Fell English SC', serif;
  font-size: 15px;
  letter-spacing: .12em;
  color: var(--paper);
  text-transform: uppercase;
}
.belt-head .count {
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  color: var(--brass);
  letter-spacing: .2em;
}
.belt-head .gear {
  width: 22px; height: 22px;
  color: var(--brass-dk);
  animation: spin-cog 6s linear infinite;
}
.belt-head .gear.reverse { animation-direction: reverse; }
.belt-head .badge {
  margin-left: auto;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  color: var(--paper-dim);
  letter-spacing: .15em;
  text-transform: uppercase;
}

.belt-surface {
  position: relative;
  overflow: hidden;
  padding: 14px 18px 24px;
  background:
    linear-gradient(180deg, #1f1610 0%, #0e0805 100%);
}
.belt-surface::before {
  /* moving conveyor stripes */
  content: '';
  position: absolute;
  inset: auto 0 4px 0;
  height: 14px;
  background-image: repeating-linear-gradient(
    -45deg,
    #2a1d12 0 14px,
    #1a110a 14px 28px
  );
  background-size: 39.6px 39.6px;
  animation: belt-roll linear infinite;
  animation-duration: var(--belt-speed, 90s);
  box-shadow:
    inset 0 1px 0 rgba(255,199,136,.06),
    inset 0 -1px 0 rgba(0,0,0,.7);
  border-top: 1px solid #0a0603;
  transition: filter .3s ease;
}
@keyframes belt-roll {
  from { background-position: 0 0; }
  to   { background-position: -200px 0; }
}

/* Belt freeze + spotlight: when hovering a belt, the conveyor stops and
   non-hovered crates dim so the foreman can inspect a single specimen. */
.belt-surface:hover::before {
  animation-play-state: paused;
  filter: brightness(.7);
}
.belt-surface:hover .crate:not(:hover) {
  opacity: .42;
  filter: saturate(.6);
}
.belt-surface:hover .crate:not(:hover):hover { opacity: 1; }
.belt-surface .crate { transition: transform .18s ease, box-shadow .18s ease, opacity .25s ease, filter .25s ease; }
.belt-surface:hover .crate:hover {
  z-index: 3;
  box-shadow:
    0 14px 28px rgba(0,0,0,.75),
    0 0 0 1px var(--brass),
    0 0 22px rgba(255,199,136,.18);
}

.belt-rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--brass-dk) transparent;
}
.belt-rail::-webkit-scrollbar { height: 6px; }
.belt-rail::-webkit-scrollbar-thumb { background: var(--brass-dk); border-radius: 3px; }

/* Crate (belt size) */
.crate {
  flex: 0 0 168px;
  height: 154px;
  position: relative;
  padding: 11px 11px 9px;
  background:
    linear-gradient(180deg, #7a4f2e 0%, #4a2c17 100%);
  border: 1.5px solid var(--wood-darkest);
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255,199,136,.12),
    inset 0 0 0 1px rgba(0,0,0,.35),
    0 6px 10px rgba(0,0,0,.55);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  color: var(--paper);
  display: flex;
  flex-direction: column;
  transform: rotate(var(--tilt, 0deg));
  transition: transform .18s ease, box-shadow .18s ease;
  font: inherit;
}
.crate:hover {
  transform: rotate(0deg) translateY(-3px);
  box-shadow:
    inset 0 1px 0 rgba(255,199,136,.18),
    0 12px 18px rgba(0,0,0,.7),
    0 0 0 1px var(--brass-dk);
  z-index: 2;
}
.crate.htmx-request { opacity: .85; }

.crate::before {
  /* horizontal plank line */
  content: '';
  position: absolute;
  left: 6px; right: 6px;
  top: 56%;
  height: 1px;
  background: rgba(0,0,0,.4);
  box-shadow: 0 -1px 0 rgba(255,199,136,.07);
}
.crate::after {
  /* corner bracket */
  content: '';
  position: absolute;
  top: 5px; left: 5px;
  width: 14px; height: 14px;
  border-top: 2px solid var(--brass);
  border-left: 2px solid var(--brass);
  opacity: .75;
}

.crate .corner-br {
  position: absolute;
  bottom: 5px; right: 5px;
  width: 14px; height: 14px;
  border-bottom: 2px solid var(--brass);
  border-right: 2px solid var(--brass);
  opacity: .75;
}

.crate .stamp {
  position: absolute;
  top: 8px; right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 6px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--paper);
  background: rgba(0,0,0,.45);
  border: 1px solid currentColor;
  border-radius: 2px;
  text-shadow: 0 0 4px rgba(0,0,0,.6);
  transform: rotate(-3deg);
}

.crate .name {
  font-family: 'IM Fell English SC', serif;
  font-size: 15px;
  line-height: 1.05;
  letter-spacing: .02em;
  color: var(--paper);
  text-shadow: 0 1px 0 rgba(0,0,0,.6);
  margin-right: 44px;
  margin-top: 2px;
  word-break: break-word;
  /* clamp to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.crate .tag-line {
  margin-top: 4px;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  color: rgba(234,216,168,.55);
  letter-spacing: .08em;
}
.crate .footer {
  position: absolute;
  bottom: 8px; left: 11px; right: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  color: var(--paper-dim);
  letter-spacing: .08em;
}
.crate .footer .star { color: var(--glow); }
.crate.archived {
  filter: grayscale(0.65) brightness(.78);
}
.crate.private::after { content: ''; }
.crate .lock {
  position: absolute;
  bottom: 8px; right: 11px;
  font-size: 10px;
  color: var(--brass);
}

/* ===== inspection rail ===================================== */

.inspection-rail {
  position: sticky;
  top: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 50px);
}

.parchment {
  background:
    radial-gradient(ellipse at 30% 0%, #f6e5b8 0%, #e8d496 50%, #d5bd7e 100%);
  color: var(--ink);
  border: 1px solid #4a3017;
  border-radius: 3px;
  padding: 22px 22px 24px;
  box-shadow:
    inset 0 0 60px rgba(120,75,30,.25),
    inset 0 0 0 1px rgba(74,48,23,.4),
    var(--shadow-deep);
  position: relative;
  overflow: hidden;
  flex: 1;
  min-height: 320px;
  font-family: 'IM Fell English', Garamond, serif;
}

.parchment::before,
.parchment::after {
  content: '';
  position: absolute;
  width: 80px; height: 80px;
  background: radial-gradient(circle at 50% 50%, rgba(0,0,0,.18), transparent 60%);
  pointer-events: none;
}
.parchment::before { top: -30px; left: -30px; }
.parchment::after  { bottom: -30px; right: -30px; }

.parchment .top-rib,
.parchment .bot-rib {
  position: absolute;
  left: 8px; right: 8px;
  height: 4px;
  background: repeating-linear-gradient(90deg, #5a4525 0 8px, transparent 8px 14px);
  opacity: .35;
}
.parchment .top-rib { top: 8px; }
.parchment .bot-rib { bottom: 8px; }

.parchment-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b34225 0%, #8a2818 55%, #4a1408 100%);
  color: var(--paper);
  border: 1.5px solid var(--ink);
  font-family: 'Special Elite', monospace;
  font-size: 14px;
  cursor: pointer;
  box-shadow:
    inset 0 -2px 4px rgba(0,0,0,.5),
    0 2px 4px rgba(0,0,0,.55);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.parchment-close:hover {
  background: radial-gradient(circle at 35% 30%, #cf5436 0%, #a8331f 55%, #5a1810 100%);
  color: var(--glow);
}
.parchment-close:active { transform: translateY(1px); }

.parchment .stamp-head {
  display: inline-block;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  letter-spacing: .25em;
  text-transform: uppercase;
  color: var(--red);
  padding: 3px 9px;
  border: 1.5px solid var(--red);
  border-radius: 2px;
  transform: rotate(-2deg);
  margin-bottom: 10px;
}

.parchment h2 {
  font-family: 'IM Fell English SC', serif;
  font-size: 22px;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: .02em;
  margin-bottom: 4px;
}
.parchment .full {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: rgba(26,15,6,.6);
  margin-bottom: 12px;
}

.parchment .summary {
  font-style: italic;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  border-left: 2px solid var(--copper-dk);
  padding-left: 10px;
  margin: 10px 0 14px;
}

.parchment .desc {
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 12px;
}

.parchment .ledger {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin: 14px 0;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--ink);
}
.parchment .ledger dt {
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: .2em;
  color: rgba(26,15,6,.55);
}
.parchment .ledger dd { font-size: 13px; }

.parchment .topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 10px 0 14px;
}
.parchment .topic-seal {
  display: inline-block;
  padding: 3px 9px;
  background: rgba(138,40,24,.85);
  color: var(--paper);
  border-radius: 12px;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}

.parchment .readme {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed rgba(74,48,23,.4);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.45;
  color: rgba(26,15,6,.85);
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.parchment .readme::-webkit-scrollbar { width: 6px; }
.parchment .readme::-webkit-scrollbar-thumb { background: rgba(74,48,23,.6); border-radius: 3px; }

.parchment .actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.parchment .actions a {
  flex: 1;
  text-align: center;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--paper);
  background: linear-gradient(180deg, var(--copper), var(--copper-dk));
  border: 1px solid var(--ink);
  padding: 7px 0;
  border-radius: 2px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.2),
    0 2px 0 var(--ink);
}
.parchment .actions a:hover { color: var(--glow); }
.parchment .actions a.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
  box-shadow: none;
}

/* Empty state */
.parchment.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: rgba(26,15,6,.55);
}
.parchment.empty .glyph {
  font-size: 48px;
  color: var(--copper-dk);
  opacity: .55;
  margin-bottom: 10px;
}
.parchment.empty p {
  font-style: italic;
  font-size: 14px;
  max-width: 240px;
  line-height: 1.4;
}
.parchment.empty .hint {
  margin-top: 12px;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--red);
  text-transform: uppercase;
}

/* ===== vault ============================================== */

.vault {
  margin-top: 18px;
  padding: 16px;
  border: 1px dashed var(--brass-vd);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(20,12,7,.6), rgba(10,6,3,.8));
}
.vault-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.vault-crate {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #2c1f14, #1a110a);
  border: 1px solid var(--wood-darkest);
  border-radius: 3px;
  font-family: 'Special Elite', monospace;
  font-size: 11px;
  color: var(--paper-dim);
  cursor: pointer;
  opacity: .7;
}
.vault-crate:hover { opacity: 1; color: var(--paper); }
.vault-crate .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.5);
}
.vault-crate .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== empty state for floor =============================== */

.no-results {
  text-align: center;
  padding: 60px 24px;
  background:
    linear-gradient(180deg, #1c130b, #100b06);
  border: 1px dashed var(--brass-vd);
  border-radius: 6px;
  color: var(--paper-dim);
}
.no-results .icon { font-size: 56px; opacity: .35; color: var(--copper); }
.no-results h2 {
  font-family: 'IM Fell English SC', serif;
  font-size: 22px;
  color: var(--paper);
  margin: 10px 0 6px;
  letter-spacing: .1em;
}
.no-results p {
  font-style: italic;
  margin-bottom: 14px;
}

/* ===== footer ============================================= */

.footer {
  margin-top: auto;
  padding: 18px 28px 22px;
  background: linear-gradient(180deg, transparent, var(--bg-2));
  border-top: 1px solid var(--brass-vd);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Special Elite', monospace;
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.footer .gear {
  width: 18px; height: 18px;
  color: var(--brass-dk);
  animation: spin-cog 8s linear infinite;
}
.footer-l, .footer-r { display: flex; align-items: center; gap: 10px; }

/* ============================================================
   MOTION — alive-factory animations
   ============================================================ */

/* Needles wobble ±1.2° around their target so the gauges feel alive
   even when the underlying value hasn't changed. */
.gauge-needle {
  transform-origin: 66px 66px;
  animation: needle-jitter 2.8s ease-in-out infinite;
}
@keyframes needle-jitter {
  0%, 100% { transform: rotate(calc(var(--target, 0deg) - 1.2deg)); }
  47%      { transform: rotate(calc(var(--target, 0deg) + 1.4deg)); }
  53%      { transform: rotate(calc(var(--target, 0deg) + 1deg)); }
}

/* Crates rock ever so slightly so the belts don't look freeze-framed. */
.crate {
  animation: crate-rock 5.5s ease-in-out infinite alternate;
}
@keyframes crate-rock {
  from { transform: rotate(var(--tilt, 0deg)) translateY(0); }
  to   { transform: rotate(calc(var(--tilt, 0deg) + .8deg)) translateY(-1px); }
}
/* Override during hover so the lift-effect still wins. */
.belt-surface:hover .crate:hover { animation: none; }
.shelf-crate { animation: crate-rock 7s ease-in-out infinite alternate; }

/* Ambient steam pluming up from each belt-head, like a working engine. */
.belt-head { position: relative; overflow: visible; }
.belt-head::after {
  content: '';
  position: absolute;
  left: 36px;
  bottom: 100%;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(234,216,168,.55) 0%, rgba(234,216,168,.18) 45%, transparent 70%);
  filter: blur(2px);
  animation: steam-rise 3.6s ease-out infinite;
  opacity: 0;
  pointer-events: none;
}
.belt-head .gear ~ .gear { /* a second offset plume via stacking */ }
@keyframes steam-rise {
  0%   { transform: translate(0, 6px) scale(.4); opacity: 0; }
  18%  { opacity: .9; }
  100% { transform: translate(-22px, -68px) scale(2.6); opacity: 0; }
}

/* Boiler vent: an animated plume between the brand and the gauges. */
.brand::after {
  content: '';
  position: absolute;
  left: 64px; bottom: 70%;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(234,216,168,.55), transparent 70%);
  filter: blur(2px);
  animation: steam-rise 4.4s ease-out infinite .8s;
  opacity: 0;
  pointer-events: none;
}
.brand { position: relative; }

/* Steam puffs spawned by JS for htmx interactions (filter swap, inspect). */
.steam-puff {
  position: fixed;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(247,231,191,.65) 0%,
    rgba(234,216,168,.35) 40%,
    rgba(234,216,168,.05) 70%,
    transparent 100%);
  filter: blur(3px);
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%) scale(.3);
  opacity: 0;
  animation: puff 1.3s cubic-bezier(.2,.6,.4,1) forwards;
}
@keyframes puff {
  0%   { transform: translate(-50%, -50%) scale(.3); opacity: 0; }
  12%  { opacity: .9; }
  100% {
    transform: translate(calc(-50% + var(--dx, -10px)), calc(-50% - 110px)) scale(2.6);
    opacity: 0;
    filter: blur(8px);
  }
}

/* Fade in newly-swapped belts. Swap replaces #floor's children, so the
   animation on .floor replays on each insertion. */
#floor > .floor {
  animation: belt-fade-in .35s ease-out;
}
@keyframes belt-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Parchment slide-in when a crate is loaded onto the bench. */
#inspection .parchment:not(.empty) {
  animation: parchment-in .42s cubic-bezier(.2,.8,.4,1) both;
}
@keyframes parchment-in {
  from { opacity: 0; transform: translateY(-6px) rotate(-.4deg); }
  to   { opacity: 1; transform: translateY(0) rotate(0); }
}

/* ============================================================
   MOBILE — portrait phones (≤640px wide)
   ============================================================ */

@media (max-width: 640px) {

  /* Topbar: collapse the 3-column grid into a centered stack so brand,
     gauges, and readouts each get a real row instead of being crushed. */
  .topbar {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 14px;
    padding: 16px 14px 18px;
  }
  .rivets.top    { top: 4px; left: 8px; right: 8px; }
  .rivets.bottom { bottom: 4px; left: 8px; right: 8px; }
  .rivet { width: 7px; height: 7px; }

  .brand { gap: 10px; }
  .brand .cog { width: 42px; height: 42px; }
  .brand h1   { font-size: 24px; }
  .brand .sub { font-size: 10px; letter-spacing: .18em; }

  .gauges { gap: 10px; padding: 0; }
  .gauge  { width: 96px; }
  .gauge svg { width: 96px; height: 96px; }
  .gauge .label { font-size: 9px; margin-top: 3px; letter-spacing: .15em; }

  .readouts { gap: 8px; flex-wrap: wrap; justify-content: center; justify-self: center; }
  .readout {
    padding: 6px 10px 7px;
    min-width: 80px;
  }
  .readout .num { font-size: 16px; }
  .readout .cap { font-size: 8px; letter-spacing: .18em; }

  /* Toolbar: stack search → sort → run, all full-width. */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px 12px;
  }
  .toolbar .search { max-width: none; }
  .toolbar .search input { font-size: 16px; /* prevent iOS zoom-on-focus */ }
  .sort-knob {
    justify-content: space-between;
    font-size: 10px;
  }
  .sort-knob select { flex: 1; font-size: 16px; padding: 8px 10px; }
  .lever-btn { padding: 10px 14px; }
  .belt-indicator { right: 14px; top: 14px; transform: none; }

  /* Viewport: tighter outer padding. */
  .viewport {
    padding: 14px;
    gap: 16px;
  }

  /* Featured shelf: 1 column on phones — 2 cramped cards look worse than
     1 readable card. */
  .shelf { grid-template-columns: 1fr; gap: 10px; }
  .shelf-crate { min-height: 110px; padding: 12px 14px; }
  .shelf-crate h3 { font-size: 17px; }
  .shelf-crate .seal { width: 32px; height: 32px; font-size: 10px; }

  /* Belt crates: shrink so 2-3 fit before scroll, instead of just over 2. */
  .crate { flex: 0 0 140px; height: 134px; padding: 10px 10px 8px; }
  .crate .name { font-size: 13px; margin-right: 36px; }
  .crate .stamp { min-width: 26px; height: 20px; font-size: 10px; padding: 0 4px; }
  .crate .footer { font-size: 9px; bottom: 7px; left: 10px; right: 10px; }
  .crate .tag-line { font-size: 9px; }

  /* Visual hint that belts scroll horizontally: a right-edge fade so a
     user knows there's more off-screen. */
  .belt-surface {
    padding: 10px 14px 20px;
    position: relative;
  }
  .belt-surface::after {
    content: '';
    position: absolute;
    top: 10px; bottom: 10px;
    right: 0;
    width: 28px;
    background: linear-gradient(90deg, transparent, rgba(14, 8, 5, .9));
    pointer-events: none;
    border-radius: 0 4px 4px 0;
  }

  .belt-head { padding: 8px 12px; gap: 8px; }
  .belt-head h3 { font-size: 13px; letter-spacing: .08em; }
  .belt-head .count { font-size: 10px; }
  .belt-head .badge { display: none; } /* "Conveyor X" badge is redundant when space is tight */

  /* Section titles + active-filter banner */
  .section-title { font-size: 12px; letter-spacing: .18em; }
  .active-filter-banner { padding: 8px 10px; gap: 8px; font-size: 10px; }
  .active-filter-banner .tally { margin-left: 0; }

  /* Filter rail: condense panels */
  .panel { padding: 14px 12px 14px; }
  .filter-list { max-height: 200px; }
  .filter-list a { padding: 5px 8px; font-size: 12px; }

  /* Vault: single readable column instead of a tight grid */
  .vault-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .vault-crate { padding: 7px 9px; font-size: 10px; }

  /* Parchment (inspection bench) */
  .parchment { padding: 18px 18px 20px; min-height: 240px; }
  .parchment h2 { font-size: 19px; }
  .parchment .full { font-size: 10px; }
  .parchment .summary, .parchment .desc { font-size: 13px; }
  .parchment .ledger { grid-template-columns: 1fr 1fr; font-size: 10px; }
  .parchment .ledger dd { font-size: 12px; }
  .parchment .readme { font-size: 10px; max-height: 200px; }
  .parchment-close { width: 34px; height: 34px; top: 10px; right: 10px; } /* easier tap target */

  /* Footer: stack the two halves so nothing wraps awkwardly */
  .footer {
    flex-direction: column;
    gap: 8px;
    padding: 14px 14px 18px;
    font-size: 9px;
    text-align: center;
  }

  /* Touch devices: hover-pause on belts doesn't apply; instead, give the
     focused crate (after tap) the same lift so the user sees a response. */
  .crate:focus, .crate:focus-visible {
    transform: rotate(0) translateY(-3px);
    box-shadow:
      0 12px 20px rgba(0,0,0,.7),
      0 0 0 1px var(--brass),
      0 0 18px rgba(255,199,136,.18);
    outline: none;
  }
}

/* Slightly larger phones / small tablets get half the mobile pass. */
@media (min-width: 641px) and (max-width: 820px) {
  .topbar { padding: 18px 22px 20px; gap: 18px; }
  .brand h1 { font-size: 26px; }
  .gauge { width: 104px; }
  .gauge svg { width: 104px; height: 104px; }
}
