*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #141c30;
  color: #1a1a1a;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#stage-wrap {
  position: relative;
  width: min(100vw, 420px);
  max-height: 100dvh;
  aspect-ratio: 360 / 740;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

#main-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: #141c30;
  cursor: crosshair;
  -webkit-tap-highlight-color: transparent;
}

#main-canvas:focus {
  outline: none;
}

#main-canvas:focus-visible {
  outline: 3px solid #4a7cff;
  outline-offset: 2px;
}

#dialogue {
  position: absolute;
  left: 92px;
  right: 10px;
  bottom: 10px;
  margin: 0;
  padding: 8px 10px;
  background: #f4efe6;
  border: 2px solid #1c2438;
  border-radius: 2px;
  font-size: 15px;
  line-height: 1.45;
  color: #1c2438;
  box-shadow: 3px 3px 0 #7a342c;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

#dialogue.visible {
  opacity: 1;
}

#dialogue .speaker {
  font-weight: 700;
  margin-right: 0.35em;
}

.dpad {
  display: none;
  position: absolute;
  left: 4px;
  bottom: 6px;
  grid-template-columns: repeat(3, 26px);
  grid-template-rows: repeat(3, 26px);
  gap: 2px;
  z-index: 3;
  opacity: 0.4;
}

body.in-shadow .dpad {
  display: grid;
}

.dpad button {
  min-width: 26px;
  min-height: 26px;
  padding: 0;
  border: 1px solid #f4efe6;
  background: rgba(18, 25, 44, 0.45);
  color: #f4efe6;
  font-size: 0.72rem;
  border-radius: 2px;
  cursor: pointer;
}

.dpad button:focus-visible {
  outline: 2px solid #4a7cff;
  outline-offset: 1px;
}

.dpad .spacer {
  visibility: hidden;
  pointer-events: none;
}

#action-bar {
  display: none;
  position: absolute;
  left: 6px;
  bottom: 98px;
  z-index: 5;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-start;
  max-width: 42%;
}

body.in-shadow #action-bar {
  display: flex;
}

#action-bar button {
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid #f4efe6;
  background: rgba(18, 25, 44, 0.72);
  color: #f4efe6;
  font: inherit;
  font-size: 0.78rem;
  border-radius: 2px;
  cursor: pointer;
}

#action-bar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#action-bar button:focus-visible,
#restart-btn:focus-visible {
  outline: 2px solid #4a7cff;
  outline-offset: 2px;
}

@media (max-width: 720px) {
  #action-bar .aux {
    display: none;
  }
}

#restart-wrap {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 64px;
  text-align: center;
  z-index: 6;
}

#restart-wrap.show {
  display: block;
}

#restart-btn {
  min-height: 44px;
  padding: 8px 18px;
  font: inherit;
  font-size: 1rem;
  border: 2px solid #e8a23c;
  background: #243456;
  color: #f4efe6;
  cursor: pointer;
  border-radius: 2px;
}

body.ended .dpad,
body.ended #action-bar {
  display: none !important;
}

@media (min-width: 720px) {
  #stage-wrap {
    width: min(92vw, 900px);
    aspect-ratio: 16 / 10;
    max-height: 92vh;
  }

  .dpad {
    display: none !important;
  }

  #action-bar {
    top: auto;
    right: auto;
    left: 12px;
    bottom: 12px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #dialogue {
    transition: none;
  }
}
