/* ==========================================================================
   PSP-3000 XMB portfolio
   Sizes scale with --u (set from JS, ~1 on a 1000px-wide window).
   ========================================================================== */

:root {
  --u: 1;
  --ax: 240px;              /* x of the focused column, set from JS */
  --accent: #2f86d0;
  --font: "M PLUS 1p", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", system-ui, sans-serif;
  --ease: cubic-bezier(.22, .7, .28, 1);
  --glow: 0 0 calc(var(--u) * 8px) rgba(255, 255, 255, .45);
  --shadow: 0 1px 3px rgba(0, 0, 0, .45);
}

/* Photo wallpapers can be light, so white text gets a stronger dark outline */
body.wallpaper-theme {
  --shadow: 0 1px 2px rgba(45, 22, 6, .9), 0 0 6px rgba(45, 22, 6, .55);
  --glow: 0 0 calc(var(--u) * 10px) rgba(45, 22, 6, .6);
}
body.wallpaper-theme .battery { box-shadow: 0 0 3px rgba(45, 22, 6, .8); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: #fff;
  font-family: var(--font);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* The screen frame. Its transform makes it the containing block for the fixed
   elements inside, so in PSP Screen mode everything sits in the 480:272 frame. */
#screen {
  position: fixed; left: 0; top: 0;
  width: 100vw; height: 100vh;
  overflow: hidden;
  transform: translateZ(0);
  --sw: 100vw;
}

#wave { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- Status bar ---------- */

#status {
  position: fixed;
  top: calc(env(safe-area-inset-top) + var(--u) * 14px);
  right: calc(env(safe-area-inset-right) + var(--u) * 20px);
  display: flex; align-items: center; gap: calc(var(--u) * 10px);
  font-size: calc(var(--u) * 15px);
  letter-spacing: .02em;
  text-shadow: var(--shadow);
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s;
}
body.ready #status { opacity: 1; }


