:root {
  color-scheme: dark;
  --bg: #070b14;
  --nav: #101722;
  --panel: #162033;
  --card: #1c283c;
  --line: #31425c;
  --text: #f4f7fb;
  --muted: #9aabc2;
  --accent: #ff8a1e;
  --accent-ink: #2a1408;
  --ok: #8ed39a;
  --danger: #e25b4a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(900px 320px at 50% -10%, rgba(255, 138, 30, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

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

button { cursor: pointer; }

.shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(180px, 460px) auto;
  gap: 16px;
  align-items: center;
  padding: 14px 22px 6px;
}

.status { display: flex; gap: 8px; justify-content: flex-end; }
.status span, .dock .nav-btn {
  border: 1px solid var(--line);
  background: rgba(16, 23, 34, 0.9);
}

.status span {
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.dock {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 18px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.35));
}

.dock .nav-btn {
  border-radius: 12px;
  padding: 12px 8px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

.dock .nav-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 700;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
}

.mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 20px;
}

.brand strong { display: block; }
.brand span, .hint, .list-count, .now-meta, .nav-note, .settings dd {
  color: var(--muted);
  font-size: 12px;
}

.toolbar-actions button, .menu button, .detail-actions button, .pad button, .file-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
}

.toolbar-actions button.active, .filters button.active, .platforms button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.view { min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.view.hidden { display: none; }

.playbar, .settings, #view-settings { padding: 14px 22px 0; }
.shelf-tools { padding: 0 22px; }
#view-settings { overflow: auto; }
#view-settings h2 { margin: 8px 0 12px; }

.search input {
  width: 100%;
  background: rgba(8, 12, 20, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
}

.field select, .cheat-form input, select {
  width: 100%;
  background: #12151c;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.history, .filters, .platforms, .toolbar-row, .toolbar-actions, .play-actions, .menu-grid, .detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.history { min-height: 0; margin: 0 22px 4px; }
.history:empty { display: none; }
.history button, .filters button, .platforms button {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 4px 10px;
}

.toolbar-row { justify-content: space-between; margin: 8px 0; }
.toolbar-actions select { width: auto; padding: 6px 8px; }
.list-count { margin: 4px 22px 0; }

.grid {
  overflow: auto;
  padding: 0 22px 18px;
  min-height: 0;
}

#list { flex: 1; min-height: 0; }
.shelves {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}
.shelf h2 {
  margin: 8px 0 0;
  font-size: 18px;
}
.shelf h2::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 14px;
  margin-right: 8px;
  border-radius: 4px;
  background: var(--accent);
  vertical-align: -1px;
}
.row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 10px 2px 16px;
  scroll-snap-type: x proximity;
}
.row .card { flex: 0 0 196px; scroll-snap-align: start; }

.grid.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  align-content: start;
}

.grid.list { display: flex; flex-direction: column; gap: 6px; }

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-width: 0;
}

.grid.list .card { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; }

.game {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 10px;
  border-radius: 14px;
}

.cover {
  display: grid;
  place-items: center;
  height: 110px;
  border-radius: 10px;
  background: #343042;
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
}

