:root {
  --ink: #12121f;
  --ink-2: #0b0b12;
  --cream: #f7e6c8;
  --cream-dim: #cbb99b;
  --wood: #7a4a26;
  --wood-dark: #4a2b16;
  --wood-light: #b9824a;
  --orange: #e08b3c;
  --orange-dark: #b5611f;
  --red: #d63a3a;
  --green: #8fc45a;
  --forest: #3a5c2e;
  --blue: #4fc3f7;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Pixelify Sans", "Trebuchet MS", sans-serif;
  -webkit-font-smoothing: none;
  font-smooth: never;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#page {
  min-height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
}

/* ---------------- wooden rim and screen ---------------- */

#frame {
  position: relative;
  padding: 7px;
  background-color: var(--wood);
  background-image:
    repeating-linear-gradient(90deg, var(--wood) 0 22px, var(--wood-dark) 22px 24px, var(--wood-light) 24px 26px, var(--wood) 26px 48px);
  border: 2px solid var(--wood-dark);
  line-height: 0;
  flex: 0 0 auto;
}


#stage {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  line-height: normal;
  image-rendering: pixelated;
}

#world {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#ui {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: none;
  z-index: 2;
  font-family: "Pixelify Sans", sans-serif;
}

#ui .hidden, .hidden { display: none !important; }

/* hard 1px pixel outline for text on the world */
.outline,
#hp-text,
#gold-text,
#subtitle,
.dialogue-text,
.bubble,
.shop-heading,
.shop-msg,
.shop-hint,
.shop-row,
.help-body,
.pixel-btn {
  text-shadow:
     1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2),
     0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2),
     1px 1px 0 var(--ink-2), -1px 1px 0 var(--ink-2),
     1px -1px 0 var(--ink-2), -1px -1px 0 var(--ink-2);
}

/* ---------------- HUD ---------------- */

#hud {
  position: absolute;
  top: 7px;
  left: 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
}

.hearts {
  display: flex;
  gap: 1px;
  height: 15px;
  align-items: center;
}
.hearts img {
  width: 14px;
  height: 14px;
  display: block;
  image-rendering: pixelated;
}

.hp-line {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0.4px;
  color: var(--cream);
  padding-left: 1px;
  transform-origin: left center;
}
.hp-line.pulse { animation: hpPulse 240ms steps(1, end) 1; }
@keyframes hpPulse {
  0% { color: var(--green); transform: translateY(-1px); }
  50% { color: var(--orange); transform: translateY(0); }
  100% { color: var(--cream); transform: translateY(0); }
}

.rage-row {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 1px;
}
.rage-orb {
  width: 15px;
  height: 15px;
  display: block;
  image-rendering: pixelated;
  opacity: 0.75;
}
.rage-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 116px;
  height: 9px;
  padding: 2px;
  background: #26202c;
  border: 1px solid var(--ink-2);
  box-shadow: inset 0 0 0 1px #6a5741;
}
.rage-bar .pip {
  width: 6px;
  height: 4px;
  background: #7a4a26;
  border-top: 1px solid #b9824a;
  border-bottom: 1px solid #4a2b16;
}
.rage-bar .pip.on {
  background: var(--orange);
  border-top-color: #ffc27a;
  border-bottom-color: var(--orange-dark);
}

.gold-row {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 2px;
}
.gold-row .coin {
  width: 13px;
  height: 13px;
  display: block;
  image-rendering: pixelated;
}
#gold-text {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 10px;
  color: var(--cream);
}
#gold-text.pulse { animation: goldPulse 220ms steps(1, end) 1; }
@keyframes goldPulse {
  0% { color: #ffd76a; transform: translateY(-1px); }
  100% { color: var(--cream); transform: translateY(0); }
}

/* ---------------- press E ---------------- */

#prompt {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  transform: translate(-50%, -100%);
  animation: promptBlink 1.2s steps(1, end) infinite;
  z-index: 6;
}
#prompt .prompt-arrow { display: block; margin-bottom: 1px; }
#prompt .keycap {
  width: 19px;
  height: 17px;
  display: block;
  image-rendering: pixelated;
}
@keyframes promptBlink {
  0%, 68% { opacity: 1; }
  69%, 100% { opacity: 0; }
}

/* ---------------- speech bubbles and translation ---------------- */

#bubbles { position: absolute; inset: 0; }

.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  background: var(--cream);
  color: var(--wood-dark);
  border: 2px solid var(--ink-2);
  padding: 3px 6px 2px;
  font-family: "Pixelify Sans", sans-serif;
  font-weight: 700;
  font-size: 8px;
  line-height: 1.1;
  letter-spacing: 0.3px;
  white-space: nowrap;
  text-shadow: none;
  z-index: 5;
}
.bubble::after {
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  bottom: -8px;
  width: 10px;
  height: 8px;
  background: var(--ink-2);
  clip-path: polygon(0 0, 10px 0, 10px 2px, 6px 2px, 6px 5px, 3px 5px, 3px 8px, 0 8px);
}
.bubble::before {
  content: "";
  position: absolute;
  left: calc(50% - 3px);
  bottom: -4px;
  width: 6px;
  height: 4px;
  background: var(--cream);
  z-index: 1;
}

