html,
body {
  margin: 0;
  height: 100%;
  background: #ffffff;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.main {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  box-sizing: border-box;
  max-width: 812px;
  border-radius: 10px;
  margin: auto;
  box-shadow:
    0 0 0 5px #da4a4a,
    0 0 0 20px #474f51;
  background: #da4a4a;
  height: 100%;
  max-height: 414px;
  padding: 10px;
}

.panel {
  position: relative;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
  background: #f8f1d7;
  border-radius: 15px;
  display: flex;
  flex-direction: row;
  box-shadow: inset 8px 8px #fffef7;
}

.function-area {
  flex: 1;
  display: flex;
  padding: 0 20px;
  justify-content: center;
  flex-direction: column;
}

.controller-area {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: row;
}

.action-area {
  display: flex;
  flex-direction: row;
}

.controller {
  position: relative;
  width: 140px;
  height: 140px;
  align-self: flex-end;
  filter: drop-shadow(5px 5px 0px rgba(255, 255, 255, 0.8));
}

.controller button {
  position: absolute;
  z-index: 1;
  border: 8px solid #474f51;
  background: #857b7a;
  color: transparent;
  border-radius: 15px;
  box-sizing: border-box;
  outline: 0;
  width: 56px;
  height: 56px;
  left: 50%;
  top: 50%;
  user-select: none;
  transform: translate(-50%, -50%);
}

.controller::before {
  content: '';
  position: absolute;
  z-index: 0;
  pointer-events: none;
  box-sizing: border-box;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  background: #857b7a;
  transform: translate(-50%, -50%);
}

.controller::after {
  content: '';
  z-index: 2;
  position: absolute;
  pointer-events: none;
  box-sizing: border-box;
  width: 42px;
  height: 42px;
  border: 8px solid #474f51;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow:
    inset 0px 8px 0 0px #736a6d,
    inset 0px -8px 0 0px rgba(255, 255, 255, 0.4);
}

button.up.joydirection {
  top: 0;
  transform: translate(-50%, 0);
  border-bottom: 0;
  height: 50px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
  box-shadow: inset 0px 8px 0 0px rgba(255, 255, 255, 0.5);
}

button.right.joydirection {
  left: auto;
  right: 0;
  transform: translate(0, -50%);
  border-left: 0;
  width: 50px;
  border-bottom-left-radius: 0;
  border-top-left-radius: 0;
  box-shadow:
    inset 8px 0 0 0px #857b7a,
    inset 6px 6px 0 0px rgba(255, 255, 255, 0.4),
    inset 8px -8px 0 0px rgba(0, 0, 0, 0.1);
}

button.down.joydirection {
  top: auto;
  transform: translate(-50%, 0);
  bottom: 0;
  border-top: 0;
  height: 50px;
  border-top-right-radius: 0;
  border-top-left-radius: 0;
  box-shadow: inset 0px -8px 0 0px rgba(0, 0, 0, 0.1);
}

button.left.joydirection {
  left: 0;
  transform: translate(0, -50%);
  border-right: 0;
  width: 50px;
  border-bottom-right-radius: 0;
  border-top-right-radius: 0;
  box-shadow:
    inset 0px 8px 0 0px rgba(255, 255, 255, 0.4),
    inset -8px 0px 0 0px #857b7a,
    inset -8px -8px 0 0px rgba(0, 0, 0, 0.1);
}

.function {
  display: flex;
  padding: 8px 15px;
  border-radius: 50px;
  align-self: center;
  background: #da4a4a;
  box-shadow: 5px 5px 0 rgba(255, 255, 255, 0.8);
}

.function button {
  user-select: none;
  margin: 10px;
  height: 32px;
  width: auto;
  outline: 0;
  border: 3px solid #474f51;
  box-shadow:
    0 0 0 8px rgba(255, 255, 255, 0.1),
    inset 4px 4px 0 0px rgba(255, 255, 255, 0.4);
  background: #857b7a;
  color: #000;
  border-radius: 15px;
}

.action {
  display: flex;
  align-self: flex-end;
}

