:root {
  --bg: #0e1116;
  --bg2: #161b22;
  --panel: #1b222c;
  --border: #2b3543;
  --text: #e6edf3;
  --muted: #8b97a8;
  --accent: #e5484d;
  --accent2: #3b82f6;
  --green: #3fb950;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #1a2230 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 18px 40px;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

h1 {
  font-size: 20px;
  letter-spacing: 2px;
  margin: 0;
  text-shadow: 0 0 14px rgba(229, 72, 77, .55);
}

.rom-info { font-size: 13px; color: var(--muted); }
.rom-info .label { margin-right: 6px; opacity: .7; }
#romName { color: var(--text); font-weight: 600; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

/* ---------- Screen ---------- */
.screen-wrap {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6), inset 0 0 0 1px rgba(255,255,255,.03);
  aspect-ratio: 256 / 240;
  width: 100%;
}

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

.screen-wrap:fullscreen {
  aspect-ratio: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
}
.screen-wrap:fullscreen #screen { width: auto; height: 100vh; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 15, .92);
  backdrop-filter: blur(3px);
  text-align: center;
  transition: opacity .2s;
}
.overlay.hidden { display: none; }
.overlay.dragover { background: rgba(59, 130, 246, .22); outline: 2px dashed var(--accent2); outline-offset: -14px; }

.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px; }
.drop-icon { font-size: 40px; opacity: .6; }
.drop-inner p { margin: 0; color: var(--muted); }
.drop-inner code { color: var(--accent2); }
.small { font-size: 12px; }

.pause-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,.65);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  letter-spacing: 1px;
}
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #232c38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover:not(:disabled) { background: #2c3846; border-color: #3a4757; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #f0565b; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }

/* ---------- Panel ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.panel .row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.panel .row > .btn { flex: 1; }

.volume-row { align-items: center; flex-wrap: nowrap; }
.volume-row input[type=range] { flex: 1; accent-color: var(--accent); }
.fps { font-size: 11px; color: var(--muted); min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 18px 0 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.panel h2 .hint { font-size: 10px; text-transform: none; letter-spacing: 0; opacity: .65; font-weight: 400; }

/* ---------- Save slots ---------- */
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #12171e;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.slot .thumb {
  width: 100%;
  aspect-ratio: 256 / 240;
  background: #05070a;
  border-radius: 5px;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}
.slot .thumb.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #46505f;
}
.slot .meta { font-size: 10.5px; color: var(--muted); display: flex; justify-content: space-between; }
.slot .acts { display: flex; gap: 4px; }
.slot .acts button {
  flex: 1;
  background: #232c38;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  font-size: 11px;
  padding: 4px 0;
  cursor: pointer;
}
.slot .acts button:hover:not(:disabled) { background: #2c3846; }
.slot .acts button:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Keys ---------- */
.keys { width: 100%; border-collapse: collapse; font-size: 12px; }
.keys td { padding: 5px 4px; border-bottom: 1px solid #232c38; color: var(--muted); }
.keys td:first-child { color: var(--text); white-space: nowrap; width: 45%; }

.status { font-size: 12px; color: var(--muted); margin: 14px 0 0; min-height: 16px; line-height: 1.5; }
.status.error { color: var(--accent); }
.status.ok { color: var(--green); }

.game-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.game-list .btn { flex: 0 1 auto; text-align: left; }

.rom-row { align-items: center; }
.game-select {
  flex: 1 1 auto;
  min-width: 0;
  background: #232c38;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  cursor: pointer;
}
.game-select:disabled { opacity: .5; cursor: default; }
/* 图标按钮：窄、不右伸；覆盖 .panel .row > .btn 的 flex:1 */
.panel .row.rom-row > .btn.icon {
  flex: 0 0 auto;
  width: 40px;
  padding: 9px 0;
  font-size: 16px;
  line-height: 1;
}

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  .slots { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---------- 错误弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 13, .66);
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 22px 24px;
  width: calc(100% - 40px);
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  animation: pop .12s ease-out;
}
@keyframes pop { from { transform: scale(.96); opacity: .6; } to { transform: scale(1); opacity: 1; } }
.modal-box h3 { margin: 0 0 10px; color: var(--accent); font-size: 17px; }
.modal-box p { margin: 0 0 18px; color: var(--text); line-height: 1.75; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

