/* sm64coopdx-web page: ROM screen and loading screen styled exactly like the game's DJUI menus (dark theme,
   centered panels: src/pc/djui/djui_theme.c, djui_panel_menu.c, djui_button.c, loading.c). Sizes are DJUI
   units times --s, which djui.js sets with the game's own UI-scale rule. No external fonts/images (CSP). */
:root { --s: 1; --blb-handoff: #000; }   /* = the html background (blb-site handoff.css) */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: #dcdcdc; overflow: hidden; }
body { font: 16px/1.4 system-ui, sans-serif; }
[hidden] { display: none !important; }

/* ---- game stage ---- */
#stage { position: fixed; inset: 0; display: none; background: #000; z-index: 0; }
canvas#canvas { width: 100%; height: 100%; display: block; outline: none; }

/* ---- DJUI text (drawn by djui.js with the game's bitmap fonts) ---- */
.dj { display: block; position: relative; min-height: 1px; }
.dj canvas { display: block; } /* scaled up smoothly by the browser on high-DPI screens, like the game canvas */
.dj[data-align="center"] canvas { margin: 0 auto; }
.dj[data-align="right"] canvas { margin-left: auto; }
.dj-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- panel: djui_panel_menu_create with the centered theme (width x1.3, height x0.921) ---- */
#setup { position: fixed; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; }
/* the arcade's EXIT link (handoff.css) sits in the corner, out of the flex centring that holds the ROM card */
#setup > .blb-exit { position: absolute; top: 14px; left: 14px; margin: 0; }
.dj-panel {
  position: relative;
  display: flex; flex-direction: column;
  width: calc(692px * var(--s));
  height: 92.1vh;
  max-width: calc(100vw - 8px);
  padding: calc(16px * var(--s));
  background: rgba(0, 0, 0, 0.902);                                   /* rectColor 0,0,0,230 */
  border: calc(8px * var(--s)) solid rgba(0, 0, 0, 0.784);              /* borderColor 0,0,0,200 */
  overflow-y: auto;
}
.dj-header { flex: none; height: calc(64px * var(--s)); }
.dj-body {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  gap: calc(16px * var(--s));                                          /* flow layout margin 16 */
}
.dj-body > .state { flex-direction: column; gap: calc(16px * var(--s)); }
/* main menu: logo (550x275) and buttons form one centred group, all nudged up 30 */
#rom-card { justify-content: center; padding-bottom: calc(44px * var(--s)); /* room for the footer line */ }
/* the add-a-ROM views hold more than the main menu does, so the logo is smaller there */
#rom-card:not([data-state="saved"]) > .dj-logo { width: calc(360px * var(--s)); height: calc(180px * var(--s)); margin-bottom: calc(8px * var(--s)); }
#rom-card > .dj-logo, #rom-card > .dj-body { flex: none; }
#rom-card[data-state="saved"] > .dj-logo, #rom-card[data-state="saved"] > .dj-body { transform: translateY(calc(-30px * var(--s))); }
.dj-logo {
  flex: none; align-self: center;
  width: calc(550px * var(--s)); height: calc(275px * var(--s)); max-width: 100%; object-fit: contain;
  margin-bottom: calc(16px * var(--s));
}
.dj-foot { position: absolute; left: calc(16px * var(--s)); right: calc(16px * var(--s)); bottom: calc(12px * var(--s)); }

/* one panel, several states: only the parts for the current data-state show */
.state { display: none; }
[data-state="pick"] .state-pick,
[data-state="checking"] .state-checking,
[data-state="error"] .state-error,
[data-state="saved"] .state-saved { display: flex; }

/* ---- buttons: djui_button.c, dark theme, with the menu-rect gradient (bottom = colour x 0x96/0xff) ---- */
.dj-btn {
  appearance: none; margin: 0; padding: 0; font: inherit; color: inherit;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: calc(50px * var(--s));
  border: calc(2px * var(--s)) solid rgb(75, 75, 75);                  /* defaultBorderColor */
  background: linear-gradient(rgb(22, 22, 22), rgb(13, 13, 13));       /* defaultRectColor */
  cursor: pointer; outline: none;
}
.dj-btn .dj { width: 100%; }
.dj-btn:hover, .dj-btn:focus-visible {
  border-color: rgb(0, 120, 215);                                      /* hoveredBorderColor */
  background: linear-gradient(rgb(80, 80, 80), rgb(47, 47, 47));        /* hoveredRectColor */
}
.dj-btn:hover .dj, .dj-btn:focus-visible .dj { transform: translate(calc(-1px * var(--s)), calc(-1px * var(--s))); }
.dj-btn:active {
  border-color: rgb(0, 84, 153);                                       /* cursorDownBorderColor */
  background: linear-gradient(rgb(100, 100, 100), rgb(59, 59, 59));    /* cursorDownRectColor */
}
.dj-btn:active .dj { transform: translate(calc(1px * var(--s)), calc(1px * var(--s))); }
/* DJUI_BUTTON_STYLE_BACK: default colours shaded x0.6 */
.dj-btn.back { border-color: rgb(45, 45, 45); background: linear-gradient(rgb(13, 13, 13), rgb(8, 8, 8)); }
.dj-btn.back:hover, .dj-btn.back:focus-visible { border-color: rgb(0, 120, 215); background: linear-gradient(rgb(80, 80, 80), rgb(47, 47, 47)); }
.dj-btn.back:active { border-color: rgb(0, 84, 153); background: linear-gradient(rgb(100, 100, 100), rgb(59, 59, 59)); }

/* left/right button pairs: each 0.485 of the width (djui_button_left/right_create) */
.dj-btn-row { display: flex; justify-content: space-between; }
.dj-btn-row > .dj-btn { width: 48.5%; }
.dj-btn-row > .dj-btn:only-child, .dj-btn-row > .dj-btn[hidden] + .dj-btn { width: 100%; }

/* ---- ROM drop area: a big DJUI rect that lights up like a hovered button ---- */
.dj-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: calc(10px * var(--s));
  height: calc(120px * var(--s));
  border: calc(2px * var(--s)) solid rgb(75, 75, 75);
  background: linear-gradient(rgb(22, 22, 22), rgb(13, 13, 13));
  cursor: pointer; outline: none;
}
.dj-drop .dj { width: 100%; }
.dj-drop > div { display: flex; flex-direction: column; gap: calc(10px * var(--s)); width: 100%; }
.dj-drop:hover, .dj-drop:focus-visible, .dj-drop.over {
  border-color: rgb(0, 120, 215);
  background: linear-gradient(rgb(80, 80, 80), rgb(47, 47, 47));
}
.drop-checking { display: none !important; }
[data-state="checking"] .drop-idle { display: none !important; }
[data-state="checking"] .drop-checking { display: flex !important; }
[data-state="checking"] .dj-drop { cursor: progress; }

