/* PKCamp launcher. Layout: the game canvas fills the window behind; in launcher mode an opaque page
   sits on top (header, engine status, ROM import, game grid, credits); in game mode only a small menu button. */
:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2740;
  --line: #2a3552;
  --fg: #e9edf6;
  --muted: #9aa6c0;
  --red: #e3350d;      /* Poké Ball red */
  --red-2: #ff5a36;
  --ok: #34c77b;
  --warn: #ffcb05;     /* the yellow of the logo, used for the Beta badge only */
  --display: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--body); }
body { overscroll-behavior: contain; }

#canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: #000; outline: none; }
#spinner { display: none !important; }
.mode-launcher #canvas { visibility: hidden; }

#launcher {
  position: fixed; inset: 0; overflow-y: auto; background:
    radial-gradient(1200px 500px at 85% -10%, rgba(227, 53, 13, 0.16), transparent 60%),
    radial-gradient(900px 400px at -10% 110%, rgba(64, 120, 255, 0.10), transparent 60%),
    var(--bg);
  padding-block: max(20px, env(safe-area-inset-top)) 32px;
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 18px; align-items: center;
}
.mode-game #launcher { display: none; }
#launcher > * { width: 100%; max-width: 1040px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 50%; flex: none; position: relative;
  background: linear-gradient(var(--red) 0 46%, #10131c 46% 54%, #f4f6fb 54%);
  box-shadow: 0 0 0 3px #10131c inset, 0 6px 18px rgba(227, 53, 13, .35);
}
.logo::after { content: ""; position: absolute; inset: 15px; border-radius: 50%; background: #f4f6fb; box-shadow: 0 0 0 4px #10131c; }
h1 { font-family: var(--display); font-size: 28px; margin: 0; letter-spacing: .5px; }
h2 { font-family: var(--display); font-size: 18px; margin: 0 0 10px; }
.tag { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.badge { font-size: 11px; vertical-align: middle; background: var(--warn); color: #1b1b1b; padding: 2px 7px; border-radius: 99px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.top-links a { color: var(--muted); text-decoration: none; font-size: 14px; border: 1px solid var(--line); padding: 7px 12px; border-radius: 8px; }
.top-links a:hover { color: var(--fg); border-color: var(--muted); }

.engine, .import { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.engine-row { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 8px; gap: 12px; }
.bar { height: 8px; border-radius: 99px; background: #0b0f18; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red), var(--red-2)); transition: width .25s; }
.engine.done { display: none; }

.import-box { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.import-box p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; max-width: 62ch; }
.import-box.drag { outline: 2px dashed var(--red-2); outline-offset: 6px; border-radius: 8px; }
.work { margin-top: 14px; }
.error { margin: 12px 0 0; color: #ffb4a6; background: rgba(227, 53, 13, .12); border: 1px solid rgba(227, 53, 13, .4); padding: 10px 12px; border-radius: 8px; font-size: 14px; }

.btn {
  font: 600 14px var(--body); color: var(--fg); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 9px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--red-2), var(--red)); border-color: #b52a09; }
.btn.ghost { background: transparent; }
.btn:focus-visible { outline: 2px solid var(--warn); outline-offset: 2px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.game { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.game.ready { border-color: rgba(52, 199, 123, .45); }
.game-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.game-name { font-family: var(--display); font-weight: 700; font-size: 17px; }
.gen { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.state { font-size: 13px; color: var(--muted); }
.game.ready .state { color: var(--ok); }
.slots { display: grid; gap: 6px; }
.slot { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; background: #121827; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.slot span:last-child { color: var(--muted); }
.game .btn { justify-content: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: 1px; }

.foot { color: var(--muted); font-size: 12px; line-height: 1.55; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 6px; }
.foot .warn { color: #ffd3c9; }
.foot a { color: #8fb6ff; }

.menu-btn {
  position: fixed; z-index: 20; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid #10131c; color: #fff; font: 700 12px var(--display);
  background: linear-gradient(var(--red) 0 50%, #f4f6fb 50%); opacity: .55; cursor: pointer; text-shadow: 0 1px 2px #000;
}
.menu-btn:hover { opacity: 1; }
.menu[hidden], .menu-btn[hidden] { display: none; }
.menu {
  position: fixed; z-index: 21; top: calc(max(10px, env(safe-area-inset-top)) + 48px); left: max(10px, env(safe-area-inset-left));
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; min-width: 190px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}

@media (max-width: 640px) {
  .import-box { flex-direction: column; align-items: stretch; }
  .import-box .btn { justify-content: center; }
  h1 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { .bar i { transition: none; } }

/* v2: game dialog, mods, news, storage, small buttons, phone layout */
.top-links { display: flex; align-items: center; gap: 8px; }
.top-links select { background: var(--panel-2); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: 600 13px var(--body); }
.btn.small { padding: 7px 11px; font-size: 13px; }
.dot.ok { background: var(--ok); }
.game-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.game-actions .btn.ghost { padding-inline: 14px; font-size: 18px; line-height: 1; }
.news { background: rgba(255, 203, 5, .08); border: 1px solid rgba(255, 203, 5, .35); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.storage { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

.dlg { width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 14px; padding: 0; box-shadow: 0 24px 80px rgba(0, 0, 0, .6); }
.dlg::backdrop { background: rgba(5, 8, 14, .7); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.dlg-head h2 { margin: 0 0 2px; }
.x { background: none; border: 1px solid var(--line); color: var(--fg); width: 34px; height: 34px; border-radius: 9px; font-size: 20px; cursor: pointer; flex: none; }
.dlg-body { padding: 14px 18px 18px; display: grid; gap: 12px; }
.dlg-body h3 { margin: 6px 0 0; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.slot.big { display: grid; gap: 8px; padding: 10px 12px; }
.slot.big .meta, .mod .meta { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.slot-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.danger-text { color: #ffb4a6 !important; }
.hint { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.5; }
.mods { display: grid; gap: 8px; }
.mod { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; background: #121827; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.mod .hint { margin-top: 4px; }
.danger { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 6px; justify-items: start; }
.toast { margin: 0; font-size: 13px; background: #121827; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; }
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .game { padding: 10px; gap: 6px; }
  .game-name { font-size: 15px; }
  .gen { font-size: 10px; }
  .state { font-size: 12px; }
  .slot-actions .btn { flex: 1 1 auto; justify-content: center; }
}
@media (max-width: 380px) { .grid { grid-template-columns: 1fr; } }

/* v3: entry like OTCamp. Wallpaper behind three screens (opening, sign in, loading); only one shows at a time. */
.wall {
  position: fixed; inset: 0; z-index: 1;
  background: linear-gradient(180deg, rgba(8, 11, 20, .25), rgba(8, 11, 20, .75)), url(img/wallpaper.webp) center / cover no-repeat, var(--bg);
  image-rendering: pixelated;
}
@media (max-width: 700px) { .wall { background-image: linear-gradient(180deg, rgba(8, 11, 20, .3), rgba(8, 11, 20, .8)), url(img/wallpaper-small.webp); } }
.mode-game .wall, .mode-game .screen { display: none !important; }
.screen {
  position: fixed; inset: 0; z-index: 2; display: none; overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left));
  flex-direction: column; align-items: center; gap: 16px;
}
.screen-boot #screen-boot, .screen-load #screen-load { display: flex; justify-content: center; }
.screen-auth #screen-auth { display: flex; }
.logo-img { display: block; width: 212px; height: auto; image-rendering: pixelated; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, .6)); }
.logo-img.small { width: 106px; }
.boot-bar { width: min(360px, 100%); height: 10px; border-radius: 99px; background: rgba(5, 8, 14, .75); border: 1px solid rgba(255, 255, 255, .12); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red), var(--warn)); transition: width .25s; }
.boot-text { margin: 0; color: #dfe5f2; font-size: 14px; text-shadow: 0 1px 3px #000; text-align: center; min-height: 1.4em; }
.load-title { margin: 0; font: 700 20px var(--display); text-shadow: 0 2px 6px #000; }
#screen-load .error { max-width: 420px; }

.auth-card {
  width: min(440px, 100%); margin-top: auto; background: rgba(15, 20, 32, .9); border: 1px solid var(--line); border-radius: 16px;
  padding: 18px 20px 20px; box-shadow: 0 24px 70px rgba(0, 0, 0, .55); backdrop-filter: blur(6px);
}
.auth-card:has(#hub:not([hidden])) { width: min(820px, 100%); }
.auth-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.auth-head select { margin-left: auto; background: var(--panel-2); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: 600 13px var(--body); }
.auth-card form { display: grid; gap: 10px; }
.auth-card form[hidden], #hub[hidden] { display: none; }
.auth-card h2 { margin: 0; }
.auth-card h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.auth-card label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.auth-card input:not([type=checkbox]):not([type=file]) {
  width: 100%; background: #0b0f18; color: var(--fg); border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px; font: 15px var(--body);
}
.auth-card input:focus-visible { outline: 2px solid var(--warn); outline-offset: 1px; }
.file { position: relative; display: flex; align-items: center; gap: 8px; background: #0b0f18; border: 1px dashed var(--muted); border-radius: 9px; padding: 11px 12px; cursor: pointer; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file b { font-weight: 600; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file::before { content: "📁"; }
.file:focus-within { outline: 2px solid var(--warn); outline-offset: 1px; }
.check { display: flex !important; grid-template-columns: none; align-items: flex-start; gap: 8px !important; }
.check input { margin-top: 2px; }
.check a, .auth-links a, .hub-user a { color: #8fb6ff; }
.btn.big { width: 100%; justify-content: center; padding: 13px 16px; font-size: 16px; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; flex-wrap: wrap; }
.ok-msg { margin: 0; color: #bff0d4; background: rgba(52, 199, 123, .12); border: 1px solid rgba(52, 199, 123, .4); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.auth-card .error { margin: 0; }
.hub-user { font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; margin-bottom: 10px; flex-wrap: wrap; }
.hub-user b { color: var(--fg); }
.hub-user a { margin-left: auto; }
#screen-auth .news, #screen-auth .foot { width: min(820px, 100%); }
#screen-auth .news { background: rgba(30, 26, 8, .85); }
#screen-auth .foot { margin-top: auto; background: rgba(8, 11, 20, .8); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.menu-cloud { margin: 0; font-size: 12px; color: var(--muted); max-width: 220px; }
.menu-cloud:empty { display: none; }
@media (max-width: 640px) {
  .auth-card { padding: 14px; border-radius: 14px; }
  .logo-img { width: 170px; }
}
@media (prefers-reduced-motion: reduce) { .boot-bar i { transition: none; } }