#subtitle {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 2px 6px;
  text-align: center;
  font-size: 9px;
  line-height: 1.25;
  color: var(--cream);
  white-space: nowrap;
  z-index: 4;
}

/* ---------------- dialogue and shop panels ---------------- */

.panel {
  position: absolute;
  pointer-events: auto;
  left: 12px;
  right: 12px;
  bottom: 9px;
  background-color: transparent;
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAE0lEQVR4nGMQEpL/zwADQkLy/wET4gKFS7SgRgAAAABJRU5ErkJggg==");
  background-size: 2px 2px;
  background-repeat: repeat;
  border: 2px solid var(--ink-2);
  box-shadow:
    inset 0 0 0 2px var(--cream),
    inset 0 0 0 3px var(--ink-2);
  padding: 11px 13px 9px;
  z-index: 8;
}

.corner {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--cream);
  border: 2px solid var(--ink-2);
  z-index: 1;
}
.corner.tl { left: -4px; top: -4px; }
.corner.tr { right: -4px; top: -4px; }
.corner.bl { left: -4px; bottom: -4px; }
.corner.br { right: -4px; bottom: -4px; }

.panel.show { animation: panelIn 130ms steps(1, end) 1 both; }
@keyframes panelIn {
  0% { transform: translateY(9px); }
  34% { transform: translateY(6px); }
  67% { transform: translateY(3px); }
  100% { transform: translateY(0); }
}

.name-tab {
  position: absolute;
  top: -14px;
  left: 13px;
  height: 15px;
  min-width: 64px;
  padding: 0 7px;
  display: flex;
  align-items: center;
  background: var(--cream);
  border: 2px solid var(--ink-2);
  color: var(--wood-dark);
  font-family: "Press Start 2P", monospace;
  font-size: 6px;
  letter-spacing: 0.6px;
  white-space: nowrap;
  text-shadow: none;
}

#dialogue { height: 63px; }
.dialogue-text {
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.5px;
  color: var(--cream);
  padding-top: 2px;
  max-width: 100%;
  white-space: pre-wrap;
}
.blink-tri {
  position: absolute;
  right: 9px;
  bottom: 7px;
  animation: triBlink 1s steps(1, end) infinite;
}
@keyframes triBlink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

#shop { height: 118px; padding-bottom: 7px; }
.shop-heading {
  font-family: "Press Start 2P", monospace;
  font-size: 5px;
  letter-spacing: 0.5px;
  color: var(--orange);
  margin: 0 0 4px 2px;
}
#shop-rows { display: flex; flex-direction: column; gap: 1px; }
.shop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 20px;
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--cream);
  font-family: "Pixelify Sans", sans-serif;
  font-size: 9px;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  line-height: 1;
}
.shop-row .row-arrow {
  width: 8px;
  color: transparent;
  font-family: "Press Start 2P", monospace;
  font-size: 6px;
}
.shop-row img {
  width: 13px;
  height: 17px;
  object-fit: contain;
  image-rendering: pixelated;
}
.shop-row .row-name { flex: 1 1 auto; letter-spacing: 0.4px; }
.shop-row .row-heal { color: var(--cream-dim); font-size: 8px; width: 46px; }
.shop-row .row-price {
  width: 34px;
  text-align: right;
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 8px;
  color: var(--cream);
}
.shop-row.sel { box-shadow: inset 2px 0 0 var(--cream-dim); }
.shop-row.sel .row-arrow { color: var(--orange); }
.shop-row.sel .row-name { color: var(--orange); }
.shop-row.sel .row-price { color: #ffd76a; }
.shop-row.leave .row-name { color: var(--cream-dim); }
.shop-msg {
  height: 11px;
  margin-top: 3px;
  font-size: 8px;
  color: var(--orange);
  letter-spacing: 0.3px;
  overflow: hidden;
}
.shop-hint {
  position: absolute;
  right: 9px;
  bottom: 4px;
  font-family: "Press Start 2P", monospace;
  font-size: 5px;
  color: var(--cream-dim);
  letter-spacing: 0.3px;
}

/* ---------------- help ---------------- */

#help {
  position: absolute;
  inset: 0;
  background: var(--ink);
  z-index: 20;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-card {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  pointer-events: auto;
  width: 78%;
  max-width: 300px;
  padding: 16px 14px 12px;
}
.help-body {
  font-size: 9px;
  line-height: 1.55;
  letter-spacing: 0.3px;
  color: var(--cream);
}
.help-body b { color: var(--orange); font-weight: 700; }
.pixel-btn {
  margin-top: 8px;
  padding: 4px 8px;
  background: var(--wood);
  border: 2px solid var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--cream);
  color: var(--cream);
  font-family: "Press Start 2P", monospace;
  font-size: 6px;
  letter-spacing: 0.5px;
  cursor: pointer;
  pointer-events: auto;
}
.pixel-btn:active { transform: translateY(1px); }

