:root {
  --table: #121318;
  --table-2: #1b1d25;
  --surface: #17181f;
  --surface-2: #1d1f28;
  --paper: #e7e9f2;
  --paper-dim: #a7abc2;
  --muted: #8b8fa6;
  --line: #2a2d3a;
  --accent: #8e64bf;
  --accent-2: #8090ec;
  --icon: #9aa0ff;
  --grad: linear-gradient(135deg, #9a6bd0, #5f7fe6);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--table);
  color: var(--paper);
  font: 500 .95rem/1.5 Onest, system-ui, sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "bar" "main" "dock";
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
::selection { background: #3b2f5a; color: var(--paper); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.bar {
  grid-area: bar;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 19, 24, .92);
  position: relative; z-index: 5;
}
.bar__head { min-width: 0; margin-right: auto; }
.back {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; margin-right: -4px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--icon);
  transition: border-color .2s;
}
.back:hover { border-color: #4a4f66; }
.bar h1 { font-size: clamp(1.15rem, 3.4vw, 1.5rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.15; margin: 0; white-space: nowrap; }
.bar__sub { margin: 2px 0 0; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.search { position: relative; flex: 0 1 380px; min-width: 0; display: flex; align-items: center; }
.search > svg { position: absolute; left: 13px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 42px; padding: 0 40px 0 40px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  color: var(--paper); font: 600 .92rem Onest, system-ui, sans-serif;
  transition: border-color .2s, background-color .2s;
}
.search input::placeholder { color: var(--muted); }
.search input:hover { border-color: #3a3e50; }
.search input:focus { outline: none; border-color: var(--accent-2); background: #20222c; }
.search input::-webkit-search-cancel-button { display: none; }
.search__clear { position: absolute; right: 6px; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.search__clear:hover { color: var(--paper); background: var(--surface); }
.search__clear[hidden], .sugg[hidden] { display: none; }
.search__clear svg { width: 16px; height: 16px; }
.sugg {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 10;
  margin: 0; padding: 6px; list-style: none;
  background: #191a22; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .5);
  max-height: min(60vh, 460px); overflow: auto;
}
.sugg li { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center; padding: 6px 8px; border-radius: 11px; cursor: pointer; }
.sugg li[aria-selected="true"], .sugg li:hover { background: #262838; }
.sugg img, .sugg .ph { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.sugg b { display: block; font-weight: 700; font-size: .9rem; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugg small { display: block; color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugg mark { background: none; color: var(--icon); }
.sugg .sugg__none { display: block; padding: 10px 12px; color: var(--muted); cursor: default; }

.seg { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; flex: none; }
.seg__b {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 99px; border: 0; background: transparent;
  color: var(--paper-dim); font-weight: 600; font-size: .86rem; cursor: pointer;
  transition: color .2s, background-color .2s;
}
.seg__b:hover { color: var(--paper); }
.seg__b[aria-pressed="true"] { background: #2b2440; color: var(--paper); }
.seg__b svg { width: 16px; height: 16px; color: var(--icon); }

/* ---------- shelf stage ---------- */
.stage {
  grid-area: main;
  position: relative; min-height: 0; overflow: hidden;
  background:
    radial-gradient(90% 60% at 50% -12%, #2a2c3d 0%, rgba(42, 44, 61, 0) 70%),
    radial-gradient(60% 40% at 50% 112%, #181a23 0%, rgba(24, 26, 35, 0) 70%),
    var(--table);
}
body[data-mode="list"] .stage { display: none; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl.is-hover { cursor: pointer; }
#gl.is-drag { cursor: grabbing; }
#gl:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent-2); }

.rowlabels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.rowlabel {
  position: absolute; left: 20px; transform: translateY(-50%);
  max-width: min(46vw, 420px);
  padding: 3px 10px 4px; border-radius: 99px;
  background: rgba(18, 19, 24, .8); border: 1px solid var(--line);
  font-size: .74rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--paper-dim);
}
.rowlabel b { color: var(--paper); font-weight: 700; }
.rowlabel.is-above { transform: translateY(-100%); }
.stage.is-picked .rowlabels { opacity: 0; transition: opacity .3s; }

.zoom { position: absolute; right: 56px; bottom: 18px; display: grid; gap: 6px; z-index: 2; }
.zoom button {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; border: 1px solid var(--line); background: rgba(29, 31, 40, .9); color: var(--paper); cursor: pointer;
  transition: border-color .2s, transform .2s var(--ease-out);
}
.zoom button:hover { border-color: #4a4f66; }
.zoom button:active { transform: scale(.96); }
.zoom svg { color: var(--icon); }
.stage.is-picked .zoom { opacity: 0; pointer-events: none; }

/* where the picked case lands (measured by JS) */
.slot { position: absolute; left: 4%; right: calc(380px + 6%); top: 7%; bottom: 7%; pointer-events: none; }

/* ---------- info panel ---------- */
.info {
  position: absolute; z-index: 3;
  right: 28px; top: 50%; width: 360px;
  transform: translateY(-50%);
  padding: 22px 22px 18px;
  background: rgba(23, 24, 31, .95);
  border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
  animation: info-in .5s var(--ease-out) both;
}
.info[hidden] { display: none; }
@keyframes info-in { from { opacity: 0; transform: translate(16px, -50%); } }
.info h2 { margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; text-wrap: balance; }
.info__meta { margin: 6px 0 0; color: var(--paper-dim); font-weight: 600; font-variant-numeric: tabular-nums; }
.info__facts { margin: 16px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: .88rem; }
.info__facts dt { color: var(--muted); }
.info__facts dd { margin: 0; overflow-wrap: anywhere; }
.info__facts a { color: var(--icon); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(154, 160, 255, .4); }
.info__acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--paper);
  font: 700 .88rem/1 Onest, system-ui, sans-serif; text-decoration: none; cursor: pointer;
  transition: border-color .2s, transform .2s var(--ease-out), box-shadow .2s;
}
.btn:hover { border-color: #4a4f66; }
.btn:active { transform: translateY(1px); }
.btn svg { color: var(--icon); }
.btn--primary { background: var(--grad); border: 0; color: #fff; box-shadow: 0 10px 22px rgba(95, 127, 230, .28); flex: 1 1 100%; justify-content: center; }
.btn--primary svg { color: #fff; }
.btn--primary:hover { box-shadow: 0 12px 26px rgba(95, 127, 230, .38); }
.btn--quiet { background: transparent; }
.info__hint { margin: 14px 0 0; color: var(--muted); font-size: .8rem; }
.info__more { display: none; }
/* about the game: a YouTube video (poster first, the player only on a click) and the description */
.info { max-height: calc(100% - 32px); overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #343747 transparent; }
.info__media[hidden] { display: none; }
.info__media { margin-top: 14px; }
.vbox[hidden] { display: none; }
.vthumb[hidden] { display: none; }
.vthumb, .vbox iframe { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 12px; overflow: hidden; background: #0d0e12; padding: 0; cursor: pointer; }
.vthumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .35s var(--ease-out); }
.vthumb:hover img { transform: scale(1.03); }
.vthumb__play { position: absolute; left: 50%; top: 50%; width: 56px; height: 40px; margin: -20px 0 0 -28px; display: grid; place-items: center; border-radius: 12px; background: rgba(18, 19, 24, .78); }
.vthumb__play svg { width: 22px; height: 22px; fill: #fff; stroke: none; }
.vthumb:hover .vthumb__play { background: #e62117; }
.vcap { margin: 6px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.35; }
.vcap a, .info__src a { color: var(--icon); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(154, 160, 255, .4); }
.info__desc { margin: 10px 0 0; font-size: .86rem; line-height: 1.5; color: var(--paper-dim); display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.info__desc.is-full { -webkit-line-clamp: unset; display: block; }
.info__src { margin: 4px 0 0; color: var(--muted); font-size: .74rem; }

.loading {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0;
  color: var(--paper-dim); font-weight: 600;
  transition: opacity .5s;
}
.loading.is-done { opacity: 0; pointer-events: none; }

/* ---------- A-Z index ---------- */
.az {
  grid-area: main; z-index: 4;
  justify-self: end; align-self: center;
  margin-right: 10px;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 3px; border-radius: 99px;
  background: rgba(23, 24, 31, .78); border: 1px solid var(--line);
  max-height: calc(100% - 24px); overflow: hidden;
}
.az button {
  width: 26px; height: 20px; padding: 0; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-size: .7rem; font-weight: 700; line-height: 20px; cursor: pointer;
}
.az button:hover { color: var(--paper); background: var(--surface-2); }
.az button[aria-current="true"] { color: #fff; background: #2b2440; }
.stage.is-picked ~ .az { opacity: 0; pointer-events: none; }

/* ---------- list (PS Store style grid) ---------- */
.list { grid-area: main; min-height: 0; overflow-y: auto; padding: 18px 56px 40px 20px; scrollbar-color: #343747 transparent; scrollbar-width: thin; }
.list[hidden] { display: none; }
.list__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 16px; }
.list__count { margin: 0; color: var(--paper-dim); font-weight: 600; font-variant-numeric: tabular-nums; }
.sort select {
  height: 38px; padding: 0 34px 0 12px; border-radius: 12px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa0ff' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line); color: var(--paper); font: 600 .86rem Onest, system-ui, sans-serif; appearance: none; cursor: pointer;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 16px; }
.tile { display: block; color: inherit; text-decoration: none; border-radius: 14px; outline-offset: 4px; }
.tile__cover {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--surface-2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 8px 18px rgba(0, 0, 0, .35);
  transition: transform .35s var(--ease-out), box-shadow .35s var(--ease-out);
}
.tile__cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile__poster {
  position: absolute; inset: 0; padding: 12px; display: flex; align-items: flex-end;
  background: linear-gradient(160deg, #262838, #15161c);
  font-weight: 800; font-size: .9rem; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere;
}
.tile__poster small { position: absolute; top: 10px; left: 12px; color: var(--muted); font-size: .66rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.tile:hover .tile__cover, .tile:focus-visible .tile__cover { transform: translateY(-4px); box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 16px 30px rgba(0, 0, 0, .5); }
.tile b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 10px; font-weight: 700; font-size: .9rem; line-height: 1.25; overflow-wrap: anywhere; }
.tile small { display: block; margin-top: 3px; color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tile.is-flash .tile__cover { box-shadow: 0 0 0 2px var(--accent-2), 0 16px 30px rgba(0, 0, 0, .5); }
.list__empty { color: var(--paper-dim); text-align: center; padding: 60px 0; }
#more { height: 1px; }

/* ---------- dock ---------- */
.dock {
  grid-area: dock;
  display: flex; align-items: center; justify-content: flex-end; gap: 18px;
  padding: 9px 20px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(18, 19, 24, .92);
}
.hint { margin: 0; color: var(--muted); font-size: .8rem; }
body[data-mode="list"] .dock { display: none; }
body[data-mode="list"] { grid-template-rows: auto 1fr 0; }

@media (max-width: 900px) {
  .bar { flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  .bar__sub { display: none; }
  .search { order: 3; flex: 1 1 100%; }
  /* 16px or iOS zooms the whole page in when the field gets focus */
  .search input { font-size: 16px; }
  .seg__b { padding: 6px 11px; font-size: .8rem; }
  .slot { left: 4%; right: 4%; top: 3%; bottom: 47%; }
  .info {
    left: 10px; right: 10px; top: auto; bottom: 10px; width: auto;
    transform: none; padding: 14px 14px 10px; border-radius: 18px;
    max-height: 62%; overflow: auto; overscroll-behavior: contain;
    display: flex; flex-direction: column;
    animation-name: info-up;
  }
  @keyframes info-up { from { opacity: 0; transform: translateY(16px); } }
  .info h2 { font-size: 1.05rem; order: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .info__meta { order: 2; margin-top: 2px; font-size: .86rem; }
  .info__acts { order: 3; margin-top: 10px; flex-wrap: nowrap; }
  .info__more {
    order: 4; display: flex; align-items: center; justify-content: center; gap: 6px;
    height: 32px; margin-top: 4px; border: 0; background: transparent;
    color: var(--muted); font-size: .8rem; font-weight: 600; cursor: pointer;
  }
  .info__more svg { width: 14px; height: 14px; transition: transform .25s var(--ease-out); }
  .info__more[aria-expanded="true"] svg { transform: rotate(180deg); }
  .info__facts { order: 5; display: none; margin-top: 4px; font-size: .84rem; }
  .info.is-more .info__facts { display: grid; }
  .info__media { order: 5; display: none; margin-top: 10px; }
  .info.is-more .info__media:not([hidden]) { display: block; }
  .btn--primary { flex: 1 1 auto; }
  .btn { height: 44px; padding: 0 13px; }
  .btn--m-icon { width: 44px; padding: 0; justify-content: center; font-size: 0; gap: 0; flex: none; }
  .btn--m-icon svg { width: 20px; height: 20px; }
  .info__hint { display: none; }
  /* the A-Z strip gets its own lane instead of covering the spines */
  body[data-mode="shelf"] .stage { margin-right: 32px; }
  .az { margin-right: 3px; padding: 4px 2px; background: none; border: 0; }
  .dock { display: none; }
  body { grid-template-rows: auto 1fr 0; }
  .rowlabel { left: 12px; max-width: calc(100% - 24px); }
  .zoom { right: auto; left: 12px; bottom: 12px; grid-auto-flow: column; }
  .list { padding: 14px 44px 30px 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 18px 12px; }
  .az button { width: 22px; height: 17px; line-height: 17px; font-size: .62rem; }
}

@media (prefers-reduced-motion: reduce) {
  .info { animation: none; }
  .btn, .seg__b, .loading, .tile__cover, .zoom button { transition: none; }
}

/* no WebGL: the list only, with a short note why */
.list__note { margin: 0 0 14px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--paper-dim); font-size: .88rem; }
body.no-gl .seg__b[data-mode="shelf"] { display: none; }