.action button {
  user-select: none;
  width: 56px;
  height: 56px;
  background: #857b7a;
  border-radius: 50%;
  outline: 0;
  color: #000;
  border: 8px solid #474f51;
  box-shadow:
    0 0 0 10px rgba(255, 255, 255, 0.8),
    inset 5px 8px 0 0px rgba(255, 255, 255, 0.4),
    inset -5px -8px 0 0px rgba(0, 0, 0, 0.1);
}

.action button:first-child {
  margin-right: 24px;
}
.sign {
  position: absolute;
  font-weight: bold;
  font-size: 20px;
  /* font-style: italic; */
  height: 10px;
  right: 0;
  top: 0;
  background: #da4a4a;
  color: #f8f1d7;
  /* text-shadow: 0 -2px #fffef7; */
  /* padding: 0 0 15px 15px; */
  letter-spacing: 0.1em;
  border-bottom-left-radius: 15px;
  filter: drop-shadow(0 8px #fffef7);
}

.sign::before {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  left: -15px;
  top: 0;
  background: radial-gradient(
    circle at left bottom,
    transparent 14px,
    #da4a4a 15px
  );
}

.sign::after {
  content: '';
  position: absolute;
  width: 15px;
  height: 15px;
  bottom: -15px;
  right: 0;
  background: radial-gradient(
    circle at left bottom,
    transparent 14px,
    #da4a4a 15px
  );
}

.joy {
  position: absolute;
  left: 0;
  top: 0;
  width: 50px;
  height: 50px;
  background: #857b7a;
  border-radius: 5px;
  text-align: center;
  line-height: 50px;
  color: #f8f1d7;
  font-weight: bold;
  font-size: 30px;
}

.screen {
  flex: 1;
  display: flex;
  width: 100%;
  transition: 0.3s;
  background: #000;
  margin-bottom: 5px;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto !important;
  height: 100% !important;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* 让canvas在保持宽高比的同时尽可能放大 */
.nes-screen {
  max-width: 100% !important;
  max-height: 100% !important;
  width: auto !important;
  height: 100% !important;
  object-fit: contain !important;
}

#emulator {
  position: relative;
}

/* 完全隐藏emulator中的控制元素，避免加载时闪烁 */
#emulator .nes-roms,
#emulator .nes-controls {
  display: none !important;
  visibility: hidden !important;
}

/* 初始状态下隐藏按键说明按钮 */
.controller-area .nes-keyhelp {
  display: none;
}

#emulator > div {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.nes-screen {
  flex: 1;
  min-height: 0;
}

#game-controls-container {
  position: absolute;
  left: 0;
  top: 140px;
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 容器内元素正常显示 */
#game-controls-container > * {
  opacity: 1;
}

.nes-roms {
  background: #857b7a;
  padding: 5px;
  border-radius: 5px;
}

/* 确保移动到game-controls-container的元素可见 */
#game-controls-container .nes-roms {
  display: block !important;
  visibility: visible !important;
}

.nes-roms > select {
  width: 100%;
  padding: 5px;
  font-size: 12px;
  border: 2px solid #474f51;
  border-radius: 3px;
  background: #f8f1d7;
  cursor: pointer;
  box-sizing: border-box;
}

.nes-controls {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: #857b7a;
  padding: 5px;
  border-radius: 5px;
}

/* 确保移动到game-controls-container的控制按钮可见 */
#game-controls-container .nes-controls {
  display: flex !important;
  visibility: visible !important;
}

.nes-controls input[type='button'],
.nes-keyhelp {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  border: 2px solid #474f51;
  border-radius: 3px;
  background: #f8f1d7;
  color: #000;
  cursor: pointer;
  transition: all 0.3s;
  box-sizing: border-box;
  font-weight: bold;
}

/* 确保移动到controls内的按键说明按钮可见 */
.nes-controls .nes-keyhelp {
  display: block !important;
}

.nes-controls input[type='button']:hover:not(:disabled),
.nes-keyhelp:hover {
  background: #fffef7;
  transform: translateY(-1px);
}

