/* Shared styling for the cabinet and the player.
   Deliberately self-contained: no external fonts or assets, so the whole
   thing works offline once the service worker has cached it. */

:root {
  --bg: #12111a;
  --bg-raised: #1d1b28;
  --edge: #2f2c40;
  --ink: #f4f2ff;
  --ink-dim: #a09cb8;
  --accent: #4f9d69;
  --touch-min: 56px; /* never build a tap target smaller than this */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont,
               "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  /* Kids will drag on the screen constantly; none of it should scroll,
     bounce, select text, or pop a callout menu. */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---------------------------------------------------------------- cabinet */

.cabinet {
  min-height: 100%;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.cabinet__head { text-align: center; }

.cabinet__title {
  margin: 0;
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.cabinet__sub {
  margin: 6px 0 0;
  color: var(--ink-dim);
  font-size: clamp(14px, 2.4vw, 17px);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  margin: 0 auto;
  width: 100%;
  max-width: 1100px;
  padding: 0;
  list-style: none;
}

.tile {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  min-height: 190px;
  padding: 20px;
  border: 1px solid var(--edge);
  border-radius: 20px;
  background:
    radial-gradient(120% 100% at 50% 0%, color-mix(in srgb, var(--tile-accent) 34%, transparent), transparent 70%),
    var(--bg-raised);
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.tile:active { transform: scale(0.97); border-color: var(--tile-accent); }

.tile__title { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
.tile__meta  { font-size: 14px; color: var(--ink-dim); }
.tile__blurb { font-size: 14px; color: var(--ink-dim); line-height: 1.35; }

.tile__hint {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tile-accent);
}

/* A file that cannot run still gets a tile, so the reason is visible rather
   than the game just missing. Not a link, and visibly inert. */
.tile--broken {
  opacity: 0.55;
  border-style: dashed;
}

.tile--broken:active { transform: none; }

.tile__problem {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.35;
  color: #e0a3a3;
}

.notice {
  margin: 0 auto;
  max-width: 640px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 15px;
  line-height: 1.5;
}

/* ----------------------------------------------------------------- player */

.player { position: fixed; inset: 0; background: #000; }

#game { width: 100%; height: 100%; }

/* Small persistent way back to the cabinet. Positioned clear of the
   virtual gamepad and inside the safe area so it survives notches. */
.exit {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 60;
  min-width: var(--touch-min);
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  opacity: 0.35;
  transition: opacity 0.15s ease;
}

.exit:active { opacity: 1; }

/* Status shown while the core downloads, and for fatal errors. */
.status {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
  background: var(--bg);
}

.status[hidden] { display: none; }
.status__title { font-size: 24px; font-weight: 800; }
.status__body  { max-width: 34rem; color: var(--ink-dim); line-height: 1.5; }

.status__link {
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
  padding: 0 24px;
  border-radius: 999px;
  background: var(--accent);
  color: #06130b;
  font-weight: 800;
  text-decoration: none;
}

/* --------------------------------------------- EmulatorJS overrides
   EmulatorJS renders its own start button. We reuse it rather than
   building a parallel one, because its click handler is what unlocks
   WebAudio on iOS -- but we restyle it into something a child can hit. */

.ejs_start_button {
  min-width: min(340px, 74vw) !important;
  min-height: 92px !important;
  border-radius: 999px !important;
  background: var(--accent) !important;
  color: #06130b !important;
  font-family: inherit !important;
  font-size: 34px !important;
  font-weight: 900 !important;
  letter-spacing: 0.04em !important;
  border: none !important;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5) !important;
  animation: none !important;
}

/* Bigger, more legible virtual gamepad than the stock one.
   The action-button offsets in games.json are px within a ~130px-wide zone
   anchored at the screen edge, so they are tuned against this size -- change
   one and re-check the other. */
.ejs_virtualGamepad_parent .ejs_virtualGamepad_button {
  min-width: 66px;
  min-height: 66px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.ejs_virtualGamepad_parent .ejs_virtualGamepad_button_down {
  background: rgba(255, 255, 255, 0.42);
}

/* The d-pad is the least forgiving control on glass, so give it more
   contrast than the stock translucent grey. */
.ejs_virtualGamepad_parent .ejs_dpad_bar {
  background: rgba(255, 255, 255, 0.62);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
