:root {
  --bg: #12131a;
  --panel: #1d1f2b;
  --panel2: #272a3a;
  --text: #eef0f7;
  --muted: #9aa0b8;
  --accent: #7c6cff;
  --accent2: #4cd3a5;
  --danger: #ff6b6b;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }

/* library */
#library { overflow-y: auto; padding: 24px 16px; align-items: center; }
.top { text-align: center; }
.top h1 { margin: 8px 0 4px; font-size: 28px; letter-spacing: .5px; }
.sub { margin: 0 0 18px; color: var(--muted); }
.bigbtn { display: block; width: 100%; max-width: 420px; text-align: center; padding: 18px; border-radius: var(--radius);
  background: var(--accent); font-weight: 600; font-size: 17px; cursor: pointer; }
.bigbtn:active { transform: scale(.98); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 18px; text-align: center; }
h2 { font-size: 16px; color: var(--muted); align-self: stretch; max-width: 420px; margin: 8px auto; width: 100%; }
.recent { list-style: none; padding: 0; margin: 0; width: 100%; max-width: 420px; }
.recent li { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; }
.recent li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.recent li button { background: none; border: 0; color: var(--muted); padding: 4px 8px; }
.foot { margin-top: auto; padding-top: 24px; color: var(--muted); font-size: 12px; text-align: center; max-width: 520px; }
.notice { max-width: 420px; width: 100%; background: #3a2b14; color: #ffd28a; padding: 12px 14px; border-radius: var(--radius);
  margin-bottom: 14px; font-size: 14px; }
.notice a, .notice button { color: #fff; }

/* game */
#game { background: #000; position: relative; }
#stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; }
#screen { image-rendering: pixelated; image-rendering: crisp-edges; background: #000; max-width: 100%; max-height: 100%; }
#screen.smooth { image-rendering: auto; }
#banner { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(20,22,32,.85);
  padding: 6px 12px; border-radius: 10px; font-size: 13px; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
#toast { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(20,22,32,.92);
  padding: 8px 14px; border-radius: 10px; font-size: 14px; }
#fps { position: absolute; top: 6px; left: 8px; font: 12px monospace; color: #8f8; text-shadow: 0 0 2px #000; }
.menubtn { position: absolute; top: 8px; right: 8px; width: 42px; height: 42px; border-radius: 12px; border: 0;
  background: rgba(40,42,58,.7); font-size: 20px; z-index: 5; }

/* touch pad */
#pad { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); user-select: none; -webkit-user-select: none; touch-action: none; }
#pad button { border: 0; background: rgba(255,255,255,.12); border-radius: 50%; color: #fff; font-weight: 700; touch-action: none; }
#pad button.on { background: rgba(124,108,255,.65); }
.shoulder { display: flex; justify-content: space-between; margin-bottom: 8px; }
.shoulder button { width: 84px; height: 38px; border-radius: 12px !important; }
.padrow { display: flex; align-items: center; justify-content: space-between; }
.dpad { position: relative; width: 150px; height: 150px; }
.dpad button { position: absolute; width: 50px; height: 50px; border-radius: 10px !important; font-size: 16px; }
.dpad .up { left: 50px; top: 0; } .dpad .down { left: 50px; bottom: 0; }
.dpad .left { left: 0; top: 50px; } .dpad .right { right: 0; top: 50px; }
.ab { position: relative; width: 150px; height: 130px; }
.ab button { position: absolute; width: 64px; height: 64px; font-size: 20px; }
.ab .a { right: 0; top: 10px; } .ab .b { left: 6px; bottom: 6px; }
.tabs { display: flex; flex-direction: column; gap: 10px; }
.tabs button { width: 44px; height: 32px; border-radius: 10px !important; font-size: 14px; }
.sys { display: flex; justify-content: center; gap: 22px; margin-top: 6px; }
.sys button { width: 78px; height: 26px; border-radius: 13px !important; font-size: 11px !important; }
@media (orientation: landscape) and (max-height: 520px) {
  #game { flex-direction: row; }
  #pad { position: absolute; inset: 0; padding: 10px; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; }
  #pad > * { pointer-events: auto; }
  #pad button { background: rgba(255,255,255,.10); }
  .padrow { flex: 1; align-items: flex-end; }
  .tabs { align-self: flex-start; }
}

/* menu */
.overlay { position: fixed; inset: 0; background: rgba(5,6,10,.72); display: flex; align-items: center; justify-content: center; z-index: 20; }
.panel { width: min(460px, 100% - 24px); max-height: calc(100% - 24px); background: var(--panel); border-radius: 18px; display: flex; flex-direction: column; overflow: hidden; }
.panelhead { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid #2c2f42; }
.panelhead h3 { margin: 0; flex: 1; font-size: 17px; }
.panelhead button { background: none; border: 0; font-size: 18px; padding: 4px 8px; color: var(--muted); }
.panelbody { overflow-y: auto; padding: 10px; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--panel2); border: 0;
  border-radius: 12px; padding: 13px 14px; margin-bottom: 7px; }
.item:hover { background: #303450; }
.item .label { flex: 1; }
.item .val { color: var(--muted); font-size: 14px; }
.item.primary { background: var(--accent); }
.item.green { background: #1f6b55; }
.item.danger { color: var(--danger); }
.item[disabled] { opacity: .45; cursor: default; }
.sect { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; margin: 12px 4px 6px; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.slot { background: var(--panel2); border: 0; border-radius: 10px; padding: 6px; text-align: center; font-size: 12px; color: var(--muted); }
.slot img, .slot .empty { width: 100%; aspect-ratio: 3/2; border-radius: 6px; display: block; background: #111; image-rendering: pixelated; }
.slot .empty { display: flex; align-items: center; justify-content: center; color: #555; }
.field { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid #3a3e58; background: #14151d; color: var(--text); font: inherit; margin-bottom: 8px; }
.code { font: 700 34px/1.2 ui-monospace, monospace; letter-spacing: 6px; text-align: center; padding: 14px; background: #14151d; border-radius: 12px; margin: 8px 0; user-select: all; }
.small { color: var(--muted); font-size: 13px; margin: 6px 4px 10px; }
input[type=range] { width: 140px; }
.spinner { width: 42px; height: 42px; border: 4px solid #333; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
#loading { flex-direction: column; gap: 14px; background: var(--bg); }
@keyframes spin { to { transform: rotate(360deg); } }
