/* Rogueslop — portrait phone layout: top 60% scene, bottom 40% panel. */

@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/fonts/press-start-2p.woff2') format('woff2');
  font-display: swap;
}
@font-face {
  font-family: 'VT323';
  src: url('../assets/fonts/vt323.woff2') format('woff2');
  font-display: swap;
}

:root {
  --bg: #0d0b14;
  --panel: #17142a;
  --line: #3a3560;
  --text: #e8e4d4;
  --dim: #9a96b0;
  --gold: #f2c84b;
  --good: #7ed67e;
  --bad: #ff6b6b;
  --hit: #ffd27a;
  --head: 'Press Start 2P', ui-monospace, monospace;
  --body: 'VT323', ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  font: 20px/1 var(--body);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

img,
canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

#app {
  position: absolute;
  inset: 0;
  max-width: 500px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 3fr) minmax(0, 2fr); /* the 60/40 split */
}

/* ---- Scene (top 60%) --------------------------------------------------- */

#scene {
  position: relative;
  overflow: hidden;
  background: #07060c;
  container-type: size;
}

.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#village {
  background: #1b1630;
}

/* A square that covers the scene, so the hotspots stay glued to the art. */
.village-art {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 130vw;
  height: 130vw;
  width: max(100cqw, 100cqh);
  height: max(100cqw, 100cqh);
  transform: translate(-50%, -50%);
  background: url('../assets/img/village.png') center / 100% 100% no-repeat;
  image-rendering: pixelated;
}

/* --x is the spot's place on the art; the clamp keeps the label on screen
   when the sides of the art are cropped. */
.spot {
  position: absolute;
  left: var(--x);
  left: clamp(50% - 50cqw + 48px, var(--x), 50% + 50cqw - 48px);
  transform: translate(-50%, -50%);
  min-width: 48px;
  min-height: 48px;
  padding: 6px 8px;
  font: 9px/1 var(--head);
  color: var(--gold);
  background: rgba(13, 11, 20, 0.86);
  border: 2px solid var(--gold);
  border-radius: 0;
  animation: bob 1.6s steps(2) infinite;
}

.spot.on {
  color: #1a1408;
  background: var(--gold);
}

/* The hero stands in the village square, wearing what is equipped. */
#v-hero {
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-42%);
  pointer-events: none;
}
#v-hero canvas,
.fighter-hero canvas {
  display: block;
  width: 36vw;
  width: min(36cqw, 31cqh);
  aspect-ratio: 1;
}

#battle {
  background: #14121f url('../assets/img/battle.png') center bottom / cover no-repeat;
  image-rendering: pixelated;
}

.plate {
  position: absolute;
  top: calc(6px + env(safe-area-inset-top));
  display: block;
  width: 47%;
  margin: 0;
  padding: 4px 6px 3px;
  font: inherit;
  color: inherit;
  text-align: left;
  background: rgba(13, 11, 20, 0.84);
  border: 2px solid var(--line);
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}
.plate-mon {
  z-index: 6;
  min-height: 48px;
  border-color: var(--gold);
}
.plate-traits {
  font-size: 15px;
  color: var(--hit);
  text-overflow: ellipsis;
}
.plate-hero {
  left: 2%;
}
.plate-mon {
  right: 2%;
}
.plate-name {
  margin-bottom: 3px;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plate-mon.boss .plate-name {
  color: var(--gold);
}
.plate-sub {
  margin-top: 3px;
  font-size: 16px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
}

.bar {
  position: relative;
  height: 16px;
  background: #000;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
}
.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  background: #c0392b;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.22);
  transition: width 0.25s steps(6);
}
.bar.xp i {
  background: #3b6fd4;
}
.bar span {
  position: relative;
  display: block;
  font: 16px/12px var(--body);
  text-align: center;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  white-space: nowrap;
}

