:root {
  color-scheme: dark;
  --line: rgba(235, 241, 232, .78);
  --panel: rgba(10, 14, 16, .86);
  --text: #f7f4e8;
  --muted: #cfd6da;
  --gold: #ffd43a;
  --green: #7bd63b;
  --blue: #3ba7ff;
  --purple: #8b67dd;
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #05090b;
  color: var(--text);
}

body {
  display: grid;
  place-items: start center;
  padding: 8px;
}

.shell {
  width: min(100%, 1600px);
  min-width: 0;
}

.game-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 3px solid rgba(250, 246, 225, .62);
  border-radius: 8px;
  overflow: hidden;
  background: #0d1215;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #05090b;
  font: 800 clamp(20px, 4vw, 48px)/1 sans-serif;
  letter-spacing: .05em;
}

.loading.hidden {
  display: none;
}

.touch-controls {
  display: none;
}

.panels {
  display: grid;
  grid-template-columns: 1.35fr 1.25fr .9fr .75fr;
  gap: 8px;
  margin-top: 8px;
}

.panel {
  min-height: 136px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel h2 {
  margin: 0 0 8px;
  font-size: clamp(14px, 1.3vw, 20px);
  line-height: 1.25;
}

.panel p {
  margin: 6px 0;
  color: var(--muted);
  font-size: clamp(12px, 1.1vw, 15px);
  line-height: 1.45;
}

.weapon-card {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 4px 8px;
  min-height: 38px;
  margin-top: 6px;
  padding: 7px;
  border-radius: 6px;
}

.weapon-card p {
  grid-column: 2;
  margin: 0;
}

.weapon-card.green {
  background: rgba(76, 151, 45, .56);
}

.weapon-card.blue {
  background: rgba(30, 97, 153, .56);
}

.weapon-card.purple {
  background: rgba(86, 61, 133, .56);
}

.num {
  display: grid;
  place-items: center;
  min-width: 28px;
  padding: 0 5px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, .72);
  border-radius: 6px;
  font-weight: 900;
}

.flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}

.flow span {
  min-height: 54px;
  display: grid;
  place-items: center;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 6px;
  background: rgba(255, 255, 255, .08);
  text-align: center;
  font-weight: 700;
  font-size: clamp(11px, 1vw, 14px);
}

.flow b {
  color: var(--gold);
  font-size: 24px;
}

.special-list {
  display: grid;
  gap: 6px;
}

.ui-help {
  background: linear-gradient(180deg, rgba(15, 24, 30, .9), rgba(8, 10, 12, .9));
}

