* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
}

body {
  background:
    radial-gradient(
      circle at 50% 50%,
      rgba(6, 12, 24, .9) 0%,
      rgba(1, 3, 8, .98) 45%,
      #000 82%
    );
}

.scene {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

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

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;

  background:
    radial-gradient(
      ellipse at center,
      transparent 30%,
      rgba(0,0,0,.22) 66%,
      rgba(0,0,0,.72) 100%
    );
}

.controls {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 20;
  width: min(320px, calc(100vw - 32px));
  padding: 14px 14px 12px;
  border: 1px solid rgba(120, 157, 255, .18);
  border-radius: 14px;
  background: rgba(2, 7, 18, .62);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: rgba(224, 234, 255, .9);
  font-family: "PS2 Site", Arial, sans-serif;
  box-shadow: 0 0 28px rgba(24, 54, 140, .12);
}

.control-row + .control-row {
  margin-top: 12px;
}

.control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 12px;
  letter-spacing: .04em;
}

.control-value {
  min-width: 52px;
  text-align: right;
  color: rgba(163, 191, 255, .95);
  font-variant-numeric: tabular-nums;
}

.controls input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: #6f91ff;
}

.controls button {
  width: 100%;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(120, 157, 255, .18);
  border-radius: 9px;
  background: rgba(19, 38, 88, .34);
  color: rgba(217, 229, 255, .85);
  font: inherit;
  font-size: 11px;
  letter-spacing: .04em;
  cursor: pointer;
}

.controls button:active {
  transform: scale(.99);
}

/* ---- Type ----
   All lettering is Two Weekend Go (CSM's own type, with the rounded,
   Japanese-console look of the PlayStation and Nintendo menus). The PS2
   font (btseps2) is CSM's logo: only the word "CSM" is set in it. */
@font-face {
  font-family: "PS2 Site";
  src: url("../assets/fonts/twoweekendgo-semibold.otf") format("opentype");
  font-display: block;
  font-weight: 100 900;
}
@font-face {
  font-family: "PS2 System";
  src: url("../assets/fonts/btseps2.ttf") format("truetype");
  font-display: block;
}

/* ---- On-screen display: lettering over the scene (visuals/osd.js) ---- */

.osd {
  position: absolute;
  inset: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: "PS2 Site", Arial, Helvetica, sans-serif;
  color: #f4f6fb;
  /* The PS2 outlines its white type in dark grey. */
  --outline: rgba(28, 30, 36, .92);
  text-shadow:
    -1.5px -1.5px 0 var(--outline), 1.5px -1.5px 0 var(--outline),
    -1.5px 1.5px 0 var(--outline), 1.5px 1.5px 0 var(--outline),
    0 2px 6px rgba(0, 0, 0, .45);
  z-index: 5;
}
.osd > div {
  position: absolute;
  inset: 0;
  transition: opacity .9s ease, visibility 0s linear 0s;
  will-change: opacity;
}
/* Lettering that has gone takes no touches (once it has faded). */
.osd > div:not(.shown) {
  visibility: hidden;
  transition: opacity .9s ease, visibility 0s linear .9s;
}

.osd-clock .osd-left,
.osd-clock .osd-right {
  position: absolute;
  top: max(22px, env(safe-area-inset-top));
  font-size: clamp(15px, 4.5vw, 28px);
  letter-spacing: .03em;
  white-space: nowrap;
}
.osd-clock .osd-left { left: 6vw; }
.osd-clock .osd-right { right: 6vw; }

