/* NIKEVERSE — Dimensional Walker */

:root {
  --ui-bg: #f8f8e8;
  --ui-border: #404058;
  --ui-text: #202030;
  --accent: #e8425a;
  --hp-green: #58d058;
  --hp-yellow: #f0c040;
  --hp-red: #e84040;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: #10101e;
  overflow: hidden;
  font-family: 'Courier New', Courier, monospace;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-frame {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  width: var(--cw, 480px);
  height: var(--ch, 320px);
  /* GBA-shell double rim + ambient glow */
  box-shadow: 0 0 60px rgba(80, 80, 160, 0.35), 0 0 0 4px #20203a, 0 0 0 6px #4a4a72;
}

/* ===== UI layer overlays the canvas exactly ===== */
#ui-layer {
  position: absolute;
  width: var(--cw, 480px);
  height: var(--ch, 320px);
  left: 50%;
  top: var(--ct, 50%);
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: calc(var(--ch, 320px) / 24);
}

.hidden { display: none !important; }

/* ===== Dialogue box ===== */
#dialogue-box {
  position: absolute;
  left: 2%;
  right: 2%;
  bottom: 2%;
  min-height: 26%;
  background: linear-gradient(#fffef4, var(--ui-bg) 18%);
  border: 0.22em solid var(--ui-border);
  border-radius: 0.35em;
  box-shadow: inset 0 0 0 0.12em #fff, 0 0.2em 0 rgba(0,0,0,0.45);
  padding: 0.55em 0.8em 0.8em 0.8em;
  color: var(--ui-text);
  pointer-events: auto;
  z-index: 30;
  line-height: 1.45;
  animation: nv-panel-in 120ms ease-out;
}
@keyframes nv-panel-in { from { transform: translateY(0.4em); opacity: 0.4; } }
#dialogue-speaker {
  display: inline-block;
  font-weight: bold;
  color: #fff;
  background: var(--ui-border);
  border-radius: 0.25em;
  padding: 0.05em 0.6em;
  margin-bottom: 0.25em;
  font-size: 0.85em;
  letter-spacing: 0.05em;
}
#dialogue-speaker:empty { display: none; }
#dialogue-text {
  font-weight: bold;
  font-size: 0.95em;
  white-space: pre-wrap;
}
#dialogue-next {
  position: absolute;
  right: 0.7em;
  bottom: 0.3em;
  color: var(--accent);
  animation: bounce 0.7s infinite alternate;
  font-size: 0.9em;
}
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(0.22em); } }

/* ===== Menu box (lists: battle actions, choices, party...) ===== */
#menu-box {
  position: absolute;
  background: var(--ui-bg);
  border: 0.22em solid var(--ui-border);
  border-radius: 0.35em;
  box-shadow: inset 0 0 0 0.12em #fff, 0 0.2em 0 rgba(0,0,0,0.45);
  color: var(--ui-text);
  font-weight: bold;
  pointer-events: auto;
  z-index: 40;
  padding: 0.4em 0.4em;
  max-height: 96%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #b0a890 transparent;
  /* margin/opacity pop (no transform — menu-center relies on translate) */
  animation: nv-menu-in 100ms ease-out;
}
@keyframes nv-menu-in { from { opacity: 0.4; margin-top: 0.3em; } }
#menu-box.menu-br { right: 2%; bottom: 2%; min-width: 38%; }
#menu-box.menu-center {
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  min-width: 62%;
}
#menu-box.menu-full {
  left: 2%; right: 2%; top: 2%; bottom: 2%;
}
#menu-box .menu-title {
  font-size: 0.8em;
  color: #707088;
  padding: 0.1em 0.5em 0.3em 0.5em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#menu-box .menu-item {
  padding: 0.32em 0.6em 0.32em 1.2em;
  position: relative;
  border-radius: 0.25em;
  font-size: 0.95em;
  cursor: pointer;
  line-height: 1.3;
}
#menu-box .menu-item .sub {
  display: block;
  font-size: 0.72em;
  color: #686880;
  font-weight: normal;
}
#menu-box .menu-item + .menu-item { border-top: 1px solid rgba(64, 64, 88, 0.08); }
#menu-box .menu-item.selected {
  background: #e8e0c8;
  box-shadow: inset 0.18em 0 0 var(--accent);
}
#menu-box .menu-item.selected::before {
  content: '\25B6';
  position: absolute;
  left: 0.25em;
  color: var(--accent);
  font-size: 0.8em;
  top: 0.45em;
  animation: nv-arrow 0.55s steps(2) infinite;
}
@keyframes nv-arrow { from { left: 0.25em; } to { left: 0.4em; } }
#menu-box .menu-item.disabled { color: #a0a0b0; }