.nes-controls input[type='button']:active:not(:disabled),
.nes-keyhelp:active {
  transform: translateY(0);
}

.nes-controls input[type='button']:disabled {
  background: #d0d0d0;
  color: #888;
  cursor: not-allowed;
  opacity: 0.6;
}

.nes-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.8);
  padding: 10px 20px;
  border-radius: 5px;
  z-index: 5;
}

@media screen and (orientation: portrait) {
  /*ç«–å± css*/
  .main {
    max-height: 100%;
  }
  .function-area {
    position: absolute;
    left: 0;
    right: 0;
    top: 80px;
    bottom: 100px;
    padding-bottom: 80px;
  }
  .function {
    position: absolute;
    bottom: 0;
    align-self: flex-end;
    transform: translateX(20px);
    padding: 8px 10px;
    border-radius: 50px 0 0 50px;
    box-shadow: 0px 5px 0 rgba(255, 255, 255, 0.8);
  }
  .function::before {
    content: '';
    position: absolute;
    width: 15px;
    height: 15px;
    right: 0;
    top: -15px;
    background: radial-gradient(
      circle at left top,
      transparent 14px,
      #da4a4a 15px
    );
  }
  .function::after {
    content: '';
    position: absolute;
    width: 15px;
    height: 15px;
    bottom: -15px;
    right: 0;
    background: radial-gradient(
      circle at left bottom,
      transparent 14px,
      #da4a4a 15px
    );
  }
  .screen {
    margin-bottom: 0;
    max-height: 300px;
  }
  .function button {
    width: 56px;
    margin: 10px;
  }
  .action-area {
    flex: 1;
    justify-content: flex-end;
  }
  .action button:first-child {
    margin-right: 20px;
  }

  /* 竖屏时让控制区元素悬浮显示 */
  #game-controls-container {
    position: static;
    width: 0;
    height: 0;
    overflow: visible;
  }

  #game-controls-container .nes-roms,
  .nes-roms {
    position: fixed !important;
    top: 5px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 100 !important;
    width: auto !important;
    max-width: 80% !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  .nes-roms > select {
    font-size: 12px !important;
    padding: 5px 8px !important;
  }

  #game-controls-container .nes-controls,
  .nes-controls {
    position: fixed !important;
    top: 35px !important;
    bottom: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 100 !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    width: auto !important;
    max-width: 95% !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    gap: 4px !important;
    background: rgba(248, 241, 215, 0.9) !important;
    padding: 5px 8px !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
  }

  .nes-controls input[type='button'],
  .nes-keyhelp {
    width: auto;
    white-space: nowrap;
    font-size: 11px !important;
    padding: 6px 10px !important;
  }
}

@media screen and (orientation: landscape) {
  /*æ¨ªå± css*/
}

@media screen and (min-width: 600px) {
  /* PC大屏幕优化 */
  .main {
    max-width: calc(50vh + 400px);
    max-height: none;
    width: auto;
    height: 90vh;
    margin: auto;
  }

  /* PC端隐藏虚拟按键，只保留游戏控制容器 */
  .controller-area .controller,
  .controller-area .joy,
  .action-area,
  .function {
    display: none !important;
  }

  /* panel居中布局 */
  .panel {
    justify-content: center;
    align-items: center;
  }

  /* 左侧控制区域调整 */
  .controller-area {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 200px;
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }

  /* 游戏显示区域改为正方形并居中 */
  .function-area {
    flex: none;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .screen {
    width: 80vh;
    height: 80vh;
    min-width: 80vh;
    min-height: 80vh;
    max-width: 80vh;
    max-height: 80vh;
    flex: none;
  }

  .sign {
    font-size: 20px;
    height: 10px;
    padding: 0 0 15px 15px;
  }

  /* PC端游戏控制区域优化 */
  #game-controls-container {
    position: static;
    width: 100%;
    margin-top: 15px;
  }

  .nes-roms > select {
    font-size: 14px;
    padding: 6px;
  }

  .nes-controls input[type='button'],
  .nes-keyhelp {
    font-size: 13px;
    padding: 8px 10px;
  }

  /* PC端canvas充满正方形区域 */
  .screen canvas,
  .nes-screen {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
  }
}