.osd-save .osd-card {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  left: 5vw;
  right: 38vw;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.osd-save .osd-card-icon {
  flex: none;
  width: clamp(18px, 5.6vw, 34px);
  aspect-ratio: 1;
  margin-top: 3px;
  background: #050506;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 3px 8px rgba(0, 0, 0, .5);
}
.osd-save .osd-title {
  font-size: clamp(18px, 5.4vw, 34px);
  line-height: 1.08;
  overflow-wrap: anywhere;
}
.osd-save .osd-lines {
  margin-top: 4px;
  font-size: clamp(13px, 3.7vw, 22px);
  line-height: 1.25;
}
.osd-save .osd-aside {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: 5vw;
  max-width: 34vw;
  text-align: right;
  color: #f2e93a;
  font-size: clamp(13px, 3.9vw, 26px);
  line-height: 1.12;
}

/* The CSM logo: the word CSM, wherever it is written. */
.osd-logo {
  font-family: "PS2 System", Arial, Helvetica, sans-serif;
  letter-spacing: .04em;
}

/* A tower's top tracks (its contributions), low on the left. */
.osd-save .osd-list {
  position: absolute;
  left: 5vw;
  right: 5vw;
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 14px));
  font-size: clamp(12px, 3.5vw, 18px);
  line-height: 1.35;
}
.osd-save .osd-list-title { color: #f2e93a; margin-bottom: 4px; }
.osd-save .osd-list-rows > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Words beside things in the space (a tower's albums). */
.osd-labels > .osd-label {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 52vw;
  font-size: clamp(12px, 3.6vw, 17px);
  line-height: 1.15;
  white-space: nowrap;
  will-change: transform;
}
.osd-label .osd-label-text { overflow: hidden; text-overflow: ellipsis; }
.osd-label .osd-label-sub { font-size: .82em; color: rgba(236, 240, 250, .78); }
.osd-label.strong .osd-label-text { font-size: 1.12em; }
.osd-label.strong .osd-label-sub { color: #f2e93a; }
.osd-label.left { text-align: right; }

/* Settings: the PS2's System Configuration kind of list, over the middle
   of the screen; it scrolls, and a tap on a line does it. */
.osd-settings {
  display: flex;
  flex-direction: column;
  padding: calc(max(20px, env(safe-area-inset-top)) + 6px) 5vw max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(4, 6, 12, .5) 0%, rgba(4, 6, 12, .66) 30%, rgba(4, 6, 12, .72) 100%);
}
.osd-settings-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 4px; }
.osd-settings-title { color: #f2e93a; font-size: clamp(20px, 6vw, 30px); }
.osd-back, .osd-row, .osd-tab, .osd-rail button {
  pointer-events: auto;
  font: inherit;
  font-family: "PS2 Site", Arial, sans-serif;
  color: inherit;
  text-shadow: inherit;
  background: none;
  border: 0;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.osd-back { font-size: clamp(14px, 4vw, 18px); color: rgba(236, 240, 250, .85); padding: 4px 0; }
.osd-settings-body {
  pointer-events: auto;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 30px;
  /* lines leave softly under the title as you scroll */
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 12px);
  mask-image: linear-gradient(180deg, transparent 0, #000 12px);
}
.osd-section { margin: 14px 0 22px; }
.osd-section-title { color: #f2e93a; font-size: clamp(15px, 4.4vw, 21px); margin-bottom: 6px; }
.osd-section-status { font-size: clamp(11px, 3.2vw, 15px); color: rgba(236, 240, 250, .75); margin-top: 6px; line-height: 1.3; }
.osd-section-status.good { color: #bff5db; }
.osd-section-status.bad { color: #ffc4c4; }
.osd-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  font-size: clamp(15px, 4.4vw, 21px);
  padding: 8px 10px;
  border-radius: 3px;
  cursor: pointer;
}
.osd-row:active { background: rgba(160, 190, 255, .16); box-shadow: inset 3px 0 0 #9fc0ff; }
.osd-row.info { cursor: default; color: rgba(236, 240, 250, .74); font-size: clamp(12px, 3.5vw, 16px); padding: 4px 10px; }
.osd-row.disabled { opacity: .42; cursor: default; }
.osd-row-value { color: #f2e93a; flex: none; }
.osd-row.input, .osd-row.file { flex-direction: column; align-items: stretch; gap: 4px; }
.osd-row-input {
  font: inherit; font-family: "PS2 Site", Arial, sans-serif; color: #f4f6fb;
  background: rgba(0, 0, 0, .35); border: 0; border-bottom: 1px solid rgba(200, 215, 255, .5);
  padding: 4px 2px; outline: none; width: 100%;
}
.osd-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.osd-row.file .osd-row-text::before { content: "＋ "; color: #9fc0ff; }
.osd-row.progress { padding: 6px 10px; cursor: default; }
.osd-progress { display: block; height: 3px; background: linear-gradient(90deg, #9fc0ff, #f2e93a); border-radius: 2px; box-shadow: 0 0 8px rgba(159, 192, 255, .6); }

/* The browser's names: under each icon, beside each row, over each section. */
.osd-shelf > .osd-shelf-item {
  position: absolute;
  left: 0;
  top: 0;
  font-size: clamp(10px, 2.9vw, 14px);
  line-height: 1.15;
  will-change: transform;
}
.osd-shelf-item.grid { text-align: center; }
.osd-shelf-item .osd-shelf-text, .osd-shelf-item .osd-shelf-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.osd-shelf-item .osd-shelf-sub { font-size: .86em; color: rgba(236, 240, 250, .72); }
.osd-shelf-item.row { font-size: clamp(12px, 3.5vw, 16px); }
.osd-shelf-item.header { color: #f2e93a; font-size: clamp(13px, 3.8vw, 18px); max-width: 84vw; }
.osd-shelf-item.strong .osd-shelf-text { color: #f2e93a; }

/* The browser's tabs: the library's sections, one line that scrolls. */
.osd-tabs {
  pointer-events: auto;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -5vw 8px;
  padding: 0 5vw;
}
.osd-tabs::-webkit-scrollbar { display: none; }
.osd-tab {
  flex: none;
  font-size: clamp(13px, 3.8vw, 17px);
  padding: 6px 10px;
  color: rgba(236, 240, 250, .7);
  border-radius: 3px;
  white-space: nowrap;
}
.osd-tab.active { color: #f4f6fb; background: rgba(160, 190, 255, .16); box-shadow: inset 0 -2px 0 #9fc0ff; }

/* Narrow screens: the yellow label sits under the card's lines instead of
   beside it, so the title has the whole width. */
@media (max-aspect-ratio: 3/4) {
  .osd-save .osd-card { right: 5vw; }
  .osd-save .osd-title { font-size: clamp(20px, 6.6vw, 30px); }
  .osd-save .osd-lines { font-size: clamp(15px, 4.6vw, 21px); line-height: 1.3; }
  .osd-save .osd-aside {
    position: static;
    margin: 8px 0 0 calc(5vw + clamp(18px, 5.6vw, 34px) + 12px);
    text-align: left;
    max-width: none;
    font-size: clamp(14px, 4.3vw, 20px);
  }
  .osd-save { display: flex; flex-direction: column; padding-top: 0; }
  .osd-save .osd-card { position: relative; top: auto; left: auto; margin: max(20px, env(safe-area-inset-top)) 5vw 0; right: auto; }
}

/* The browser (the Directory hall, the Recap room): its search and choices
   low on the screen, in the PS2's lettering over a dark band; the A–Z rail
   down the right edge. Only these take a touch. */
.osd-browse .osd-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 26px 5vw max(18px, calc(env(safe-area-inset-bottom) + 10px));
  background: linear-gradient(180deg, rgba(4, 6, 12, 0) 0%, rgba(4, 6, 12, .72) 34%, rgba(4, 6, 12, .84) 100%);
}
.osd-browse .osd-bar-note {
  color: #f2e93a;
  font-size: clamp(11px, 3.2vw, 15px);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.osd-browse .osd-bar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
}
.osd-control {
  pointer-events: auto;
  font: inherit;
  font-family: "PS2 Site", Arial, sans-serif;
  font-size: clamp(14px, 4vw, 18px);
  color: #f4f6fb;
  text-shadow: inherit;
  background: rgba(0, 0, 0, .32);
  border: 0;
  border-bottom: 1px solid rgba(200, 215, 255, .5);
  border-radius: 2px;
  padding: 6px 8px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.osd-control:focus { border-bottom-color: #9fc0ff; background: rgba(20, 30, 60, .5); }
.osd-control:disabled { opacity: .55; }
.osd-control-search { flex: 1 1 100%; }
.osd-control-select {
  flex: 1 1 28%;
  min-width: 0;
  font-size: clamp(13px, 3.6vw, 17px);
  padding-right: 18px;
  background-image: linear-gradient(45deg, transparent 50%, #c8d6f0 50%), linear-gradient(135deg, #c8d6f0 50%, transparent 50%);
  background-position: calc(100% - 12px) 55%, calc(100% - 7px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.osd-control-select option { color: #111; text-shadow: none; }
.osd-control-date { flex: 1 1 40%; color-scheme: dark; }
.osd-browse .osd-rail {
  position: absolute;
  right: max(4px, env(safe-area-inset-right));
  top: 26%;
  bottom: 30%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.osd-rail button {
  pointer-events: auto;
  font: inherit;
  font-family: "PS2 Site", Arial, sans-serif;
  font-size: clamp(9px, 2.6vw, 13px);
  line-height: 1;
  color: rgba(236, 240, 250, .8);
  text-shadow: inherit;
  background: none;
  border: 0;
  padding: 1px 6px;
}
.osd-rail button.active { color: #f2e93a; }
