:root {
  --navy: #16213f;        /* blazer */
  --navy-2: #1e2c52;      /* raised panels */
  --navy-3: #2a3b6a;      /* lines, inputs */
  --manila: #d8b46a;      /* case-file folder */
  --manila-dk: #b8924a;
  --red: #c8202f;         /* bow tie */
  --sky: #7cc3ea;         /* bought, not arrived */
  --paper: #eef1f7;
  --muted: #9aa6c4;
  --display: "Dela Gothic One", "Zen Kaku Gothic New", system-ui, sans-serif;
  --body: "Zen Kaku Gothic New", system-ui, "Hiragino Sans", "Yu Gothic", sans-serif;
  --r: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--navy); color: var(--paper);
  font: 15px/1.5 var(--body);
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--manila); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- header + folder tabs ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-end; gap: 1.25rem;
  padding: .6rem 1rem 0; background: var(--navy);
  border-bottom: 3px solid var(--manila);
}
.brand { display: flex; align-items: center; gap: .5rem; padding-bottom: .55rem; flex: none; }
.bowtie { width: 30px; fill: var(--red); }
.brand h1 { font: 1.05rem/1 var(--display); margin: 0; letter-spacing: .01em; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 0; cursor: pointer;
  padding: .45rem 1rem .4rem; border-radius: 10px 10px 0 0;
  background: var(--navy-2); color: var(--muted); font-weight: 700;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 100%, 0 100%);
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--paper); }
.tab[aria-selected="true"] { background: var(--manila); color: var(--navy); }

main { max-width: 1280px; margin: 0 auto; padding: 1rem; }
.status { color: var(--muted); text-align: center; padding: 3rem 1rem; }

/* ---------- case file header ---------- */
.file-head { display: flex; align-items: center; gap: 1.1rem; margin: .25rem 0 1rem; }
.stamp {
  flex: none; font: 1.6rem/1 var(--display); color: var(--red);
  border: 3px solid var(--red); border-radius: 6px; padding: .35rem .6rem .3rem;
  transform: rotate(-4deg); background: rgba(200, 32, 47, .06);
  font-variant-numeric: tabular-nums; min-width: 6.5ch; text-align: center;
}
.stamp small { font-size: .55em; color: var(--paper); opacity: .7; }
.stamp.solved { color: var(--manila); border-color: var(--manila); }
.file-meta { flex: 1; min-width: 0; }
.file-title { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: 0 0 .45rem; }
.file-meta h2 { font: 1.25rem/1.2 var(--display); margin: 0; min-width: 0; }
.lock {
  flex: none; display: inline-flex; align-items: center; gap: .35rem; cursor: pointer;
  border: 1px solid var(--navy-3); background: var(--navy-2); color: var(--muted);
  border-radius: 999px; padding: .25rem .7rem .25rem .55rem; font-size: .82rem; font-weight: 700;
}
.lock svg { width: 15px; height: 15px; fill: currentColor; stroke: currentColor; }
.lock:hover { color: var(--paper); border-color: var(--muted); }
.lock.open { color: var(--navy); background: var(--manila); border-color: var(--manila); }
.lock.open .shackle { transform: translate(4px, -2px) rotate(18deg); transform-origin: 13px 9px; }
.bar { height: 8px; background: var(--navy-3); border-radius: 4px; overflow: hidden; }
.bar { display: flex; }
.bar span { display: block; height: 100%; width: 0; background: var(--manila); transition: width .4s ease; }
.bar .px { background: repeating-linear-gradient(135deg, var(--manila) 0 4px, var(--manila-dk) 4px 8px); opacity: .75; }
.file-stats { margin: .35rem 0 0; color: var(--muted); font-size: .85rem; }

/* ---------- filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  padding: .6rem; background: var(--navy-2); border-radius: var(--r);
  position: sticky; top: 52px; z-index: 4;
}
.filters input[type=search], .filters select {
  background: var(--navy); border: 1px solid var(--navy-3); border-radius: 6px;
  padding: .38rem .6rem; min-height: 34px;
}
.filters input[type=search] { flex: 1 1 180px; min-width: 0; }
.seg { display: flex; border: 1px solid var(--navy-3); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: .35rem .7rem; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--navy-3); }
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--navy); font-weight: 700; }
.colors { display: flex; gap: 5px; }
.chip {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; background: var(--c); box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
  opacity: .55; transition: opacity .15s, transform .15s;
}
.chip[aria-pressed="true"] { opacity: 1; border-color: var(--paper); transform: scale(1.08); }
.count { color: var(--muted); font-size: .85rem; margin: .75rem .1rem .5rem; }

/* ---------- card grid ---------- */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
}
.card { position: relative; }
.card .art {
  display: block; width: 100%; padding: 0; border: 0; background: var(--navy-2);
  border-radius: 6px; overflow: hidden; cursor: pointer; aspect-ratio: 63 / 88;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter .2s, opacity .2s; }
