:root {
  --gb-body: #c4c6b8;
  --gb-body-dark: #9aa090;
  --gb-bezel: #6b7160;
  --gb-screen: #9bbc0f;
  --gb-px0: #0f380f;
  --gb-px1: #306230;
  --gb-px2: #8bac0f;
  --gb-px3: #9bbc0f;
  --gb-purple: #8b3a62;
  --gb-a: #9a3460;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #2a2c28;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #1a1a1a;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#app { min-height: 100%; padding: calc(8px + var(--safe-t)) 10px calc(12px + var(--safe-b)); }
.view { display: none; }
.view.active { display: block; }

.gb-shell {
  max-width: 420px;
  margin: 0 auto;
  background: linear-gradient(160deg, #d0d2c4 0%, var(--gb-body) 40%, var(--gb-body-dark) 100%);
  border-radius: 18px 18px 60px 60px;
  padding: 14px 16px 28px;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.45),
    inset 0 -3px 8px rgba(0,0,0,.18),
    0 12px 28px rgba(0,0,0,.45);
}
.home-shell { padding-bottom: 22px; }

.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; gap: 8px;
}
.link-btn {
  background: transparent; border: none; color: #333;
  font-size: 14px; font-weight: 600; padding: 6px 4px; cursor: pointer;
}

.gb-bezel {
  background: var(--gb-bezel);
  border-radius: 12px 12px 28px 12px;
  padding: 18px 16px 22px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.45);
}
.gb-screen-frame {
  position: relative;
  background: #1a1c16;
  border-radius: 6px;
  padding: 10px 10px 10px 18px;
  aspect-ratio: 160 / 144;
  overflow: hidden;
}
.gb-power {
  position: absolute; left: 6px; top: 50%; width: 6px; height: 6px;
  border-radius: 50%; background: #2a1008;
  box-shadow: 0 0 0 1px #111;
}
.gb-power.on {
  background: #d32;
  box-shadow: 0 0 6px #f44;
}
#briques-canvas, #gb-canvas {
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  background: var(--gb-screen);
  border-radius: 2px;
}
.overlay {
  position: absolute; inset: 10px 10px 10px 18px;
  background: rgba(15,56,15,.92);
  color: var(--gb-px3);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 12px; text-align: center; font-size: 13px; line-height: 1.35;
  border-radius: 2px;
}
.overlay.hidden { display: none; }
.overlay strong { color: #fff; }
.tiny { font-size: 11px; opacity: .85; margin: 0; }

.home-screen {
  height: 100%;
  background: var(--gb-screen);
  color: var(--gb-px0);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 10px; border-radius: 2px;
}
.boot-logo {
  font-family: "Courier New", monospace;
  font-weight: 900; letter-spacing: 2px; font-size: 18px;
  color: var(--gb-px0);
}
.home-title { margin: 0 0 6px; font-size: 14px; font-weight: 700; }
.home-hint { margin: 8px 0 0; font-size: 11px; text-align: center; opacity: .85; max-width: 220px; }

.menu-btn, .file-btn {
  appearance: none; border: 2px solid var(--gb-px0);
  background: var(--gb-px2); color: var(--gb-px0);
  font-weight: 700; font-size: 14px; padding: 10px 16px;
  border-radius: 8px; cursor: pointer; min-width: 180px;
}
.menu-btn.small, .file-btn { min-width: 0; font-size: 12px; padding: 8px 12px; }
.menu-btn:active, .file-btn:active { transform: scale(.97); }

.gb-brand {
  margin: 10px 0 6px 4px;
  font-family: "Courier New", monospace;
  font-style: italic; font-weight: 700; font-size: 18px;
  color: #2a2c4a;
}
.gb-brand span { font-size: 12px; font-style: normal; opacity: .7; margin-left: 4px; }

.controls {
  position: relative;
  height: 180px;
  margin-top: 8px;
}
.dpad {
  position: absolute; left: 8px; top: 18px;
  width: 118px; height: 118px;
}
.dpad-btn {
  position: absolute; width: 38px; height: 38px;
  background: #2a2a2a; border: none; border-radius: 4px;
  box-shadow: 0 3px 0 #111, inset 0 1px 0 rgba(255,255,255,.15);
  cursor: pointer; touch-action: none;
}
.dpad-btn.pressed, .round-btn.pressed, .pill-btn.pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #111, inset 0 2px 4px rgba(0,0,0,.4);
}
.dpad-btn.up { left: 40px; top: 0; border-radius: 6px 6px 2px 2px; }
.dpad-btn.down { left: 40px; bottom: 0; border-radius: 2px 2px 6px 6px; }
.dpad-btn.left { left: 0; top: 40px; border-radius: 6px 2px 2px 6px; }
.dpad-btn.right { right: 0; top: 40px; border-radius: 2px 6px 6px 2px; }
.dpad-center {
  position: absolute; left: 40px; top: 40px; width: 38px; height: 38px;
  background: #333; border-radius: 4px; pointer-events: none;
}
.ab-cluster {
  position: absolute; right: 12px; top: 28px;
  width: 120px; height: 100px;
}
.round-btn {
  position: absolute; width: 54px; height: 54px; border-radius: 50%;
  border: none; background: var(--gb-a); color: #f5d0de;
  font-weight: 800; font-size: 16px; cursor: pointer; touch-action: none;
  box-shadow: 0 4px 0 #5a1838, inset 0 2px 0 rgba(255,255,255,.25);
}
.round-btn.b { left: 0; bottom: 8px; }
.round-btn.a { right: 0; top: 0; }
.ss-cluster {
  position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%);
  display: flex; gap: 18px;
}
.pill-btn {
  width: 56px; height: 18px; border-radius: 10px;
  border: none; background: #555; color: #bbb;
  font-size: 9px; text-transform: uppercase; letter-spacing: .5px;
  transform: rotate(-28deg); cursor: pointer; touch-action: none;
  box-shadow: 0 2px 0 #222;
}

.emu-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 2px;
}
.tool-btn {
  flex: 1 1 70px; border: none; border-radius: 8px;
  background: #7a7e6e; color: #eee; font-size: 12px; font-weight: 600;
  padding: 8px 6px; cursor: pointer;
}
.help {
  margin: 10px 4px 0; font-size: 11px; color: #333; opacity: .8; line-height: 1.3;
}
.legal-note {
  margin: 10px 4px 0; font-size: 10px; color: #333; opacity: .75; line-height: 1.35;
}
.legal-note a { color: #2a2c4a; }

.ios-hint {
  position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b));
  background: #1a1a1a; color: #eee; border-radius: 12px;
  padding: 12px 14px; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 20;
}
.ios-hint.hidden { display: none; }
.ios-hint button {
  border: none; background: var(--gb-px2); color: var(--gb-px0);
  font-weight: 700; border-radius: 8px; padding: 8px 12px; cursor: pointer;
}

@media (min-width: 480px) {
  .gb-shell { padding: 18px 22px 34px; }
  .controls { height: 200px; }
}