/* 按键说明弹窗样式 - 优化版 */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: #ffffff;
  margin: 5% auto;
  padding: 0;
  border: 1px solid rgba(218, 74, 74, 0.15);
  border-radius: 16px;
  width: 90%;
  max-width: 550px;
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  animation: slideDown 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
  position: relative;
  overflow: hidden;
}

@keyframes slideDown {
  from {
    transform: translateY(-80px) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* 弹窗顶部简约装饰 */
.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #da4a4a 50%, transparent);
  opacity: 0.6;
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  color: #999;
  font-size: 28px;
  font-weight: normal;
  line-height: 32px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
}

.modal-close:hover {
  color: #da4a4a;
  background: rgba(218, 74, 74, 0.08);
  transform: scale(1.1);
}

.modal-content h2 {
  margin: 0;
  padding: 32px 50px 24px 32px;
  color: #333;
  font-size: 24px;
  font-weight: 600;
  text-align: left;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  letter-spacing: 0.5px;
  position: relative;
}

/* 标题装饰点 */
.modal-content h2::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  background: #da4a4a;
  border-radius: 2px;
}

.modal-content h2::after {
  content: '';
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  opacity: 0.5;
}

.help-desc {
  color: #666;
  font-size: 14px;
  margin: 24px 32px 20px;
  text-align: center;
  padding: 0;
  background: transparent;
  line-height: 1.6;
}

.key-table {
  width: calc(100% - 64px);
  margin: 0 32px 32px;
  border-collapse: collapse;
  border-spacing: 0;
}

.key-table thead {
  background: #fafafa;
  border-bottom: 2px solid #f0f0f0;
}

.key-table th {
  padding: 14px 20px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.key-table th:first-child {
  padding-left: 24px;
  width: 35%;
}

.key-table th:nth-child(2),
.key-table th:nth-child(3) {
  text-align: center;
  width: 32.5%;
}

.key-table td {
  padding: 16px 20px;
  text-align: left;
  font-size: 15px;
  border-bottom: 1px solid #f5f5f5;
}

.key-table tbody tr {
  background: #fff;
  transition: background 0.2s ease;
}

.key-table tbody tr:hover {
  background: #fafafa;
}

.key-table tbody tr:last-child td {
  border-bottom: none;
}

.key-table td:first-child {
  font-weight: 500;
  color: #333;
  padding-left: 24px;
}

.key-table td:nth-child(2),
.key-table td:nth-child(3) {
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
  font-weight: 500;
  color: #da4a4a;
  text-align: center;
  font-size: 14px;
  background: #fafafa;
}

.key-table td:nth-child(2) {
  border-right: 1px solid #f0f0f0;
}

/* 移动端弹窗优化 */
@media screen and (max-width: 600px) {
  .modal-content {
    width: 95%;
    margin: 10% auto;
    border-radius: 14px;
  }

  .modal-content h2 {
    font-size: 20px;
    padding: 24px 50px 20px 28px;
  }

  .modal-content h2::before {
    left: 10px;
    width: 3px;
    height: 20px;
  }

  .modal-content h2::after {
    font-size: 18px;
    right: 16px;
  }

  .help-desc {
    font-size: 13px;
    margin: 20px 24px 16px;
  }

  .key-table {
    width: calc(100% - 48px);
    margin: 0 24px 28px;
  }

  .key-table th {
    padding: 12px 12px;
    font-size: 12px;
  }

  .key-table th:first-child {
    padding-left: 16px;
  }

  .key-table td {
    padding: 14px 12px;
    font-size: 14px;
  }

  .key-table td:first-child {
    padding-left: 16px;
    font-size: 14px;
  }

  .key-table td:nth-child(2),
  .key-table td:nth-child(3) {
    font-size: 13px;
  }

  .modal-close {
    font-size: 26px;
    top: 16px;
    right: 16px;
    width: 30px;
    height: 30px;
  }
}

/* 嵌入模式样式 - 隐藏所有游戏按键 */
body.embed-mode > .controller-area .controller,
body.embed-mode > .controller-area .joy,
body.embed-mode .action-area,
body.embed-mode .function {
  display: none !important;
}

/* 嵌入模式下调整布局 */
body.embed-mode .main {
  padding-bottom: 100px;
  box-sizing: border-box;
}

body.embed-mode .panel {
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

/* 嵌入模式下 controller-area 样式（已移到 body 下） */
body.embed-mode > .controller-area {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  transform: none;
  width: 100%;
  flex: none;
  display: flex !important;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    to top,
    rgba(255, 255, 255, 0.98),
    rgba(255, 255, 255, 0.95)
  );
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 20px 24px;
  box-shadow:
    0 -4px 20px rgba(0, 0, 0, 0.08),
    0 -2px 8px rgba(0, 0, 0, 0.04);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 1000;
  gap: 12px;
  visibility: visible !important;
  opacity: 1 !important;
}

body.embed-mode .function-area {
  flex: 1;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

body.embed-mode .screen {
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  max-width: 98%;
  max-height: 98%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.embed-mode #emulator {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 嵌入模式下游戏控制容器横向排列 */
body.embed-mode #game-controls-container {
  position: static;
  width: auto;
  flex-direction: row;
  align-items: flex-end;
  gap: 20px;
}

/* 添加动画效果 */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

body.embed-mode #game-controls-container .nes-roms {
  position: relative;
}

/* 嵌入模式下游戏选择下拉框样式 */
body.embed-mode #game-controls-container .nes-roms {
  width: 300px;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  position: static !important;
  transform: none !important;
  margin: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  flex-direction: column;
  gap: 8px;
}

