/* SUSHI BOY web player */
:root {
  --ink: #07080f;
  --ink2: #0f111c;
  --card: rgba(18, 20, 33, 0.78);
  --line: rgba(231, 180, 80, 0.28);
  --gold: #e7b450;
  --gold2: #ffd98a;
  --red: #d7322b;
  --salmon: #ff7a45;
  --cream: #f7ecd9;
  --muted: #a3a8bd;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--cream); font: 500 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; color: inherit; }
a { color: inherit; }
.logo-text { font-family: Bungee, Inter, sans-serif; letter-spacing: 0.02em; color: #ffd21f; -webkit-text-stroke: 2px #1c49c8; paint-order: stroke fill; text-shadow: 0 3px 0 #0b2a85, 0 10px 30px rgba(255, 210, 31, 0.25); }

/* ---------- buttons, chips, toasts ---------- */
.btn-gold { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 0 28px; border: 0; border-radius: 999px; cursor: pointer; text-decoration: none;
  font: 800 17px/1 Inter, sans-serif; letter-spacing: 0.04em; color: #241503;
  background: linear-gradient(180deg, #ffe7a6 0%, #f2c15a 45%, #c98a22 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 -2px 0 rgba(120, 70, 0, 0.45) inset, 0 10px 28px rgba(231, 180, 80, 0.32); transition: transform .12s ease, filter .12s ease; }
.btn-gold:hover { filter: brightness(1.06); }
.btn-gold:active { transform: translateY(1px) scale(0.985); }
.btn-ghost { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer; text-decoration: none;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); color: var(--cream); font-weight: 600; font-size: 14px; transition: background .12s; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.11); }
.btn-ghost svg, .btn-gold svg { width: 18px; height: 18px; flex: none; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font: 800 11px/1 Inter, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; }
.badge.gba { background: rgba(124, 92, 255, 0.18); color: #c9b9ff; border: 1px solid rgba(160, 135, 255, 0.35); }
.badge.gbc { background: rgba(231, 180, 80, 0.16); color: var(--gold2); border: 1px solid rgba(231, 180, 80, 0.4); }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 90;
  padding: 11px 18px; border-radius: 14px; background: rgba(15, 17, 28, 0.94); border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); font-weight: 600; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- unlock dialog ---------- */
dialog.unlock { border: 1px solid var(--line); border-radius: 22px; background: #11131f; color: var(--cream); padding: 26px; width: min(380px, calc(100vw - 32px)); box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7); }
dialog.unlock::backdrop { background: rgba(4, 5, 10, 0.72); backdrop-filter: blur(6px); }
dialog.unlock h2 { margin: 0 0 6px; font: 400 22px/1.2 Bungee, sans-serif; color: var(--gold2); }
dialog.unlock p { margin: 0 0 16px; color: var(--muted); }
dialog.unlock input { width: 100%; min-height: 50px; padding: 0 16px; border-radius: 14px; border: 1px solid rgba(255, 255, 255, 0.16); background: rgba(255, 255, 255, 0.05); color: var(--cream); font: 700 18px/1 Inter, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 14px; outline: none; }
dialog.unlock input:focus { border-color: var(--gold); }
dialog.unlock .err { color: #ff9b8f; min-height: 20px; margin: -6px 0 10px; font-size: 13px; }
dialog.unlock .btn-gold { width: 100%; }

/* ---------- the iPhone "Add to Home Screen" hint ---------- */
.ios-hint { display: none; margin-top: 18px; padding: 12px 14px; border-radius: 16px; background: rgba(255, 255, 255, 0.05); border: 1px dashed rgba(255, 255, 255, 0.16); color: var(--muted); font-size: 13px; }
.ios-hint.show { display: block; }

/* ================= PLAYER ================= */
body.player { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; background: #000; }
body.player.skin-nihao { --accent: var(--gold); --panel: url(../img/ui/nihao_panel.jpg); --bezel: #0b0b10; }
#app { position: absolute; inset: 0; display: flex; flex-direction: column; }
#screenWrap { position: relative; flex: none; display: grid; place-items: center; padding: calc(10px + var(--sat)) calc(10px + var(--sar)) 10px calc(10px + var(--sal)); background: radial-gradient(120% 120% at 50% 0%, #1a1c2b 0%, #07080f 70%); }
#screen { position: relative; width: var(--sw, 100%); height: var(--sh, auto); border-radius: 10px; overflow: hidden; background: #000; box-shadow: 0 0 0 3px var(--bezel), 0 0 0 4px rgba(231, 180, 80, 0.35), 0 16px 40px rgba(0, 0, 0, 0.6); }
#game { position: absolute; inset: 0; }
#game canvas { image-rendering: pixelated; }
/* the emulator's own bars and pads are replaced by ours */
#game .ejs_menu_bar, #game .ejs_virtualGamepad_parent, #game .ejs_context_menu, #game .ejs_virtualGamepad_open, #game .ejs_start_button { display: none !important; }
#game .ejs_message { font: 600 13px Inter, sans-serif !important; }

/* ---------- the controller ---------- */
#pad { position: relative; flex: 1; min-height: 0; background: var(--panel) center top / cover no-repeat, #0a0a10; border-top: 1px solid rgba(231, 180, 80, 0.25); touch-action: none; }
#pad::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0) 30%); pointer-events: none; }
.pb { position: absolute; display: grid; place-items: center; border: 0; padding: 0; background: none; cursor: pointer; touch-action: none; -webkit-user-select: none; user-select: none; }
.pb img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55)); transition: transform .05s, filter .05s; }
.pb .lbl { position: absolute; pointer-events: none; font: 800 var(--lsize, 22px)/1 Inter, sans-serif; color: rgba(255, 244, 220, 0.92); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.pb.on img { transform: scale(0.94); filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)) brightness(1.15); }
.pb.cap .lbl { position: static; margin-top: 6px; font-size: 11px; letter-spacing: 0.16em; color: rgba(247, 236, 217, 0.72); }
.pb.cap { display: flex; flex-direction: column; align-items: center; }
.pb.cap img { height: auto; }
.dpad { position: absolute; touch-action: none; }
.dpad img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.6)); transition: transform .06s; }
.dpad[data-dir="u"] img { transform: perspective(500px) rotateX(9deg); }
.dpad[data-dir="d"] img { transform: perspective(500px) rotateX(-9deg); }
.dpad[data-dir="l"] img { transform: perspective(500px) rotateY(-9deg); }
.dpad[data-dir="r"] img { transform: perspective(500px) rotateY(9deg); }
.dpad[data-dir="ul"] img { transform: perspective(500px) rotateX(7deg) rotateY(-7deg); }
.dpad[data-dir="ur"] img { transform: perspective(500px) rotateX(7deg) rotateY(7deg); }
.dpad[data-dir="dl"] img { transform: perspective(500px) rotateX(-7deg) rotateY(-7deg); }
.dpad[data-dir="dr"] img { transform: perspective(500px) rotateX(-7deg) rotateY(7deg); }
.sh .lbl { font-size: 16px; letter-spacing: 0.1em; }
.sh-r img { transform: scaleX(-1); }
.sh-r.on img { transform: scaleX(-1) scale(0.95); }
.chip { position: absolute; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(231, 180, 80, 0.35);
  background: rgba(10, 10, 16, 0.78); color: var(--cream); font: 800 12px/1 Inter, sans-serif; letter-spacing: 0.08em; cursor: pointer; touch-action: none; }
