/* =========================================================
   Max's Website — the minifig display case
   loaded after style.css, which provides --px
   sprites are drawn in tools/display_case.py
   ========================================================= */

html { overflow-y: scroll; }

body.case-room {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #f1e6c8;
  background: #323c5a url("assets/sprites/case-wall.png") repeat 0 0 /
    calc(64px * var(--px)) calc(64px * var(--px));
  image-rendering: pixelated;
}

/* ---------- header ---------- */
.case-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 30px 16px 26px;
  text-align: center;
}
.back-tag {
  align-self: flex-start;
  padding: 6px 16px;
  font: 700 14px "Trebuchet MS", sans-serif;
  color: #3c2c10;
  text-decoration: none;
  background: #e0b45c;
  border: 3px solid #2e1c06;
  box-shadow: 3px 3px 0 #2e1c06;
}
.back-tag:hover { background: #f0ca79; }
.back-tag:active { transform: translate(3px, 3px); box-shadow: none; }
.case-title {
  margin: 0;
  padding: 10px 30px 12px;
  font: 400 clamp(24px, 4vw, 38px) Georgia, "Times New Roman", serif;
  letter-spacing: 5px;
  text-transform: uppercase;
  color: #3c2c10;
  background: linear-gradient(180deg, #f2d77e, #c79a3a 55%, #a67c2a);
  border: 4px solid #2e1c06;
  box-shadow: 0 0 0 3px #e0b84a, 0 0 0 7px #2e1c06, 6px 10px 0 4px rgba(0, 0, 0, 0.35),
    inset 0 2px 0 #fff6c8;
  text-shadow: 0 1px 0 #f6e6a8;
}
.case-count {
  margin: 8px 0 0;
  font-size: 17px;
  color: #f6e6a8;
  text-shadow: 2px 2px 0 #1a1f33;
}
.case-count b { font-size: 22px; }
.case-count small { display: block; margin-top: 2px; font-size: 13px; color: #c9c2ae; }

/* the label maker (Max's computer only) */
.add-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  padding: 10px 14px;
  background: #1a1f33;
  border: 3px solid #0c0f1c;
  box-shadow: inset 0 0 0 2px #3f4b6d;
}
.add-form[hidden] { display: none; }
.add-form label { font-size: 13px; color: #c9c2ae; text-transform: uppercase; letter-spacing: 1px; }
.add-form input {
  width: 9em;
  padding: 6px 8px;
  font: 700 16px Consolas, "Courier New", monospace;
  color: #1a1f33;
  background: #f6efd8;
  border: 2px solid #0c0f1c;
}
.add-form button, .card-edit button {
  padding: 7px 14px;
  font: 700 14px "Trebuchet MS", sans-serif;
  color: #3c2c10;
  background: #e0b45c;
  border: 3px solid #2e1c06;
  box-shadow: 3px 3px 0 #2e1c06;
  cursor: pointer;
}
.add-form button:hover, .card-edit button:hover { background: #f0ca79; }
.add-form button:active, .card-edit button:active { transform: translate(3px, 3px); box-shadow: none; }
.add-form button:disabled { opacity: 0.6; cursor: progress; }
.add-status { flex-basis: 100%; min-height: 1.2em; margin: 0; font-size: 14px; }
.add-status.bad { color: #ffb4a2; }
.keys-warning {
  flex-basis: 100%;
  max-width: 34em;
  margin: 0;
  padding: 6px 10px;
  font-size: 13px;
  color: #3c2c10;
  background: #f0ca79;
  border: 2px solid #2e1c06;
}
.keys-warning[hidden] { display: none; }
.keys-warning code { font: 700 12px Consolas, monospace; }

/* ---------- the cabinet ---------- */
.cabinet {
  --wood: calc(12px * var(--px));
  position: relative;
  width: min(100% - 24px, 1500px);
  filter: drop-shadow(calc(4px * var(--px)) calc(4px * var(--px)) 0 rgba(8, 10, 20, 0.45));
}
.cabinet-crown {
  height: calc(20px * var(--px));
  margin: 0 calc(-4px * var(--px));
  background: url("assets/sprites/case-crown.png") repeat-x 0 0 /
    calc(24px * var(--px)) calc(20px * var(--px));
}
.cabinet-body {
  position: relative;
  padding: 0 var(--wood);
  background:
    url("assets/sprites/case-post.png") repeat-y left top / var(--wood) calc(72px * var(--px)),
    url("assets/sprites/case-post.png") repeat-y right top / var(--wood) calc(72px * var(--px));
}
/* the back panel: the same warm white the photos are tinted to (PANEL in minifigs.js),
   so BrickLink's white-background photos sit on it without any cutting out */
.cabinet-inside {
  --panel: #faf8f3;
  position: relative;
  min-height: calc(80px * var(--px));
  background: var(--panel);
}
/* shade at the top and sides of the case, drawn OVER the figures so photo and panel
   are shaded alike */
.cabinet-inside::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  box-shadow: inset 0 calc(5px * var(--px)) calc(6px * var(--px)) rgba(60, 40, 20, 0.28),
    inset calc(3px * var(--px)) 0 calc(4px * var(--px)) rgba(60, 40, 20, 0.12),
    inset calc(-3px * var(--px)) 0 calc(4px * var(--px)) rgba(60, 40, 20, 0.12);
}
.cabinet-plinth {
  height: calc(16px * var(--px));
  margin: 0 calc(-4px * var(--px));
  background: url("assets/sprites/case-plinth.png") repeat-x 0 0 /
    calc(24px * var(--px)) calc(16px * var(--px));
}
/* glass front: a couple of faint diagonal glints, clicks go straight through */
.glass {
  position: absolute;
  inset: 0 var(--wood);
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 18%, rgba(150, 175, 200, 0.10) 18% 21%, transparent 21% 24%,
      rgba(150, 175, 200, 0.07) 24% 25.5%, transparent 25.5% 70%, rgba(150, 175, 200, 0.08) 70% 72%, transparent 72%);
  z-index: 4;
}
.floor {
  align-self: stretch;
  flex: 1;
  min-height: calc(40px * var(--px));
  margin-top: calc(-14px * var(--px));
  background: url("assets/sprites/case-floor.png") repeat 0 0 / calc(96px * var(--px)) calc(28px * var(--px));
  position: relative;
  z-index: -1;
}

/* ---------- shelves: one per theme ---------- */
.shelf {
  position: relative;
  padding-top: calc(10px * var(--px));
}
/* a warm light strip under the shelf above */
.shelf::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: calc(34px * var(--px));
  z-index: 3;                      /* over the figures, so photo and panel are lit alike */
  background: radial-gradient(ellipse 60% 100% at 50% 0, rgba(255, 214, 140, 0.14), transparent 70%);
  pointer-events: none;
}
.shelf-plate {
  position: relative;
  display: table;
  margin: 0 auto 8px;
  padding: 3px 14px 4px;
  font: 700 13px "Trebuchet MS", sans-serif;
  letter-spacing: 1px;
  color: #3c2c10;
  background: linear-gradient(180deg, #f2d77e, #c79a3a 60%, #a67c2a);
  border: 2px solid #2e1c06;
  box-shadow: inset 0 1px 0 #fff6c8;
}
.shelf-plate span { font-weight: 400; margin-left: 8px; }
.shelf-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--per, 5), max-content);
  justify-content: center;
  align-items: end;
  gap: calc(4px * var(--px)) calc(5px * var(--px));
  padding: 4px calc(6px * var(--px)) 0;
}
.shelf-row + .shelf-plank + .shelf-row { margin-top: calc(10px * var(--px)); }
.shelf-plank {
  height: calc(12px * var(--px));
  background: url("assets/sprites/case-shelf.png") repeat-x 0 0 / calc(80px * var(--px)) calc(12px * var(--px));
}
.case-empty {
  margin: 0;
  padding: calc(24px * var(--px)) 20px;
  text-align: center;
  font: italic 18px Georgia, serif;
  color: #6f6758;
}