/* 游戏选择提示标签 */
body.embed-mode #game-controls-container .nes-roms::before {
  content: '🎮 点击选择游戏';
  font-size: 14px;
  font-weight: 600;
  color: #333;
  letter-spacing: 0.5px;
  animation: fadeInDown 0.6s ease-out;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  display: block;
  line-height: 1.4;
}

body.embed-mode .nes-roms > select {
  min-width: 220px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  background: #ffffff;
  border: 1.5px solid #e0e0e0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

body.embed-mode .nes-roms > select:hover {
  border-color: #da4a4a;
  box-shadow: 0 4px 12px rgba(218, 74, 74, 0.12);
  transform: translateY(-1px);
}

body.embed-mode .nes-roms > select:focus {
  border-color: #da4a4a;
  box-shadow:
    0 0 0 3px rgba(218, 74, 74, 0.1),
    0 4px 12px rgba(218, 74, 74, 0.15);
}

/* 嵌入模式下控制按钮横向排列 */
body.embed-mode #game-controls-container .nes-controls {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  position: static !important;
  transform: none !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  gap: 8px;
  margin: 0;
  background: transparent;
  padding: 0 0 0 20px;
  border-radius: 0;
  border-left: 1px solid rgba(0, 0, 0, 0.08);
}

body.embed-mode .nes-controls input[type='button'],
body.embed-mode .nes-keyhelp {
  white-space: nowrap;
  margin: 0;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(135deg, #da4a4a 0%, #c93939 100%);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  box-shadow:
    0 2px 8px rgba(218, 74, 74, 0.25),
    0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
  z-index: 1;
}

body.embed-mode .nes-controls input[type='button']::before,
body.embed-mode .nes-keyhelp::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.15),
    rgba(255, 255, 255, 0.05)
  );
  opacity: 0;
  transition: opacity 0.25s;
  z-index: -1;
  pointer-events: none;
}

body.embed-mode .nes-controls input[type='button']:hover:not(:disabled),
body.embed-mode .nes-keyhelp:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 16px rgba(218, 74, 74, 0.35),
    0 3px 6px rgba(0, 0, 0, 0.15);
  background: linear-gradient(135deg, #e55555 0%, #d44444 100%);
}

body.embed-mode .nes-controls input[type='button']:hover:not(:disabled)::before,
body.embed-mode .nes-keyhelp:hover::before {
  opacity: 1;
}

