@font-face {
  font-family: Rubik;
  src: url("../rubik.ttf") format("truetype");
  font-weight: 300 900;
  font-display: swap;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { color: #f8fbf9; background: #18252b; font: 400 1rem/1.35 Rubik, Arial, sans-serif; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid #f8e095; outline-offset: 4px; }
[hidden] { display: none !important; }

.game {
  --side: clamp(12px, 2.2vw, 32px);
  --top: calc(clamp(12px, 2.2vw, 32px) + env(safe-area-inset-top, 0px));
  --left: calc(var(--side) + env(safe-area-inset-left, 0px));
  --right: calc(var(--side) + env(safe-area-inset-right, 0px));
  --bottom: calc(clamp(10px, 2vw, 24px) + env(safe-area-inset-bottom, 0px));
  --spell-ink: #c8faef;
  --spell-edge: #73d8c1;
  --cast-bg: #c6f2e4;
  --cast-ink: #13332e;
  position: relative;
  isolation: isolate;
  direction: ltr;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.game[data-spell="accio"] {
  --spell-ink: #f0d9fd;
  --spell-edge: #dbabea;
  --cast-bg: #efdcf8;
  --cast-ink: #3b2049;
}

.world, .world canvas { display: block; width: 100%; height: 100%; }
.world {
  position: absolute;
  inset: 0;
  background: linear-gradient(#263b55 0%, #25383c 56%, #273729 56%);
  touch-action: none;
}
.world canvas { image-rendering: pixelated; cursor: grab; touch-action: none; }
.world canvas.is-dragging { cursor: grabbing; }
.game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(180deg, #101b2940, transparent 24%, transparent 70%, #1420106b);
}

.game-top {
  position: absolute;
  z-index: 4;
  inset: var(--top) var(--right) auto var(--left);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}
.game-title { display: flex; direction: ltr; align-items: center; gap: 10px; }
.game-title h1, .game-title p { margin: 0; }
.game-title h1 { color: #fff; font-size: clamp(1.05rem, 2.4vw, 1.5rem); font-weight: 650; text-shadow: 1px 2px #1b2939, 0 2px 8px #1b2939aa; }
.game-title p { margin-top: 1px; color: #f5f8fa; font-size: .85rem; font-weight: 480; text-shadow: 0 1px 4px #172739, 0 2px 8px #172739; }
.title-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid #ebf2e889;
  background: #192825eb;
  box-shadow: inset 0 0 0 2px #ffffff12, 0 3px 0 #10201e73;
}
.title-icon canvas { width: 29px; height: 29px; image-rendering: pixelated; }
.game-nav { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.game-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 44px;
  border: 1px solid #c1d1c0a3;
  border-radius: 4px;
  padding: 8px 12px;
  background: #1b2b25f2;
  box-shadow: inset 0 1px #edf7e82e, inset 0 -3px #0d1c185e, 0 2px 4px #14201555;
  color: #f7faf7;
  direction: rtl;
  font-size: .9rem;
  font-weight: 570;
  line-height: 1.15;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: none;
}
.game-button:disabled { opacity: .6; cursor: default; }
@media (hover: hover) {
  .game-button:not(:disabled):hover { background: #303f35; }
  .cast:not(:disabled):hover { filter: brightness(1.1); background: var(--cast-bg); }
}
.game-button:active:not(:disabled), .game-button.is-held {
  box-shadow: inset 0 2px 0 #101d2ba6;
  transform: translateY(1px);
}

.game-status {
  position: absolute;
  z-index: 3;
  top: calc(var(--top) + 55px);
  left: var(--left);
  margin: 0;
  max-width: min(270px, calc(100vw - var(--left) - var(--right)));
  pointer-events: none;
  font-size: .84rem;
  font-weight: 490;
  direction: rtl;
  text-align: left;
}
.game-status:not(:empty) {
  padding: 5px 8px;
  background: #172723eb;
  border: 1px solid #e8eee64a;
}
.switch {
  justify-content: flex-start;
  direction: ltr;
  gap: 5px;
  padding: 4px 7px;
  border-left: 2px solid var(--spell-edge);
}
.switch-label { display: grid; text-align: left; }
.switch-label span { font-size: .76rem; line-height: 1.06; font-weight: 480; }
#spell-name { color: var(--spell-ink); font-size: .91rem; font-weight: 660; line-height: 1.2; }
.spell-icon { flex: 0 0 auto; width: 23px; height: 23px; image-rendering: pixelated; }
.switch kbd { margin-inline-start: auto; }

.reticle {
  --cross: #fbfff6;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 17px;
  height: 17px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(1px 1px 0 #14231e);
}
.reticle::before, .reticle::after { position: absolute; content: ""; background: var(--cross); }
.reticle::before { inset: 8px 1px 7px; }
.reticle::after { inset: 1px 7px 1px 8px; }
.reticle.is-targeted { --cross: var(--spell-edge); }

.inventory {
  position: absolute;
  z-index: 3;
  bottom: var(--bottom);
  left: 50%;
  width: min(402px, calc(100% - var(--left) - var(--right)));
  transform: translateX(-50%);
  pointer-events: none;
}
.vitals { display: flex; align-items: flex-end; justify-content: space-between; padding: 0 3px 5px; }
.vitals canvas { width: 44.8%; height: auto; image-rendering: pixelated; filter: drop-shadow(0 1px 0 #121713a6); }
.hotbar {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: 100%;
  margin: 0;
  padding: 2px;
  border: 2px solid #192119;
  background: #455346;
  box-shadow: 0 2px 0 #131c175e;
  list-style: none;
}
.hotbar li {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid #a9b0a49e;
  background: #1b251ac9;
  box-shadow: inset 2px 2px 0 #070e0c90, inset -2px -2px 0 #cdd3bb24;
}
.hotbar li.selected {
  z-index: 1;
  border-color: #f5f9df;
  outline: 2px solid #c7d8b5;
  background: #334734;
  box-shadow: inset 2px 2px 0 #e2f3d06b, inset -2px -2px 0 #71886b83;
}
.hotbar canvas { width: 78%; height: auto; image-rendering: pixelated; }
.desktop-instructions {
  margin: 10px -4px 0;
  color: #fff;
  direction: rtl;
  text-align: center;
  font-size: .83rem;
  font-weight: 490;
  text-shadow: 0 1px 2px #141b18, 0 1px 5px #131d14;
}
.desktop-instructions span { color: #dce6d9; padding-inline: 2px; }
.actions {
  position: absolute;
  z-index: 4;
  right: var(--right);
  bottom: var(--bottom);
  display: flex;
  flex-flow: column;
  align-items: stretch;
  width: clamp(112px, 12.1vw, 152px);
  gap: 6px;
}
.cast {
  border-color: #f3ffef;
  background: var(--cast-bg);
  box-shadow: inset 0 -3px #192f362e, 0 2px 6px #15201875;
  color: var(--cast-ink);
  font-weight: 680;
}
kbd {
  display: grid;
  place-items: center;
  width: 19px;
  height: 20px;
  padding-top: 1px;
  border: 1px solid #d8e7d695;
  background: #f4fff216;
  color: #fff;
  font: 500 .76rem/1 ui-monospace, monospace;
}
.touch-hint, .move-pad { display: none; }
.game-message {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 5;
  width: max-content;
  max-width: calc(100% - 36px);
  transform: translate(-50%, -50%);
  padding: 16px 20px;
  border: 1px solid #c1d1c07a;
  background: #1b2b25f2;
  direction: rtl;
  text-align: center;
}
.game-message p { margin: 0; }
.game-message .game-button { margin-top: 10px; }
.game:not(.is-playing) :is(.reticle, .game-status, .inventory, .actions, .move-pad) { visibility: hidden; }

@media (max-width: 730px) and (hover: hover) {
  .inventory { width: min(350px, 55vw); }
}

@media (any-pointer: coarse) {
  .desktop-instructions { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .move-pad {
    position: absolute;
    z-index: 4;
    left: var(--left);
    bottom: calc(var(--bottom) + var(--controls-lift));
    display: grid;
    grid-template-columns: repeat(3, 46px);
    grid-auto-rows: 46px;
    gap: 4px;
  }
  .move-pad button { min-height: 0; padding: 0; background: #203229e8; }
  .move-pad i {
    width: 10px;
    height: 10px;
    border-top: 2px solid #f5f9ef;
    border-left: 2px solid #f5f9ef;
    transform: translateY(2px) rotate(45deg);
  }
  .move-up { grid-column: 2; grid-row: 1; }
  .move-left { grid-column: 1; grid-row: 2; }
  .move-down { grid-column: 2; grid-row: 2; }
  .move-right { grid-column: 3; grid-row: 2; }
  .move-left i { transform: translateX(2px) rotate(-45deg); }
  .move-right i { transform: translateX(-2px) rotate(135deg); }
  .move-down i { transform: translateY(-2px) rotate(225deg); }
  .game { --controls-lift: 68px; }
  .inventory { width: min(354px, calc(100% - var(--left) - var(--right))); }
  .actions { bottom: calc(var(--bottom) + var(--controls-lift)); }
  .actions kbd { display: none; }
  .touch-hint { display: block; margin: 0 1px 1px; text-align: center; font-weight: 500; font-size: .83rem; text-shadow: 0 1px 2px #142015, 0 1px 5px #142015; }
}

@media (any-pointer: coarse) and (orientation: landscape), (any-pointer: coarse) and (min-width: 730px) {
  .game { --controls-lift: 0px; }
  .inventory { width: min(374px, 38vw); }
  .touch-hint { display: none; }
}

@media (max-width: 410px) {
  .game-nav { gap: 5px; }
  .game-nav .game-button { padding-inline: 8px; }
  .game-title { gap: 7px; }
  .title-icon { width: 36px; height: 36px; }
  .title-icon canvas { width: 25px; height: 25px; }
}

@media (orientation: landscape) and (max-height: 545px) {
  .game { --top: calc(9px + env(safe-area-inset-top, 0px)); }
  .game-title { gap: 7px; }
  .game-title p { display: none; }
  .title-icon { width: 36px; height: 36px; }
  .title-icon canvas { width: 25px; height: 25px; }
  .game-title h1 { font-size: 1.1rem; }
}

@media (any-pointer: coarse) and (orientation: landscape) and (max-width: 620px) {
  .inventory { width: 31vw; }
  .move-pad { grid-template-columns: repeat(3, 42px); grid-auto-rows: 42px; }
  .actions { width: 102px; }
}
