/* Retro Room — phase 8c: the look.
 *
 * Loaded last, so it overrides the functional styles in index.html without
 * those needing to know it exists. Nothing here changes layout or behaviour —
 * if this file were deleted the app would still work, just plainly.
 *
 * The brief was "retro / PS1 / quiet / slightly blurry / theme-accurate font /
 * animations". The "quiet" is the constraint that shapes the rest: the palette
 * is saturated but the motion is slow and low-contrast, so the menus read as
 * atmospheric rather than busy. Nothing animates while a game is running.
 */

:root {
  /* The four PlayStation logo colours, which is as era-accurate as a palette
     gets, pulled up slightly so they hold against a near-black ground. */
  --ps-red: #e8384f;
  --ps-yellow: #f2b134;
  --ps-green: #4cb96b;
  --ps-blue: #4a90d9;
  --ps-magenta: #dc7ab5;

  --ink: #e9ecf5;
  --ink-dim: #9aa3bd;
  --panel: rgba(18, 20, 30, 0.72);
  --edge: rgba(120, 132, 175, 0.28);

  --font-display: 'Press Start 2P', 'Courier New', monospace;
  --font-body: 'VT323', 'Courier New', monospace;
}

/* ---- Stacking ----
 * `body`'s background propagates to the viewport canvas, which paints over any
 * pseudo-element sitting at a negative z-index — so the drifting layer was
 * rendering and being covered. Keep the dark ground on `html`, make `body`
 * transparent, and stack forwards instead of backwards.
 */
html { background: #07080d; }
body { background: transparent; }
#app { position: relative; z-index: 1; }

/* ---- Moving background ----
 * Three slowly drifting blurred blobs over a dark ground. Heavily blurred on
 * purpose: "slightly blurry" reads as depth, and it also means the animation
 * can be coarse and cheap without looking it. Fixed and behind everything, so
 * no layout is affected.
 */

body::before {
  content: '';
  position: fixed;
  inset: -25%;
  z-index: 0;
  background:
    radial-gradient(38% 42% at 22% 28%, rgba(232, 56, 79, 0.30), transparent 70%),
    radial-gradient(34% 38% at 78% 24%, rgba(74, 144, 217, 0.30), transparent 70%),
    radial-gradient(40% 44% at 52% 82%, rgba(76, 185, 107, 0.22), transparent 70%),
    radial-gradient(30% 34% at 86% 76%, rgba(242, 177, 52, 0.20), transparent 70%);
  filter: blur(68px) saturate(125%);
  animation: drift 46s ease-in-out infinite alternate;
  will-change: transform;
}

@keyframes drift {
  0%   { transform: translate3d(-3%, -2%, 0) scale(1.04) rotate(0deg); }
  50%  { transform: translate3d(3%, 2%, 0) scale(1.12) rotate(4deg); }
  100% { transform: translate3d(-2%, 3%, 0) scale(1.06) rotate(-3deg); }
}

/* Scanlines. Very low contrast — at full strength this stops being a texture
   and starts being a filter you have to read through. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.022) 0 1px,
    transparent 1px 3px
  );
}

/* A game is on screen: stop all of it. The stage covers the background anyway,
   so animating it would be pure battery cost on a phone. */
body.playing::before { animation: none; opacity: 0; }
body.playing::after { display: none; }

/* Someone who has asked the OS for less motion gets the palette without the
   movement — the look does not depend on the drift. */
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* ---- Type ---- */

body {
  font-family: var(--font-body);
  font-size: 19px;          /* VT323 runs small and condensed */
  color: var(--ink);
  letter-spacing: 0.01em;
}

#picker h1,
#library h1,
#settings h1 {
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1.7;
  letter-spacing: 0.02em;
  color: #fff;
  /* Offset colour ghosts rather than a glow: closer to a CRT's convergence
     error than to a neon sign, and it stays legible. */
  text-shadow:
    -2px 0 rgba(232, 56, 79, 0.55),
    2px 0 rgba(74, 144, 217, 0.55),
    0 3px 18px rgba(0, 0, 0, 0.7);
  animation: title-in 600ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes title-in {
  from { opacity: 0; transform: translateY(8px); letter-spacing: 0.16em; }
  to   { opacity: 1; transform: none; letter-spacing: 0.02em; }
}

.settings-group h2,
.library-item h3 {
  font-family: var(--font-display);
  font-size: 11px;
  line-height: 1.8;
  letter-spacing: 0.02em;
  color: var(--ink);
}

#picker p,
.settings-group p,
#library-empty {
  font-size: 18px;
  color: var(--ink-dim);
}