/* ===== Toast banner ===== */
#toast {
  position: absolute;
  top: 3%;
  left: 50%;
  transform: translate(-50%, 0);
  animation: nv-toast 180ms ease-out;
  background: rgba(20, 20, 40, 0.92);
  color: #ffe890;
  border: 0.18em solid #ffe890;
  border-radius: 0.4em;
  padding: 0.4em 1em;
  font-weight: bold;
  font-size: 0.85em;
  z-index: 60;
  text-align: center;
  max-width: 90%;
}
@keyframes nv-toast { from { transform: translate(-50%, -0.8em); opacity: 0; } }

/* ===== Touch controls ===== */
#touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 100;
}
body.touch #touch-controls { display: block; }

/* button-ified controls: neutralize UA styles, keep the existing look
   (placed before the visual rules so they win on shared properties) */
.dpad-btn, .act-btn, #start-button {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

#dpad {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 144px;
  height: 144px;
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  pointer-events: auto;
  opacity: 0.82;
}
.dpad-btn {
  background: #2a2a44;
  border: 2px solid #50506e;
  color: #b8b8d8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
#dpad-up    { grid-area: 1 / 2; border-radius: 10px 10px 0 0; }
#dpad-left  { grid-area: 2 / 1; border-radius: 10px 0 0 10px; }
#dpad-center{ grid-area: 2 / 2; border-width: 0 2px; border-style: solid; border-color: #50506e; }
#dpad-right { grid-area: 2 / 3; border-radius: 0 10px 10px 0; }
#dpad-down  { grid-area: 3 / 2; border-radius: 0 0 10px 10px; }
.dpad-btn.pressed { background: #4a4a77; transform: scale(0.96); }

#action-buttons {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  pointer-events: auto;
  display: flex;
  gap: 14px;
  align-items: flex-end;
}
.act-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #88283c;
  border: 3px solid #c04a62;
  color: #ffd8e0;
  font-weight: bold;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}
#btn-b { margin-bottom: 26px; background: #28385c; border-color: #4a62a0; color: #d8e4ff; }
.act-btn.pressed { filter: brightness(1.6); transform: scale(0.94); }

#start-button {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #2a2a44;
  border: 2px solid #50506e;
  color: #b8b8d8;
  border-radius: 12px;
  padding: 6px 22px;
  font-weight: bold;
  font-size: 13px;
  pointer-events: auto;
  opacity: 0.82;
}
#start-button.pressed { background: #4a4a77; }

/* On touch devices in landscape, keep controls clear of the canvas */
@media (pointer: coarse) and (orientation: portrait) {
  #game-frame { align-items: flex-start; }
}

/* scrollbar styling for menus */
#menu-box::-webkit-scrollbar { width: 6px; }
#menu-box::-webkit-scrollbar-thumb { background: #b0a890; border-radius: 3px; }

/* ===== text input overlay (name entry, nicknames) ===== */
.text-input-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 18, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  z-index: 80;
}
.text-input-panel {
  background: var(--ui-bg);
  border: 0.22em solid var(--ui-border);
  border-radius: 0.35em;
  box-shadow: inset 0 0 0 0.12em #fff, 0 0.2em 0 rgba(0,0,0,0.45);
  padding: 0.7em 0.9em;
  min-width: 60%;
  max-width: 92%;
  color: var(--ui-text);
}
.text-input-title {
  font-weight: bold;
  font-size: 0.85em;
  margin-bottom: 0.5em;
}
.text-input-field {
  width: 100%;
  font: inherit;
  font-weight: bold;
  font-size: 1em;
  padding: 0.3em 0.45em;
  border: 0.16em solid var(--ui-border);
  border-radius: 0.25em;
  background: #fff;
  color: var(--ui-text);
  box-sizing: border-box;
}
.text-input-field:focus { outline: 0.14em solid var(--accent); }
.text-input-buttons {
  display: flex;
  gap: 0.6em;
  justify-content: flex-end;
  margin-top: 0.55em;
}
.text-input-btn {
  background: var(--ui-border);
  color: #fff;
  font-weight: bold;
  font-size: 0.85em;
  padding: 0.25em 0.9em;
  border-radius: 0.25em;
  cursor: pointer;
}
.text-input-btn.ok { background: var(--accent); }
.text-input-btn:active { filter: brightness(1.3); }

/* ===== accessibility ===== */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }
@media (prefers-reduced-motion: reduce) {
  #dialogue-box, #menu-box, #toast, #dialogue-next,
  #menu-box .menu-item.selected::before { animation: none !important; }
}
