:root {
  --bg: #08080d;
  --bg-elev: #0f0f18;
  --panel: #14141f;
  --panel-2: #1a1a28;
  --border: #262639;
  --border-soft: #1e1e2e;
  --text: #ececf5;
  --muted: #9092ab;
  --muted-2: #6c6e86;
  --accent: #7c6cff;
  --accent-2: #a29bfe;
  --accent-soft: rgba(124, 108, 255, 0.16);
  --danger: #ff5c7a;
  --ok: #3ddc97;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(124, 108, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 92, 138, 0.1), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#i-play path,
#i-pause path,
#i-github path {
  fill: currentColor;
  stroke: none;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ------------------------------------------------------------- structure */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(14px, 4vw, 32px);
  background: rgba(8, 8, 13, 0.72);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 4px;
  border-radius: 10px;
  color: var(--text);
}

.brand:hover {
  background: rgba(255, 255, 255, 0.05);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #4d3de0);
  color: #fff;
  box-shadow: 0 6px 18px rgba(124, 108, 255, 0.35);
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.brand-text {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.4px;
}

.brand-text span {
  color: var(--accent-2);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.engine-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid rgba(124, 108, 255, 0.3);
  border-radius: 999px;
  padding: 4px 9px;
  margin-right: 4px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  transition: 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

a.icon-btn {
  text-decoration: none;
}

a.repo-link:hover {
  color: var(--text);
}

.icon-btn.small {
  width: 30px;
  height: 30px;
}

.app-main {
  min-height: calc(100dvh - 62px);
}

.view {
  animation: view-in 0.25s ease both;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------------ home */

.home-view {
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 64px) clamp(16px, 4vw, 32px) 64px;
}

.hero {
  text-align: center;
  max-width: 760px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  color: var(--accent-2);
}

.hero h1 {
  margin: 0;
  font-size: clamp(34px, 6vw, 58px);
  line-height: 1.08;
  letter-spacing: -1.5px;
  font-weight: 850;
}

.grad {
  background: linear-gradient(100deg, #a29bfe 0%, #7c6cff 45%, #ff7ab0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero .sub {
  margin: 14px auto 0;
  max-width: 620px;
  color: var(--muted);
  font-size: clamp(14px, 1.6vw, 16px);
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 28px 0 26px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
  transition: 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  border-color: #3a3a55;
  background: var(--panel-2);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #5b48e6);
  border-color: transparent;
  box-shadow: 0 10px 26px rgba(124, 108, 255, 0.32);
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
}

.btn.big {
  padding: 14px 26px;
  font-size: 16px;
  border-radius: 14px;
}

.btn.tiny {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 9px;
  gap: 5px;
}

.btn.tiny svg {
  width: 14px;
  height: 14px;
}

.btn.danger {
  color: #ffb3c1;
  border-color: rgba(255, 92, 122, 0.35);
  background: rgba(255, 92, 122, 0.08);
}

.btn.danger:hover {
  background: rgba(255, 92, 122, 0.16);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 30px 22px;
  border: 1.5px dashed #34344f;
  border-radius: 20px;
  background: rgba(20, 20, 31, 0.5);
  color: var(--muted);
  cursor: pointer;
  transition: 0.18s ease;
  outline: none;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(124, 108, 255, 0.07);
  color: var(--text);
}

.drop-icon {
  width: 34px;
  height: 34px;
  color: var(--accent-2);
  margin-bottom: 4px;
}

.dropzone strong {
  font-size: 15px;
  color: var(--text);
}

.dropzone span {
  font-size: 12.5px;
  color: var(--muted-2);
}

.features {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  padding: 0;
  margin: 24px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.features li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.features svg {
  width: 15px;
  height: 15px;
  color: var(--accent-2);
}

.disclaimer {
  margin: 30px auto 0;
  font-size: 12px;
  color: var(--muted-2);
}

.isolation-banner {
  margin: 0 auto 24px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 186, 92, 0.45);
  background: rgba(255, 186, 92, 0.1);
  color: #ffd8a3;
  font-size: 12.5px;
  line-height: 1.6;
}

.isolation-banner code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 11.5px;
}

.fatal-error {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  max-width: min(92vw, 640px);
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 92, 122, 0.5);
  background: rgba(40, 10, 18, 0.96);
  color: #ffd0d9;
  font-size: 13px;
  line-height: 1.6;
}

body.in-game {
  overflow: hidden;
}

/* --------------------------------------------------------------- library */

.library-section {
  margin-top: 58px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.2px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.rom-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: var(--panel);
  transition: 0.15s ease;
  position: relative;
}

.rom-card:hover {
  border-color: #37375a;
  transform: translateY(-1px);
}

.rom-thumb-btn {
  flex: none;
  width: 96px;
  aspect-ratio: 3 / 2;
  padding: 0;
  border: 1px solid #2a2a40;
  border-radius: 9px;
  overflow: hidden;
  background: #05050a;
  cursor: pointer;
}

.rom-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}

