@font-face {
  font-family: "Rajdhani";
  font-style: normal;
  font-weight: 700;
  font-display: block;
  src: url("/assets/fonts/Rajdhani/Rajdhani-Bold.ttf") format("truetype");
}

@font-face {
  font-family: "Rajdhani";
  font-style: normal;
  font-weight: 600;
  font-display: block;
  src: url("/assets/fonts/Rajdhani/Rajdhani-SemiBold.ttf") format("truetype");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: block;
  src: url("/assets/fonts/Inter/static/Inter_18pt-Medium.ttf") format("truetype");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100 800;
  font-display: block;
  src: url("/assets/fonts/JetBrains_Mono/JetBrainsMono-VariableFont_wght.ttf") format("truetype");
}

:root {
  color-scheme: dark;
  --ink: #edf4ee;
  --muted: #9faea7;
  --panel: rgba(10, 16, 20, 0.82);
  --panel-strong: rgba(12, 20, 25, 0.94);
  --line: rgba(255, 255, 255, 0.13);
  --accent: #7ee0b8;
  --accent-2: #e9b35f;
  --danger: #f07c63;
  --shadow: rgba(0, 0, 0, 0.35);
  --font-heading: "Rajdhani";
  --font-label: "Rajdhani";
  --font-copy: "Inter";
  --font-stat: "JetBrains Mono";
  --z-world: 1;
  --z-actors: 2;
  --z-hud: 10;
  --z-hud-raised: 11;
  --z-hud-panel: 12;
  --z-battle-canvas: 20;
  font-family: var(--font-copy);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071014;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  color: var(--ink);
  cursor: pointer;
}

.shell,
.game-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#gameCanvas,
#roamCanvas {
  /* position: absolute;
  inset: 0;
  z-index: var(--z-world); */
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  background: #071014;
}

#gameCanvasFront {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: transparent;
}

/** Roam POC: draw tiles that sort in front of the Spine layer (trees, props). */
#roamCanvasFront {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: transparent;
}

.roam-hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 4;
  margin: 0;
  padding: 10px 14px;
  max-width: min(420px, 92vw);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted, #9fb5bc);
  background: rgba(8, 14, 18, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  pointer-events: none;
}

.spine-layer {
  position: absolute;
  inset: 0;
  z-index: var(--z-actors);
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.battle-canvas-panel {
  position: absolute;
  inset: 0;
  z-index: var(--z-battle-canvas);
  display: none;
  align-items: center;
  justify-content: center;
  background: #020711;
}

.battle-canvas-panel.is-open {
  display: flex;
}

.battle-canvas-shell {
  position: relative;
  width: min(100vw, calc(100vh * 3840 / 2160));
  aspect-ratio: 3840 / 2160;
  overflow: hidden;
  background: #020711;
}

#battleCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #020711;
}

.hud {
  position: absolute;
  z-index: var(--z-hud);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 48px var(--shadow);
  backdrop-filter: blur(14px);
}

.hud-top {
  top: 14px;
  left: 14px;
  right: auto;
  display: grid;
  grid-template-columns: auto;
  align-items: center;
  gap: 16px;
  min-height: 66px;
  width: min(260px, calc(100vw - 28px));
  padding: 10px 12px;
  border-radius: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 172px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 2px solid #d9fbff;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 4px, transparent 5px),
    conic-gradient(from 22deg, #7ee0b8, #e9b35f, #83b7e8, #7ee0b8);
  box-shadow: 0 0 26px rgba(126, 224, 184, 0.34);
  flex: 0 0 auto;
}

.brand strong {
  display: block;
  letter-spacing: 0;
  font-size: 16px;
  line-height: 1.1;
}

.brand span:not(.brand-mark) {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.action-strip button,
.touch-pad button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  outline: none;
}

.stat-panel {
  left: 14px;
  top: 96px;
  display: grid;
  width: 180px;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
}

.stat-panel div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 30px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-panel div:last-child {
  border-bottom: 0;
}

.stat-panel span {
  color: var(--muted);
  font-size: 12px;
}

.stat-panel strong {
  max-width: 78px;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-map-wrap {
  right: 14px;
  top: 96px;
  width: 172px;
  height: 172px;
  padding: 8px;
  border-radius: 8px;
}

#miniMap {
  display: block;
  width: 156px;
  height: 156px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #0d171a;
}

.action-strip {
  left: 50%;
  bottom: 18px;
  display: flex;
  align-items: center;
  min-width: min(520px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  min-height: 54px;
  transform: translateX(-50%);
  gap: 12px;
  padding: 8px;
  border-radius: 8px;
  pointer-events: none;
}

.action-strip span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: #dce8e2;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-strip button {
  min-width: 104px;
  padding: 0 14px;
  color: #071014;
  border-color: rgba(233, 179, 95, 0.9);
  background: var(--accent-2);
  font-weight: 750;
  pointer-events: auto;
}

.action-strip button:disabled {
  color: #b6c0bc;
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.08);
  cursor: default;
}

