:root {
  --bg: #14111c;
  --bg-soft: #1c1728;
  --panel: #241d33;
  --panel-hi: #2f2643;
  --line: #3a3050;
  --ink: #ece8f7;
  --ink-dim: #9d93b8;
  --accent: #9a5cff;
  --accent-deep: #6f2bd6;
  --lcd: #0a0810;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 6px;
}

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

.logo {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--accent), var(--accent-deep));
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(111, 43, 214, .45);
}

.titles { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.titles strong { font-size: 15px; letter-spacing: .3px; }
.titles span {
  font-size: 11px;
  color: var(--ink-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}

.sound {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  display: grid; place-items: center;
}
.sound.off { opacity: .45; }

/* ---------- 屏幕 ---------- */
.screen-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
}

.screen-frame {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 10 / 9;
  padding: 8px;
  border-radius: 18px;
  background: #0d0a14;
  border: 1px solid #2a2238;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.03), 0 14px 34px rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--lcd);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

.overlay {
  position: absolute;
  inset: 8px;
  border-radius: 8px;
  background: rgba(10, 8, 16, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  transition: opacity .22s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.ov-title { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.ov-sub { margin: 0 0 16px; font-size: 12px; color: var(--ink-dim); }

.cta {
  border: 0;
  border-radius: 12px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(160deg, var(--accent), var(--accent-deep));
  box-shadow: 0 8px 18px rgba(111, 43, 214, .38);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 16, 30, .92);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 控制区 ---------- */
.pad {
  flex: 0 0 auto;
  padding: 4px 18px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pad-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

/* 十字键 */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  grid-template-areas:
    ". up ."
    "left core right"
    ". down .";
  touch-action: none;
}

.db {
  border: 1px solid #41355c;
  background: linear-gradient(180deg, #332a47, #251e35);
  color: transparent;
  position: relative;
  padding: 0;
  touch-action: none;
}
.db::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 0; height: 0;
  border: 7px solid transparent;
}
.db.up { grid-area: up; border-radius: 12px 12px 4px 4px; }
.db.up::after { border-bottom-color: #b9aed6; margin-top: -4px; }
.db.down { grid-area: down; border-radius: 4px 4px 12px 12px; }
.db.down::after { border-top-color: #b9aed6; margin-bottom: -4px; }
.db.left { grid-area: left; border-radius: 12px 4px 4px 12px; }
.db.left::after { border-right-color: #b9aed6; margin-left: -4px; }
.db.right { grid-area: right; border-radius: 4px 12px 12px 4px; }
.db.right::after { border-left-color: #b9aed6; margin-right: -4px; }

.dpad-core {
  grid-area: core;
  background: #221b31;
  border-top: 1px solid #3a2f52;
  border-bottom: 1px solid #1a1425;
}

.db.active { background: linear-gradient(180deg, #4b3a6b, #34284d); }
.db.active::after { filter: brightness(1.4); }

/* A / B */
.ab {
  position: relative;
  width: 148px;
  height: 132px;
  touch-action: none;
}

.rbtn {
  position: absolute;
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 1px solid #40345c;
  background: radial-gradient(circle at 35% 30%, #3d3157, #241c34 70%);
  color: #d9d1ee;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .5px;
  box-shadow: 0 6px 14px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.07);
  touch-action: none;
}
.rbtn.a { right: 0; top: 8px; width: 76px; height: 76px; }
.rbtn.b { left: 0; bottom: 5px; }
.rbtn.active {
  background: radial-gradient(circle at 35% 30%, #6c4aa8, #3a2a5c 70%);
  color: #fff;
  transform: scale(.97);
}

/* SELECT / START */
.menu { display: flex; justify-content: center; gap: 14px; }

.pill {
  flex: 1 1 0;
  max-width: 168px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: none;
}
.pill i {
  width: 14px; height: 6px;
  border-radius: 999px;
  background: #4b3f66;
  display: block;
}
.pill.active { background: #2b2340; color: var(--ink); border-color: #54446f; }
.pill.active i { background: var(--accent); }

/* 工具按钮 */
.tools { display: flex; gap: 10px; }

.tool {
  flex: 1 1 0;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}
.tool:active { background: var(--panel-hi); }

.tool:disabled { opacity: .45; }

/* 横屏时并排 */
@media (orientation: landscape) and (max-height: 560px) {
  body { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .topbar { flex: 1 0 100%; }
  .screen-area { flex: 1 1 55%; padding: 4px 8px; }
  .pad { flex: 1 1 42%; padding: 4px 12px; gap: 8px; }
  .dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
  .ab { width: 132px; height: 112px; }
  .rbtn { width: 58px; height: 58px; font-size: 16px; }
  .rbtn.a { width: 66px; height: 66px; }
}

/* ---------- 拖拽高亮 ---------- */
.screen-frame.dragging {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(154, 92, 255, .35), 0 14px 34px rgba(0, 0, 0, .5);
}

/* ---------- 槽位选择面板 ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 6, 12, .62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.sheet[hidden] { display: none; }

.sheet-card {
  width: 100%;
  max-width: 480px;
  padding: 18px 18px calc(16px + env(safe-area-inset-bottom));
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  animation: sheet-up .2s ease;
}

@keyframes sheet-up {
  from { transform: translateY(14px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
}

.sheet-sub {
  margin: 0 0 14px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-dim);
  text-align: center;
  word-break: break-all;
}

.sheet-slots { display: flex; gap: 10px; }

.sheet-slots button {
  flex: 1 1 0;
  height: 64px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.sheet-slots button b { font-size: 18px; }
.sheet-slots button span { font-size: 11px; color: var(--ink-dim); }
.sheet-slots button:active { background: var(--panel-hi); }

.sheet-cancel {
  width: 100%;
  height: 44px;
  margin-top: 12px;
  border: 0;
  border-radius: 12px;
  background: #221b31;
  color: var(--ink-dim);
  font-size: 13px;
}
