:root {
  color-scheme: light;
  --ink: #433638;
  --paper: #f8f0e8;
  --edo-blue: #8fbdd4;
  --seal-red: #b95145;
  --gold: #e2b84e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 14% 10%, rgba(255, 238, 184, 0.36), transparent 22rem),
    linear-gradient(135deg, #dceef2 0%, #f8efe1 43%, #d7e8dc 100%);
  color: var(--ink);
  font-family:
    "Hiragino Maru Gothic ProN",
    "Yu Gothic",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 32px);
}

.game-shell {
  position: relative;
  width: min(100%, 1179px);
  aspect-ratio: 1179 / 543;
  border: 4px solid rgba(67, 54, 56, 0.82);
  border-radius: 8px;
  background: var(--paper);
  box-shadow:
    0 18px 48px rgba(79, 57, 45, 0.2),
    inset 0 0 0 4px rgba(255, 255, 255, 0.45);
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
  background: #edf6f4;
  touch-action: none;
}

.mobile-controls[hidden] {
  display: none !important;
}

.mobile-controls {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.mobile-joystick {
  position: absolute;
  left: clamp(12px, 3.5%, 36px);
  bottom: clamp(12px, 5%, 34px);
  width: clamp(96px, 15vw, 138px);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

.mobile-joystick__ring {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 249, 239, 0.58);
  border-radius: 50%;
  background: rgba(38, 42, 48, 0.13);
  box-shadow:
    inset 0 0 0 6px rgba(255, 255, 255, 0.045),
    0 2px 8px rgba(44, 35, 37, 0.12);
}

.mobile-joystick__thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 43%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 249, 239, 0.74);
  border-radius: 50%;
  background: rgba(127, 182, 211, 0.38);
  box-shadow: 0 2px 7px rgba(44, 35, 37, 0.18);
  will-change: transform;
}

.mobile-control-actions {
  position: absolute;
  right: clamp(10px, 2.5%, 30px);
  bottom: clamp(8px, 3%, 24px);
  width: clamp(196px, 28vw, 270px);
  height: clamp(142px, 22vw, 204px);
  pointer-events: none;
}

.mobile-action {
  position: absolute;
  display: grid;
  place-content: center;
  gap: 1px;
  margin: 0;
  padding: 0;
  border: 2px solid rgba(255, 249, 239, 0.68);
  border-radius: 50%;
  color: #fffaf0;
  font: inherit;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  text-shadow: 0 1px 3px rgba(44, 35, 37, 0.78);
  box-shadow:
    0 2px 8px rgba(44, 35, 37, 0.16),
    inset 0 0 10px rgba(255, 255, 255, 0.06);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-action > span:not(.mobile-action__charges) {
  font-size: clamp(20px, 3.2vw, 32px);
}

.mobile-action small {
  font-size: clamp(9px, 1.25vw, 12px);
  font-weight: 700;
  opacity: 0.72;
}

.mobile-action:active {
  transform: scale(0.92);
  filter: brightness(1.12);
}

.mobile-action.is-cooling {
  opacity: 0.38;
  filter: grayscale(0.45);
}

.mobile-action--attack {
  right: 0;
  bottom: 0;
  width: clamp(74px, 10.5vw, 100px);
  aspect-ratio: 1;
  background: rgba(185, 77, 69, 0.42);
}

.mobile-action--block {
  left: 4%;
  bottom: 2%;
  width: clamp(58px, 8vw, 76px);
  aspect-ratio: 1;
  background: rgba(92, 145, 121, 0.34);
}

.mobile-action--special {
  right: 35%;
  top: 0;
  width: clamp(62px, 8.6vw, 82px);
  aspect-ratio: 1;
  background: rgba(205, 158, 49, 0.38);
}

.mobile-action--dash {
  right: 0;
  top: 2%;
  width: clamp(58px, 8vw, 76px);
  aspect-ratio: 1;
  background: rgba(82, 143, 177, 0.36);
}

.mobile-action__charges {
  position: absolute;
  left: 50%;
  top: -11px;
  display: flex;
  gap: 5px;
  transform: translateX(-50%);
  pointer-events: none;
}

.mobile-action__charges i {
  display: block;
  width: clamp(7px, 1vw, 10px);
  aspect-ratio: 1;
  border: 1.5px solid rgba(255, 249, 239, 0.78);
  border-radius: 50%;
  background: rgba(44, 35, 37, 0.24);
  box-shadow: 0 1px 3px rgba(44, 35, 37, 0.32);
  transition: background-color 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.mobile-action__charges i.is-filled {
  background: rgba(255, 249, 239, 0.96);
  box-shadow:
    0 0 0 2px rgba(82, 143, 177, 0.3),
    0 0 7px rgba(255, 249, 239, 0.68);
}

@media (pointer: coarse) and (max-width: 1100px) {
  html,
  body {
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
  }

  body {
    padding: 0;
  }

  .game-shell {
    width: min(100vw, calc(100dvh * 1179 / 543));
    border-width: 2px;
    border-radius: 0;
    touch-action: none;
  }
}

@media (pointer: coarse) and (max-width: 1100px) and (orientation: portrait) {
  .mobile-joystick {
    transform: scale(0.78);
    transform-origin: left bottom;
  }

  .mobile-control-actions {
    transform: scale(0.78);
    transform-origin: right bottom;
  }
}