/* ---- storage rows: label left, value right, like the host panel rows ---- */
#usage { display: flex; flex-direction: column; gap: calc(6px * var(--s)); }
.dj-row { display: flex; justify-content: space-between; align-items: center; }
.dj-row .dj { flex: 1; }

/* ---- loading screen: loading.c on a black screen ---- */
#loading { position: fixed; inset: 0; z-index: 5; background: #000; transition: opacity .2s ease; }
#loading.done { opacity: 0; pointer-events: none; }
/* status text: a 3-line box centred on the screen; logo sits right above it; bar 64 below, half width */
#load-text { position: absolute; left: 0; right: 0; top: calc(50% - 48px * var(--s)); padding: 0 8vw; }
.load-logo {
  position: absolute; left: 50%; transform: translateX(-50%);
  width: calc(512px * var(--s)); height: calc(256px * var(--s)); max-width: 92vw; object-fit: contain;
  top: calc(50% - 48px * var(--s) - 256px * var(--s));
}
.load-bar {                                                             /* djui_progress_bar: border 2 (173), fill 220 */
  position: absolute; left: 25%; width: 50%;
  top: calc(50% + 48px * var(--s) + 64px * var(--s));
  height: calc(16px * var(--s));
  border: calc(2px * var(--s)) solid rgb(173, 173, 173);
}
.load-fill { height: 100%; width: 0; background: linear-gradient(rgb(220, 220, 220), rgb(129, 129, 129)); transition: width .25s ease-out; }
.load-failed {
  display: none; position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(50% + 48px * var(--s) + 40px * var(--s)); width: min(calc(320px * var(--s)), 80vw);
  flex-direction: column; align-items: stretch; gap: calc(16px * var(--s));
}
#loading[data-state="failed"] .load-failed { display: flex; }
#loading[data-state="failed"] .load-bar { display: none; }
.details { color: #8c8c8c; font-size: 12px; }
.details summary { cursor: pointer; text-align: center; }
#log {
  white-space: pre-wrap; font: 11px/1.4 ui-monospace, monospace; color: #a0a0a0; text-align: left;
  max-height: 22vh; overflow: auto; background: #111; border: 1px solid #333; padding: 8px; margin: 8px 0 0;
}

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