/* ---------------- touch controls ---------------- */

#touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
}
.dpad {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 112px;
  height: 112px;
}
.tbtn {
  position: absolute;
  width: 36px;
  height: 36px;
  padding: 0;
  background: #26202c;
  color: var(--cream);
  border: 2px solid var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--cream-dim);
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  line-height: 1;
  pointer-events: auto;
  touch-action: none;
}
.tbtn:active { background: var(--wood); }
.dpad .up { left: 38px; top: 0; }
.dpad .left { left: 0; top: 38px; }
.dpad .right { left: 76px; top: 38px; }
.dpad .down { left: 38px; top: 76px; }
.ebtn {
  left: auto;
  right: 14px;
  bottom: 22px;
  width: 50px;
  height: 50px;
  font-size: 18px;
  background: var(--wood);
  box-shadow: inset 0 0 0 2px var(--cream);
}

/* ---------------- title ---------------- */

#title {
  position: absolute;
  inset: 0;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 0 10px;
  z-index: 40;
  cursor: pointer;
  pointer-events: auto;
}
#title-art {
  width: 252px;
  max-width: 84%;
  height: auto;
  image-rendering: pixelated;
  animation: titleBob 1.5s steps(1, end) infinite;
}
@keyframes titleBob {
  0%, 49% { transform: translateY(0); }
  50%, 100% { transform: translateY(-1px); }
}
#title-fox {
  width: auto;
  height: 104px;
  margin-top: 3px;
  image-rendering: pixelated;
  animation: foxBob 1.9s steps(1, end) infinite;
}
@keyframes foxBob {
  0%, 59% { transform: translateY(0); }
  60%, 100% { transform: translateY(-1px); }
}
#title-prompt {
  margin-top: 7px;
  font-family: "Press Start 2P", monospace;
  font-size: 7px;
  letter-spacing: 1px;
  color: var(--cream);
  text-shadow:
     1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2),
     0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
  animation: promptBlink 1.4s steps(1, end) infinite;
  text-align: center;
}
#title.gone { animation: titleOut 170ms steps(1, end) 1 both; }
@keyframes titleOut {
  0% { transform: translateY(0); }
  33% { transform: translateY(-34%); }
  66% { transform: translateY(-67%); }
  100% { transform: translateY(-100%); }
}

/* ---------------- footer ---------------- */

#footer {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #8f7f70;
  font-family: "Press Start 2P", monospace;
  font-size: 6px;
  letter-spacing: 0.4px;
  line-height: 1.4;
  flex: 0 0 auto;
  user-select: none;
}
#help-btn {
  width: 24px;
  height: 20px;
  padding: 0;
  background: var(--wood);
  border: 2px solid var(--wood-dark);
  box-shadow: inset 0 0 0 1px var(--wood-light);
  color: var(--cream);
  font-family: "Press Start 2P", monospace;
  font-size: 7px;
  cursor: pointer;
}
#help-btn:active { transform: translateY(1px); }

@media (max-width: 640px) {
  #page { padding: 8px; gap: 6px; }
  #footer { font-size: 6px; gap: 8px; }
  #frame { padding: 5px; }
  #help-btn { width: 30px; height: 26px; font-size: 8px; }
}

@media (max-height: 560px) {
  #footer { display: none; }
  #page { padding: 6px; }
  #frame { padding: 5px; }
}


/* purchase bottle pop */
.potion-pop {
  position: absolute;
  width: 16px;
  height: auto;
  transform: translate(-50%, -100%);
  image-rendering: pixelated;
  z-index: 7;
  animation: potPop 800ms steps(1, end) 1 both;
}
@keyframes potPop {
  0% { opacity: 1; transform: translate(-50%, -100%); }
  18% { opacity: 0; transform: translate(-50%, -108%); }
  36% { opacity: 1; transform: translate(-50%, -116%); }
  54% { opacity: 0; transform: translate(-50%, -124%); }
  72% { opacity: 1; transform: translate(-50%, -132%); }
  100% { opacity: 0; transform: translate(-50%, -140%); }
}