@media (max-width: 980px) {
  body {
    padding: 4px;
  }

  .panels {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .panels {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  html,
  body,
  canvas,
  .game-frame,
  .touch-controls,
  .touch-button {
    touch-action: none;
  }

  body {
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior: none;
  }

  .shell,
  .panels,
  .panel {
    min-width: 0;
  }

  .shell,
  .game-frame {
    width: calc(100vw - 8px);
    max-width: calc(100vw - 8px);
  }

  .touch-controls.is-visible {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .touch-pad {
    position: absolute;
    bottom: max(20px, env(safe-area-inset-bottom));
    display: grid;
    pointer-events: auto;
  }

  .touch-pad-move {
    left: max(20px, env(safe-area-inset-left));
    grid-template-columns: repeat(3, clamp(58px, 14.8vw, 84px));
    grid-template-rows: repeat(2, clamp(58px, 14.8vw, 84px));
    gap: clamp(8px, 2.2vw, 14px);
    align-items: center;
    justify-items: center;
  }

  .touch-pad-attack {
    right: max(20px, env(safe-area-inset-right));
    grid-template-columns: repeat(3, clamp(62px, 15.7vw, 92px));
    gap: clamp(8px, 2vw, 14px);
    align-items: end;
  }

  .touch-button {
    display: grid;
    place-items: center;
    width: clamp(58px, 14.8vw, 84px);
    height: clamp(58px, 14.8vw, 84px);
    padding: 0;
    border: 2px solid rgba(222, 244, 255, .58);
    border-radius: 999px;
    background:
      radial-gradient(circle at 42% 28%, rgba(255, 255, 255, .18), rgba(255, 255, 255, 0) 34%),
      rgba(13, 27, 34, .48);
    color: rgba(255, 255, 255, .96);
    box-shadow:
      inset 0 0 22px rgba(160, 223, 255, .12),
      0 0 0 1px rgba(255, 255, 255, .08),
      0 7px 20px rgba(0, 0, 0, .34);
    font: 900 18px/1 "Yu Gothic", "Meiryo", system-ui, sans-serif;
    text-align: center;
    text-shadow: 0 2px 3px rgba(0, 0, 0, .78);
    -webkit-tap-highlight-color: transparent;
  }

  .touch-button-dir {
    grid-row: 2;
  }

  .touch-button-dir:first-child {
    grid-column: 1;
  }

  .touch-button-dir:nth-child(2) {
    grid-column: 3;
  }

  .touch-button-jump {
    grid-column: 2;
    grid-row: 1;
  }

  .touch-button-attack {
    width: clamp(62px, 15.7vw, 92px);
    height: clamp(62px, 15.7vw, 92px);
    grid-template-rows: 1fr auto;
    padding: 10px 6px 9px;
  }

  .touch-button-j {
    border-color: rgba(222, 122, 255, .76);
    background:
      radial-gradient(circle at 42% 28%, rgba(255, 255, 255, .18), rgba(255, 255, 255, 0) 34%),
      rgba(82, 37, 105, .54);
    box-shadow: inset 0 0 26px rgba(226, 88, 255, .24), 0 0 18px rgba(207, 78, 255, .22);
  }

  .touch-button-k {
    border-color: rgba(99, 239, 126, .78);
    background:
      radial-gradient(circle at 42% 28%, rgba(255, 255, 255, .18), rgba(255, 255, 255, 0) 34%),
      rgba(34, 101, 48, .54);
    box-shadow: inset 0 0 26px rgba(85, 255, 122, .2), 0 0 18px rgba(72, 255, 105, .18);
  }

  .touch-button-l {
    border-color: rgba(91, 183, 255, .82);
    background:
      radial-gradient(circle at 42% 28%, rgba(255, 255, 255, .18), rgba(255, 255, 255, 0) 34%),
      rgba(24, 70, 105, .56);
    box-shadow: inset 0 0 26px rgba(84, 190, 255, .22), 0 0 18px rgba(75, 184, 255, .2);
  }

  .touch-button.is-disabled {
    border-color: rgba(255, 255, 255, .28);
    background:
      radial-gradient(circle at 42% 28%, rgba(255, 255, 255, .08), rgba(255, 255, 255, 0) 34%),
      rgba(20, 23, 25, .44);
    color: rgba(255, 255, 255, .45);
    box-shadow:
      inset 0 0 18px rgba(255, 255, 255, .05),
      0 0 0 1px rgba(255, 255, 255, .04),
      0 5px 14px rgba(0, 0, 0, .28);
  }

  .touch-glyph {
    display: block;
    font-size: clamp(28px, 8vw, 48px);
    line-height: .9;
  }

  .touch-button-attack .touch-glyph {
    font-size: clamp(27px, 7.2vw, 42px);
  }

  .touch-label {
    display: block;
    margin-top: 2px;
    font-size: clamp(10px, 2.8vw, 14px);
    font-weight: 900;
    line-height: 1.08;
    letter-spacing: 0;
  }

  .touch-button:active,
  .touch-button.is-pressed {
    border-color: rgba(255, 255, 255, .92);
    filter: brightness(1.2);
    transform: scale(.96);
  }

  .touch-button.is-disabled:active,
  .touch-button.is-disabled.is-pressed {
    border-color: rgba(255, 255, 255, .34);
    filter: none;
  }
}

@media (max-width: 768px) and (orientation: portrait) {
  .touch-pad {
    bottom: max(16px, env(safe-area-inset-bottom));
  }

  .touch-pad-move {
    left: max(14px, env(safe-area-inset-left));
    grid-template-columns: repeat(3, clamp(46px, 12.8vw, 54px));
    grid-template-rows: repeat(2, clamp(46px, 12.8vw, 54px));
    gap: 7px;
  }

  .touch-pad-attack {
    right: max(14px, env(safe-area-inset-right));
    grid-template-columns: repeat(3, clamp(48px, 13.2vw, 56px));
    gap: 7px;
  }

  .touch-button {
    width: clamp(46px, 12.8vw, 54px);
    height: clamp(46px, 12.8vw, 54px);
  }

  .touch-button-attack {
    width: clamp(48px, 13.2vw, 56px);
    height: clamp(48px, 13.2vw, 56px);
    padding: 7px 4px 6px;
  }

  .touch-glyph {
    font-size: clamp(24px, 6.4vw, 32px);
  }

  .touch-button-attack .touch-glyph {
    font-size: clamp(23px, 6vw, 30px);
  }

  .touch-label {
    font-size: clamp(8px, 2.25vw, 10px);
  }
}