#picker p.warn { color: var(--ps-yellow); }
#status[data-tone='error'] { color: var(--ps-red); }

/* ---- Navigation ---- */

#main-nav { gap: 8px; }

.nav-btn {
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.04em;
  padding: 11px 13px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  color: var(--ink-dim);
  backdrop-filter: blur(8px);
  transition: color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}

.nav-btn:hover { color: var(--ink); border-color: rgba(74, 144, 217, 0.6); }
.nav-btn:active { transform: translateY(1px); }

.nav-btn.active {
  color: #fff;
  border-color: rgba(74, 144, 217, 0.85);
  box-shadow: 0 0 0 1px rgba(74, 144, 217, 0.35), 0 6px 22px rgba(74, 144, 217, 0.22);
}

/* ---- Surfaces ---- */

.settings-group,
.library-item {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  animation: rise 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Cards arrive in sequence rather than all at once. Cheap, and it makes the
   library feel assembled instead of dumped. */
.settings-group:nth-child(1), .library-item:nth-child(1) { animation-delay: 0ms; }
.settings-group:nth-child(2), .library-item:nth-child(2) { animation-delay: 55ms; }
.settings-group:nth-child(3), .library-item:nth-child(3) { animation-delay: 110ms; }
.settings-group:nth-child(4), .library-item:nth-child(4) { animation-delay: 165ms; }
.settings-group:nth-child(5), .library-item:nth-child(5) { animation-delay: 220ms; }
.settings-group:nth-child(n+6), .library-item:nth-child(n+6) { animation-delay: 275ms; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.settings-group:hover,
.library-item:hover {
  border-color: rgba(120, 132, 175, 0.5);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
}

/* A thin colour bar down the left of each settings card, cycling the four
   logo colours, so the menu has colour without anything shouting. */
.settings-group { position: relative; overflow: hidden; }
.settings-group::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--ps-blue);
}
.settings-group:nth-of-type(4n+1)::before { background: var(--ps-red); }
.settings-group:nth-of-type(4n+2)::before { background: var(--ps-yellow); }
.settings-group:nth-of-type(4n+3)::before { background: var(--ps-green); }
.settings-group:nth-of-type(4n+4)::before { background: var(--ps-blue); }

/* ---- Buttons ---- */

#pick-btn {
  font-family: var(--font-display);
  font-size: 11px;
  line-height: 1.7;
  padding: 16px 22px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, rgba(74, 144, 217, 0.9), rgba(41, 92, 156, 0.9));
  border: 1px solid rgba(140, 190, 240, 0.45);
  box-shadow: 0 8px 26px rgba(74, 144, 217, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 120ms ease, box-shadow 160ms ease, filter 160ms ease;
}
#pick-btn:hover { filter: brightness(1.1); box-shadow: 0 10px 32px rgba(74, 144, 217, 0.42); }
#pick-btn:active { transform: translateY(2px) scale(0.985); }

#picker-join-btn,
.settings-group button,
.library-item-actions button {
  font-family: var(--font-display);
  font-size: 9px;
  line-height: 1.8;
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(30, 34, 48, 0.85);
  border: 1px solid var(--edge);
  color: var(--ink);
  transition: transform 110ms ease, border-color 160ms ease, background 160ms ease;
}
#picker-join-btn:hover,
.settings-group button:hover,
.library-item-actions button:hover {
  border-color: rgba(74, 144, 217, 0.65);
  background: rgba(40, 46, 66, 0.9);
}
#picker-join-btn:active,
.settings-group button:active,
.library-item-actions button:active { transform: translateY(1px) scale(0.97); }

.library-item-actions button.delete,
.settings-group button.danger {
  color: var(--ps-red);
  border-color: rgba(232, 56, 79, 0.4);
}
.library-item-actions button.delete:hover,
.settings-group button.danger:hover {
  background: rgba(232, 56, 79, 0.14);
  border-color: rgba(232, 56, 79, 0.75);
}

/* ---- Play chrome keeps the type, loses the decoration ---- */

#play-toolbar button,
#ui-toggle {
  font-family: var(--font-display);
  font-size: 9px;
  line-height: 1.6;
  backdrop-filter: blur(6px);
}