/* ---------- a figure ---------- */
.fig {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: calc(52px * var(--px));
  padding: 0;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.fig:focus-visible { outline: 3px dashed #fbe58a; outline-offset: 4px; }
.fig-art {
  position: relative;
  width: 100%;
  height: calc(60px * var(--px));
}
/* two copies of the picture (white background cut away in minifigs.js):
   a grey ghost underneath and the colour one on top, revealed bottom-up */
.fig-art canvas {
  position: absolute;
  left: 50%;
  bottom: 0;
  max-width: 100%;
  max-height: 100%;
  transform: translateX(-50%);
  image-rendering: pixelated;
}
.fig-art canvas.smooth { image-rendering: auto; }
/* the ghost (wanted) is drawn grey and faded in minifigs.js */
.fig-art .colour { clip-path: inset(100% 0 0 0); }
.fig.owned .fig-art .colour { clip-path: inset(0 0 0 0); }
.fig.owned .fig-art .ghost { opacity: 0; }
.fig:hover .fig-art, .fig:focus-visible .fig-art { transform: translateY(calc(-1px * var(--px))); }

/* the little shadow each figure casts on the shelf */
.fig-art::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: calc(-1px * var(--px));
  height: calc(2px * var(--px));
  background: rgba(0, 0, 0, 0.45);
  border-radius: 50%;
  z-index: -1;
}

/* price tag hanging off the shelf edge */
.fig-tag {
  position: relative;
  z-index: 2;
  margin-top: calc(1px * var(--px));
  width: 100%;
  padding: 3px 4px 4px;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  color: #2a2116;
  background: #f6efd8;
  border: 2px solid #2e1c06;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.4);
}
.fig-tag b {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
}
.fig-tag .price { color: #6b3b12; font-weight: 700; }
.fig-tag .stars { color: #b8860b; letter-spacing: -1px; }
.fig.owned .fig-tag { background: #fff8e2; }
.fig.owned .fig-tag::before {
  content: "\2713";
  position: absolute;
  top: -10px;
  right: -8px;
  width: 18px;
  height: 18px;
  font: 700 12px/16px sans-serif;
  color: #fff;
  background: #3f8f3a;
  border: 2px solid #1d3d1a;
}

/* ---------- the colour fill-in ----------
   the colour rises from the feet like paint filling a mould, in pixel
   steps, with a bright line riding the edge; then a hop and a twinkle */
.fig.filling .fig-art .colour { animation: fill-up 1.5s steps(22, end) forwards; }
.fig.filling .fig-art .ghost { animation: ghost-out 1.5s steps(22, end) forwards; }
.fig.filling .fig-art::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: 10%;
  right: 10%;
  height: calc(1px * var(--px));
  background: #fff6c8;
  box-shadow: 0 0 calc(3px * var(--px)) #ffe9a0;
  animation: fill-line 1.5s steps(22, end) forwards;
}
.fig.filling .fig-art { animation: hop 0.5s steps(5, end) 1.5s; }
.fig.draining .fig-art .colour { animation: fill-up 0.6s steps(10, end) reverse forwards; }

@keyframes fill-up {
  from { clip-path: inset(100% 0 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}
@keyframes ghost-out {
  0%, 90% { opacity: 1; }
  100%    { opacity: 0; }
}
@keyframes fill-line {
  0%   { bottom: 0;    opacity: 1; }
  96%  { bottom: 100%; opacity: 1; }
  100% { bottom: 100%; opacity: 0; }
}
@keyframes hop {
  0%   { transform: translateY(0); }
  40%  { transform: translateY(calc(-5px * var(--px))); }
  100% { transform: translateY(0); }
}
.sparkle {
  position: absolute;
  z-index: 3;
  width: calc(9px * var(--px));
  height: calc(9px * var(--px));
  pointer-events: none;
  background: url("assets/sprites/sparkle.png") no-repeat 0 0 / calc(27px * var(--px)) calc(9px * var(--px));
  animation: twinkle 0.6s steps(1, end) forwards;
}
@keyframes twinkle {
  0%   { background-position: calc(-18px * var(--px)) 0; }
  20%  { background-position: calc(-9px * var(--px)) 0; }
  45%  { background-position: 0 0; }
  70%  { background-position: calc(-9px * var(--px)) 0; }
  85%  { background-position: calc(-18px * var(--px)) 0; }
  100% { background-position: calc(-27px * var(--px)) 0; }
}
/* a new wanted figure drops onto the shelf */
.fig.arriving .fig-art { animation: arrive 0.45s steps(6, end); }
@keyframes arrive {
  from { transform: translateY(calc(-14px * var(--px))); opacity: 0; }
  60%  { transform: translateY(0); opacity: 1; }
  80%  { transform: translateY(calc(-2px * var(--px))); }
  to   { transform: translateY(0); }
}

/* ---------- the figure's card ---------- */
.fig-card {
  width: min(94vw, 640px);
  max-height: 90vh;
  padding: 0;
  color: #2a2116;
  background: #f6efd8;
  border: 4px solid #2e1c06;
  box-shadow: 0 0 0 3px #e0b84a, 0 0 0 7px #2e1c06, 10px 14px 0 6px rgba(0, 0, 0, 0.4);
}
.fig-card::backdrop { background: rgba(10, 12, 24, 0.7); }
.fig-card[open] { display: flex; flex-wrap: wrap; }
.card-close {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  font-size: 22px;
  line-height: 1;
  color: #3c2c10;
  background: #e0b45c;
  border: 2px solid #2e1c06;
  cursor: pointer;
}
.card-art {
  position: relative;
  flex: 0 0 180px;
  min-height: 220px;
  background: #fff;
  border-right: 2px dashed #c9b98f;
}
.card-art img {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  object-fit: contain;
  image-rendering: pixelated;
  background: #fff;
}
.card-art img.ghost { filter: grayscale(1) brightness(0.8); }
.card-body { flex: 1 1 300px; padding: 16px 18px 18px; }
.card-body h2 { margin: 0 34px 2px 0; font: 700 21px Georgia, serif; }
.card-meta { margin: 0 0 10px; font-size: 13px; color: #6a5d48; }
.card-prices, .card-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 0 0 10px;
  font-size: 14px;
}
.card-prices dt, .card-facts dt { color: #6a5d48; }
.card-prices dd, .card-facts dd { margin: 0; font-weight: 700; }
.card-prices dd small { font-weight: 400; color: #6a5d48; }
.card-status { margin: 0 0 10px; font-weight: 700; }
.card-status.owned { color: #2f6e2b; }
.card-status.wanted { color: #7a5a1a; }
.card-links { margin: 0; font-size: 14px; display: flex; gap: 14px; flex-wrap: wrap; }
.card-links a { color: #6b3b12; font-weight: 700; }
.card-edit { margin-top: 12px; padding-top: 12px; border-top: 2px dashed #c9b98f; }
.card-edit[hidden] { display: none; }
.got-it { width: 100%; margin-bottom: 12px; font-size: 16px !important; }
.got-it.is-owned { background: #9fd18f !important; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.edit-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #6a5d48; }
.edit-grid .wide { grid-column: 1 / -1; }
.edit-grid input, .edit-grid select, .edit-grid textarea {
  padding: 5px 6px;
  font: 14px "Trebuchet MS", sans-serif;
  color: #2a2116;
  background: #fffdf4;
  border: 2px solid #8c7a55;
}
.by-hand { margin-top: 10px; font-size: 13px; }
.by-hand summary { cursor: pointer; color: #6a5d48; margin-bottom: 8px; }
.card-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.card-edit .remove { background: #e8c2b4; }
.card-edit .remove:hover { background: #f2d3c7; }
.card-msg { min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }
.card-msg.bad { color: #a3341f; }

@media (max-width: 640px) {
  .fig { width: calc(44px * var(--px)); }
  .fig-art { height: calc(48px * var(--px)); }
  .edit-grid { grid-template-columns: 1fr; }
  .card-art { flex-basis: 100%; min-height: 180px; }
}

.fig-tag .where { font-size: 10px; color: #8a7a5a; }