.card.case img { object-fit: contain; }
.card.missing img { filter: grayscale(1) brightness(.55); }
.card .meta { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-top: 4px; }
.card .num { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qty { display: flex; align-items: center; background: var(--navy-2); border-radius: 5px; }
.qty button {
  border: 0; background: transparent; width: 24px; height: 24px; cursor: pointer;
  color: var(--paper); font-size: 1rem; line-height: 1; border-radius: 5px;
}
.qty button:hover { background: var(--navy-3); }
.qty button:disabled { opacity: .3; cursor: default; background: transparent; }
.qty output { min-width: 1.4ch; text-align: center; font-weight: 700; font-size: .85rem; font-variant-numeric: tabular-nums; }
.card .badge {
  position: absolute; top: 5px; right: 5px; pointer-events: none;
  background: var(--red); color: #fff; font: .72rem/1 var(--display);
  padding: .25rem .4rem; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
/* proxy tag on the tile: always shown when set, otherwise on hover/focus (and faintly on touch screens) */
.proxy-tag {
  position: absolute; top: 5px; left: 5px; border: 0; cursor: pointer;
  font: 700 .68rem/1 var(--body); padding: .28rem .45rem; border-radius: 4px;
  background: rgba(22, 33, 63, .85); color: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.4);
  opacity: 0; transition: opacity .15s;
}
.card:hover .proxy-tag, .proxy-tag:focus-visible { opacity: 1; }
@media (hover: none) { .card.missing .proxy-tag { opacity: .7; } }
.proxy-tag.on { opacity: 1; background: var(--manila); color: var(--navy); }
.card.proxied .art { outline: 2px dashed var(--manila); outline-offset: -2px; }
.card.proxied img { filter: saturate(.75); }
.bought-tag {
  position: absolute; left: 5px; bottom: 34px; pointer-events: none;
  font: 700 .68rem/1 var(--body); padding: .28rem .45rem; border-radius: 4px;
  background: var(--sky); color: var(--navy); box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.card.bought .art { outline: 2px solid var(--sky); outline-offset: -2px; }

/* ---------- overview ---------- */
.overview h2 { font: 1.2rem/1.2 var(--display); margin: .5rem 0 1rem; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; max-width: 720px; }
.board li {
  display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .75rem;
  background: var(--navy-2); padding: .65rem .85rem; border-radius: var(--r); cursor: pointer;
  border-left: 4px solid var(--manila);
}
.board li:hover { background: var(--navy-3); }
.board .rank { font: 1rem var(--display); color: var(--manila); text-align: center; }
.board .who { font-weight: 700; }
.board .bar { display: flex; margin-top: .35rem; height: 6px; }
.board .n { font: 1rem var(--display); font-variant-numeric: tabular-nums; min-width: 10.5rem; text-align: right; }
.board .n small { color: var(--muted); font: .8rem var(--body); }

/* ---------- detail dialog ---------- */
dialog {
  border: 0; padding: 0; border-radius: 12px; max-width: min(860px, 94vw); width: 100%;
  background: var(--navy-2); color: var(--paper); box-shadow: 0 20px 60px rgba(0,0,0,.6);
  border-top: 5px solid var(--manila);
}
dialog::backdrop { background: rgba(8, 12, 28, .75); }
.d-close { position: absolute; top: .4rem; right: .5rem; margin: 0; }
.d-close button { border: 0; background: transparent; font-size: 1.8rem; line-height: 1; cursor: pointer; color: var(--muted); padding: .2rem .5rem; }
.d-close button:hover { color: var(--paper); }
.d-body { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 1.25rem; padding: 1.25rem; }
.d-body > img { width: 100%; border-radius: 8px; align-self: start; }
.d-num { white-space: pre; margin: 0; color: var(--manila); font-weight: 700; font-variant-numeric: tabular-nums; }
.d-info h3 { font: 1.45rem/1.25 var(--display); margin: .1rem 2rem .6rem 0; }
.d-counts { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-bottom: .35rem; }
.d-qty { display: flex; align-items: center; gap: .45rem; }
.d-label { font-size: .85rem; color: var(--muted); min-width: 5.5rem; }
.d-qty.proxy output { color: var(--manila); }
.d-qty.bought output { color: var(--sky); }
.d-qty.proxy { cursor: pointer; min-height: 34px; }
.switch {
  appearance: none; width: 40px; height: 22px; border-radius: 11px; margin: 0 .2rem 0 0; cursor: pointer;
  background: var(--navy-3); position: relative; transition: background .15s; flex: none;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--paper); transition: transform .15s;
}
.switch:checked { background: var(--manila); }
.switch:checked::after { transform: translateX(18px); }
.d-switch-text { font-size: .85rem; color: var(--muted); }
.d-counts { flex-direction: column; gap: .45rem; }
.d-qty .d-received {
  width: auto; padding: 0 .75rem; font-size: .85rem; font-weight: 700;
  background: var(--sky); color: var(--navy); border-color: var(--sky);
}
.d-qty button:disabled { opacity: .35; cursor: default; }
.d-hint { margin: 0 0 .9rem; font-size: .8rem; color: var(--muted); }
.d-qty button {
  width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--navy-3);
  background: var(--navy); cursor: pointer; font-size: 1.15rem;
}
.d-qty button:hover { border-color: var(--manila); }
.d-qty output { font: 1.3rem var(--display); min-width: 2ch; text-align: center; }
.d-who-label { color: var(--muted); font-size: .85rem; margin: -.3rem 0 .4rem; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .9rem; margin: 0 0 .9rem; font-size: .9rem; }
dt { color: var(--muted); }
dd { margin: 0; }
.d-text { font-size: .9rem; white-space: pre-line; max-height: 14rem; overflow: auto; padding-right: .25rem; }
.d-text p { margin: 0 0 .6rem; padding: .55rem .7rem; background: var(--navy); border-radius: 6px; }
.d-text a { color: var(--manila); }
.d-owners h4 { font: .95rem var(--display); margin: .6rem 0 .35rem; }
.d-owners ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.d-owners li { background: var(--navy); border-radius: 999px; padding: .15rem .65rem; font-size: .85rem; }
.d-owners li.proxy-only { border: 1px dashed var(--manila); color: var(--manila); }
.d-owners li.none { color: var(--muted); background: transparent; padding-left: 0; }