#rotate-hint {
  font-family: var(--font-display);
  font-size: 10px;
  line-height: 1.9;
  animation: nudge 2.4s ease-in-out infinite;
}

@keyframes nudge {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  50%      { transform: translate(-50%, -50%) rotate(-7deg); }
}

/* Monospace stays monospace — a pixel font in the diagnostics dump would make
   it unreadable, and that panel exists to be read and pasted. */
#diag-output { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Library was full-bleed while Settings was centred at 600px; with cards now
   carrying a visible surface the difference read as a bug. */
#library {
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}
.library-item small { font-size: 16px; color: var(--ink-dim); }
.library-item h3 { font-size: 11px; }

/* #settings and #library are flex columns, so their cards were being shrunk
   below their content height. That was always happening; adding `overflow:
   hidden` for the colour bar turned invisible overlap into visible clipping.
   The containers already scroll, so the cards simply must not shrink. */
.settings-group,
.library-item { flex: none; }

/* Owner tag above the title — small, quiet, and in the display face so it
   reads as part of the sign rather than a stray line of body text. */
#owner-tag {
  margin: 0 0 2px !important;
  font-family: var(--font-display);
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.12em;
  color: var(--ps-yellow);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  animation: title-in 600ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ---- Library: featured game + strip (phase 8f) ---- */

#library-hero {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--edge);
  backdrop-filter: blur(10px);
  flex: none;
  overflow: hidden;
}

/* Re-applied by removing and re-adding the class, so each swap replays. */
#library-hero.swapping #hero-art,
#library-hero.swapping #hero-info { animation: hero-swap 420ms cubic-bezier(0.16, 1, 0.3, 1) both; }
#library-hero.swapping #hero-info { animation-delay: 60ms; }

@keyframes hero-swap {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: none; }
}

#hero-art {
  flex: none;
  width: 104px;
  height: 121px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.55);
}
#hero-art .game-art { display: block; width: 100%; height: 100%; }

#hero-info { min-width: 0; }

#hero-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 12px;
  line-height: 1.7;
  color: #fff;
  /* Long ROM names are the norm, and they must not push the buttons off. */
  overflow-wrap: anywhere;
}

#hero-meta { margin: 0 0 12px; font-size: 16px; color: var(--ink-dim); }

#hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }

#hero-play {
  font-family: var(--font-display);
  font-size: 10px;
  line-height: 1.7;
  padding: 12px 16px;
  border-radius: 10px;
  color: #fff;
  border: 1px solid rgba(140, 190, 240, 0.45);
  background: linear-gradient(135deg, rgba(74, 144, 217, 0.92), rgba(41, 92, 156, 0.92));
  box-shadow: 0 6px 20px rgba(74, 144, 217, 0.3);
  cursor: pointer;
}
#hero-play:active { transform: translateY(2px) scale(0.985); }

#hero-delete {
  font-family: var(--font-display);
  font-size: 9px;
  line-height: 1.8;
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(30, 34, 48, 0.85);
  border: 1px solid rgba(232, 56, 79, 0.4);
  color: var(--ps-red);
  cursor: pointer;
}
#hero-delete:hover { background: rgba(232, 56, 79, 0.14); border-color: rgba(232, 56, 79, 0.75); }

/* The strip below: rows that *feature* a game rather than launching it. */
#library-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.library-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  cursor: pointer;
}

.library-thumb {
  flex: none;
  width: 44px;
  height: 51px;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}
.library-thumb .game-art { display: block; width: 100%; height: 100%; }

.library-item-info { min-width: 0; }
.library-item h3 { margin: 0 0 3px; overflow-wrap: anywhere; }

/* Which row the hero is currently showing. */
.library-item.featured {
  border-color: rgba(74, 144, 217, 0.75);
  box-shadow: 0 0 0 1px rgba(74, 144, 217, 0.3), 0 8px 24px rgba(0, 0, 0, 0.4);
}

@media (max-width: 620px) {
  #library-hero { gap: 12px; padding: 12px; }
  #hero-art { width: 78px; height: 91px; }
  #hero-title { font-size: 10px; }
  #hero-meta { font-size: 15px; margin-bottom: 10px; }
}

/* The initials on generated cover art. Set here rather than as an SVG
   font-family attribute: a multi-word family is not parsed from that attribute
   unquoted, and it silently inherited the body face instead. */
.game-art text { font-family: var(--font-display); }