.battery {
  position: relative;
  display: inline-flex; gap: calc(var(--u) * 1.5px);
  width: calc(var(--u) * 28px); height: calc(var(--u) * 13px);
  padding: calc(var(--u) * 1.5px);
  border: calc(var(--u) * 1.5px) solid #fff;
  border-radius: calc(var(--u) * 2px);
  box-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.battery::after {
  content: ""; position: absolute; right: calc(var(--u) * -4.5px); top: 25%;
  width: calc(var(--u) * 3px); height: 50%; background: #fff; border-radius: 0 1px 1px 0;
}
.battery i { flex: 1; background: #fff; border-radius: 1px; }
.battery i.off { opacity: .15; }
.battery.charging i { animation: charge 1.5s steps(1) infinite; }
.battery.charging i:nth-child(2) { animation-delay: .5s; }
.battery.charging i:nth-child(3) { animation-delay: 1s; }
@keyframes charge { 0% { opacity: 1; } 66% { opacity: .15; } }

/* ---------- XMB ---------- */

#xmb {
  position: fixed; inset: 0;
  touch-action: none;
  transition: opacity .35s var(--ease), transform .45s var(--ease);
}
#xmb.away { opacity: 0; transform: scale(1.04); pointer-events: none; }
#xmb.intro { opacity: 0; transform: translateX(calc(var(--u) * 60px)); }

.ico { width: 100%; height: 100%; display: block; color: #fff; overflow: visible; }
img.ico { object-fit: contain; -webkit-user-drag: none; }
/* Image icons include transparent padding, so draw them a little larger than the SVGs */
.cat img.ico { transform: scale(1.18); }
.item-icon > img.ico { width: calc(var(--u) * 64px); height: calc(var(--u) * 64px); }
.detail-icon img.ico { width: 92px; height: 92px; }
.link-btn img.ico { width: 22px; height: 22px; margin: -2px 0; }

.cat {
  position: absolute; left: 0; top: 0;
  width: calc(var(--u) * 70px); height: calc(var(--u) * 70px);
  margin: calc(var(--u) * -35px) 0 0 calc(var(--u) * -35px);
  cursor: pointer;
  transition: transform .24s var(--ease), opacity .24s;
}
.cat .ico {
  filter: drop-shadow(0 0 calc(var(--u) * 5px) rgba(255,255,255,.3)) drop-shadow(0 2px 3px rgba(0,0,0,.35));
  opacity: .82;
  transition: opacity .2s, filter .2s;
}
.cat.sel .ico {
  opacity: 1;
  filter: drop-shadow(0 0 calc(var(--u) * 9px) rgba(255,255,255,.7)) drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.cat-label {
  position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  margin-top: calc(var(--u) * 7px);
  font-size: calc(var(--u) * 15px);
  white-space: nowrap;
  text-shadow: var(--shadow), var(--glow);
  opacity: 0;
  transition: opacity .18s;
}
.cat.sel .cat-label { opacity: 1; }

.col {
  position: absolute; left: 0; top: 0;
  --iw: calc(var(--u) * 62px);
  --ih: calc(var(--u) * 62px);
  opacity: 0;
  pointer-events: none;
  transition: transform .24s var(--ease), opacity .18s;
}
.col.tiles { --iw: calc(var(--u) * 116px); --ih: calc(var(--u) * 64px); }
.col.sel { opacity: 1; pointer-events: auto; transition: transform .24s var(--ease), opacity .3s .05s; }

.item {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: center;
  height: var(--ih);
  margin: calc(var(--ih) / -2) 0 0 calc(var(--iw) / -2);
  cursor: pointer;
  transition: transform .22s var(--ease), opacity .22s;
}
.item-icon {
  flex: none;
  width: var(--iw); height: var(--ih);
  display: grid; place-items: center;
  transform: scale(.7);
  opacity: .8;
  transition: transform .22s var(--ease), opacity .22s;
}
.item-icon > .ico {
  width: calc(var(--u) * 48px); height: calc(var(--u) * 48px);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.3));
}
.item.sel .item-icon { transform: scale(1); opacity: 1; }
.item.sel .item-icon > .ico { filter: drop-shadow(0 0 calc(var(--u) * 8px) rgba(255,255,255,.6)) drop-shadow(0 2px 3px rgba(0,0,0,.3)); }

.item-text {
  position: relative;
  margin-left: calc(var(--u) * 12px);
  max-width: calc(var(--sw) - var(--ax) - var(--iw) / 2 - var(--u) * 12px - 16px);
}
.item-title {
  font-size: calc(var(--u) * 17px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: var(--shadow);
  opacity: .78;
  transition: opacity .2s, text-shadow .2s;
}
.item.sel .item-title { opacity: 1; font-weight: 500; text-shadow: var(--shadow), var(--glow); }
.item-sub {
  position: absolute; top: 100%; left: 0;
  width: max-content;
  max-width: calc(var(--sw) - var(--ax) - var(--iw) / 2 - var(--u) * 12px - 16px);
  margin-top: calc(var(--u) * 2px);
  font-size: calc(var(--u) * 12.5px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s;
}
.item.sel .item-sub { opacity: .85; }

/* PSP "ICON0"-style game tiles */
.tile {
  position: relative;
  width: 100%; height: 100%;
  border-radius: calc(var(--u) * 3px);
  background:
    linear-gradient(160deg, rgba(255,255,255,.35), rgba(255,255,255,0) 45%),
    linear-gradient(135deg, var(--a, #444), var(--b, #111));
  box-shadow: 0 2px 8px rgba(0,0,0,.4), inset 0 0 0 1px rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.tile span {
  font-weight: 700;
  font-size: calc(var(--u) * 17px);
  letter-spacing: .08em;
  text-transform: uppercase;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.tile::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.05) 0 2px, transparent 2px 6px);
}
.item.sel .tile { box-shadow: 0 0 calc(var(--u) * 14px) rgba(255,255,255,.45), inset 0 0 0 1px rgba(255,255,255,.35); }

.item-icon { position: relative; }

/* Photo thumbnails in the Photo column */
.tile.photo { background: #111 center / cover no-repeat; }
.tile.photo::after { display: none; }

/* ---------- Hints ---------- */

#hints {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 20px);
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: flex; gap: 18px;
  font-size: 12px;
  text-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .8s;
  pointer-events: none;
}
body.ready #hints { opacity: .75; }
body.ready #hints.gone { opacity: 0; }
#hints kbd { font-family: inherit; font-size: 11px; opacity: .9; margin-right: 3px; }
.for-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .for-keys { display: none; }
  .for-touch { display: inline; }
  #hints { left: 0; right: 0; justify-content: center; }
}

/* PSP face buttons */
.btn {
  display: inline-grid; place-items: center;
  width: 1.45em; height: 1.45em;
  margin-right: .35em;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
  font-size: .9em; font-weight: 700; line-height: 1;
  vertical-align: -.25em;
}
.btn-x { color: #8fb8ff; }
.btn-o { color: #ff8f8f; }

/* ---------- Information screen ---------- */

#detail {
  position: fixed; inset: 0;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s var(--ease);
}
#detail.open { opacity: 1; pointer-events: auto; }

.detail-scroll {
  position: absolute;
  top: calc(env(safe-area-inset-top) + var(--u) * 64px);
  bottom: calc(env(safe-area-inset-bottom) + 64px);
  left: max(16px, 9%); right: max(16px, 9%);
  max-width: 860px;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.35) transparent;
  padding-right: 6px;
  transform: translateY(14px);
  transition: transform .45s var(--ease);
  user-select: text; -webkit-user-select: text;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
          mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
  padding-bottom: 28px;
}
#detail.open .detail-scroll { transform: none; }

.detail-head { display: flex; align-items: center; gap: 22px; margin-bottom: 22px; }
.detail-icon {
  flex: none;
  width: 92px; height: 92px;
  display: grid; place-items: center;
  --u: 1.5;
}
.detail-icon .ico { width: 76px; height: 76px; filter: drop-shadow(0 0 10px rgba(255,255,255,.5)); }
.detail-icon.is-tile { width: 176px; height: 98px; }
.detail-icon.is-tile .tile span { font-size: 24px; }
.detail-head h1 {
  margin: 0;
  font-size: clamp(22px, 3.2vw, 32px);
  font-weight: 500;
  line-height: 1.2;
  text-shadow: var(--shadow), 0 0 14px rgba(255,255,255,.35);
}
.detail-head p { margin: 6px 0 0; font-size: 15px; opacity: .8; text-shadow: var(--shadow); }

.detail-meta { margin: 0 0 22px; border-top: 1px solid rgba(255,255,255,.28); }
.detail-meta .row {
  display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: 16px;
  padding: 9px 4px;
  border-bottom: 1px solid rgba(255,255,255,.18);
  font-size: 14.5px;
  text-shadow: var(--shadow);
}
.detail-meta dt { opacity: .7; }
.detail-meta dd { margin: 0; }
.detail-meta:empty { display: none; }

.detail-body { font-size: 15.5px; line-height: 1.75; text-shadow: var(--shadow); max-width: 68ch; }
.detail-body p { margin: 0 0 14px; }
.detail-body ul { margin: 0 0 14px; padding-left: 1.2em; }
.detail-body li { margin-bottom: 8px; }
.detail-body li::marker { color: rgba(255,255,255,.6); }
.detail-body a { color: #fff; }

.detail-groups:empty, .detail-links:empty { display: none; }
.detail-group { margin: 18px 0; }
.detail-group h2 {
  font-size: 13px; font-weight: 500; letter-spacing: .14em; text-transform: uppercase;
  opacity: .7; margin: 0 0 10px;
}
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  padding: 5px 12px;
  font-size: 13px;
  border-radius: 999px;
  background: rgba(0,0,0,.22);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.3);
}

.detail-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.link-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  border-radius: 4px;
  font-size: 14.5px;
  color: #fff; text-decoration: none;
  background: rgba(0,0,0,.28);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.3);
  transition: background .2s, box-shadow .2s;
}
.link-btn .ico { width: 18px; height: 18px; }
.link-btn.sel {
  background: rgba(255,255,255,.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.85), 0 0 16px rgba(255,255,255,.35);
}