.rom-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--muted-2);
}

.rom-thumb.placeholder svg {
  width: 26px;
  height: 26px;
}

.rom-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.rom-name {
  font-weight: 650;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rom-meta {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted-2);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.rom-delete {
  flex: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.rom-card:hover .rom-delete,
.rom-card:focus-within .rom-delete {
  opacity: 1;
}

@media (pointer: coarse) {
  .rom-delete {
    opacity: 0.75;
  }
}

/* ---------------------------------------------------------------- player */

.player-view {
  height: calc(100dvh - 62px);
  padding: 10px clamp(10px, 2vw, 20px) 12px;
}

.player-shell {
  height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
  min-height: 24px;
}

.game-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-stats {
  display: flex;
  gap: 10px;
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--muted-2);
}

.stat {
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

#hud-speed {
  color: var(--accent-2);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020205;
  border: 1px solid #22223a;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.7);
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(4, 4, 9, 0.82);
  backdrop-filter: blur(4px);
  z-index: 5;
  font-size: 13px;
  color: var(--muted);
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(124, 108, 255, 0.25);
  border-top-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pause-hint {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: rgba(4, 4, 9, 0.62);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.4px;
  backdrop-filter: blur(2px);
}

.osd {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -8px);
  z-index: 8;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 10, 18, 0.88);
  border: 1px solid rgba(124, 108, 255, 0.35);
  color: #ded9ff;
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  max-width: 90%;
  text-align: center;
}

.osd.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* toolbar */

.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  background: rgba(20, 20, 31, 0.9);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.toolbar::-webkit-scrollbar {
  display: none;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tool-sep {
  width: 1px;
  height: 26px;
  background: var(--border-soft);
  margin: 0 6px;
  flex: none;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 10px;
  min-width: 46px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  transition: 0.12s ease;
  position: relative;
}

.tool:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.tool:active {
  transform: scale(0.96);
}

.tool svg {
  width: 19px;
  height: 19px;
}

.tool span {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.tool.active {
  color: var(--accent-2);
  background: var(--accent-soft);
}

.slot-pill {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 9px;
  line-height: 1;
  min-width: 14px;
  padding: 2px 3px;
  border-radius: 5px;
  background: rgba(124, 108, 255, 0.3);
  color: #fff;
  text-align: center;
}

.volume-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 2px;
}

.volume-wrap .tool {
  min-width: 34px;
  padding: 6px;
}

input[type="range"].volume {
  width: 76px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* fullscreen */

.player-view:fullscreen,
.player-shell:fullscreen {
  background: #000;
  padding: 0;
  height: 100dvh;
}

.player-view:fullscreen .player-shell {
  max-width: none;
  gap: 0;
}

.player-view:fullscreen .player-meta {
  position: absolute;
  top: 10px;
  left: 14px;
  z-index: 6;
  padding: 0;
  background: transparent;
}

.player-view:fullscreen .stage {
  border: 0;
  border-radius: 0;
}

.player-view:fullscreen .toolbar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: max-content;
  max-width: calc(100vw - 24px);
  background: rgba(12, 12, 20, 0.82);
  backdrop-filter: blur(12px);
}

.player-view:fullscreen .player-meta,
.player-view:fullscreen .toolbar {
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.player-view:fullscreen.chrome-hidden .player-meta,
.player-view:fullscreen.chrome-hidden .toolbar {
  opacity: 0;
  pointer-events: none;
}

.player-view:fullscreen.chrome-hidden .player-meta {
  transform: translateY(-10px);
}

.player-view:fullscreen.chrome-hidden .toolbar {
  transform: translate(-50%, 14px);
}

.player-view:fullscreen.chrome-hidden {
  cursor: none;
}

/* --------------------------------------------------------- touch controls */

.touch-controls {
  flex: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px 10px;
  user-select: none;
  -webkit-user-select: none;
}

.touch-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.touch-top {
  align-items: flex-start;
}

.touch-main {
  align-items: flex-end;
}

.touch-system {
  justify-content: center;
  gap: 18px;
  margin-bottom: 2px;
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(30, 30, 48, 0.42);
  color: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(6px);
  font-weight: 700;
  transition: background 0.08s ease, transform 0.08s ease;
}

.tbtn.active {
  background: rgba(124, 108, 255, 0.72);
  border-color: rgba(200, 195, 255, 0.9);
  transform: scale(0.97);
}

.tbtn.shoulder {
  width: 66px;
  height: 34px;
  border-radius: 10px;
  font-size: 12px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 2px;
}

.tbtn.dp {
  border-radius: 10px;
  font-size: 13px;
}

.dpad .up {
  grid-area: 1 / 2;
}
.dpad .left {
  grid-area: 2 / 1;
}
.dpad .right {
  grid-area: 2 / 3;
}
.dpad .down {
  grid-area: 3 / 2;
}

.face {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}

.tbtn.face-a,
.tbtn.face-b {
  border-radius: 50%;
}

.tbtn.face-a {
  width: 62px;
  height: 62px;
  font-size: 17px;
}

.tbtn.face-b {
  width: 54px;
  height: 54px;
  margin-bottom: 26px;
  font-size: 15px;
}

.tbtn.pill {
  width: 76px;
  height: 28px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.6px;
}

/* show touch controls automatically on coarse pointers */
@media (pointer: coarse) {
  body.touch-auto .touch-controls {
    display: flex;
  }
}

/* ------------------------------------------------------------ side panel */

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(390px, 100vw);
  height: 100dvh;
  z-index: 60;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 70px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  padding: 16px;
  animation: slide-in 0.22s ease both;
}

@keyframes slide-in {
  from {
    transform: translateX(30px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.panel-head,
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head h2,
.dialog-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.2px;
}

.panel-note {
  margin: 8px 0 14px;
  font-size: 12px;
  color: var(--muted);
}

.states-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
  padding-right: 2px;
}

.state-card {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  display: flex;
  flex-direction: column;
}

.state-card.current {
  border-color: rgba(124, 108, 255, 0.6);
  box-shadow: 0 0 0 1px rgba(124, 108, 255, 0.25);
}

.state-thumb {
  aspect-ratio: 3 / 2;
  background: #05050a;
  position: relative;
  cursor: pointer;
  border: 0;
  padding: 0;
  width: 100%;
  overflow: hidden;
}

.state-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}

.state-thumb .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted-2);
  font-size: 11px;
  gap: 4px;
}