.grid.list .cover { display: none; }
.game .name { display: block; font-size: 14px; }
.game .sub { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.game .sub.ok { color: var(--ok); }
.card.locked { opacity: 0.62; }
.card.current, .card:focus-within {
  outline: 3px solid var(--accent);
  transform: translateY(-2px);
}

.star, .info {
  position: absolute;
  top: 8px;
  border: 0;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  padding: 2px 6px;
}

.grid.list .star, .grid.list .info { position: static; align-self: center; margin-right: 8px; }
.star { right: 8px; }
.info { right: 36px; }
.star.on { color: var(--accent); }

#view-play { position: relative; background: #000; }

.playbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 16px 28px;
  background: linear-gradient(rgba(0, 0, 0, 0.72), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

#view-play:hover .playbar,
#view-play:focus-within .playbar { opacity: 1; }

.now-title { font-size: 18px; font-weight: 700; }

.stage {
  position: absolute;
  inset: 0;
  min-height: 0;
}

.menu.hidden { display: none; }
.stage.menu-off .menu { display: none; }

.bezel {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
}

.screen {
  flex: 1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen canvas {
  image-rendering: pixelated;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  text-align: center;
  color: var(--accent);
  pointer-events: none;
}

.overlay.hidden { display: none; }

.menu {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  width: min(360px, 92vw);
  overflow: auto;
  background: rgba(22, 32, 51, 0.94);
  border-left: 1px solid var(--line);
  padding: 12px;
}

.menu h2, .menu h3 { margin: 10px 0 8px; font-size: 14px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; }
.field { display: block; margin: 8px 0; font-size: 13px; }
.field select { margin-top: 4px; }

.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.slot {
  border: 1px solid var(--line);
  background: #12151c;
  border-radius: 8px;
  padding: 4px;
  text-align: center;
  font-size: 12px;
}
.slot img { width: 100%; height: 52px; object-fit: contain; background: #000; display: block; }
.slot small { display: block; color: var(--muted); }

.cheat-form { display: flex; gap: 6px; }
.cheat-form input { flex: 1; }
.cheat-list { list-style: none; padding: 0; margin: 8px 0; }
.cheat-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }

.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.keys button.wait { outline: 2px solid var(--accent); }

.file-btn { position: relative; overflow: hidden; text-align: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.pad { display: none; }

.dpad, .face { display: grid; grid-template-columns: repeat(4, 52px); gap: 6px; }
.pad button { height: 40px; border-radius: 10px; text-align: center; user-select: none; touch-action: none; }
.pad button.a { background: var(--danger); border-color: var(--danger); }
.pad button.b { background: #b45309; border-color: #b45309; }

.settings { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; }
.settings dt { color: var(--accent); }
.settings dd { margin: 0; }

.detail {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
}

.detail.hidden { display: none; }
.detail-card {
  width: min(480px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}
.detail-card h2 { margin: 0 0 8px; }
.detail-actions { margin-top: 12px; }
#detailPlay { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(12px);
  background: #2c313d;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

button:disabled { opacity: 0.45; cursor: default; }

.hidden { display: none !important; }

.key-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 5;
}

.key-panel {
  width: min(860px, 100%);
  background: #1b1e27;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.key-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.key-head button {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  font-size: 22px;
}

.key-body {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  min-height: 420px;
}

.joy {
  display: grid;
  place-items: center;
  background: #151820;
}

.joy-body {
  width: min(420px, 90%);
  height: 180px;
  border-radius: 28px;
  background: linear-gradient(#f3e2b8, #e7cc93);
  border: 8px solid #c4473a;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  padding: 0 22px;
  box-shadow: inset 0 0 0 3px #f8edd2;
}

.joy-dpad {
  width: 72px;
  height: 72px;
  background:
    linear-gradient(#1c1c1c, #1c1c1c) center/24px 72px no-repeat,
    linear-gradient(#1c1c1c, #1c1c1c) center/72px 24px no-repeat;
}

.joy-mid, .joy-ab {
  display: flex;
  justify-content: center;
  gap: 10px;
  color: #3a2a16;
  font-size: 11px;
  font-weight: 700;
}

.joy-ab span, .joy-mid span {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #1c1c1c;
  color: #f4efe4;
}

.joy-mid span {
  width: 36px;
  height: 16px;
  border-radius: 8px;
  font-size: 8px;
}

.key-side { padding: 16px; }
.player-switch, .key-tabs { display: flex; justify-content: center; gap: 8px; align-items: center; }
.player-switch { margin-bottom: 8px; }
.player-switch button, .key-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
}
.key-tabs button.active { color: #b48cff; }

.key-table { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow: auto; }
.key-row {
  display: flex;
  justify-content: space-between;
  border: 1px solid #3a3348;
  background: #221f2b;
  border-radius: 8px;
  padding: 8px 10px;
}
.key-row.wait { outline: 2px solid #b48cff; }
.pad-panel { color: var(--muted); font-size: 13px; line-height: 1.6; }
#resetKeys { margin-top: 10px; width: 100%; }

body[data-page="play"] .topbar,
body[data-page="play"] .dock { display: none; }
body[data-page="play"] .shell { grid-template-rows: minmax(0, 1fr); }

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; }
  .status { justify-content: flex-start; }
  .dock .nav-btn { font-size: 13px; padding: 10px 4px; }
  .menu { width: 100%; max-height: 70%; top: auto; }
  .key-body { grid-template-columns: 1fr; }
  .joy { min-height: 220px; }
}