.hintbar {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  display: flex; justify-content: flex-end; gap: 22px;
  padding: 0 max(16px, 4%);
  font-size: 14px;
  text-shadow: var(--shadow);
}
.hintbar::before {
  content: ""; position: absolute; left: 0; right: 0; top: -12px;
  height: 1px; background: linear-gradient(90deg, transparent, rgba(255,255,255,.35) 30%, rgba(255,255,255,.35) 70%, transparent);
}
.hint { display: inline-flex; align-items: center; padding: 4px 2px; }
#detail-open[hidden] { display: none; }

/* ---------- Photo viewer ---------- */

#photo-viewer {
  position: fixed; inset: 0;
  z-index: 11;
  background: #000;
  opacity: 0; pointer-events: none;
  transition: opacity .3s var(--ease);
  touch-action: none;
}
#photo-viewer.open { opacity: 1; pointer-events: auto; }
body.viewing #status { opacity: 0; }
#pv-img {
  position: absolute; left: 0; top: 0;
  width: 100%; height: calc(100% - 52px - env(safe-area-inset-bottom));
  object-fit: contain;
  transition: opacity .25s ease;
  -webkit-user-drag: none;
}
#pv-img.loading { opacity: 0; }
.pv-bar {
  position: absolute; left: 0; right: 0;
  top: calc(env(safe-area-inset-top) + 14px);
  display: flex; justify-content: space-between; gap: 16px;
  padding: 0 max(16px, 3%);
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
  pointer-events: none;
}
#pv-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pv-count { opacity: .75; flex: none; }
.pv-nav {
  position: absolute; top: 50%;
  width: 48px; height: 72px; margin-top: -36px;
  font-size: 44px; line-height: 1;
  color: #fff; opacity: .35;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  transition: opacity .2s;
}
.pv-nav:hover { opacity: .9; }
.pv-nav.prev { left: max(8px, 1.5%); }
.pv-nav.next { right: max(8px, 1.5%); }
.pv-nav[hidden] { display: none; }
#photo-viewer .hintbar { align-items: center; }
#photo-viewer kbd { font-family: inherit; opacity: .8; }