.chip svg { width: 18px; height: 18px; }
.chip.c-mute, .chip.c-save { width: 36px; padding: 0; }
/* A and B are round: their touch areas too, so a tap on B never lands in A's corner */
#pad .b-a, #pad .b-b { border-radius: 50%; }
.chip.c-mute.muted { color: #ff8a7a; border-color: rgba(255, 120, 100, 0.55); }
/* desktop: the sound chip floats in the screen's top-right corner, faint until the pointer comes near */
.desk-mute { display: none; z-index: 4; top: 10px; right: 10px; opacity: 0.55; transition: opacity .15s; }
body.layout-desktop .desk-mute { display: inline-flex; }
body.layout-desktop .desk-mute:hover, body.layout-desktop .desk-mute.muted { opacity: 1; }
.chip.on { background: linear-gradient(180deg, #ffe7a6, #d99a2e); color: #241503; border-color: transparent; box-shadow: 0 0 18px rgba(231, 180, 80, 0.55); }

/* portrait phone: the screen on top, the controller below (positions in % of the pad) */
body.layout-portrait #screenWrap { padding-bottom: 14px; }
/* the D-pad big (D), A and B smaller (S) and centred on it, SELECT/START right under them (owner) */
body.layout-portrait #pad { --D: min(50vw, 236px); --S: min(20vw, 94px); --T: 28%; }
body.layout-portrait .dpad { left: 3%; top: var(--T); width: var(--D); height: var(--D); }
body.layout-portrait .b-a { right: 4%; top: calc(var(--T) + var(--D) / 2 - var(--S) * 0.83); width: var(--S); height: var(--S); --lsize: 25px; }
body.layout-portrait .b-b { right: calc(4% + var(--S) * 0.98); top: calc(var(--T) + var(--D) / 2 - var(--S) * 0.83 + var(--S) * 0.66); width: var(--S); height: var(--S); --lsize: 25px; }
body.layout-portrait .sh-l { left: 3%; top: 4%; width: min(30vw, 150px); height: auto; }
body.layout-portrait .sh-r { right: 3%; top: 4%; width: min(30vw, 150px); height: auto; }
body.layout-portrait .b-select { left: calc(50% - min(22vw, 100px) - 8px); top: calc(var(--T) + var(--D) + 14px); width: min(22vw, 100px); }
body.layout-portrait .b-start { left: calc(50% + 8px); top: calc(var(--T) + var(--D) + 14px); width: min(22vw, 100px); }
/* the chip row (menu, sound, fast forward) sits centred just under L and R */
body.layout-portrait .c-menu, body.layout-portrait .c-mute, body.layout-portrait .c-ff { top: calc(4% + min(30vw, 150px) * 0.29 + 12px); }
body.layout-portrait .c-save { top: calc(4% + min(30vw, 150px) * 0.29 + 12px); }
body.layout-portrait .c-menu { left: calc(50% - 104px); }
body.layout-portrait .c-save { left: calc(50% - 52px); }
body.layout-portrait .c-mute { left: calc(50% - 8px); }
body.layout-portrait .c-ff { left: calc(50% + 36px); }

/* landscape phone: the screen centred, the controls float at its sides */
body.layout-landscape #app { flex-direction: row; }
body.layout-landscape #screenWrap { position: absolute; inset: 0; padding: calc(6px + var(--sat)) calc(6px + var(--sar)) calc(6px + var(--sab)) calc(6px + var(--sal)); background: radial-gradient(90% 120% at 50% 50%, #151726 0%, #05060b 75%); }
body.layout-landscape #pad { position: absolute; inset: 0; background: none; border: 0; pointer-events: none; }
body.layout-landscape #pad::before { display: none; }
body.layout-landscape #pad > * { pointer-events: auto; }
body.layout-landscape .pb img, body.layout-landscape .dpad img { opacity: 0.88; }
body.layout-landscape #pad { --D: min(21vw, 44vh, 190px); --S: min(9vw, 20vh, 84px); }
body.layout-landscape .dpad { left: calc(2.5vw + var(--sal)); top: calc(50% - var(--D) / 2 + 4vh); width: var(--D); height: var(--D); }
body.layout-landscape .b-a { right: calc(2.5vw + var(--sar)); top: calc(50% - var(--S) + 2vh); width: var(--S); height: var(--S); --lsize: 22px; }
body.layout-landscape .b-b { right: calc(2.5vw + var(--sar) + var(--S) * 0.98); top: calc(50% - var(--S) * 0.35 + 2vh); width: var(--S); height: var(--S); --lsize: 22px; }
body.layout-landscape .sh-l { left: calc(1.5vw + var(--sal)); top: calc(3vh + var(--sat)); width: min(16vw, 140px); }
body.layout-landscape .sh-r { right: calc(1.5vw + var(--sar)); top: calc(3vh + var(--sat)); width: min(16vw, 140px); }
body.layout-landscape .b-select { left: calc(3vw + var(--sal)); bottom: calc(4vh + var(--sab)); width: min(11vw, 90px); }
body.layout-landscape .b-start { right: calc(3vw + var(--sar)); bottom: calc(4vh + var(--sab)); width: min(11vw, 90px); }
body.layout-landscape .c-menu { left: calc(2vw + var(--sal)); top: calc(50% - var(--D) / 2 - 40px); }
body.layout-landscape .c-mute { left: calc(2vw + var(--sal) + 52px); top: calc(50% - var(--D) / 2 - 40px); }
body.layout-landscape .c-save { right: calc(2vw + var(--sar) + 78px); top: max(calc(50% - var(--S) - 52px), calc(3vh + var(--sat) + min(16vw, 140px) * 0.3 + 8px)); }
body.layout-landscape .c-ff { right: calc(2vw + var(--sar)); top: max(calc(50% - var(--S) - 52px), calc(3vh + var(--sat) + min(16vw, 140px) * 0.3 + 8px)); }

/* desktop: a big screen, a toolbar and the keyboard map; the touch controller only on request */
body.layout-desktop #app { flex-direction: column; background: radial-gradient(80% 90% at 50% 30%, #1a1c2c 0%, #05060b 70%); }
body.layout-desktop #screenWrap { flex: 1; background: none; padding: 18px 18px 8px; }
body.layout-desktop #pad { display: none; }
body.layout-desktop.show-pad #pad { display: block; }
#deskbar { display: none; }
body.layout-desktop #deskbar { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 10px 16px 18px; }
#deskbar .keys { color: var(--muted); font-size: 12px; margin-left: 10px; }
#deskbar kbd { display: inline-block; min-width: 22px; padding: 2px 6px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.18); background: rgba(255, 255, 255, 0.06); font: 700 11px/1.4 Inter, sans-serif; color: var(--cream); text-align: center; }
#deskbar .btn-ghost.on { background: linear-gradient(180deg, #ffe7a6, #d99a2e); color: #241503; border-color: transparent; }

/* ---------- start overlay ---------- */
#start { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: #05060b; }
#start .bg { position: absolute; inset: 0; background: center / cover no-repeat; filter: blur(22px) brightness(0.45) saturate(1.2); transform: scale(1.1); }
#start .card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 24px; text-align: center; max-width: 520px; }
#start .side { display: flex; flex-direction: column; align-items: center; gap: 14px; }
#start .card img { width: min(86vw, 58vh, 480px); height: auto; aspect-ratio: 1; object-fit: contain; display: block; border-radius: 26px; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 60px rgba(231, 120, 40, 0.25); }
#start .card .btn-gold { min-width: 220px; min-height: 56px; font-size: 18px; }
.start-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.btn-ghost.small { min-height: 34px; padding: 0 12px; font-size: 12.5px; }
#start .ios-hint { margin: 0; max-width: 340px; }
#start.loading .start-tools, #start.loading .ios-hint { display: none !important; }
@media (orientation: landscape) and (max-height: 520px) {
  #start .card { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 12px 22px; max-width: 760px; }
  #start .card img { width: min(44vw, 68vh, 340px); }
  #start .card .side { display: flex; flex-direction: column; align-items: center; gap: 12px; }
}
#start .state { color: var(--muted); font-size: 13px; min-height: 18px; }
#start .bar { width: 220px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.1); overflow: hidden; display: none; }
#start .bar i { display: block; height: 100%; width: 30%; background: var(--gold); border-radius: 2px; animation: load 1.1s ease-in-out infinite; }
#start.loading .bar { display: block; }
#start.loading .btn-gold { display: none; }
@keyframes load { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
#start .back { position: absolute; top: calc(14px + var(--sat)); left: calc(14px + var(--sal)); }

/* ---------- the pause menu ---------- */
#menu { position: absolute; inset: 0; z-index: 40; display: none; align-items: flex-end; justify-content: center; background: rgba(3, 4, 9, 0.62); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); touch-action: pan-y; }
#menu.open { display: flex; }
.sheet { width: min(560px, 100%); max-height: calc(100% - 20px - var(--sat)); overflow: auto; -webkit-overflow-scrolling: touch; padding: 18px calc(16px + var(--sar)) calc(18px + var(--sab)) calc(16px + var(--sal)); border-radius: 26px 26px 0 0; background: linear-gradient(180deg, #161828 0%, #0c0d16 100%); border: 1px solid var(--line); border-bottom: 0; box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6); touch-action: pan-y; user-select: none; }
@media (min-width: 700px) and (min-height: 560px) { #menu { align-items: center; } .sheet { border-radius: 26px; border-bottom: 1px solid var(--line); } }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet header h2 { margin: 0; font: 400 19px/1.15 Bungee, sans-serif; }
.sheet header .badge { margin-top: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; min-height: 76px; padding: 10px 4px; border-radius: 18px; border: 1px solid rgba(255, 255, 255, 0.09); background: rgba(255, 255, 255, 0.045); cursor: pointer; font-size: 12px; font-weight: 700; text-align: center; color: var(--cream); }
.tile svg { width: 24px; height: 24px; color: var(--gold2); }
.tile:active { transform: scale(0.97); }
.tile.on { background: linear-gradient(180deg, rgba(255, 231, 166, 0.95), rgba(217, 154, 46, 0.95)); color: #241503; border-color: transparent; }
.tile.on svg { color: #241503; }
.section { margin: 6px 0 14px; }
.section h3 { margin: 0 0 8px 2px; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.speeds { display: flex; gap: 6px; }
.speeds button { min-width: 48px; height: 36px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.12); background: rgba(255, 255, 255, 0.05); color: var(--cream); font-weight: 800; cursor: pointer; }
.speeds button.sel { border-color: var(--gold); color: var(--gold2); background: rgba(231, 180, 80, 0.12); }
.vol { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; }
.vol input { flex: 1; accent-color: var(--gold); }
.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.slot { position: relative; display: flex; flex-direction: column; border-radius: 14px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.04); cursor: pointer; text-align: left; padding: 0; }
.slot .shot { aspect-ratio: var(--ar, 3 / 2); background: #000 center / cover no-repeat; image-rendering: pixelated; display: grid; place-items: center; color: #4c5066; font-size: 22px; }
.slot .cap { padding: 6px 8px 7px; font-size: 11px; line-height: 1.25; }
.slot .cap b { display: block; font-size: 12px; color: var(--cream); }
.slot .cap span { color: var(--muted); }
.slot .x { position: absolute; top: 5px; right: 5px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.6); color: #fff; display: grid; place-items: center; cursor: pointer; }
.slot .x svg { width: 14px; height: 14px; }
.slot.auto { border-color: rgba(88, 214, 141, 0.35); }
.statesbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.1); }
.seg button { height: 32px; padding: 0 14px; border-radius: 999px; border: 0; background: none; color: var(--muted); font-weight: 800; font-size: 12px; cursor: pointer; letter-spacing: 0.06em; }
.seg button.sel { background: var(--gold); color: #241503; }
.keys-help { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 10px; font-size: 13px; color: var(--muted); }
.keys-help kbd { justify-self: start; padding: 2px 7px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(255, 255, 255, 0.06); color: var(--cream); font: 700 12px/1.4 Inter, sans-serif; }
.danger { color: #ff9b8f !important; }
.hidden { display: none !important; }
.ff-badge { position: absolute; z-index: 5; top: calc(14px + var(--sat)); left: 50%; transform: translateX(-50%); padding: 5px 12px; border-radius: 999px; background: linear-gradient(180deg, #ffe7a6, #d99a2e); color: #241503; font: 900 12px/1 Inter, sans-serif; letter-spacing: 0.1em; box-shadow: 0 6px 18px rgba(231, 180, 80, 0.45); pointer-events: none; opacity: 0; transition: opacity .35s; }
.ff-badge.show { opacity: 1; transition: none; }
body.layout-portrait .ff-badge { top: calc(16px + var(--sat)); }