.fighter {
  position: absolute;
  bottom: 8%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.fighter-hero {
  left: 1%;
  bottom: 6%;
}

/* The enemy group: three tappable enemies, the first at the back. */
.foe {
  position: absolute;
  z-index: 2;
  bottom: 6%;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
  min-height: 48px;
  margin: 0;
  padding: 0;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}
.foe-right {
  right: 1%;
}
.foe-left {
  right: 34%;
}
.foe-mid {
  z-index: 1;
  right: 17%;
  bottom: 27%;
}
.foe img.body {
  display: block;
  width: calc(22vw * var(--s, 1));
  width: calc(min(23cqw, 20cqh) * var(--s, 1));
  height: auto;
}
.foe img.crown {
  width: 24px;
  margin-bottom: -2px;
}
.foe-mark {
  visibility: hidden;
  font: 10px/1 var(--head);
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
  animation: bob 0.8s steps(2) infinite;
}
.foe-bar {
  position: relative;
  width: 46px;
  height: 7px;
  margin: 2px 0 1px;
  background: #000;
  border: 1px solid #000;
  box-shadow: 0 0 0 1px var(--line);
}
.foe-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  background: #c0392b;
  transition: width 0.25s steps(6);
}
.foe.on .foe-mark {
  visibility: visible;
}
.foe-next {
  visibility: hidden;
  margin-bottom: 2px;
  padding: 2px 3px;
  font: 8px/1 var(--head);
  color: #fff;
  background: #a32a1f;
  box-shadow: 0 0 0 1px #000;
}
.foe.next .foe-next {
  visibility: visible;
}
.foe.on .foe-bar {
  box-shadow: 0 0 0 1px var(--gold);
}
.foe.on img.body {
  filter: drop-shadow(2px 0 0 var(--gold)) drop-shadow(-2px 0 0 var(--gold)) drop-shadow(0 2px 0 var(--gold)) drop-shadow(0 -2px 0 var(--gold));
}
.foe.dead {
  opacity: 0;
  pointer-events: none;
}

#tray {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(98px + env(safe-area-inset-top));
  width: 96%;
  pointer-events: none;
  transition: opacity 0.15s;
  transform: translateX(-50%);
  padding: 5px 8px 5px;
  background: rgba(13, 11, 20, 0.88);
  border: 2px solid var(--line);
  text-align: center;
}
/* Once an action is over the tray fades so the enemies can be seen and tapped. */
#tray.idle {
  opacity: 0;
  transition: opacity 0.4s 1.4s;
}
.tray-title {
  margin-bottom: 4px;
  font: 9px/1.2 var(--head);
  color: var(--gold);
}
.tray-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 8px;
  min-height: 40px;
  font-size: 24px;
}
.tray-row + .tray-row {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 2px dashed var(--line);
}
.tray-row .vs {
  color: var(--dim);
}
/* One short line per attacking enemy. */
.tray-row.compact {
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 6px;
  min-height: 26px;
  font-size: 19px;
  text-align: left;
}
.tray-row.compact + .tray-row.compact {
  margin-top: 1px;
  padding-top: 1px;
  border-top: 0;
}
.tray-row.compact .who {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tray-row.compact .die.d20 {
  flex: none;
  width: 24px;
  height: 24px;
  font-size: 8px;
}
.tray-row.compact .res {
  font-size: 9px;
}
.tray-row.compact .dmg {
  min-width: 30px;
  color: var(--bad);
  text-align: right;
}
.tray-row.compact .venom {
  font-size: 15px;
  color: var(--good);
}
.tray-icon {
  width: 34px;
  height: 34px;
}
.tray-row .res {
  font: 11px/1.2 var(--head);
}
.res.good {
  color: var(--good);
}
.res.bad {
  color: var(--bad);
}
.res.crit {
  color: var(--gold);
}
.res.miss {
  color: var(--dim);
}

.dw {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.dw small {
  max-width: 76px;
  font-size: 13px;
  line-height: 0.9;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.die {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font: 11px/1 var(--head);
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  background: #2f6fb5;
  border: 2px solid #000;
  box-shadow:
    inset -3px -3px 0 rgba(0, 0, 0, 0.35),
    inset 3px 3px 0 rgba(255, 255, 255, 0.3);
}
.die.d20 {
  width: 38px;
  height: 38px;
  border: 0;
  background: linear-gradient(150deg, #e2574b 0 34%, #b3261e 34% 66%, #7d1712 66%);
  clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
  box-shadow: none;
}
.die.venom {
  background: #3f8f3a;
}
.die.heal {
  background: #b8336a;
}
.die.rolling {
  animation: rattle 0.12s steps(2) infinite;
}
.die.crit {
  background: var(--gold);
  color: #1a1408;
  text-shadow: none;
}
.die.fumble {
  background: #55526a;
}

#fx {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font: 12px/1 var(--head);
  color: #fff;
  text-shadow:
    2px 2px 0 #000,
    -1px -1px 0 #000;
  white-space: nowrap;
  animation: floatUp 1s ease-out forwards;
}
.float.bad {
  color: var(--bad);
}
.float.good {
  color: var(--good);
}
.float.gold {
  color: var(--gold);
}
.float.big {
  font-size: 16px;
}

#banner {
  position: absolute;
  left: 50%;
  top: 44%;
  z-index: 25;
  width: max-content;
  max-width: 92%;
  padding: 10px 12px;
  transform: translate(-50%, -50%);
  font: 12px/1.6 var(--head);
  text-align: center;
  color: var(--text);
  background: rgba(13, 11, 20, 0.93);
  border: 3px solid var(--line);
  box-shadow: 0 0 0 3px #000;
  pointer-events: none;
  animation: pop 0.18s steps(3);
}
#banner.good {
  color: var(--good);
  border-color: var(--good);
}
#banner.gold {
  color: var(--gold);
  border-color: var(--gold);
}
#banner.bad {
  color: var(--bad);
  border-color: var(--bad);
}