/* ---------- Option list (right side panel) ---------- */

#picker {
  position: fixed; top: 0; bottom: 0; right: 0;
  z-index: 12;
  width: min(360px, 62%);
  padding: calc(env(safe-area-inset-top) + 70px) 0 40px;
  display: flex; flex-direction: column;
  background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,.55) 18%, rgba(0,0,0,.62));
  transform: translateX(100%);
  transition: transform .28s var(--ease);
}
#picker.open { transform: none; }
#picker::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 18%;
  width: 1px; background: linear-gradient(transparent, rgba(255,255,255,.35) 20%, rgba(255,255,255,.35) 80%, transparent);
}
.picker-title {
  padding: 0 24px 14px calc(18% + 24px);
  font-size: 13px; letter-spacing: .12em; text-transform: uppercase; opacity: .65;
}
.picker-list {
  list-style: none; margin: 0; padding: 0 0 0 18%;
  overflow-y: auto; scrollbar-width: none;
  flex: 1;
}
.picker-list::-webkit-scrollbar { display: none; }
.picker-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 24px;
  font-size: 15.5px;
  cursor: pointer;
  opacity: .72;
  transition: opacity .15s, background .15s;
}
.picker-list li .swatch {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
}
.picker-list li.current::after { content: "●"; margin-left: auto; font-size: 8px; opacity: .8; }
.picker-list li.sel {
  opacity: 1;
  background: linear-gradient(90deg, rgba(255,255,255,.2), rgba(255,255,255,.04));
  text-shadow: var(--glow);
}

/* PSP Screen mode: scale the option panel with the rest of the UI */
body.psp-screen #picker { width: 40%; padding-top: calc(var(--u) * 52px); }
body.psp-screen .picker-title { font-size: calc(var(--u) * 10px); padding-bottom: calc(var(--u) * 10px); }
body.psp-screen .picker-list li { font-size: calc(var(--u) * 13px); padding: calc(var(--u) * 7px) calc(var(--u) * 18px); }

/* ---------- Dialog ---------- */

#dialog {
  position: fixed; inset: 0;
  z-index: 20;
  display: grid; place-items: center;
  background: rgba(0,0,0,.35);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#dialog.open { opacity: 1; pointer-events: auto; }
.dialog-box {
  width: 100%;
  padding: 30px 16px 26px;
  text-align: center;
  background: linear-gradient(rgba(0,0,0,.35), rgba(0,0,0,.6) 50%, rgba(0,0,0,.35));
  border-top: 1px solid rgba(255,255,255,.55);
  border-bottom: 1px solid rgba(255,255,255,.55);
  transform: scaleY(.6);
  transition: transform .22s var(--ease);
}
#dialog.open .dialog-box { transform: none; }
.dialog-msg { margin: 0 auto; max-width: 560px; font-size: 17px; line-height: 1.6; text-shadow: var(--shadow); word-break: break-word; }
.dialog-btns { display: flex; justify-content: center; gap: 36px; margin-top: 22px; }
.dialog-btn {
  min-width: 110px; padding: 8px 20px;
  border-radius: 4px; font-size: 15.5px;
  opacity: .75;
}
.dialog-btn.sel {
  opacity: 1;
  background: rgba(255,255,255,.16);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.8), 0 0 14px rgba(255,255,255,.3);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