@media (pointer: coarse) {
  .dialogue-text { font-size: 12px; line-height: 1.38; }
  .shop-row { height: 27px; font-size: 11px; }
  .shop-row img { width: 15px; height: 20px; }
  .shop-heading { font-size: 6px; }
  .shop-msg { font-size: 9px; height: 13px; }
  .shop-hint { font-size: 6px; }
  #subtitle { font-size: 10px; }
  .bubble { font-size: 9px; }
  .hp-line, #gold-text { font-size: 11px; }
  #title-prompt { font-size: 8px; }
  .name-tab { font-size: 7px; }
  .help-body { font-size: 11px; }
}


/* ---------------- combat ---------------- */

#rage-label {
  font-family: "Press Start 2P", monospace;
  font-size: 5px;
  letter-spacing: 0.4px;
  color: var(--cream-dim);
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
}
#rage-label.blue { color: var(--blue); }

.rage-bar .pip.blue {
  background: #2f8fc4;
  border-top-color: #9fe9ff;
  border-bottom-color: #175a7a;
}

#enemy-hud {
  position: absolute;
  width: 118px;
  transform: translate(-50%, -100%);
  z-index: 6;
  text-align: left;
}
.eh-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 3px;
  margin-bottom: 2px;
}
.eh-name {
  font-family: "Press Start 2P", monospace;
  font-size: 5px;
  letter-spacing: 0.3px;
  color: var(--cream);
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
  white-space: nowrap;
}
.eh-hp {
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 7px;
  color: var(--cream);
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
  white-space: nowrap;
}
.eh-bar {
  width: 100%;
  height: 6px;
  background: #2a1216;
  border: 2px solid var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--cream-dim);
  padding: 0;
}
.eh-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--red);
}
.eh-bar i.blue { background: var(--blue); }

#combat-hint {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  font-family: "Press Start 2P", monospace;
  font-size: 6px;
  letter-spacing: 0.6px;
  color: var(--cream);
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
  z-index: 4;
  white-space: nowrap;
}
#combat-hint.blue { color: var(--blue); }

#floaters { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.floater {
  position: absolute;
  transform: translate(-50%, -100%);
  font-family: "Silkscreen", monospace;
  font-weight: 700;
  font-size: 9px;
  color: var(--cream);
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
  white-space: nowrap;
  animation: floatUp 760ms steps(1, end) 1 both;
}
.floater.dmg { color: var(--cream); }
.floater.hurt { color: #ff6b6b; }
.floater.ko { color: var(--blue); font-size: 11px; }
.floater.heal { color: var(--green); }
@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, -100%); }
  40% { opacity: 1; transform: translate(-50%, -160%); }
  80% { opacity: 1; transform: translate(-50%, -220%); }
  100% { opacity: 0; transform: translate(-50%, -240%); }
}

#banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 24;
  pointer-events: none;
}
#banner.show { animation: bannerIn 150ms steps(1, end) 1 both; }
#banner-top {
  display: block;
  font-family: "Press Start 2P", monospace;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--orange);
  text-shadow: 2px 0 0 var(--ink-2), -2px 0 0 var(--ink-2), 0 2px 0 var(--ink-2), 0 -2px 0 var(--ink-2), 2px 2px 0 var(--ink-2), -2px -2px 0 var(--ink-2);
}
#banner-sub {
  display: block;
  margin-top: 5px;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--blue);
  text-shadow: 2px 0 0 var(--ink-2), -2px 0 0 var(--ink-2), 0 2px 0 var(--ink-2), 0 -2px 0 var(--ink-2);
}
@keyframes bannerIn {
  0% { opacity: 1; transform: translate(-50%, -46%); }
  45% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 1; transform: translate(-50%, -50%); }
}

#flash {
  position: absolute;
  inset: 0;
  background: #e9fbff;
  z-index: 22;
  pointer-events: none;
}
#flash.blue { background: #9fe9ff; }

#hurt-flash {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 6px var(--red);
  z-index: 21;
  pointer-events: none;
}

#faint {
  position: absolute;
  inset: 0;
  background: var(--ink);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}
.faint-card {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  width: 72%;
  max-width: 300px;
  padding: 18px 16px 14px;
  text-align: center;
}
.faint-title {
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  line-height: 1.4;
  color: var(--orange);
  letter-spacing: 0.5px;
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
}
.faint-line {
  margin: 8px 0 6px;
  font-size: 9px;
  color: var(--cream);
  line-height: 1.4;
  text-shadow: 1px 0 0 var(--ink-2), -1px 0 0 var(--ink-2), 0 1px 0 var(--ink-2), 0 -1px 0 var(--ink-2);
}

@media (pointer: coarse) {
  #rage-label { font-size: 6px; }
  .eh-name { font-size: 6px; }
  .eh-hp { font-size: 8px; }
  #combat-hint { font-size: 7px; }
  #banner-top { font-size: 16px; }
  #banner-sub { font-size: 10px; }
  .faint-title { font-size: 10px; }
  .faint-line { font-size: 10px; }
}