/* ---- Panel (bottom 40%) ------------------------------------------------ */

#panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 3px solid var(--line);
}

#status {
  flex: none;
}
.st-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.st-row + .st-row {
  margin-top: 5px;
}
.st-lv {
  font: 10px/1 var(--head);
  color: var(--gold);
  white-space: nowrap;
}
.st-row .bar {
  flex: 1;
}
.chips {
  justify-content: space-between;
  gap: 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}
.chip img {
  width: 18px;
  height: 18px;
}
.chip.depth {
  color: var(--gold);
}

#log {
  flex: 1;
  min-height: 0;
  padding: 3px 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  font-size: 18px;
  line-height: 1.02;
  color: #c9c5d6;
  background: var(--bg);
  border: 2px solid var(--line);
}
#log p {
  margin: 0 0 2px;
}
#log .good {
  color: var(--good);
}
#log .bad {
  color: var(--bad);
}
#log .hit {
  color: var(--hit);
}
#log .miss {
  color: var(--dim);
}
#log .gold {
  color: var(--gold);
}

#actions {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
#actions .btn {
  padding: 4px 3px;
  font-size: 9px;
  font-size: clamp(7px, 2.3vw, 9px); /* four buttons per row also fit a 320 px screen */
}
.wide {
  grid-column: 1 / -1;
}
.span2 {
  grid-column: span 2;
}
.hint {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 0 6px;
  font-size: 18px;
  text-align: center;
  color: var(--dim);
  border: 2px dashed var(--line);
}
.hint b {
  color: var(--bad);
  font-weight: normal;
}

.btn {
  -webkit-appearance: none;
  appearance: none;
  min-width: 48px;
  min-height: 48px; /* every tap target is at least 48 x 48 CSS pixels */
  margin: 0;
  padding: 4px 6px;
  font: 10px/1.3 var(--head);
  color: var(--text);
  background: #2d2850;
  border: 2px solid #000;
  border-radius: 0;
  box-shadow:
    inset -2px -2px 0 #1b1836,
    inset 2px 2px 0 #514a8a;
}
.btn:active:not(:disabled) {
  transform: translateY(2px);
  filter: brightness(1.25);
}
.btn:disabled {
  opacity: 0.45;
}
.btn.primary {
  background: #a02c1c;
  box-shadow:
    inset -2px -2px 0 #6b1a10,
    inset 2px 2px 0 #d9604c;
}
.btn.gold {
  color: #1a1408;
  background: #d9a521;
  box-shadow:
    inset -2px -2px 0 #94700f,
    inset 2px 2px 0 #f7dc7a;
}
.btn.spell {
  background: #7a3d12;
  box-shadow:
    inset -2px -2px 0 #4f2609,
    inset 2px 2px 0 #c97a35;
}

/* Village: the shop replaces the action buttons; the log shrinks to one line. */
#panel[data-mode='village'] #actions,
#panel[data-mode='dead'] #actions {
  display: none;
}
#panel[data-mode='village'] #log {
  flex: none;
  height: 28px;
}

#shop {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
#tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}
#tabs .btn {
  padding: 2px;
  font-size: 8px;
  font-size: clamp(6px, 2vw, 8px);
}
#tabs .btn.on {
  color: #1a1408;
  background: var(--gold);
  box-shadow: none;
}
#tab-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 3px 4px;
  border-bottom: 2px solid var(--line);
}
.item > img {
  flex: none;
  width: 28px;
  height: 28px;
}
.item-main {
  flex: 1;
  min-width: 0;
}
.item-name {
  font-size: 20px;
}
.item-sub {
  margin-top: 2px;
  font-size: 17px;
  color: var(--dim);
}
.item .btn {
  flex: none;
  min-width: 78px;
}
.item .btns {
  flex: none;
  display: flex;
  gap: 4px;
}
.item .btns .btn {
  min-width: 62px;
  padding: 4px 2px;
  font-size: 8px;
}
.item .tag {
  flex: none;
  min-width: 78px;
  font: 8px/1 var(--head);
  text-align: center;
  color: var(--good);
}
.note {
  padding: 6px 4px;
  font-size: 18px;
  line-height: 1.05;
  color: var(--dim);
}
.gate {
  display: grid;
  gap: 6px;
  padding-top: 2px;
}
.stepper {
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  gap: 6px;
  align-items: center;
  font: 11px/1 var(--head);
  text-align: center;
  color: var(--gold);
}