/* 确保文字始终可见 */
body.embed-mode .nes-controls input[type='button']:hover:not(:disabled),
body.embed-mode .nes-keyhelp:hover {
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

body.embed-mode .nes-controls input[type='button']:active:not(:disabled),
body.embed-mode .nes-keyhelp:active {
  transform: translateY(0);
  box-shadow:
    0 2px 4px rgba(218, 74, 74, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.1);
}

body.embed-mode .nes-controls input[type='button']:disabled {
  background: linear-gradient(135deg, #e0e0e0 0%, #d0d0d0 100%);
  color: #999;
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
  transform: none;
}

/* 嵌入模式下canvas充满区域 */
body.embed-mode .screen canvas,
body.embed-mode .nes-screen {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
}

/* 嵌入模式下的响应式设计 */
@media screen and (max-width: 768px) {
  body.embed-mode .main {
    padding-bottom: 140px;
  }

  body.embed-mode > .controller-area {
    padding: 20px 16px;
    gap: 10px;
    flex-wrap: wrap;
  }

  body.embed-mode #game-controls-container {
    gap: 10px;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  body.embed-mode #game-controls-container .nes-roms {
    width: 100%;
  }

  body.embed-mode .nes-roms > select {
    min-width: 160px;
    font-size: 13px;
    padding: 8px 12px;
    width: 100%;
  }

  body.embed-mode .nes-controls {
    border-left: none !important;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding: 12px 0 0 0 !important;
    justify-content: center;
  }

  body.embed-mode .nes-controls input[type='button'],
  body.embed-mode .nes-keyhelp {
    font-size: 13px;
    padding: 8px 14px;
  }
}

@media screen and (max-width: 480px) {
  body.embed-mode .main {
    padding-bottom: 160px;
  }

  body.embed-mode .nes-controls {
    flex-wrap: wrap;
  }

  body.embed-mode .nes-controls input[type='button'],
  body.embed-mode .nes-keyhelp {
    flex: 1 1 auto;
    min-width: 100px;
  }
}

/* 按键设置相关样式 */
.key-settings-container {
  padding: 0;
}

.key-setting-cell {
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  position: relative;
}

.key-setting-cell:hover {
  background: #f0f0f0 !important;
  color: #da4a4a !important;
  transform: scale(1.05);
}

.key-setting-cell:active {
  transform: scale(0.98);
}

.key-settings-footer {
  padding: 20px 32px 32px;
  text-align: center;
  border-top: 1px solid #f0f0f0;
}

.reset-keys-btn {
  background: #da4a4a;
  color: #fff;
  border: none;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(218, 74, 74, 0.2);
}

.reset-keys-btn:hover {
  background: #c43a3a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(218, 74, 74, 0.3);
}

.reset-keys-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(218, 74, 74, 0.2);
}

/* 按键输入小弹窗 */
.key-input-modal-content {
  max-width: 400px;
  padding: 0;
}

.key-input-container {
  padding: 32px;
  text-align: center;
}

.key-input-prompt {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin-bottom: 24px;
  padding: 20px;
  background: #fafafa;
  border-radius: 8px;
  border: 2px dashed #ddd;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.key-input-prompt.listening {
  border-color: #da4a4a;
  background: #fff5f5;
  color: #da4a4a;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

.key-input-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.clear-key-btn {
  background: #f5f5f5;
  color: #666;
  border: 1px solid #ddd;
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-key-btn:hover {
  background: #e8e8e8;
  border-color: #ccc;
  color: #333;
}

.clear-key-btn:active {
  transform: scale(0.98);
}

/* 移动端按键设置优化 */
@media screen and (max-width: 600px) {
  .key-settings-footer {
    padding: 16px 24px 24px;
  }

  .reset-keys-btn {
    padding: 10px 24px;
    font-size: 13px;
  }

  .key-input-container {
    padding: 24px;
  }

  .key-input-prompt {
    font-size: 20px;
    padding: 16px;
    min-height: 50px;
  }

  .key-input-actions {
    flex-direction: column;
  }

  .clear-key-btn {
    width: 100%;
    padding: 12px;
  }
}