.buddy-book-button {
  right: 14px;
  bottom: 18px;
  z-index: var(--z-hud-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 108px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.buddy-book-button {
  width: 96px;
  height: 96px;
}

.buddy-book-button[hidden] {
  display: none;
}

.buddy-book-button__icon {
  position: relative;
  width: 78px;
  height: 78px;
  border: 2px solid rgba(217, 251, 255, 0.72);
  border-radius: 50%;
  background:
    radial-gradient(circle at 37% 38%, #edf4ee 0 7px, transparent 8px),
    radial-gradient(circle at 61% 39%, #071014 0 5px, transparent 6px),
    linear-gradient(145deg, #7ee0b8, #4f826a 68%);
  box-shadow:
    inset -10px -10px 0 rgba(7, 16, 20, 0.18),
    0 9px 14px rgba(0, 0, 0, 0.36);
  flex: 0 0 auto;
}

.buddy-book-button__icon::after {
  position: absolute;
  top: -9px;
  left: 18px;
  width: 38px;
  height: 25px;
  border-radius: 50% 50% 38% 38%;
  background: linear-gradient(145deg, #d7f2a4, #6fb870);
  content: "";
  transform: rotate(-12deg);
}

.buddy-book-button:focus-visible {
  outline: 2px solid rgba(126, 224, 184, 0.78);
  outline-offset: -8px;
}

.buddy-book-button span:not(.buddy-book-button__icon),
.buddy-book-button strong {
  display: none;
}

.buddy-book-panel {
  right: 14px;
  bottom: 78px;
  z-index: var(--z-hud-panel);
  display: none;
  width: min(386px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 116px));
  overflow: hidden;
  border-radius: 8px;
  background: rgba(10, 16, 20, 0.94);
}

.buddy-book-panel.is-open {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.buddy-book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.buddy-book-header span,
.buddy-book-summary span,
.buddy-entry__meta {
  color: var(--muted);
}

.buddy-book-header span {
  display: block;
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.buddy-book-header h2 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: 0;
}

.buddy-book-header button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 24px;
  line-height: 1;
}

.buddy-book-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.buddy-book-summary strong {
  font-size: 15px;
}

.buddy-book-summary span {
  font-size: 12px;
}

.buddy-book-list {
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 14px;
  scrollbar-color: rgba(126, 224, 184, 0.55) rgba(255, 255, 255, 0.08);
  scrollbar-width: thin;
}

.buddy-book-list:focus {
  outline: 1px solid rgba(126, 224, 184, 0.42);
  outline-offset: -2px;
}

.buddy-entry {
  display: grid;
  gap: 8px;
  min-height: 126px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.buddy-entry {
  min-height: 150px;
}

.buddy-entry__top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.buddy-entry__name {
  min-width: 0;
}

.buddy-entry__name strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.15;
}

.buddy-entry__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  margin-top: 5px;
  font-size: 11px;
  text-transform: uppercase;
}

.buddy-entry__resources {
  display: grid;
  gap: 8px;
}

.buddy-entry__resource {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.buddy-entry__resource span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.buddy-entry__resource div {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.buddy-entry__resource i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7ee0b8, #c6fbff);
}

.buddy-entry__resource button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(233, 179, 95, 0.65);
  border-radius: 7px;
  background: rgba(233, 179, 95, 0.18);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.buddy-entry__resource button:disabled {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  cursor: default;
}

.touch-pad {
  position: absolute;
  right: 14px;
  bottom: 88px;
  z-index: var(--z-hud-raised);
  display: none;
  grid-template-columns: 46px 46px 46px 46px;
  grid-template-rows: 46px 46px;
  gap: 8px;
}

.touch-pad button {
  color: #dce8e2;
  background: var(--panel-strong);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.26);
  user-select: none;
  touch-action: none;
}

.touch-pad button[data-touch="up"] {
  grid-column: 2;
}

.touch-pad button[data-touch="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-pad button[data-touch="down"] {
  grid-column: 2;
  grid-row: 2;
}

.touch-pad button[data-touch="right"] {
  grid-column: 3;
  grid-row: 2;
}

.touch-pad button[data-touch="action"] {
  grid-column: 4;
  grid-row: 2;
  color: #071014;
  background: var(--accent-2);
}

@media (max-width: 820px) {
  .hud-top {
    grid-template-columns: auto;
    align-items: center;
  }

  .brand {
    min-width: 0;
  }

  .stat-panel {
    top: auto;
    bottom: 88px;
    width: 156px;
  }

  .mini-map-wrap {
    display: none;
  }

  .touch-pad {
    display: grid;
  }

  .buddy-book-button {
    bottom: 196px;
  }

  .buddy-book-panel {
    right: 14px;
    bottom: 14px;
    max-height: calc(100vh - 28px);
  }

}

@media (max-width: 560px) {
  .hud-top {
    left: 8px;
    right: 8px;
    top: 8px;
    gap: 10px;
    padding: 8px;
  }

  .brand span:not(.brand-mark) {
    display: none;
  }

  .stat-panel {
    left: 8px;
    bottom: 82px;
  }

  .action-strip {
    bottom: 10px;
    min-height: 50px;
  }

  .touch-pad {
    right: 8px;
    bottom: 76px;
    grid-template-columns: 42px 42px 42px 42px;
    grid-template-rows: 42px 42px;
    gap: 6px;
  }

  .buddy-book-button {
    right: 8px;
    bottom: 176px;
    width: 82px;
    height: 82px;
  }

  .buddy-book-button__icon {
    width: 66px;
    height: 66px;
  }

  .buddy-book-panel {
    right: 8px;
    bottom: 8px;
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .buddy-book-list {
    padding: 10px;
  }

  .buddy-entry__resource {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .buddy-entry__resource button {
    grid-column: 1 / -1;
  }

}