/* ---------- PIN prompt ---------- */
.pin-dlg { max-width: min(360px, 92vw); }
.pin-dlg form { padding: 1.2rem 1.25rem 1.1rem; }
.pin-dlg h3 { font: 1.15rem/1.25 var(--display); margin: 0 0 .35rem; }
.pin-help { margin: 0 0 1rem; color: var(--muted); font-size: .88rem; }
.pin-row { display: flex; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.pin-row span { width: 3.2rem; color: var(--muted); font-size: .85rem; }
.pin-row input {
  flex: 1; min-width: 0; background: var(--navy); border: 1px solid var(--navy-3); border-radius: 8px;
  padding: .5rem .7rem; font: 1.35rem/1 var(--display); letter-spacing: .45em; text-align: center;
}
.pin-row input:focus { border-color: var(--manila); outline: none; }
.pin-msg { min-height: 1.3em; margin: .2rem 0 .7rem; color: #ff8a92; font-size: .85rem; }
.pin-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.pin-actions button {
  border: 1px solid var(--manila); background: var(--manila); color: var(--navy);
  font-weight: 700; border-radius: 8px; padding: .45rem 1rem; cursor: pointer;
}
.pin-actions button.ghost { background: transparent; color: var(--paper); border-color: var(--navy-3); }
.pin-actions button:disabled { opacity: .6; cursor: default; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1rem; transform: translate(-50%, 150%);
  background: var(--paper); color: var(--navy); padding: .55rem 1rem; border-radius: 8px;
  font-weight: 700; transition: transform .25s; z-index: 20; max-width: 92vw;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--red); color: #fff; }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .top { flex-direction: column; align-items: stretch; gap: .35rem; padding-top: .5rem; }
  .brand { padding-bottom: 0; }
  .filters { position: static; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: .45rem; }
  .stamp { font-size: 1.25rem; }
  .d-body { grid-template-columns: 1fr; }
  .d-body > img { max-width: 240px; justify-self: center; }
  .colors { order: 5; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