/* ---- Arabic (phase 8g) ----
 * Press Start 2P and VT323 contain no Arabic glyphs, so in Arabic both faces
 * would fall back to whatever the system offers and the look would collapse.
 * Cairo carries the whole UI instead — heavier weights stand in for the pixel
 * display face, which is the closest thing available without a pixel Arabic
 * font existing.
 */
:root[lang='ar'] {
  --font-display: 'Cairo', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Cairo', 'Segoe UI', system-ui, sans-serif;
}
:root[lang='ar'] body { font-size: 15px; letter-spacing: 0; }
:root[lang='ar'] #picker h1,
:root[lang='ar'] #library h1,
:root[lang='ar'] #settings h1 { font-size: 24px; font-weight: 800; }
:root[lang='ar'] .settings-group h2,
:root[lang='ar'] .library-item h3,
:root[lang='ar'] #hero-title { font-size: 15px; font-weight: 700; }
:root[lang='ar'] .nav-btn,
:root[lang='ar'] #pick-btn,
:root[lang='ar'] #picker-join-btn,
:root[lang='ar'] .settings-group button,
:root[lang='ar'] #hero-play,
:root[lang='ar'] #hero-delete,
:root[lang='ar'] #play-toolbar button,
:root[lang='ar'] #ui-toggle { font-size: 13px; font-weight: 700; letter-spacing: 0; }
:root[lang='ar'] #picker p,
:root[lang='ar'] .settings-group p,
:root[lang='ar'] #hero-meta,
:root[lang='ar'] #library-empty { font-size: 14px; }
:root[lang='ar'] #owner-tag { font-size: 13px; letter-spacing: 0; }

/* The game area is never mirrored: the canvas, the toolbar and the on-screen
   pad are laid out in physical directions on purpose, so the d-pad stays under
   the left thumb whichever language the menus are in. */
#stage, #touch-overlay, #touch-panel, #play-toolbar { direction: ltr; }

/* ---- Language switch ---- */
#lang-switch { display: flex; gap: 6px; margin-bottom: 4px; }
.lang-btn {
  appearance: none;
  font-family: var(--font-display);
  font-size: 9px;
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--edge);
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease;
}
.lang-btn[lang='ar'] { font-family: 'Cairo', system-ui, sans-serif; font-size: 12px; font-weight: 700; }
.lang-btn:hover { color: var(--ink); }
.lang-btn.active {
  color: #fff;
  border-color: rgba(74, 144, 217, 0.85);
  box-shadow: 0 0 0 1px rgba(74, 144, 217, 0.3);
}

/* ---- "Add to home screen" panel (phase 8g) ----
 * Takes real space rather than being a dismissible strip: the point is that
 * someone who has only ever opened this in a tab learns there is a better way
 * to keep it. It sits above everything except a running game.
 */
#install-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 7, 11, 0.72);
  backdrop-filter: blur(6px);
  animation: install-in 340ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes install-in { from { opacity: 0; } to { opacity: 1; } }

#install-card {
  max-width: 420px;
  width: 100%;
  padding: 22px;
  text-align: center;
  border-radius: 16px;
  background: rgba(18, 20, 30, 0.96);
  border: 1px solid var(--edge);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: rise 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

#install-icon img { display: block; margin: 0 auto 12px; border-radius: 12px; }

#install-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 12px;
  line-height: 1.8;
  color: #fff;
}

#install-why, #install-how { margin: 0 0 12px; font-size: 17px; color: var(--ink-dim); line-height: 1.55; }
#install-how { color: var(--ps-yellow); }
#install-how:empty { display: none; }

#install-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

#install-do, #install-later {
  appearance: none;
  font-family: var(--font-display);
  font-size: 10px;
  line-height: 1.7;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
}
#install-do {
  color: #fff;
  border: 1px solid rgba(140, 190, 240, 0.45);
  background: linear-gradient(135deg, rgba(74, 144, 217, 0.92), rgba(41, 92, 156, 0.92));
}
#install-later {
  color: var(--ink-dim);
  border: 1px solid var(--edge);
  background: rgba(30, 34, 48, 0.85);
}
#install-do:active, #install-later:active { transform: translateY(1px) scale(0.98); }

:root[lang='ar'] #install-title { font-size: 17px; font-weight: 800; }
:root[lang='ar'] #install-why,
:root[lang='ar'] #install-how { font-size: 14px; }
:root[lang='ar'] #install-do,
:root[lang='ar'] #install-later { font-size: 13px; font-weight: 700; }
