:root {
  color-scheme: dark;
  --bg: #12141a;
  --card: #1c2030;
  --text: #e8e6e3;
  --muted: #a3a0b0;
  --accent: #6ea8fe;
  --line: #2c3348;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
/* v20261011g — 方案 A 像素风（近似，非图内原字体）
   英文标题: Press Start 2P (OFL, 自托管)
   中文/正文: Fusion Pixel Font 12px proportional zh_hans+latin（基于 Ark Pixel 等，OFL）
*/
@font-face {
  font-family: "Press Start 2P";
  src: url("/fonts/PressStart2P-Regular.woff2") format("woff2"),
       url("/fonts/PressStart2P-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fusion Pixel 12";
  src: url("/fonts/fusion-pixel-12px-zh_hans.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+4E00-9FFF, U+3400-4DBF, U+F900-FAFF, U+3000-303F, U+FF00-FFEF;
}
@font-face {
  font-family: "Fusion Pixel 12";
  src: url("/fonts/fusion-pixel-12px-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

* { box-sizing: border-box; }
/* Standalone + black-translucent: fill screen so UIKit black does not show at bottom */
html {
  margin: 0; padding: 0;
  background-color: #0a0c10;
  height: 100%;
  height: -webkit-fill-available;
}
body {
  margin: 0; padding: 0;
  background-color: transparent; color: var(--text);
  font-family: "Fusion Pixel 12", "Press Start 2P", ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
  text-rendering: geometricPrecision;
  display: flex; flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
  min-height: 100lvh;
  min-height: -webkit-fill-available;
  position: relative;
  isolation: isolate; /* keep ::before above html bg, below content */
}
/* v20261011d — 纯遗迹无 UI（/tmp/emugame-a9-ruins-only.jpg）；竖屏 cover；浅蒙版；卡片半透明无 blur */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #1a1520; /* warm dark fallback if image late */
  /* jpg first — always valid on iOS Safari; light veil so ruins stay visible */
  background-image:
    linear-gradient(180deg, rgba(8, 10, 16, 0.10) 0%, rgba(8, 10, 16, 0.16) 55%, rgba(8, 10, 16, 0.28) 100%),
    url("/assets/a9-ruins.jpg");
  background-position: 50% 45%;
  background-size: cover;
  background-repeat: no-repeat;
}
/* Optional webp when supported (does not replace jpg if this fails) */
@supports (background-image: -webkit-image-set(url("/assets/a9-ruins.webp") 1x)) {
  body::before {
    background-image:
      linear-gradient(180deg, rgba(8, 10, 16, 0.10) 0%, rgba(8, 10, 16, 0.16) 55%, rgba(8, 10, 16, 0.28) 100%),
      -webkit-image-set(
        url("/assets/a9-ruins.webp") 1x,
        url("/assets/a9-ruins.jpg") 1x
      );
  }
}
body > * {
  position: relative;
  z-index: 1;
}
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, var(--safe-t)) max(16px, var(--safe-r)) 10px max(16px, var(--safe-l));
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(10, 12, 18, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.brand h1 {
  margin: 0;
  font-family: "Press Start 2P", "Fusion Pixel 12", monospace;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
  font-weight: 400;
  -webkit-font-smoothing: none;
  font-smooth: never;
}
.sub {
  margin: 6px 0 0; color: var(--muted); font-size: 12px;
  font-family: "Fusion Pixel 12", "Press Start 2P", monospace;
  letter-spacing: 0;
}
.auth-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.page {
  flex: 1; width: 100%; max-width: 960px; margin: 0 auto;
  padding: 12px max(16px, var(--safe-r)) 0 max(16px, var(--safe-l));
  display: flex; flex-direction: column; min-height: 0;
}
.sections {
  display: flex; gap: 4px; padding: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10); margin-bottom: 14px;
  background: transparent;
}
.sections button {
  font-family: "Fusion Pixel 12", "Press Start 2P", monospace;
  font-size: 12px; line-height: 1.25;
  border: 0; border-radius: 0; padding: 10px 14px 12px;
  background: transparent; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  -webkit-font-smoothing: none; font-smooth: never;
}
.sections button:hover { color: var(--text); }
.sections button.on {
  background: transparent; color: var(--text);
  border-bottom-color: var(--accent); font-weight: 600;
}
main { flex: 1; min-height: 0; }
/* Lobby: do not stretch empty card over the ruins — height follows content */
body:not(.gba-tab) main {
  flex: 0 1 auto;
}
#panelLobby {
  height: auto;
  min-height: 0;
  width: 100%;
  align-self: flex-start;
}
#panelLobby .card {
  height: auto;
  min-height: 0;
  width: 100%;
}
.lobby-list:empty {
  display: none;
  margin: 0;
  min-height: 0;
}
.panel[hidden] { display: none !important; }
.card {
  /* v20261011b: no blur; translucent; height follows content (see #panelLobby) */
  background: rgba(10, 14, 24, 0.55); border-radius: 14px; padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}
.card .card-head h2,
.card .hint,
.card .msg,
.card .lobby-title,
.card .lobby-sub {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2 {
  margin: 0; font-size: 24px; line-height: 1.25; font-weight: 400;
  font-family: "Fusion Pixel 12", "Press Start 2P", monospace;
  -webkit-font-smoothing: none; font-smooth: never;
}
.hint, .muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
#panelLobby .card > .hint { margin: 4px 0 0; }
#lobbyAuth:not([hidden]) + .lobby-list:empty { display: none; }
.msg { color: #ffb4b4; min-height: 1.2em; font-size: 12px; }
code { font-size: 12px; background: #12151e; padding: 0.1em 0.35em; border-radius: 4px; }
button.secondary, .btn {
  font-family: "Fusion Pixel 12", "Press Start 2P", monospace;
  font-size: 12px; line-height: 1.25;
  border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: #2c3348; color: var(--text); text-decoration: none; display: inline-block;
  -webkit-font-smoothing: none; font-smooth: never;
}
.btn { background: var(--accent); color: #081018; font-weight: 600; width: 100%; }
label { display: block; margin: 10px 0; font-size: 12px; }
input, .auth-input {
  width: 100%; margin-top: 6px; padding: 10px; border-radius: 8px;
  border: 1px solid #333; background: #0e1016; color: var(--text);
  /* Clearer UI font for typing; ≥16px prevents iOS focus zoom */
  font-family: "Segoe UI", "Noto Sans SC", system-ui, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
.lobby-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.lobby-card {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px; border-radius: 12px; background: rgba(12, 15, 24, 0.48); border: 1px solid rgba(255,255,255,0.10);
}
.lobby-meta { flex: 1; min-width: 140px; }
.lobby-title { font-weight: 400; margin: 0 0 4px; font-size: 12px; }
.lobby-sub { color: var(--muted); font-size: 12px; margin: 0; }
.lobby-status {
  font-size: 12px; padding: 4px 8px; border-radius: 999px;
  background: #2c3348; color: var(--muted);
}
.lobby-status.ok { background: rgba(109,179,109,0.25); color: #9dffb0; }
.lobby-status.busy { background: rgba(110,168,254,0.2); color: #9ec5ff; }
.lobby-status.off { background: #2c3348; color: var(--muted); }
.lobby-card a.mini,
.lobby-card button.mini {
  font: inherit; cursor: pointer; font-size: 12px; color: var(--accent); text-decoration: none;
  padding: 8px 10px; border-radius: 8px; background: #1c2030; border: 1px solid var(--line);
}
body.gba-tab .page { max-width: none; padding-left: 0; padding-right: 0; background: transparent; }
body.gba-tab .sections { padding-left: max(16px, var(--safe-l)); padding-right: max(16px, var(--safe-r)); }
body.gba-tab footer { display: none; }
body.gba-tab #panelGba {
  display: flex; flex-direction: column;
  height: calc(100dvh - 120px);
}
.gba-wrap {
  flex: 1; min-height: 0; background: transparent;
  border-radius: 12px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: none;
}
.gba-wrap iframe { width: 100%; height: 100%; border: 0; display: block; background: transparent; color-scheme: dark; }
footer {
  padding: 10px max(16px, var(--safe-r)) max(12px, var(--safe-b)) max(16px, var(--safe-l));
  font-size: 12px; color: var(--muted);
}
footer a { color: var(--accent); }
.modal {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: max(16px, var(--safe-t)) max(16px, var(--safe-r)) max(16px, var(--safe-b)) max(16px, var(--safe-l));
  background: rgba(0,0,0,0.55);
}
.modal[hidden] { display: none !important; }
.modal-inner {
  width: min(400px, 100%); background: rgba(16, 20, 32, 0.92); border-radius: 14px; padding: 14px;
  border: 1px solid rgba(255,255,255,0.12); box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-head h2 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 400; }
.tabs-mini { display: flex; gap: 8px; margin: 12px 0 4px; }
.tabs-mini button {
  font: inherit; border: 0; border-radius: 10px; padding: 8px 12px;
  background: #2a3148; color: var(--text); cursor: pointer;
}
.tabs-mini button.on { background: var(--accent); color: #081018; }

/* v20261010i: iOS login input ≥16px (same approach as GBA cheat fields) */
/* v20261010j: logged-in = plain username + separate 退出 button */
.who {
  color: var(--text); font-size: 12px; max-width: min(160px, 40vw);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: "Fusion Pixel 12", monospace;
}
/* v20261010k: [hidden] must beat button.secondary { display: inline-block }
   (UA [hidden]{display:none} loses to author display). */
.auth-bar [hidden],
#loginOpenBtn[hidden],
#logoutBtn[hidden],
#who[hidden] {
  display: none !important;
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (hover: none), (pointer: coarse) {
  #loginModal input, #loginModal textarea, #loginModal select,
  input.auth-input, textarea.auth-input {
    font-size: 16px !important;
    font-size: max(16px, 1em) !important;
  }
}
@supports (-webkit-touch-callout: none) {
  #loginModal input, #loginModal textarea, #loginModal select,
  input.auth-input, textarea.auth-input {
    font-size: 16px !important;
    font-size: max(16px, 1em) !important;
  }
}


/* Desktop landscape: same clean plate (hq copy) */
@media (orientation: landscape) and (min-width: 900px) {
  body::before {
    background-image:
      linear-gradient(180deg, rgba(8, 10, 16, 0.10) 0%, rgba(8, 10, 16, 0.16) 55%, rgba(8, 10, 16, 0.28) 100%),
      url("/assets/a9-ruins-hq.jpg");
    background-position: 50% 45%;
  }
}


/* v20261011i: while GBA is playing, hide shell chrome and let iframe fill the viewport */
body.gba-playing .top,
body.gba-playing .sections {
  display: none !important;
}
body.gba-playing .page {
  max-width: none;
  padding: 0;
  margin: 0;
}
body.gba-playing #panelGba {
  position: fixed;
  inset: 0;
  z-index: 50;
  height: 100dvh !important;
  width: 100% !important;
  margin: 0;
  border-radius: 0;
}
body.gba-playing .gba-wrap {
  border: 0;
  border-radius: 0;
  height: 100%;
}


/* v20261011j: while playing, force pure black shell (avoid #0a0c10 / A9 showing as top gray strip) */
html:has(body.gba-playing),
body.gba-playing {
  background: #000 !important;
  background-color: #000 !important;
}
body.gba-playing::before { opacity: 0 !important; }
body.gba-playing .gba-wrap,
body.gba-playing .gba-wrap iframe {
  background: #000 !important;
}

/* v20261011l: lobby apply button states */
.lobby-card button.mini:disabled,
.lobby-card .mini:disabled {
  opacity: 0.45; cursor: not-allowed; color: var(--muted);
}

/* v20261011m: FC/SFC tabs share gba-tab layout */
body.gba-tab #panelFc,
body.gba-tab #panelSfc {
  display: flex; flex-direction: column;
  height: calc(100dvh - 120px);
}
