:root { --box-border: 3px; --max-w: 340px; --aspect: 3/1; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: #000; color: #fff; font-family: "Noto Sans", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
.app { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.content { display: grid; grid-template-columns: 240px 1fr; gap: 12px; align-items: start; padding: 0 12px 12px; }
.hud { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 12px 16px; }
.title { font-weight: 600; letter-spacing: .5px; }
.hint { opacity: .7; font-size: .9rem; }

.stage { display: grid; place-items: center; padding: 12px; gap: 10px; }
#battle-box {
  position: relative; width: min(70vw, var(--max-w));
  aspect-ratio: var(--aspect);
  background: #000; border: var(--box-border) solid #fff; border-radius: 6px;
  overflow: hidden;
}
#heart {
  position: absolute; left: 0; top: 0; width: 12px; height: 12px;
  image-rendering: pixelated; image-rendering: crisp-edges; user-select: none; pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(255,0,0,.5));
  transition: transform 60ms linear;
}

#joystick-zone {
  position: fixed; right: 14px; bottom: 14px; width: 140px; height: 140px;
  touch-action: none; opacity: .1;
}
@media (hover: none) and (pointer: coarse) {
  #joystick-zone { opacity: .25; }
  .hint { display: none; }
}

@font-face { font-family: "Deltarune"; src: url("/undertale-deltarune-text-font-extended.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "PapyrusUndertale"; src: url("/papyrus-font-undertale[1] (1).otf") format("opentype"); font-display: swap; }
body.font-deltarune { font-family: "Deltarune", monospace; }
body.font-papyrus { font-family: "PapyrusUndertale", cursive; }

.sidebar { position: sticky; top: 8px; align-self: start; }
.font-controls { display:flex; flex-direction:column; align-items:center; gap:.5rem; }
.font-btns { display:flex; gap:.5rem; }
.allcaps-toggle { display:inline-flex; align-items:center; gap:.5rem; border:1px solid #fff; border-radius:4px; padding:6px 10px; user-select:none; }
.allcaps-toggle input { accent-color:#fff; }

.explosion-toggle { display:inline-flex; align-items:center; gap:.5rem; border:1px solid #fff; border-radius:4px; padding:6px 10px; user-select:none; }

.shape-controls { position: relative; }
.enemy-controls { position: relative; }
.shape-menu, .enemy-menu { position:absolute; top:calc(100% + 2px); right:0; background:#000; border:1px solid #fff; border-radius:6px; padding:6px; display:none; z-index:10; }
.shape-menu.open, .enemy-menu.open { display:block; }
.shape-menu button, .enemy-menu button { display:block; width:100%; background:#111; color:#fff; border:1px solid #fff; border-radius:4px; padding:6px 10px; margin:4px 0; text-align:left; font-family: inherit; }

.donate-controls { position: relative; }
.donate-menu { position:absolute; top:calc(100% + 2px); right:0; background:#000; border:1px solid #fff; border-radius:6px; padding:6px; display:none; z-index:10; }
.donate-menu.open { display:block; }
#btn-donate { background:#111; color:#fff; border:1px solid #fff; border-radius:4px; padding:6px 10px; box-shadow:0 0 8px rgba(255,255,255,.35); }
#btn-donate:hover { box-shadow:0 0 12px rgba(255,255,255,.6); }
.donate-menu .donate-note { margin:4px 2px 6px; font-size:.85rem; opacity:.85; }

.donate-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.6);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.donate-modal[aria-hidden="false"] { opacity: 1; pointer-events: auto; }
.donate-card {
  background: #000;
  border: 2px solid #fff;
  padding: 14px;
  border-radius: 8px;
  width: min(360px, calc(100% - 40px));
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  position: relative;
  text-align: left;
}
.donate-card h3 { margin: 0 0 8px; font-weight:600; }
.donate-close {
  position: absolute;
  right: 8px;
  top: 8px;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.donate-card label { display:block; font-size:0.95rem; margin-bottom:10px; }
.donate-card input[type="number"]{
  width:100%;
  padding:8px;
  border-radius:6px;
  border:1px solid #fff;
  background:#111;
  color:#fff;
}
.donate-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:6px; }
.donate-note { margin-top:8px; font-size:.85rem; opacity:.85; }

#battle-box[data-shape="rect"]{--aspect:2.2/1;border-radius:6px;}
#battle-box[data-shape="square"]{--aspect:1/1;border-radius:6px;}
#battle-box[data-shape="tall"]{--aspect:1/1.6;border-radius:6px;}
#battle-box[data-shape="circle"]{--aspect:1/1;border-radius:9999px;}

#btn-deltarune { font-family: "Deltarune", monospace; }
#btn-papyrus { font-family: "PapyrusUndertale", cursive; }
#btn-shape { background:#111; color:#fff; border:1px solid #fff; border-radius:4px; padding:6px 10px; cursor:pointer; font-family: inherit; }

body.all-caps { text-transform: uppercase; }

button {
  background:#111; color:#fff; border:1px solid #fff; border-radius:4px;
  padding:6px 10px; cursor:pointer; font-family: inherit; text-transform: inherit;
}

.enemy-sprite { display:block; max-height:140px; width:auto; image-rendering: pixelated; margin-bottom:8px; }

.hp-wrap { 
  position: relative; margin-top: 8px; display:flex; gap:8px; align-items:center; justify-content:center;
  max-width: min(70vw, var(--max-w)); margin-left: auto; margin-right: auto; pointer-events: none;
}
.hp-bar { width: 180px; height: 12px; background:#222; border:2px solid #fff; border-radius:6px; overflow:hidden; }
.hp-text { font-size: 0.9rem; font-weight:600; letter-spacing: .4px; user-select: none; pointer-events: none; }
.hp-fill { height:100%; width:100%; background:linear-gradient(90deg,#ff4d4d,#ff0000); transition: width 220ms linear; box-shadow:0 0 6px rgba(255,0,0,.5); }

.attack-panel { 
  display:grid; grid-template-columns: repeat(4, 1fr); gap:8px;
  margin-top: 0; align-items: start; justify-items: center;
}
.attack-btn { width:100%; padding:4px; gap:4px; }
.attack-btn img { width:40px; height:40px; object-fit:contain; image-rendering: pixelated; }
.attack-btn .atk-label { font-size:.8rem; text-align:center; }
/* subtle click animation */
.attack-btn:active { transform: translateY(1px) scale(.997); }

.attack-indicator {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: transparent;
  color: #000;
  image-rendering: pixelated;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: none;
  z-index: 30;
  box-shadow: none;
}
/* small ping when hits */
.attack-indicator.hit {
  animation: hit-pulse 260ms ease-out;
}
@keyframes hit-pulse {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1.25); opacity: .9; }
  100% { transform: translate(-50%, -50%) scale(.9); opacity: .6; }
}

/* explosion sprite */
.explosion-sprite {
  position: absolute;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 35;
  filter: drop-shadow(0 0 6px rgba(255,180,50,0.6));
}

@media (max-width: 800px){
  .content { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .attack-panel { display:grid; grid-template-columns: repeat(4, minmax(56px, 1fr)); justify-items: center; }
}