:root {
  --ui-bg: rgba(40, 44, 52, 0.92);
  --ui-bg2: rgba(60, 66, 76, 0.95);
  --ui-fg: #eef0f3;
  --ui-dim: #9aa1ab;
  --ui-accent: #6dbb4a;
  --ui-border: rgba(255, 255, 255, 0.12);
  --comic: "Bangers", "Impact", "Arial Black", sans-serif;
}
body.jojo {
  --ui-bg: rgba(28, 10, 40, 0.9);
  --ui-bg2: rgba(58, 20, 78, 0.95);
  --ui-fg: #fbeefd;
  --ui-dim: #c9a6d8;
  --ui-accent: #f1c75b;
  --ui-border: rgba(241, 199, 91, 0.3);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1a1a1a; color: var(--ui-fg);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
canvas#game { position: fixed; inset: 0; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px;
  display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: var(--ui-bg); border-bottom: 2px solid var(--ui-border);
  backdrop-filter: blur(6px); z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--comic); font-size: 24px; letter-spacing: 1px; white-space: nowrap; }
.melon {
  width: 24px; height: 26px; border-radius: 50%;
  background: repeating-linear-gradient(90deg, #6dbb4a 0 5px, #3d8a2b 5px 8px);
  border: 2px solid #2c5e20;
}
.spacer { flex: 1; }
.tb {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--ui-border);
  background: var(--ui-bg2); font-size: 17px; display: grid; place-items: center;
}
.tb:hover { filter: brightness(1.25); }
.tb.on { background: var(--ui-accent); color: #1a0d24; }
.jojo-toggle {
  font-family: var(--comic); font-size: 18px; letter-spacing: 1px;
  padding: 6px 12px; border-radius: 8px; border: 2px solid #6b6f78;
  background: #3a3e46; white-space: nowrap;
}
.jojo-toggle b { color: #ff6b6b; font-weight: normal; }
body.jojo .jojo-toggle {
  border-color: #f1c75b; color: #fff;
  background: linear-gradient(135deg, #7b2fa0, #d63a86);
  box-shadow: 0 0 14px rgba(214, 58, 134, 0.6);
  transform: skewX(-8deg);
}
body.jojo .jojo-toggle b { color: #f1c75b; }

/* ---------------------------------------------------------------- tools */
#tools {
  position: fixed; left: 8px; top: 62px; z-index: 9;
  display: flex; flex-direction: column; gap: 6px;
}
#tools button {
  width: 62px; padding: 6px 0 5px; border-radius: 10px;
  background: var(--ui-bg); border: 1px solid var(--ui-border);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px;
}
#tools button span { font-size: 18px; line-height: 1; }
#tools button.active { background: var(--ui-accent); color: #1a0d24; border-color: transparent; }

/* ---------------------------------------------------------------- catalog */
#catalog {
  position: fixed; right: 8px; top: 62px; bottom: 76px; width: 210px; z-index: 9;
  overflow-y: auto; padding: 8px; border-radius: 12px;
  background: var(--ui-bg); border: 1px solid var(--ui-border);
}
#catalog h4 {
  margin: 8px 4px 6px; font-family: var(--comic); font-weight: normal; font-size: 18px;
  letter-spacing: 1px; color: var(--ui-accent);
}
#catalog h4:first-child { margin-top: 2px; }
.item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; margin-bottom: 4px; border-radius: 8px; text-align: left;
  background: var(--ui-bg2); border: 1px solid transparent;
}
.item:hover { border-color: var(--ui-border); }
.item.active { border-color: var(--ui-accent); box-shadow: inset 0 0 0 1px var(--ui-accent); }
.item .sw { width: 22px; height: 22px; border-radius: 6px; flex: none; border: 1px solid rgba(0, 0, 0, 0.4); }
.item .t { display: flex; flex-direction: column; min-width: 0; }
.item .t small { color: var(--ui-dim); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.satire .satire-toggle {
  border-color: #ffd84a; color: #fff;
  background: linear-gradient(135deg, #2a5ad0, #e8842a);
  box-shadow: 0 0 14px rgba(232, 132, 42, 0.6);
}
body.satire .satire-toggle b { color: #ffd84a; }
body.jojo:not(.satire) .satire-toggle { border-color: #6b6f78; background: #3a3e46; box-shadow: none; }
body.jojo:not(.satire) .satire-toggle b { color: #ff6b6b; }
body .satire-toggle { transform: none; margin-left: 6px; }
.cat-satire { display: none; }
body.satire .cat-satire { display: block; }
.cat-jojo { display: none; }
body.jojo .cat-jojo { display: block; }

/* ---------------------------------------------------------------- panels */
.panel {
  position: fixed; top: 60px; right: 226px; z-index: 11; width: 290px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--ui-bg); border: 1px solid var(--ui-border);
}
.panel h3 { margin: 0 0 8px; font-family: var(--comic); font-weight: normal; font-size: 20px; letter-spacing: 1px; color: var(--ui-accent); }
.panel label { display: flex; gap: 8px; align-items: center; padding: 4px 0; cursor: pointer; }

/* ---------------------------------------------------------------- HUD / action pad */
#hud {
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 9;
  width: min(460px, calc(100vw - 20px)); padding: 8px 10px 10px; border-radius: 14px;
  background: var(--ui-bg); border: 1px solid var(--ui-border);
}
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
#hudName { font-family: var(--comic); font-size: 20px; letter-spacing: 1px; }
#hudStand { font-size: 12px; color: var(--ui-dim); }
#hudRelease { background: none; border: none; font-size: 18px; color: var(--ui-dim); padding: 0 4px; }
.hpbar { height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.5); margin: 6px 0 8px; overflow: hidden; }
#hudHp { height: 100%; width: 100%; background: #5fd35f; transition: width 0.15s; }
#pad { display: flex; gap: 10px; justify-content: space-between; }
#pad .move, #pad .acts { display: flex; gap: 6px; }
#pad .acts { flex: 1; min-width: 0; }
#pad .acts button { flex: 1; min-width: 0; }
#pad button {
  position: relative; overflow: hidden; min-width: 48px; height: 52px; padding: 0 6px;
  border-radius: 10px; border: 1px solid var(--ui-border); background: var(--ui-bg2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 18px;
  touch-action: none;
}
#pad .acts button { font-size: 11px; }
#pad .acts b { font-family: var(--comic); font-size: 18px; font-weight: normal; color: var(--ui-accent); }
#pad .acts span { line-height: 1.1; text-align: center; }
#pad .acts i { position: absolute; left: 0; bottom: 0; height: 100%; width: 0; background: rgba(0, 0, 0, 0.55); pointer-events: none; }
#pad button:active { filter: brightness(1.4); }
#pad .acts button.disabled { opacity: 0.35; }

/* ---------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); padding: 16px; }
.modal-box {
  width: min(760px, 100%); max-height: 90vh; overflow-y: auto; padding: 18px 22px;
  border-radius: 14px; background: var(--ui-bg); border: 2px solid var(--ui-border);
}
.modal-box h2 { margin: 0 0 8px; font-family: var(--comic); font-weight: normal; font-size: 30px; letter-spacing: 1px; color: var(--ui-accent); }
.modal-box h4 { margin: 10px 0 4px; }
.modal-box ul { margin: 0; padding-left: 18px; }
.modal-box li { margin: 3px 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
kbd { display: inline-block; padding: 0 5px; border-radius: 4px; border: 1px solid var(--ui-border); background: var(--ui-bg2); font: 12px/18px ui-monospace, monospace; }
.close { margin-top: 14px; padding: 8px 18px; border-radius: 8px; border: none; background: var(--ui-accent); color: #1a0d24; font-weight: 700; }

#toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 12;
  padding: 6px 14px; border-radius: 8px; background: var(--ui-bg); border: 1px solid var(--ui-border);
  opacity: 0; transition: opacity 0.25s; pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; }

.only-mobile { display: none; }
body.tbc #hud, body.tbc #tools, body.tbc #catalog, body.tbc #topbar { visibility: hidden; }

@media (max-width: 760px) {
  .brand span:last-child { display: none; }
  .only-mobile { display: grid; }
  #catalog { display: none; bottom: auto; max-height: calc(100vh - 150px); }
  #catalog.open { display: block; }
  #tools button { width: 52px; font-size: 10px; }
  .panel { right: 8px; left: 8px; width: auto; }
  .cols { grid-template-columns: 1fr; }
  .tb { width: 34px; height: 34px; font-size: 15px; }
  .jojo-toggle { font-size: 14px; padding: 4px 6px; }
  .jojo-toggle .mw { display: none; }
  body .satire-toggle { margin-left: 0; }
  #topbar { gap: 4px; padding: 0 6px; }
  #hud { bottom: 6px; padding: 5px 8px 7px; }
  #hudName { font-size: 16px; }
  #hudStand { display: none; }
  .hpbar { margin: 3px 0 5px; }
  #pad button { height: 44px; }
  #pad { gap: 6px; }
  #pad .move button { min-width: 38px; }
  #pad .acts button { font-size: 10px; }
}

@media (max-width: 420px) {
  .tb { width: 30px; height: 32px; font-size: 14px; }
  .jojo-toggle { font-size: 13px; padding: 4px 5px; }
  .brand { display: none; }
}