.state-thumb .empty svg {
  width: 18px;
  height: 18px;
}

.state-body {
  padding: 7px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.state-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.state-slot {
  font-size: 11.5px;
  font-weight: 700;
}

.state-time {
  font-size: 10.5px;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.state-actions {
  display: flex;
  gap: 4px;
}

.state-actions .btn {
  flex: 1;
  padding: 4px 0;
  font-size: 11px;
  border-radius: 7px;
}

.state-actions .icon-btn {
  width: 26px;
  height: 26px;
  flex: none;
}

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
}

.slot-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- key bindings */

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.target-name {
  max-width: 58%;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#battery-save-hint {
  margin: 2px 0 0;
  line-height: 1.5;
}

.key-bindings {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 10px;
}

.keybind-heading {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted-2);
}

.keybind-heading:first-child {
  margin-top: 0;
}

.keybind-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
  flex-wrap: wrap;
}

.keybind-row.capturing {
  background: var(--accent-soft);
  border-color: rgba(124, 108, 255, 0.45);
}

.keybind-label {
  flex: 1 1 92px;
  min-width: 80px;
  font-size: 13px;
}

.key-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}

.key-chip {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  overflow: hidden;
}

.key-chip button {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 11.5px;
  padding: 4px 7px;
}

.key-rebind {
  font-weight: 600;
}

.key-rebind:hover {
  background: rgba(124, 108, 255, 0.18);
}

.key-remove {
  color: var(--muted-2) !important;
  border-left: 1px solid var(--border-soft) !important;
  padding: 4px 6px !important;
}

.key-remove:hover {
  color: var(--danger) !important;
  background: rgba(255, 92, 122, 0.12);
}

.key-add {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
}

.key-add:hover {
  color: var(--text);
  border-color: var(--accent);
}

.key-none {
  font-size: 11px;
  color: var(--muted-2);
  align-self: center;
}

#keybind-status {
  min-height: 18px;
  margin: 0 0 6px;
  line-height: 1.5;
}

.panel-actions {
  display: flex;
  margin-top: 10px;
}

.panel-actions .btn {
  width: 100%;
  justify-content: center;
}

.panel-actions .btn svg {
  width: 14px;
  height: 14px;
}

/* ---------------------------------------------------------------- dialog */


.dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-elev);
  color: var(--text);
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: min(86dvh, 760px);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(3, 3, 8, 0.66);
  backdrop-filter: blur(4px);
}

.dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: min(86dvh, 760px);
}

.dialog-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.dialog-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
}

.settings-group {
  margin-bottom: 22px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent-2);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  font-size: 13.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
}

.row:last-child {
  border-bottom: 0;
}

.row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 130px;
  outline: none;
}

.row input[type="range"] {
  width: 180px;
  accent-color: var(--accent);
}

.row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.inline-actions {
  display: flex;
  gap: 6px;
}

.about p {
  margin: 4px 0;
  font-size: 13px;
  color: var(--muted);
}

.help-body h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--accent-2);
  letter-spacing: 0.6px;
}

