:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #090b12;
  color: #f5ead8;
}

* {
  box-sizing: border-box;
}

html,
body,
#gameRoot {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 320px;
  min-height: 100vh;
  background: #090b12;
  touch-action: none;
  user-select: none;
}

#gameRoot {
  position: relative;
  isolation: isolate;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  outline: none;
  background: #090b12;
}

#hud {
  position: fixed;
  z-index: 3;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  pointer-events: none;
}

.brand-lockup,
.meter {
  border: 1px solid rgba(85, 240, 215, 0.32);
  background: rgba(9, 11, 18, 0.76);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.28), inset 0 0 0 1px rgba(255, 209, 102, 0.05);
  backdrop-filter: blur(8px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(520px, 44vw);
  padding: 12px 16px;
  border-radius: 8px;
}

.mark {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  background: #172235;
  border: 2px solid #55f0d7;
  box-shadow: 0 0 18px rgba(85, 240, 215, 0.42);
}

.mark::before,
.mark::after {
  content: "";
  position: absolute;
  inset: 10px 17px;
  background: #ff8a3d;
  transform: rotate(45deg);
}

.mark::after {
  inset: 15px 12px;
  background: #ffd166;
}

h1,
h2,
p {
  margin: 0;
}

.brand-lockup h1 {
  font-size: clamp(1.18rem, 2vw, 1.92rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand-lockup p {
  margin-top: 5px;
  color: rgba(245, 234, 216, 0.84);
  font-weight: 650;
  line-height: 1.25;
}

.meter-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 10px;
  min-width: min(520px, 52vw);
}

.meter {
  position: relative;
  min-height: 56px;
  padding: 9px 12px 13px;
  border-radius: 8px;
  overflow: hidden;
}

.meter span {
  display: block;
  color: rgba(245, 234, 216, 0.7);
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.meter b {
  display: block;
  margin-top: 3px;
  color: #fff7df;
  font-size: 1.3rem;
  line-height: 1.05;
}

.meter i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  width: var(--fill, 100%);
  background: #ff8a3d;
  box-shadow: 0 0 14px currentColor;
}

.meter.hp i {
  background: #ff5f7e;
}

.meter.level i {
  background: #55f0d7;
}

.meter.wave i {
  background: #7c4dff;
}

.meter.score i {
  background: #ffd166;
}

#touchControls {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
}

#movePad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 54px);
  gap: 8px;
  pointer-events: auto;
}

#movePad button,
.skill-button,
#modalPrimary,
.upgrade-card {
  border: 0;
  border-radius: 8px;
  color: #090b12;
  font: inherit;
  font-weight: 950;
  letter-spacing: 0;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.28), inset 0 -4px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.36);
}

#movePad button {
  min-height: 54px;
  background: linear-gradient(180deg, #55f0d7, #28bdd9);
}

#upButton {
  grid-column: 2;
  grid-row: 1;
}

#leftButton {
  grid-column: 1;
  grid-row: 2;
}

#downButton {
  grid-column: 2;
  grid-row: 3;
}

#rightButton {
  grid-column: 3;
  grid-row: 2;
}

.skill-button {
  width: 112px;
  min-height: 64px;
  pointer-events: auto;
}

#dashButton {
  background: linear-gradient(180deg, #ffd166, #ff8a3d);
}

#burstButton {
  background: linear-gradient(180deg, #ff8ab0, #ff5f7e);
}

#movePad button:active,
.skill-button:active,
#modalPrimary:active,
.upgrade-card:active {
  transform: translateY(5px);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

#modal,
#upgradePanel {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at center, rgba(124, 77, 255, 0.18), rgba(9, 11, 18, 0.78) 46%, rgba(9, 11, 18, 0.9));
}

#modal.hidden,
#upgradePanel.hidden {
  display: none;
}

.modal-frame,
.upgrade-frame {
  width: min(560px, calc(100vw - 36px));
  border: 2px solid rgba(255, 138, 61, 0.72);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(23, 34, 53, 0.98), rgba(9, 11, 18, 0.98));
  padding: 22px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5), 0 0 38px rgba(255, 138, 61, 0.22);
}

.titleplate {
  display: grid;
  grid-template-columns: 58px 1fr;
  grid-template-areas: "icon eyebrow" "icon title";
  gap: 2px 14px;
  align-items: center;
}

.crypt-emblem {
  grid-area: icon;
  width: 58px;
  height: 58px;
  background: #090b12;
  border: 2px solid #55f0d7;
  box-shadow: inset 0 0 0 7px #172235, 0 0 22px rgba(85, 240, 215, 0.36);
}

.titleplate p,
.upgrade-frame > p {
  color: #55f0d7;
  font-weight: 950;
  text-transform: uppercase;
}

.titleplate h2,
.upgrade-frame h2 {
  color: #fff7df;
  font-size: clamp(2rem, 5vw, 3.65rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.brief {
  margin-top: 18px;
  color: rgba(245, 234, 216, 0.86);
  font-size: 1.04rem;
  font-weight: 700;
  line-height: 1.45;
}

.brief-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 22px;
}

.brief-grid span {
  border: 1px solid rgba(85, 240, 215, 0.28);
  border-radius: 8px;
  padding: 10px 8px;
  color: #ffd166;
  background: rgba(9, 11, 18, 0.72);
  font-size: 0.88rem;
  font-weight: 900;
  text-align: center;
}

#modalPrimary {
  width: 100%;
  min-height: 62px;
  background: linear-gradient(180deg, #ffd166, #ff8a3d);
  font-size: 1.04rem;
}

#upgradeCards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.upgrade-card {
  min-height: 132px;
  padding: 12px;
  color: #f5ead8;
  background: linear-gradient(180deg, #24344f, #172235);
  border: 1px solid rgba(85, 240, 215, 0.28);
  text-align: left;
}

.upgrade-card strong {
  display: block;
  color: #ffd166;
  font-size: 1rem;
}

.upgrade-card span {
  display: block;
  margin-top: 8px;
  color: rgba(245, 234, 216, 0.8);
  font-size: 0.86rem;
  line-height: 1.25;
}

@media (max-width: 760px) {
  #hud {
    gap: 8px;
    align-items: stretch;
  }

  .brand-lockup {
    max-width: 48vw;
    padding: 9px;
  }

  .mark {
    width: 34px;
    height: 34px;
  }

  .brand-lockup h1 {
    font-size: 1rem;
  }

  .brand-lockup p {
    display: none;
  }

  .meter-row {
    grid-template-columns: repeat(2, minmax(74px, 1fr));
    min-width: 45vw;
    gap: 7px;
  }

  .meter {
    min-height: 48px;
    padding: 8px 9px 12px;
  }

  .meter b {
    font-size: 1.04rem;
  }

  #touchControls {
    justify-content: space-between;
    padding: 0 12px;
    gap: 8px;
  }

  #movePad {
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(3, 48px);
    gap: 6px;
  }

  #movePad button {
    min-height: 48px;
    font-size: 0.76rem;
  }

  .skill-button {
    width: 74px;
    min-height: 58px;
    font-size: 0.78rem;
  }

  #upgradeCards,
  .brief-grid {
    grid-template-columns: 1fr;
  }
}