/* ---- Overlays ---------------------------------------------------------- */

#overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(5, 4, 10, 0.84);
}
.modal {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  padding: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  text-align: center;
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: 0 0 0 3px #000;
}
.modal h1 {
  margin: 4px 0 0;
  font: 20px/1.3 var(--head);
  color: var(--gold);
  text-shadow: 3px 3px 0 #6b1a10;
}
.modal h2 {
  margin: 0;
  font: 12px/1.4 var(--head);
  color: var(--gold);
}
.modal p {
  margin: 0;
  font-size: 20px;
  line-height: 1.05;
}
.modal .dim {
  color: var(--dim);
}
.modal .art {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 18px;
}
.modal .art img {
  width: 96px;
  height: 96px;
}
.modal .pick {
  display: grid;
  gap: 3px;
  text-align: left;
}
.modal .pick .btn {
  width: 100%;
}
.modal .pick p {
  font-size: 17px;
  color: var(--dim);
}
.modal .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
/* Stays in view while a long dialog scrolls. */
.modal .foot {
  display: grid;
  position: sticky;
  bottom: -14px;
  margin-bottom: -14px;
  padding: 8px 0 14px;
  background: var(--panel);
}
.sheet {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 0;
  font-size: 19px;
  text-align: left;
}
.sheet dt {
  color: var(--dim);
}
.sheet dd {
  margin: 0;
  text-align: right;
}
.rules {
  margin: 0;
  padding-left: 18px;
  font-size: 18px;
  line-height: 1.05;
  text-align: left;
  color: #c9c5d6;
}
.rules li {
  margin-bottom: 4px;
}

/* Title: hero name. 16px keeps Safari from zooming into the field. */
.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}
input.name {
  min-width: 0;
  min-height: 48px;
  margin: 0;
  padding: 4px 8px;
  font: 22px/1 var(--body);
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
  -webkit-user-select: text;
  user-select: text;
}
input.name:focus {
  outline: none;
  border-color: var(--gold);
}
.modal canvas.hero-pic {
  width: 112px;
  height: 112px;
}

/* Level-up: ability points. */
.alloc {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.alloc .points {
  font: 10px/1.4 var(--head);
  color: var(--gold);
}
.ability {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 8px;
  align-items: center;
  text-align: left;
}
.ability .btn {
  font-size: 14px;
}
.ability-score {
  font-size: 24px;
}
.ability-text {
  font-size: 16px;
  line-height: 1;
  color: var(--dim);
}
.up,
.ability-score b.up {
  color: var(--good);
}
.ability-score b {
  font-weight: normal;
  color: var(--dim);
}

/* Enemy stats. */
.foe-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  text-align: left;
  background: var(--bg);
  border: 2px solid var(--line);
}
.foe-card.boss {
  border-color: var(--gold);
}
.foe-card.slain {
  opacity: 0.55;
}
.foe-head {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}
.foe-head img {
  width: 56px;
  height: 56px;
}
.foe-name {
  margin-bottom: 4px;
  font-size: 22px;
}
.foe-card.boss .foe-name {
  color: var(--gold);
}
.traits {
  margin: 0;
  padding-left: 18px;
  font-size: 18px;
  line-height: 1.05;
}
.traits b {
  font-weight: normal;
  color: var(--hit);
}
.modal .tag {
  font: 8px/1.6 var(--head);
  text-align: center;
  color: var(--good);
}
.modal .tag.dead {
  color: var(--dim);
}
.modal .tag.next {
  color: #ff7a6b;
}
.bag-list {
  text-align: left;
}

/* Legends. */
.legends {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.legend {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 6px;
  font-size: 18px;
  line-height: 1.05;
  text-align: left;
  background: var(--bg);
  border: 2px solid var(--line);
}
.legend img {
  width: 40px;
  height: 40px;
}
.legend-name {
  font-size: 22px;
  color: var(--gold);
}
.legend.fallen .legend-fate {
  color: var(--bad);
}
.legend.retired .legend-fate {
  color: var(--good);
}

/* ---- Animations -------------------------------------------------------- */

@keyframes bob {
  50% {
    margin-top: -3px;
  }
}
@keyframes rattle {
  0% {
    transform: translate(-2px, 1px) rotate(-8deg);
  }
  100% {
    transform: translate(2px, -1px) rotate(8deg);
  }
}
@keyframes floatUp {
  0% {
    opacity: 0;
    margin-top: 6px;
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    margin-top: -46px;
  }
}
@keyframes pop {
  0% {
    transform: translate(-50%, -50%) scale(0.6);
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

/* In the village the one-line log shows only the start of the latest line. */
#panel[data-mode='village'] #log p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