.help-body h3:first-child {
  margin-top: 0;
}

.kbd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.kbd-table td {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.kbd-table td:first-child {
  color: var(--text);
  font-weight: 600;
  width: 46%;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  background: var(--panel-2);
  font-family: inherit;
  font-size: 11.5px;
  color: var(--text);
}

.help-note {
  margin-top: 18px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(124, 108, 255, 0.25);
  font-size: 12.5px;
  color: #cfcaff;
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(92vw, 460px);
}

.toast {
  padding: 9px 15px;
  border-radius: 11px;
  background: rgba(18, 18, 28, 0.94);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.18s ease both;
  text-align: center;
}

.toast.error {
  border-color: rgba(255, 92, 122, 0.5);
  color: #ffc4cf;
}

.toast.ok {
  border-color: rgba(61, 220, 151, 0.4);
  color: #b6ffe0;
}

.toast.out {
  opacity: 0;
  transform: translateY(6px);
  transition: 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------------------------------------------------------- drop overlay */

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(5, 5, 10, 0.82);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.drop-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 44px 60px;
  border-radius: 22px;
  border: 2px dashed var(--accent);
  background: rgba(124, 108, 255, 0.1);
  color: var(--text);
}

.drop-overlay-card svg {
  width: 40px;
  height: 40px;
  color: var(--accent-2);
}

.drop-overlay-card span {
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------ boot screen */

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: rgba(4, 4, 9, 0.9);
  backdrop-filter: blur(8px);
}

.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 30px 40px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: center;
  min-width: 280px;
}

.boot-card p {
  margin: 0;
  font-size: 13px;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 760px) {
  .hero-actions {
    margin: 22px 0 20px;
  }

  .dropzone {
    padding: 24px 14px;
  }

  .features {
    gap: 6px 14px;
  }

  .player-view {
    height: calc(100dvh - 62px);
    padding: 6px 6px 8px;
  }

  .player-shell {
    gap: 6px;
  }

  /* Keep the handheld screen at its native 3:2 ratio and give the rest of
     the viewport to the on-screen controls. */
  .stage {
    flex: none;
    width: 100%;
    aspect-ratio: 3 / 2;
  }

  .toolbar {
    margin-top: auto;
  }

  .touch-controls {
    flex: none;
    height: min(46dvh, 380px);
    padding: 12px 18px 10px;
  }

  .volume-wrap input.volume {
    display: none;
  }

  .dpad {
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
  }

  .tbtn.face-a {
    width: 68px;
    height: 68px;
  }

  .tbtn.face-b {
    width: 58px;
    height: 58px;
  }

  .tbtn.shoulder {
    width: 74px;
    height: 36px;
  }

  .player-meta {
    padding: 0 2px;
  }

  .game-title {
    max-width: 46vw;
  }

  #hud-audio {
    display: none;
  }

  .toolbar {
    padding: 3px 4px;
    gap: 0;
  }

  .tool {
    min-width: 40px;
    padding: 6px 7px;
  }

  .tool span {
    display: none;
  }

  .tool svg {
    width: 20px;
    height: 20px;
  }

  #speed-label {
    display: block !important;
    font-size: 10px;
  }

  .volume-wrap input.volume {
    width: 52px;
  }

  .tool-sep {
    margin: 0 2px;
  }

  .side-panel {
    top: auto;
    bottom: 0;
    height: min(72dvh, 640px);
    width: 100vw;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    animation: sheet-in 0.22s ease both;
  }

  @keyframes sheet-in {
    from {
      transform: translateY(30px);
      opacity: 0;
    }
    to {
      transform: none;
      opacity: 1;
    }
  }

  .states-grid {
    grid-template-columns: 1fr 1fr;
  }

  .row {
    gap: 10px;
  }

  .row input[type="range"] {
    width: 130px;
  }

  .dialog {
    width: calc(100vw - 16px);
  }
}

@media (max-width: 420px) {
  .brand-text {
    font-size: 17px;
  }

  .engine-badge {
    display: none;
  }

  .rom-thumb-btn {
    width: 78px;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .player-shell {
    position: relative;
  }

  .player-meta {
    position: absolute;
    top: 4px;
    left: 10px;
    right: 10px;
    z-index: 6;
    pointer-events: none;
  }

  .stage {
    flex: 1;
    aspect-ratio: auto;
  }

  .touch-controls {
    position: absolute;
    inset: 0 0 58px 0;
    z-index: 4;
    pointer-events: none;
    padding: 10px 18px;
  }

  .touch-controls .tbtn {
    pointer-events: auto;
  }

  .toolbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    margin: 0;
  }

  .player-view:fullscreen .toolbar {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
    transform: none;
  }

  .player-view:fullscreen.chrome-hidden .toolbar {
    transform: translateY(14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
