html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 200, 61, .14), transparent 28%),
    radial-gradient(circle at 80% 18%, rgba(80, 215, 255, .12), transparent 30%),
    linear-gradient(180deg, #07090e, #11141c 52%, #080a0f);
  color: #fff;
  font-family: Arial, "Noto Sans Sinhala", "Iskoola Pota", Helvetica, sans-serif;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  min-height: 100svh;
  gap: 10px;
  padding: 8px;
  box-sizing: border-box;
}
canvas {
  box-sizing: border-box;
  width: min(96vw, 1280px);
  height: auto;
  max-height: 61vh;
  margin-top: 6px;
  border: 3px solid #596173;
  border-radius: 8px;
  box-shadow:
    0 0 0 2px rgba(255,255,255,.08),
    0 18px 58px rgba(0,0,0,.68),
    0 0 44px rgba(255,200,61,.08);
  background: #171b28;
  touch-action: none;
}
.help {
  opacity: .86;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  text-align: center;
  padding: 0 12px 10px;
  line-height: 1.35;
}
#mobileControls {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: stretch;
  width: min(98vw, 960px);
  flex-wrap: nowrap;
  touch-action: none;
  user-select: none;
}
.playerPanel, .menuPanel {
  background: linear-gradient(180deg, rgba(31,35,47,.97), rgba(13,16,24,.97));
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05), 0 10px 24px rgba(0,0,0,.34);
}
.playerPanel {
  flex: 1 1 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.menuPanel {
  width: 190px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}
.panelTitle {
  font-weight: 900;
  letter-spacing: .08em;
  font-size: 14px;
  color: #ffc83d;
  text-align: center;
}
.movementRow, .attackRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
#mobileControls button {
  border: 0;
  border-radius: 8px;
  background: #252d3f;
  color: white;
  font-weight: 900;
  font-size: 20px;
  min-height: 58px;
  font-family: inherit;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.08), 0 4px 10px rgba(0,0,0,.25);
  -webkit-tap-highlight-color: transparent;
}
#mobileControls button span {
  display: block;
  font-size: 10px;
  opacity: .8;
  font-weight: 700;
  letter-spacing: .02em;
  margin-top: 2px;
}
#mobileControls button:active {
  transform: translateY(2px) scale(.98);
  background: #3a4561;
}
.atk1 { background: linear-gradient(180deg, #27498d, #1e3561) !important; }
.atk2 { background: linear-gradient(180deg, #a67618, #62450d) !important; }
.atk3 { background: linear-gradient(180deg, #8d1230, #5a0b20) !important; }
.menuBtn {
  min-height: 56px !important;
  font-size: 15px !important;
}
.menuBtn.primary {
  background: linear-gradient(180deg, #ffc83d, #9a5d12) !important;
  color: #11141c !important;
}
.fullBtn {
  background: linear-gradient(180deg, #39d98a, #157346) !important;
  color: #07130c !important;
}
#gameMenu {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, .48);
}
body.menu-open #gameMenu {
  display: flex;
}
.menuSheet {
  width: min(96vw, 520px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(31,35,47,.98), rgba(13,16,24,.98));
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 18px 52px rgba(0,0,0,.55);
}
.menuSheet button {
  border: 0;
  border-radius: 8px;
  min-height: 58px;
  background: #252d3f;
  color: white;
  font-family: inherit;
  font-weight: 900;
  font-size: 18px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.08);
  touch-action: none;
}
.menuSheet button.primary {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, #ffc83d, #9a5d12);
  color: #11141c;
}
.menuSheet button span {
  display: block;
  font-size: 10px;
  opacity: .78;
  margin-top: 2px;
}
@media (max-width: 920px) {
  canvas { width: 98vw; max-height: 56vh; margin-top: 4px; }
  #mobileControls {
    width: 98vw;
    gap: 8px;
    flex-wrap: wrap;
  }
  .playerPanel {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "title title"
      "move attack";
    align-items: stretch;
  }
  .playerPanel .panelTitle { grid-area: title; }
  .movementRow { grid-area: move; }
  .attackRow { grid-area: attack; }
  .menuPanel {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
  }
  .menuPanel .menuBtn { flex: 1 1 0; }
  .desktopOnly { display: none; }
  .help { font-size: 11px; }
}
@media (max-width: 640px) {
  #mobileControls { margin-top: clamp(28px, 8svh, 64px); }
  #mobileControls button { min-height: 56px; font-size: 17px; }
  #mobileControls button span { font-size: 9px; }
  .panelTitle { font-size: 12px; }
  .playerPanel, .menuPanel { padding: 8px; }
  .movementRow, .attackRow { gap: 6px; }
  .menuBtn { min-height: 50px !important; }
  .help { font-size: 10px; }
}
@media (orientation: landscape) and (max-height: 560px) {
  canvas { max-height: 52vh; }
  #mobileControls { margin-top: 6px; }
  .help { display: none; }
}

canvas:fullscreen,
canvas:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #000;
  object-fit: contain;
}
