:root {
  --ink: #0b0f1a;
  --paper: #f5e9c9;
  --ring: #d43d3d;
  --accent: #ffcf3f;
  --blue: #2b3c8f;
  --good: #52d15a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Off-screen but crawlable/accessible content (game renders to <canvas>) */
.seo-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100%;
  background: #05060a;
  color: var(--paper);
  font-family: "Press Start 2P", ui-monospace, "SF Mono", Menlo, monospace;
  -webkit-font-smoothing: none;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 30%, #14203f 0%, #05060a 70%);
}

#game {
  width: min(100vw, 133.33vh);   /* keep 4:3 */
  height: min(75vw, 100vh);
  image-rendering: pixelated;
  background: #05060a;
  box-shadow: 0 0 0 4px #000, 0 0 40px rgba(0,0,0,.8);
}

/* ---------- loading screen ---------- */
#loading {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, #14203f 0%, #05060a 72%);
  z-index: 60;
  display: grid;
  place-items: center;
  opacity: 1;
  transition: opacity .4s ease;
}
#loading.hide { opacity: 0; }
.loadInner { width: min(480px, 88vw); text-align: center; display: grid; gap: 26px; }
.loadTitle {
  font-size: clamp(16px, 4vw, 30px);
  line-height: 1.4;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 3px 3px 0 var(--ring), 6px 6px 0 rgba(0,0,0,.5);
}
.loadTitle span { color: var(--paper); }
.loadBarWrap {
  height: 18px;
  border: 3px solid rgba(245,233,201,.4);
  border-radius: 6px;
  overflow: hidden;
  background: #0c1226;
  box-shadow: 0 0 0 3px #000;
}
#loadBar {
  height: 100%;
  width: 4%;
  background: linear-gradient(90deg, var(--ring), var(--accent));
  transition: width .3s ease;
}
.loadStatus { font-size: 10px; letter-spacing: 2px; opacity: .75; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- SMW-style boot intro ---------- */
#intro {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 44px;
  z-index: 50;
  opacity: 1;
  transition: opacity .4s ease;
  cursor: pointer;
}
#intro.fade { opacity: 0; }

/* "press any key" gate (after loading, before TEAM FIEND PRESENTS) */
.boot-hidden { display: none !important; }
#press {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity .3s ease;
  cursor: pointer;
}
#press.fade { opacity: 0; }
.pressText {
  font-size: clamp(11px, 2.4vw, 16px);
  letter-spacing: 4px;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
.introText {
  color: #fff;
  text-align: center;
  font-size: clamp(13px, 3vw, 24px);
  letter-spacing: 4px;
  line-height: 2.1;
  opacity: 0;
  animation: introIn .7s steps(1) .45s forwards;
}
.introText span { color: #fff; }
@keyframes introIn { to { opacity: 1; } }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4vmin;
  background: rgba(4, 6, 12, .78);
  backdrop-filter: blur(2px);
  z-index: 10;
}
.hidden { display: none !important; }

.panel {
  width: min(560px, 92vw);
  text-align: center;
  display: grid;
  gap: 22px;
}

h1 {
  font-size: clamp(20px, 5vw, 40px);
  line-height: 1.35;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 4px 4px 0 var(--ring), 8px 8px 0 rgba(0,0,0,.5);
}
h1 span { color: var(--paper); }

.tagline {
  margin-top: 10px;
  font-size: clamp(7px, 1.4vw, 10px);
  letter-spacing: 1px;
  color: var(--paper);
  opacity: 0.55;
}

.big { font-size: clamp(12px, 2.6vw, 16px); color: var(--accent); }
.small { font-size: 11px; opacity: .7; margin: 4px 0; }
.hint { font-size: 9px; line-height: 1.6; opacity: .65; margin-top: 8px; }

/* dropzone */
.dropzone {
  border: 3px dashed rgba(255,207,63,.5);
  border-radius: 14px;
  padding: 28px 18px;
  display: grid;
  gap: 8px;
  justify-items: center;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: rgba(255,207,63,.08); }

/* buttons */
.btn {
  font-family: inherit;
  font-size: 11px;
  color: var(--ink);
  background: var(--accent);
  border: none;
  border-bottom: 4px solid #b9902a;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform .05s;
}
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.primary { background: var(--good); border-bottom-color: #2f8a35; }
.btn.ghost { background: transparent; color: var(--paper); border: 2px solid rgba(245,233,201,.4); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* align / crop */
.align { display: grid; gap: 18px; justify-items: center; }
.cropWrap { position: relative; width: 256px; height: 256px; }
#cropCanvas {
  width: 256px; height: 256px;
  border-radius: 12px;
  background: #111;
  cursor: grab;
  touch-action: none;
}
#cropCanvas:active { cursor: grabbing; }
.cropRing {
  position: absolute; inset: 0;
  border-radius: 12px;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.55) inset;
  -webkit-mask: radial-gradient(circle at 50% 50%, transparent 43%, #000 44%);
          mask: radial-gradient(circle at 50% 50%, transparent 43%, #000 44%);
}
.controls { display: grid; gap: 8px; justify-items: center; width: 100%; }
.controls label { font-size: 9px; display: flex; align-items: center; gap: 10px; }
input[type="range"] { width: 200px; accent-color: var(--accent); }

/* result banner */
.bannerText {
  font-size: clamp(28px, 9vw, 72px);
  color: var(--accent);
  text-shadow: 5px 5px 0 var(--ring), 10px 10px 0 rgba(0,0,0,.6);
  animation: pop .25s ease-out;
}
#banner { flex-direction: column; gap: 22px; background: rgba(4,6,12,.5); }
#banner { display: grid; grid-auto-flow: row; gap: 20px; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* key hint */
.keyhint {
  position: absolute;
  bottom: 10px;
  font-size: clamp(7px, 1.5vw, 10px);
  opacity: .6;
  letter-spacing: 1px;
  z-index: 5;
  text-align: center;
  padding: 0 8px;
}

/* on-screen touch controls */
.touch {
  position: absolute;
  bottom: 12px;
  left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 3vw;
  z-index: 6;
  pointer-events: none;
}
.pad { display: flex; gap: 8px; pointer-events: auto; }
/* right pad stacks BLOCK/★ above L/R so the centre keyboard hint stays clear */
.pad.right { flex-direction: column; align-items: flex-end; gap: 8px; }
.btnrow { display: flex; gap: 8px; }
.tbtn {
  font-family: inherit;
  font-size: 12px;
  min-width: 52px;
  min-height: 52px;
  border-radius: 12px;
  border: none;
  border-bottom: 4px solid rgba(0,0,0,.45);
  background: rgba(43, 60, 143, .85);
  color: #fff;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.tbtn:active { transform: translateY(2px); border-bottom-width: 2px; filter: brightness(1.3); }
.tbtn.punch { background: rgba(212, 61, 61, .9); }
.tbtn.star { background: var(--accent); color: var(--ink); font-size: 20px; }

/* show touch controls only on coarse pointers */
@media (pointer: coarse) {
  .keyhint { display: none; }
}
